use of org.apache.helix.HelixAdmin in project ambry by linkedin.
the class HelixBootstrapUpgradeUtil method controlPartitionState.
/**
* Control state of partition on certain node. (i.e. DisablePartition, EnablePartition)
*/
private void controlPartitionState() {
// in adminForDc map.
if (adminForDc.size() != 1) {
throw new IllegalStateException("The dc count is not 1 for partition state control operation");
}
HelixAdmin helixAdmin = adminForDc.values().iterator().next();
String instanceName;
if (portNum == null) {
Optional<DataNodeId> optionalDataNode = staticClusterMap.getDataNodeIds().stream().filter(node -> node.getHostname().equals(hostName)).findFirst();
if (!optionalDataNode.isPresent()) {
throw new IllegalStateException("Host " + hostName + " is not found in static clustermap");
}
DataNode dataNode = (DataNode) optionalDataNode.get();
instanceName = getInstanceName(dataNode);
} else {
instanceName = ClusterMapUtils.getInstanceName(hostName, portNum);
}
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
String resourceNameForPartition = getResourceNameOfPartition(helixAdmin, clusterName, partitionName);
info("{} partition {} under resource {} on node {}", helixAdminOperation == HelixAdminOperation.EnablePartition ? "Enabling" : "Disabling", partitionName, resourceNameForPartition, instanceName);
instanceConfig.setInstanceEnabledForPartition(resourceNameForPartition, partitionName, helixAdminOperation == HelixAdminOperation.EnablePartition);
// clean up the disabled partition entry if it exists and is empty.
Map<String, String> disabledPartitions = instanceConfig.getRecord().getMapFields().get(HELIX_DISABLED_PARTITION_STR);
if (disabledPartitions != null && disabledPartitions.isEmpty()) {
instanceConfig.getRecord().getMapFields().remove(HELIX_DISABLED_PARTITION_STR);
}
helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
instancesUpdated.getAndIncrement();
if (helixAdminOperation == HelixAdminOperation.EnablePartition) {
partitionsEnabled.getAndIncrement();
} else {
partitionsDisabled.getAndIncrement();
}
}
use of org.apache.helix.HelixAdmin in project ambry by linkedin.
the class HelixBootstrapUpgradeUtil method dropCluster.
/**
* Drop a cluster from Helix.
* @param zkLayoutPath the path to the zookeeper layout file.
* @param clusterName the name of the cluster in Helix.
* @param dcs the comma-separated list of data centers that needs to be upgraded/bootstrapped.
* @param helixAdminFactory the {@link HelixAdminFactory} to use to instantiate {@link HelixAdmin}
* @throws Exception if there is an error reading a file or in parsing json.
*/
static void dropCluster(String zkLayoutPath, String clusterName, String dcs, HelixAdminFactory helixAdminFactory) throws Exception {
Map<String, ClusterMapUtils.DcZkInfo> dataCenterToZkAddress = parseAndUpdateDcInfoFromArg(dcs, zkLayoutPath);
info("Dropping cluster {} from Helix", clusterName);
for (Map.Entry<String, ClusterMapUtils.DcZkInfo> entry : dataCenterToZkAddress.entrySet()) {
List<String> zkConnectStrs = entry.getValue().getZkConnectStrs();
if (zkConnectStrs.size() != 1) {
throw new IllegalArgumentException(entry.getKey() + " has invalid number of ZK endpoints: " + zkConnectStrs.size());
}
HelixAdmin admin = helixAdminFactory.getHelixAdmin(zkConnectStrs.get(0));
admin.dropCluster(clusterName);
info("Dropped cluster from {}", entry.getKey());
}
}
use of org.apache.helix.HelixAdmin in project ambry by linkedin.
the class HelixBootstrapUpgradeUtil method maybeAddCluster.
/**
* Initialize a map of dataCenter to HelixAdmin based on the given zk Connect Strings.
*/
private void maybeAddCluster() {
for (Map.Entry<String, HelixAdmin> entry : adminForDc.entrySet()) {
// Add a cluster entry in every DC
String dcName = entry.getKey();
HelixAdmin admin = entry.getValue();
if (!isClusterPresent(dcName)) {
info("Adding cluster {} in {}", clusterName, dcName);
admin.addCluster(clusterName);
info("Adding state model {} to cluster {}", stateModelDef, clusterName);
admin.addStateModelDef(clusterName, stateModelDef, getStateModelDefinition(stateModelDef));
}
}
}
use of org.apache.helix.HelixAdmin in project ambry by linkedin.
the class HelixBootstrapUpgradeUtil method resetPartition.
/**
* Reset the partition on specific node.
*/
private void resetPartition() {
if (adminForDc.size() != 1) {
throw new IllegalStateException("The dc count is not 1 for resetting partition operation");
}
HelixAdmin helixAdmin = adminForDc.values().iterator().next();
String instanceName;
if (portNum == null) {
Optional<DataNodeId> optionalDataNode = staticClusterMap.getDataNodeIds().stream().filter(node -> node.getHostname().equals(hostName)).findFirst();
if (!optionalDataNode.isPresent()) {
throw new IllegalStateException("Host " + hostName + " is not found in static clustermap");
}
DataNodeId dataNodeId = optionalDataNode.get();
instanceName = getInstanceName(dataNodeId);
} else {
instanceName = ClusterMapUtils.getInstanceName(hostName, portNum);
}
String resourceName = getResourceNameOfPartition(helixAdmin, clusterName, partitionName);
info("Resetting partition {} under resource {} on node {}", partitionName, resourceName, hostName);
helixAdmin.resetPartition(clusterName, instanceName, resourceName, Collections.singletonList(partitionName));
partitionsReset.getAndIncrement();
}
use of org.apache.helix.HelixAdmin 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);
}
Aggregations