use of org.apache.helix.zookeeper.api.client.HelixZkClient in project ambry by linkedin.
the class VcrTestUtil method populateZkInfoAndStartController.
/**
* Populate info on ZooKeeper server and start {@link HelixControllerManager}.
* @param zkConnectString zk connect string to zk server.
* @param vcrClusterName the vcr cluster name.
* @param clusterMap the {@link ClusterMap} to use.
* @param vcrHelixStateModel the state model to use for helix cluster events.
* @return the created {@link HelixControllerManager}.
*/
public static HelixControllerManager populateZkInfoAndStartController(String zkConnectString, String vcrClusterName, ClusterMap clusterMap, String vcrHelixStateModel) {
HelixZkClient zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkConnectString), new HelixZkClient.ZkClientConfig());
try {
zkClient.setZkSerializer(new ZNRecordSerializer());
ClusterSetup clusterSetup = new ClusterSetup(zkClient);
clusterSetup.addCluster(vcrClusterName, true);
HelixAdmin admin = new ZKHelixAdmin(zkClient);
// set ALLOW_PARTICIPANT_AUTO_JOIN
HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(vcrClusterName).build();
Map<String, String> helixClusterProperties = new HashMap<>();
helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
admin.setConfig(configScope, helixClusterProperties);
// set PersistBestPossibleAssignment
ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(vcrClusterName);
clusterConfig.setPersistBestPossibleAssignment(true);
configAccessor.setClusterConfig(vcrClusterName, clusterConfig);
FullAutoModeISBuilder builder = new FullAutoModeISBuilder(helixResource);
builder.setStateModel(vcrHelixStateModel);
for (PartitionId partitionId : clusterMap.getAllPartitionIds(null)) {
builder.add(partitionId.toPathString());
}
builder.setMinActiveReplica(MIN_ACTIVE_REPLICAS);
builder.setRebalanceDelay((int) REBALANCE_DELAY_MS);
builder.setRebalancerClass(DelayedAutoRebalancer.class.getName());
builder.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
IdealState idealState = builder.build();
admin.addResource(vcrClusterName, helixResource, idealState);
admin.rebalance(vcrClusterName, helixResource, NUM_REPLICAS, "", "");
HelixControllerManager helixControllerManager = new HelixControllerManager(zkConnectString, vcrClusterName);
helixControllerManager.syncStart();
return helixControllerManager;
} finally {
zkClient.close();
}
}
use of org.apache.helix.zookeeper.api.client.HelixZkClient in project ambry by linkedin.
the class HelixVcrUtil method controlResource.
/**
* Enable or disable a resource in dest cluster.
* @param destZkString the cluster's zk string
* @param destClusterName the cluster's name
* @param resourceName the resource to enable/disable
* @param enable enable the resource if true
*/
static void controlResource(String destZkString, String destClusterName, String resourceName, boolean enable) {
HelixZkClient destZkClient = getHelixZkClient(destZkString);
HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
destAdmin.enableResource(destClusterName, resourceName, enable);
}
use of org.apache.helix.zookeeper.api.client.HelixZkClient in project ambry by linkedin.
the class HelixVcrUtil method getHelixZkClient.
/**
* @return the {@link HelixZkClient} from the zookeeper connection string.
* @param zkString the zookeeper connection string.
*/
static HelixZkClient getHelixZkClient(String zkString) {
HelixZkClient zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkString));
zkClient.setZkSerializer(ZN_RECORD_SERIALIZER);
return zkClient;
}
use of org.apache.helix.zookeeper.api.client.HelixZkClient 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.zookeeper.api.client.HelixZkClient 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);
}
Aggregations