Search in sources :

Example 1 with HelixZkClient

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();
    }
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) HashMap(java.util.HashMap) CrushEdRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) HelixControllerManager(com.github.ambry.utils.HelixControllerManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) PartitionId(com.github.ambry.clustermap.PartitionId) DelayedAutoRebalancer(org.apache.helix.controller.rebalancer.DelayedAutoRebalancer) IdealState(org.apache.helix.model.IdealState) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HelixConfigScope(org.apache.helix.model.HelixConfigScope) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 2 with HelixZkClient

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);
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin)

Example 3 with HelixZkClient

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;
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient)

Example 4 with HelixZkClient

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);
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HashMap(java.util.HashMap) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 5 with HelixZkClient

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);
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin)

Aggregations

HelixZkClient (org.apache.helix.zookeeper.api.client.HelixZkClient)5 HelixAdmin (org.apache.helix.HelixAdmin)4 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)4 HashMap (java.util.HashMap)2 HelixConfigScope (org.apache.helix.model.HelixConfigScope)2 FullAutoModeISBuilder (org.apache.helix.model.builder.FullAutoModeISBuilder)2 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)2 ClusterSetup (org.apache.helix.tools.ClusterSetup)2 PartitionId (com.github.ambry.clustermap.PartitionId)1 HelixControllerManager (com.github.ambry.utils.HelixControllerManager)1 ConfigAccessor (org.apache.helix.ConfigAccessor)1 DelayedAutoRebalancer (org.apache.helix.controller.rebalancer.DelayedAutoRebalancer)1 CrushEdRebalanceStrategy (org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 ClusterConfig (org.apache.helix.model.ClusterConfig)1 IdealState (org.apache.helix.model.IdealState)1