本文整理汇总了Java中org.apache.helix.model.IdealState.getPartitionSet方法的典型用法代码示例。如果您正苦于以下问题:Java IdealState.getPartitionSet方法的具体用法?Java IdealState.getPartitionSet怎么用?Java IdealState.getPartitionSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.IdealState
的用法示例。
在下文中一共展示了IdealState.getPartitionSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceToTopicPartitionsMap
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* From IdealStates.
*
* @return InstanceToNumTopicPartitionMap
*/
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
HelixManager helixManager) {
Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
new HashMap<String, Set<TopicPartition>>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
for (String partition : is.getPartitionSet()) {
TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
for (String instance : is.getInstanceSet(partition)) {
if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
}
instanceToNumTopicPartitionMap.get(instance).add(tpi);
}
}
}
return instanceToNumTopicPartitionMap;
}
示例2: getInstanceToTopicPartitionsMap
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* From IdealStates.
* @param helixManager
* @return InstanceToNumTopicPartitionMap
*/
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
HelixManager helixManager) {
Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
new HashMap<String, Set<TopicPartition>>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
for (String partition : is.getPartitionSet()) {
TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
for (String instance : is.getInstanceSet(partition)) {
if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
}
instanceToNumTopicPartitionMap.get(instance).add(tpi);
}
}
}
return instanceToNumTopicPartitionMap;
}
示例3: calculateDeviationForResource
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
static double calculateDeviationForResource(String resource,
IdealState idealState,
RoutingTableProvider routingTableProvider) {
Set<String> partitions = idealState.getPartitionSet();
int totalAssignments = 0, totalDeviations = 0;
// Check if the external view has deviated from the actual view.
for (String partition : partitions) {
// Make a copy of the instance mapping in the ideal state.
Set<String> idealInstances = new HashSet(idealState.getInstanceSet(partition));
totalAssignments += idealInstances.size();
// Now check against our real state and count the amount of deviating
// assignments.
List<InstanceConfig> currentInstanceConfigs = routingTableProvider.getInstances(
resource, partition, "ONLINE");
Set<String> currentInstances = Sets.newHashSetWithExpectedSize(
currentInstanceConfigs.size());
if (currentInstanceConfigs != null) {
for (InstanceConfig instanceConfig : currentInstanceConfigs) {
currentInstances.add(instanceConfig.getHostName());
}
}
idealInstances.removeAll(currentInstances);
totalDeviations += idealInstances.size();
}
return (double)totalDeviations / totalAssignments;
}
示例4: isServerTenantDeletable
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isServerTenantDeletable(String tenantName) {
Set<String> taggedInstances =
new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName)));
taggedInstances.addAll(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName)));
for (String tableName : getAllTableNames()) {
if (tableName.equals(CommonConstants.Helix.BROKER_RESOURCE_INSTANCE)) {
continue;
}
IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
for (String partition : tableIdealState.getPartitionSet()) {
for (String instance : tableIdealState.getInstanceSet(partition)) {
if (taggedInstances.contains(instance)) {
return false;
}
}
}
}
return true;
}
示例5: getInstanceToSegmentsInATableMap
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public Map<String, List<String>> getInstanceToSegmentsInATableMap(String tableName) {
Map<String, List<String>> instancesToSegmentsMap = new HashMap<String, List<String>>();
IdealState is = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
Set<String> segments = is.getPartitionSet();
for (String segment : segments) {
Set<String> instances = is.getInstanceSet(segment);
for (String instance : instances) {
if (instancesToSegmentsMap.containsKey(instance)) {
instancesToSegmentsMap.get(instance).add(segment);
} else {
List<String> a = new ArrayList<String>();
a.add(segment);
instancesToSegmentsMap.put(instance, a);
}
}
}
return instancesToSegmentsMap;
}
示例6: updateIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private IdealState updateIdealState(IdealState idealState, int newNumReplicas) {
idealState.setReplicas(Integer.toString(newNumReplicas));
Set<String> segmentIds = idealState.getPartitionSet();
for (String segmentId : segmentIds) {
Map<String, String> instanceStateMap = idealState.getInstanceStateMap(segmentId);
if (instanceStateMap.size() > newNumReplicas) {
Set<String> keys = instanceStateMap.keySet();
while (instanceStateMap.size() > newNumReplicas) {
instanceStateMap.remove(keys.iterator().next());
}
} else if (instanceStateMap.size() < newNumReplicas) {
throw new RuntimeException("Segment " + segmentId + " has " + instanceStateMap.size() +
" replicas but want changed to " + newNumReplicas);
}
}
return idealState;
}
示例7: hasInstanceMapChanged
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private boolean hasInstanceMapChanged(Map<Partition, Map<String, String>> newAssiments,
IdealState idealState) {
Set<Partition> partitions = new HashSet<Partition>(newAssiments.keySet());
for (String p : idealState.getPartitionSet()) {
partitions.add(new Partition(p));
}
for (Partition partition : partitions) {
Map<String, String> instanceMap = newAssiments.get(partition);
Map<String, String> existInstanceMap =
idealState.getInstanceStateMap(partition.getPartitionName());
if (instanceMap == null && existInstanceMap == null) {
continue;
}
if (instanceMap == null || existInstanceMap == null || !instanceMap
.equals(existInstanceMap)) {
return true;
}
}
return false;
}
示例8: verifySemiAutoMasterSlaveAssignment
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void verifySemiAutoMasterSlaveAssignment(IdealState idealState) {
for (String partition : idealState.getPartitionSet()) {
Map<String, String> instanceStateMap = idealState.getInstanceStateMap(partition);
List<String> preferenceList = idealState.getPreferenceList(partition);
int numMaster = 0;
for (String ins : preferenceList) {
Assert.assertTrue(instanceStateMap.containsKey(ins),
String.format("Instance %s from preference list not in the map", ins));
String state = instanceStateMap.get(ins);
Assert.assertTrue(state.equals(MasterSlaveSMD.States.MASTER.name()) || state
.equals(MasterSlaveSMD.States.SLAVE.name()), "Actual State" + state);
if (state.equals(MasterSlaveSMD.States.MASTER.name())) {
numMaster++;
}
}
Assert.assertEquals(numMaster, 1);
}
}
示例9: removeSegmentsFromIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public static void removeSegmentsFromIdealState(HelixManager helixManager, String tableName, final List<String> segments) {
Function<IdealState, IdealState> updater = new Function<IdealState, IdealState>() {
@Nullable
@Override
public IdealState apply(@Nullable IdealState idealState) {
if (idealState == null) {
return idealState;
}
// partitionSet is never null but let's be defensive anyway
Set<String> partitionSet = idealState.getPartitionSet();
if (partitionSet != null) {
partitionSet.removeAll(segments);
}
return idealState;
}
};
updateIdealState(helixManager, tableName, updater, DEFAULT_RETRY_POLICY);
}
示例10: computeNewIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public IdealState computeNewIdealState(String resourceName, IdealState currentIdealState,
CurrentStateOutput currentStateOutput, ClusterDataCache clusterData) {
testRebalancerInvoked = true;
List<String> liveNodes = Lists.newArrayList(clusterData.getLiveInstances().keySet());
int i = 0;
for (String partition : currentIdealState.getPartitionSet()) {
int index = i++ % liveNodes.size();
String instance = liveNodes.get(index);
currentIdealState.getPreferenceList(partition).clear();
currentIdealState.getPreferenceList(partition).add(instance);
currentIdealState.getInstanceStateMap(partition).clear();
currentIdealState.getInstanceStateMap(partition).put(instance, "MASTER");
}
currentIdealState.setReplicas("1");
return currentIdealState;
}
示例11: isServerTenantDeletable
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isServerTenantDeletable(String tenantName) {
Set<String> taggedInstances =
new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName)));
taggedInstances.addAll(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName)));
for (String resourceName : getAllResources()) {
if (!TableNameBuilder.isTableResource(resourceName)) {
continue;
}
IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, resourceName);
for (String partition : tableIdealState.getPartitionSet()) {
for (String instance : tableIdealState.getInstanceSet(partition)) {
if (taggedInstances.contains(instance)) {
return false;
}
}
}
}
return true;
}
示例12: updateIdealstateInfo
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void updateIdealstateInfo(Map<String, Integer> topicPartitionMapForIdealState,
IdealState idealStateForTopic) {
for (String partition : idealStateForTopic.getPartitionSet()) {
Map<String, String> idealStatesMap = idealStateForTopic.getInstanceStateMap(partition);
for (String instance : idealStatesMap.keySet()) {
if (!topicPartitionMapForIdealState.containsKey(instance)) {
topicPartitionMapForIdealState.put(instance, 1);
} else {
topicPartitionMapForIdealState.put(instance,
topicPartitionMapForIdealState.get(instance) + 1);
}
}
}
}
示例13: isBrokerTenantDeletable
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isBrokerTenantDeletable(String tenantName) {
String brokerTag = ControllerTenantNameBuilder.getBrokerTenantNameForTenant(tenantName);
Set<String> taggedInstances =
new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName, brokerTag));
String brokerName = CommonConstants.Helix.BROKER_RESOURCE_INSTANCE;
IdealState brokerIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, brokerName);
for (String partition : brokerIdealState.getPartitionSet()) {
for (String instance : brokerIdealState.getInstanceSet(partition)) {
if (taggedInstances.contains(instance)) {
return false;
}
}
}
return true;
}
示例14: getAllInstancesForTable
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private Set<String> getAllInstancesForTable(String tableName) {
Set<String> instanceSet = new HashSet<String>();
IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
for (String partition : tableIdealState.getPartitionSet()) {
instanceSet.addAll(tableIdealState.getInstanceSet(partition));
}
return instanceSet;
}
示例15: removeSegmentFromIdealStateFor
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* Remove a segment is also required to recompute the ideal state.
*
* @param tableName
* @param segmentId
* @param helixAdmin
* @param helixClusterName
* @return
*/
public synchronized static IdealState removeSegmentFromIdealStateFor(String tableName, String segmentId,
HelixAdmin helixAdmin, String helixClusterName) {
final IdealState currentIdealState = helixAdmin.getResourceIdealState(helixClusterName, tableName);
if (currentIdealState != null && currentIdealState.getPartitionSet() != null
&& currentIdealState.getPartitionSet().contains(segmentId)) {
currentIdealState.getPartitionSet().remove(segmentId);
} else {
throw new RuntimeException("Cannot found segmentId - " + segmentId + " in table - " + tableName);
}
return currentIdealState;
}