use of org.apache.helix.manager.zk.ZKHelixAdmin in project ambry by linkedin.
the class HelixParticipantTest method clear.
@After
public void clear() {
ZKHelixAdmin admin = new ZKHelixAdmin("localhost:" + zkInfo.getPort());
admin.dropCluster(clusterName);
}
use of org.apache.helix.manager.zk.ZKHelixAdmin in project ambry by linkedin.
the class HelixVcrUtil method createCluster.
/**
* Create a helix cluster with given information.
* @param destZkString the cluster's zk string
* @param destClusterName the cluster's name
*/
public static void createCluster(String destZkString, String destClusterName, VcrHelixConfig config) {
HelixZkClient destZkClient = getHelixZkClient(destZkString);
HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
if (ZKUtil.isClusterSetup(destClusterName, destZkClient)) {
errorAndExit("Failed to create cluster because " + destClusterName + " already exist.");
}
ClusterSetup clusterSetup = new ClusterSetup.Builder().setZkAddress(destZkString).build();
clusterSetup.addCluster(destClusterName, true);
// set ALLOW_PARTICIPANT_AUTO_JOIN
HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(destClusterName).build();
Map<String, String> helixClusterProperties = new HashMap<>();
helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(config.getClusterConfigFields().isAllowAutoJoin()));
destAdmin.setConfig(configScope, helixClusterProperties);
setClusterConfig(destZkClient, destClusterName, config, false);
logger.info("Cluster {} is created successfully!", destClusterName);
}
use of org.apache.helix.manager.zk.ZKHelixAdmin in project ambry by linkedin.
the class HelixVcrUtil method updateResourceAndPartition.
/**
* Update dest cluster information based on src cluster.
* Dest cluster resource will be recreated if it mismatches that in src cluster.
* @param srcZkString the src cluster's zk string
* @param srcClusterName the src cluster's name
* @param destZkString the dest cluster's zk string
* @param destClusterName the dest cluster's name
* @param dryRun run the update process but without actual change.
*/
public static void updateResourceAndPartition(String srcZkString, String srcClusterName, String destZkString, String destClusterName, VcrHelixConfig config, boolean dryRun) {
HelixAdmin srcAdmin = new ZKHelixAdmin(srcZkString);
Set<String> srcResources = new HashSet<>(srcAdmin.getResourcesInCluster(srcClusterName));
HelixAdmin destAdmin = new ZKHelixAdmin(destZkString);
Set<String> destResources = new HashSet<>(destAdmin.getResourcesInCluster(destClusterName));
logger.info("========VCR Helix Update Starts========");
// Remove stale resources
for (String resource : destResources) {
if (!srcResources.contains(resource)) {
if (dryRun) {
logger.info("DryRun: Drop Resource {}", resource);
} else {
// This resource need to be dropped.
logger.info("Dropped Resource {}, Partitions: {}", resource, destAdmin.getResourceIdealState(destClusterName, resource).getPartitionSet());
destAdmin.dropResource(destClusterName, resource);
}
}
}
for (String resource : srcResources) {
if (ignoreResourceKeyWords.stream().anyMatch(resource::contains)) {
logger.info("Resource {} from src cluster is ignored", resource);
continue;
}
boolean createNewResource = false;
boolean dropResource = false;
if (destResources.contains(resource)) {
// check if every partition exist.
Set<String> srcPartitions = srcAdmin.getResourceIdealState(srcClusterName, resource).getPartitionSet();
Set<String> destPartitions = destAdmin.getResourceIdealState(destClusterName, resource).getPartitionSet();
if (srcPartitions.size() != destPartitions.size()) {
dropResource = true;
createNewResource = true;
} else {
for (String partition : srcPartitions) {
if (!destPartitions.contains(partition)) {
dropResource = true;
createNewResource = true;
break;
}
}
}
if (dropResource && dryRun) {
logger.info("DryRun: Drop Resource {}", resource);
} else if (dropResource) {
// This resource need to be recreate.
logger.info("Dropped Resource {}, Partitions: {}", resource, destAdmin.getResourceIdealState(destClusterName, resource).getPartitionSet());
destAdmin.dropResource(destClusterName, resource);
}
} else {
createNewResource = true;
}
if (createNewResource) {
// add new resource
Set<String> srcPartitions = srcAdmin.getResourceIdealState(srcClusterName, resource).getPartitionSet();
IdealState idealState = buildIdealState(resource, srcPartitions, config.getIdealStateConfigFields());
if (dryRun) {
logger.info("DryRun: Add Resource {} with partition {}", resource, srcPartitions);
} else {
destAdmin.addResource(destClusterName, resource, idealState);
destAdmin.rebalance(destClusterName, resource, config.getIdealStateConfigFields().getNumReplicas(), "", "");
logger.info("Added Resource {} with partition {}", resource, srcPartitions);
}
} else {
logger.info("Resource {} is up to date. No action needed.", resource);
}
}
logger.info("Cluster {} is updated successfully!", destClusterName);
logger.info("========VCR Helix Update Ends========");
}
use of org.apache.helix.manager.zk.ZKHelixAdmin in project ambry by linkedin.
the class HelixVcrUtil method maintainCluster.
/**
* Enable or disable maintenance mode for a cluster.
* @param destZkString the cluster's zk string
* @param destClusterName the cluster's name
* @param enable enter maintenance mode if true
*/
public static void maintainCluster(String destZkString, String destClusterName, boolean enable) {
HelixZkClient destZkClient = getHelixZkClient(destZkString);
HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
destAdmin.enableMaintenanceMode(destClusterName, enable);
}
use of org.apache.helix.manager.zk.ZKHelixAdmin in project ambry by linkedin.
the class HelixVcrUtil method isSrcDestSync.
/**
* A method to verify resources and partitions in src cluster and dest cluster are same.
*/
public static boolean isSrcDestSync(String srcZkString, String srcClusterName, String destZkString, String destClusterName) {
HelixAdmin srcAdmin = new ZKHelixAdmin(srcZkString);
Set<String> srcResources = new HashSet<>(srcAdmin.getResourcesInCluster(srcClusterName));
HelixAdmin destAdmin = new ZKHelixAdmin(destZkString);
Set<String> destResources = new HashSet<>(destAdmin.getResourcesInCluster(destClusterName));
for (String resource : srcResources) {
if (HelixVcrUtil.ignoreResourceKeyWords.stream().anyMatch(resource::contains)) {
System.out.println("Resource " + resource + " from src cluster is ignored");
continue;
}
if (destResources.contains(resource)) {
// check if every partition exist.
Set<String> srcPartitions = srcAdmin.getResourceIdealState(srcClusterName, resource).getPartitionSet();
Set<String> destPartitions = destAdmin.getResourceIdealState(destClusterName, resource).getPartitionSet();
for (String partition : srcPartitions) {
if (!destPartitions.contains(partition)) {
return false;
}
}
} else {
return false;
}
}
return true;
}
Aggregations