use of org.apache.helix.HelixAdmin 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.HelixAdmin 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.HelixAdmin 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;
}
use of org.apache.helix.HelixAdmin in project ambry by linkedin.
the class TestUtils 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;
}
use of org.apache.helix.HelixAdmin in project helix by apache.
the class HelixStateTransitionHandler method disablePartition.
void disablePartition() {
String instanceName = _manager.getInstanceName();
String resourceName = _message.getResourceName();
String partitionName = _message.getPartitionName();
String clusterName = _manager.getClusterName();
HelixAdmin admin = _manager.getClusterManagmentTool();
admin.enablePartition(false, clusterName, instanceName, resourceName, Arrays.asList(partitionName));
logger.info("error in transit from ERROR to " + _message.getToState() + " for partition: " + partitionName + ". disable it on " + instanceName);
}
Aggregations