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);
}
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);
}
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;
}
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();
}
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;
}
Aggregations