Search in sources :

Example 1 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project incubator-gobblin by apache.

the class HelixUtils method createGobblinHelixCluster.

/**
 * Create a Helix cluster for the Gobblin Cluster application.
 *
 * @param zkConnectionString the ZooKeeper connection string
 * @param clusterName the Helix cluster name
 * @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
 */
public static void createGobblinHelixCluster(String zkConnectionString, String clusterName, boolean overwrite) {
    ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
    // Create the cluster and overwrite if it already exists
    clusterSetup.addCluster(clusterName, overwrite);
    // Helix 0.6.x requires a configuration property to have the form key=value.
    String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
    clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
Also used : ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 2 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project incubator-gobblin by apache.

the class HelixUtils method createGobblinHelixCluster.

/**
 * Create a Helix cluster for the Gobblin Cluster application.
 *
 * @param zkConnectionString the ZooKeeper connection string
 * @param clusterName the Helix cluster name
 * @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
 */
public static void createGobblinHelixCluster(String zkConnectionString, String clusterName, boolean overwrite) {
    ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
    // Create the cluster and overwrite if it already exists
    clusterSetup.addCluster(clusterName, overwrite);
    // Helix 0.6.x requires a configuration property to have the form key=value.
    String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
    clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
Also used : ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 3 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ClusterResource method delete.

/**
 * Remove a cluster
 * <p>
 * Usage: <code> curl -X DELETE http://{host:port}/clusters/{clusterName}
 */
@Override
public Representation delete() {
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        setupTool.deleteCluster(clusterName);
        getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 4 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ClusterResource method post.

/**
 * Activate/deactivate a cluster in distributed controller mode
 * <p>
 * Usage: <code> curl -d 'jsonParameters=
 * {"command":"activateCluster","grandCluster":"{controllerCluster}","enabled":"{true/false}"}' -H
 * "Content-Type: application/json" http://{host:port}/clusters/{clusterName}}
 */
@Override
public Representation post(Representation entity) {
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        if (command == null) {
            throw new HelixException("Could NOT find 'command' in parameterMap: " + jsonParameters._parameterMap);
        } else if (command.equalsIgnoreCase(ClusterSetup.activateCluster) || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.activateCluster).contains(command)) {
            jsonParameters.verifyCommand(ClusterSetup.activateCluster);
            boolean enabled = true;
            if (jsonParameters.getParameter(JsonParameters.ENABLED) != null) {
                enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
            }
            String grandCluster = jsonParameters.getParameter(JsonParameters.GRAND_CLUSTER);
            setupTool.activateCluster(clusterName, grandCluster, enabled);
        } else if (command.equalsIgnoreCase(ClusterSetup.expandCluster)) {
            setupTool.expandCluster(clusterName);
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.activateCluster + ", " + ClusterSetup.expandCluster + "]");
        }
        getResponse().setEntity(getClusterRepresentation(clusterName));
        getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
    }
    return getResponseEntity();
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 5 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ClustersResource method post.

/**
 * Add a new Helix cluster
 * <p>
 * Usage: <code> curl -d 'jsonParameters={"command":"addCluster","clusterName":"{clusterName}"}' -H
 * "Content-Type: application/json" http://{host:port}/clusters
 */
@Override
public Representation post(Representation entity) {
    try {
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        if (command == null) {
            throw new HelixException("Could NOT find 'command' in parameterMap: " + jsonParameters._parameterMap);
        } else if (command.equalsIgnoreCase(ClusterSetup.addCluster)) {
            jsonParameters.verifyCommand(ClusterSetup.addCluster);
            ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
            ClusterSetup setupTool = new ClusterSetup(zkClient);
            setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), false);
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.addCluster + "]");
        }
        getResponse().setEntity(getClustersRepresentation());
        getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
        LOG.error("Error in posting " + entity, e);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Aggregations

ClusterSetup (org.apache.helix.tools.ClusterSetup)79 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)33 BeforeClass (org.testng.annotations.BeforeClass)33 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)28 ZkClient (org.apache.helix.manager.zk.ZkClient)26 Date (java.util.Date)23 IOException (java.io.IOException)14 HelixException (org.apache.helix.HelixException)14 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)11 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)11 Test (org.testng.annotations.Test)11 ConfigAccessor (org.apache.helix.ConfigAccessor)9 ZNRecord (org.apache.helix.ZNRecord)9 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 IdealState (org.apache.helix.model.IdealState)8 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)7 HelixAdmin (org.apache.helix.HelixAdmin)6 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)6 StringRepresentation (org.restlet.representation.StringRepresentation)6 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)5