本文整理汇总了Java中org.apache.helix.HelixAdmin.getInstanceConfig方法的典型用法代码示例。如果您正苦于以下问题:Java HelixAdmin.getInstanceConfig方法的具体用法?Java HelixAdmin.getInstanceConfig怎么用?Java HelixAdmin.getInstanceConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixAdmin
的用法示例。
在下文中一共展示了HelixAdmin.getInstanceConfig方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLiveInstanceChange
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
@Override
public void onLiveInstanceChange(List<LiveInstance> list, NotificationContext notificationContext) {
List<InetSocketAddress> addresses = new ArrayList<>();
HelixAdmin helixAdmin = helixConnection.createClusterManagementTool();
for (LiveInstance liveInstance : list) {
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(
clusterName,
liveInstance.getInstanceName());
InetSocketAddress address = new InetSocketAddress(
instanceConfig.getHostName(),
Integer.valueOf(instanceConfig.getPort()));
addresses.add(address);
}
services.set(addresses);
}
示例2: main
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println("USAGE: MySQLAgentLauncher zkAddress clusterName instanceName");
}
String zkAddress = args[0];
String clusterName = args[1];
String instanceName = args[2];
HelixAdmin admin = new ZKHelixAdmin(zkAddress);
List<String> clusters = admin.getClusters();
System.out.println(clusters);
if (!clusters.contains(clusterName)) {
System.err.println("Cluster is not setup. Use cluster-admin to create a new cluster");
System.exit(1);
}
InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
if (instanceConfig == null) {
String msg =
"Agent is not yet configured in the cluster. Use cluster-admin to first configure the new Mysql Agent";
System.err.println(msg);
System.exit(1);
}
admin.close();
MySQLAgent agent = new MySQLAgent(zkAddress, clusterName, instanceConfig);
agent.start();
Thread.currentThread().join();
}
示例3: main
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ConsoleAppender ca = new ConsoleAppender();
ca.setThreshold(Level.INFO);
ca.setWriter(new OutputStreamWriter(System.out));
ca.setLayout(new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"));
Logger.getRootLogger().addAppender(ca);
String clusterName = "mysql-cluster-test";
String instanceName = "kgopalak-ld.linkedin.biz_5555";
String zkAddress = "localhost:2181";
// TODO:stand alone way to start the agent
HelixAdmin admin = new ZKHelixAdmin(zkAddress);
InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
MySQLAgent agent = new MySQLAgent(zkAddress, clusterName, instanceConfig);
agent.start();
Thread.currentThread().join();
}
示例4: getEnabledInstancesWithTag
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
public static List<String> getEnabledInstancesWithTag(HelixAdmin helixAdmin, String helixClusterName,
String instanceTag) {
List<String> instances = helixAdmin.getInstancesInCluster(helixClusterName);
List<String> enabledInstances = new ArrayList<>();
for (String instance : instances) {
try {
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(helixClusterName, instance);
if (instanceConfig.containsTag(instanceTag) && instanceConfig.getInstanceEnabled()) {
enabledInstances.add(instance);
}
} catch (Exception e) {
LOGGER.error("Caught exception while fetching instance config for instance: {}", instance, e);
}
}
return enabledInstances;
}
示例5: testEnableDisablePartitions
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
@Test
public void testEnableDisablePartitions() {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
String instanceName = "TestInstance";
String testResourcePrefix = "TestResource";
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.addCluster(clusterName, true);
admin.addInstance(clusterName, new InstanceConfig(instanceName));
// Test disable instances with resources
admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "0",
Arrays.asList(new String[]{"1", "2"}));
admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "1",
Arrays.asList(new String[]{"2", "3", "4"}));
InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 2);
Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 3);
// Test disable partition across resources
// TODO : Remove this part once setInstanceEnabledForPartition(partition, enabled) is removed
instanceConfig.setInstanceEnabledForPartition("10", false);
Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 3);
Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 4);
}
示例6: deleteInstance
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
@DELETE
@Path("{instanceName}")
public Response deleteInstance(@PathParam("clusterId") String clusterId,
@PathParam("instanceName") String instanceName) {
HelixAdmin admin = getHelixAdmin();
try {
InstanceConfig instanceConfig = admin.getInstanceConfig(clusterId, instanceName);
admin.dropInstance(clusterId, instanceConfig);
} catch (HelixException e) {
return badRequest(e.getMessage());
}
return OK();
}
示例7: getSealedReplicas
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Get the list of sealed replicas from the HelixAdmin
* @return list of sealed replicas from HelixAdmin
*/
private List<String> getSealedReplicas() {
HelixAdmin helixAdmin = manager.getClusterManagmentTool();
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
if (instanceConfig == null) {
throw new IllegalStateException(
"No instance config found for cluster: \"" + clusterName + "\", instance: \"" + instanceName + "\"");
}
return ClusterMapUtils.getSealedReplicas(instanceConfig);
}
示例8: setSealedReplicas
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Set the list of sealed replicas in the HelixAdmin
* @param sealedReplicas list of sealed replicas to be set in the HelixAdmin
* @return whether the operation succeeded or not
*/
private boolean setSealedReplicas(List<String> sealedReplicas) {
HelixAdmin helixAdmin = manager.getClusterManagmentTool();
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
if (instanceConfig == null) {
throw new IllegalStateException(
"No instance config found for cluster: \"" + clusterName + "\", instance: \"" + instanceName + "\"");
}
instanceConfig.getRecord().setListField(ClusterMapUtils.SEALED_STR, sealedReplicas);
return helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
}
示例9: updatePartitionInfoIfChanged
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Goes through each existing partition and updates the {@link PartitionState} and capacity information for the
* replicas in each of the instances that hosts a replica for this partition, if it has changed and is different from
* the current information in the static cluster map.
* @param partition the partition whose {@link PartitionState} and/or capacity may have to be updated.
*/
private void updatePartitionInfoIfChanged(Partition partition) {
for (Map.Entry<String, HelixAdmin> entry : adminForDc.entrySet()) {
String dcName = entry.getKey();
HelixAdmin dcAdmin = entry.getValue();
String partitionName = Long.toString(partition.getId());
long replicaCapacityInStatic = partition.getReplicaCapacityInBytes();
boolean isSealed = partition.getPartitionState().equals(PartitionState.READ_ONLY);
List<ReplicaId> replicaList = getReplicasInDc(partition, dcName);
for (ReplicaId replicaId : replicaList) {
DataNodeId node = replicaId.getDataNodeId();
String instanceName = getInstanceName(node);
InstanceConfig instanceConfig = dcAdmin.getInstanceConfig(clusterName, instanceName);
boolean shouldSetInstanceConfig = false;
if (updateSealedStateIfRequired(partitionName, instanceConfig, isSealed)) {
System.out.println(
"Sealed state change of partition " + partitionName + " will be updated for instance " + instanceName);
shouldSetInstanceConfig = true;
}
if (updateReplicaCapacityIfRequired(partitionName, instanceConfig, replicaId.getMountPath(),
replicaCapacityInStatic)) {
System.out.println(
"Replica capacity change of partition " + partitionName + " will be updated for instance" + instanceName);
shouldSetInstanceConfig = true;
}
if (shouldSetInstanceConfig) {
dcAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
System.out.println("Successfully updated InstanceConfig for instance " + instanceName);
}
}
}
}
示例10: updateInstancesAndGetInstanceNames
import org.apache.helix.HelixAdmin; //导入方法依赖的package包/类
/**
* Updates instances that hosts replicas of this partition with the replica information (including the mount points
* on which these replicas should reside, which will be purely an instance level information).
* @param dcAdmin the admin to the Zk server on which this operation is to be done.
* @param partitionName the partition name.
* @param replicaList the list of replicas of this partition.
* @param sealed whether the given partition state is sealed.
* @return an array of Strings containing the names of the instances on which the replicas of this partition reside.
*/
private String[] updateInstancesAndGetInstanceNames(HelixAdmin dcAdmin, String partitionName,
List<ReplicaId> replicaList, boolean sealed) {
String[] instances = new String[replicaList.size()];
for (int i = 0; i < replicaList.size(); i++) {
Replica replica = (Replica) replicaList.get(i);
DataNodeId node = replica.getDataNodeId();
String instanceName = getInstanceName(node);
instances[i] = instanceName;
InstanceConfig instanceConfig = dcAdmin.getInstanceConfig(clusterName, instanceName);
Map<String, String> diskInfo = instanceConfig.getRecord().getMapField(replica.getMountPath());
String replicasStr = diskInfo.get(ClusterMapUtils.REPLICAS_STR);
replicasStr +=
replica.getPartition().getId() + ClusterMapUtils.REPLICAS_STR_SEPARATOR + replica.getCapacityInBytes()
+ ClusterMapUtils.REPLICAS_DELIM_STR;
diskInfo.put(ClusterMapUtils.REPLICAS_STR, replicasStr);
instanceConfig.getRecord().setMapField(replica.getMountPath(), diskInfo);
if (sealed) {
List<String> currentSealedPartitions = instanceConfig.getRecord().getListField(ClusterMapUtils.SEALED_STR);
List<String> newSealedPartitionsList = new ArrayList<>(currentSealedPartitions);
newSealedPartitionsList.add(partitionName);
instanceConfig.getRecord().setListField(ClusterMapUtils.SEALED_STR, newSealedPartitionsList);
}
dcAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
}
return instances;
}