本文整理汇总了Java中org.apache.helix.HelixAdmin.getResourcesInCluster方法的典型用法代码示例。如果您正苦于以下问题:Java HelixAdmin.getResourcesInCluster方法的具体用法?Java HelixAdmin.getResourcesInCluster怎么用?Java HelixAdmin.getResourcesInCluster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixAdmin
的用法示例。
在下文中一共展示了HelixAdmin.getResourcesInCluster方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceToTopicPartitionsMap
import org.apache.helix.HelixAdmin; //导入方法依赖的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: getUnassignedPartitions
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
public static Set<TopicPartition> getUnassignedPartitions(HelixManager helixManager) {
Set<TopicPartition> unassignedPartitions = new HashSet<TopicPartition>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
int numPartitions = is.getNumPartitions();
for (int partition = 0; partition < numPartitions; ++partition) {
if (is.getInstanceSet(Integer.toString(partition)).isEmpty()) {
TopicPartition tpi = new TopicPartition(topic, partition);
unassignedPartitions.add(tpi);
}
}
}
return unassignedPartitions;
}
示例3: getInstanceToTopicPartitionsMap
import org.apache.helix.HelixAdmin; //导入方法依赖的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;
}
示例4: getExternalViews
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
private List<ExternalView> getExternalViews() {
String clusterName = helixManager.getClusterName();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);
for (String resourceName : resourcesInCluster) {
ExternalView ev =
helixManager.getClusterManagmentTool().getResourceExternalView(clusterName, resourceName);
if (ev != null) {
externalViewList.add(ev);
}
}
return externalViewList;
}
示例5: populateResourcesAndPartitionsSet
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Populate the set of existing resources and existing partitions in the cluster. This assumes that all partitions
* and resources exist in all datacenters (This assumption helps simplify the logic. This can be gotten rid of in
* the future if need be).
* @param dcAdmin the reference admin (preferably the admin to the zookeeper server in the local datacenter).
*/
private void populateResourcesAndPartitionsSet(HelixAdmin dcAdmin) {
for (String resource : dcAdmin.getResourcesInCluster(clusterName)) {
existingResources.add(Long.valueOf(resource));
for (String partition : dcAdmin.getResourceIdealState(clusterName, resource).getPartitionSet()) {
existingPartitions.add(Long.valueOf(partition));
}
}
}
示例6: testGetResourcesWithTag
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
@Test
public void testGetResourcesWithTag() {
String TEST_TAG = "TestTAG";
final String clusterName = getShortClassName();
String rootPath = "/" + clusterName;
if (_gZkClient.exists(rootPath)) {
_gZkClient.deleteRecursive(rootPath);
}
HelixAdmin tool = new ZKHelixAdmin(_gZkClient);
tool.addCluster(clusterName, true);
Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient));
tool.addStateModelDef(clusterName, "OnlineOffline",
new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline()));
for (int i = 0; i < 4; i++) {
String instanceName = "host" + i + "_9999";
InstanceConfig config = new InstanceConfig(instanceName);
config.setHostName("host" + i);
config.setPort("9999");
// set tag to two instances
if (i < 2) {
config.addTag(TEST_TAG);
}
tool.addInstance(clusterName, config);
tool.enableInstance(clusterName, instanceName, true);
String path = PropertyPathBuilder.instance(clusterName, instanceName);
AssertJUnit.assertTrue(_gZkClient.exists(path));
}
for (int i = 0; i < 4; i++) {
String resourceName = "database_" + i;
IdealState is = new IdealState(resourceName);
is.setStateModelDefRef("OnlineOffline");
is.setNumPartitions(2);
is.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
is.setReplicas("1");
is.enable(true);
if (i < 2) {
is.setInstanceGroupTag(TEST_TAG);
}
tool.addResource(clusterName, resourceName, is);
}
List<String> allResources = tool.getResourcesInCluster(clusterName);
List<String> resourcesWithTag = tool.getResourcesInClusterWithTag(clusterName, TEST_TAG);
AssertJUnit.assertEquals(allResources.size(), 4);
AssertJUnit.assertEquals(resourcesWithTag.size(), 2);
}
示例7: verifyResourcesAndPartitionEquivalencyInDc
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Verify that the partition layout information is in sync.
* @param dc the datacenter whose information is to be verified.
* @param clusterName the cluster to be verified.
* @param partitionLayout the {@link PartitionLayout} of the static clustermap.
*/
private void verifyResourcesAndPartitionEquivalencyInDc(Datacenter dc, String clusterName,
PartitionLayout partitionLayout) {
String dcName = dc.getName();
HelixAdmin admin = adminForDc.get(dc.getName());
Map<String, Set<String>> allPartitionsToInstancesInHelix = new HashMap<>();
for (String resourceName : admin.getResourcesInCluster(clusterName)) {
IdealState resourceIS = admin.getResourceIdealState(clusterName, resourceName);
ensureOrThrow(resourceIS.getStateModelDefRef().equals(LeaderStandbySMD.name),
"StateModel name mismatch for resource " + resourceName);
int numReplicasAtResourceLevel = Integer.valueOf(resourceIS.getReplicas());
Set<String> resourcePartitions = resourceIS.getPartitionSet();
for (String resourcePartition : resourcePartitions) {
Set<String> partitionInstanceSet = resourceIS.getInstanceSet(resourcePartition);
ensureOrThrow(numReplicasAtResourceLevel == partitionInstanceSet.size(),
"NumReplicas at resource level " + numReplicasAtResourceLevel
+ " different from number of replicas for partition " + partitionInstanceSet);
ensureOrThrow(allPartitionsToInstancesInHelix.put(resourcePartition, partitionInstanceSet) == null,
"Partition " + resourcePartition + " already found under a different resource.");
}
}
for (PartitionId partitionId : partitionLayout.getPartitions()) {
Partition partition = (Partition) partitionId;
String partitionName = Long.toString(partition.getId());
Set<String> replicaHostsInHelix = allPartitionsToInstancesInHelix.remove(partitionName);
ensureOrThrow(replicaHostsInHelix != null, "No replicas found for partition " + partitionName + " in Helix");
for (Replica replica : partition.getReplicas()) {
if (replica.getDataNodeId().getDatacenterName().equals(dcName)) {
String instanceName = getInstanceName(replica.getDataNodeId());
ensureOrThrow(replicaHostsInHelix.remove(instanceName),
"Instance " + instanceName + " for the given " + "replica in the clustermap not found in Helix");
}
}
ensureOrThrow(replicaHostsInHelix.isEmpty(),
"More instances in Helix than in clustermap for partition: " + partitionName + " additional instances: "
+ replicaHostsInHelix);
}
ensureOrThrow(allPartitionsToInstancesInHelix.isEmpty(),
"More partitions in Helix than in clustermap, additional partitions: "
+ allPartitionsToInstancesInHelix.keySet());
}