use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ControllerResource method post.
/**
* Enable/disable Helix controller
* <p>
* Usage:
* <code>curl -d 'jsonParameters={"command":"enableCluster","enabled":"{true/false}"}'
* -H "Content-Type: application/json" http://{host:port}/clusters/{cluster}/Controller
*/
@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.enableCluster)) {
boolean enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
setupTool.getClusterManagementTool().enableCluster(clusterName, enabled);
} else {
throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.enableCluster + "]");
}
getResponse().setEntity(getControllerRepresentation(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 ResourceGroupResource method post.
@Override
public Representation post(Representation entity) {
try {
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
String resourceName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.RESOURCE_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.equalsIgnoreCase(ClusterSetup.resetResource)) {
setupTool.getClusterManagementTool().resetResource(clusterName, Arrays.asList(resourceName));
} else if (command.equalsIgnoreCase(ClusterSetup.enableResource)) {
jsonParameters.verifyCommand(ClusterSetup.enableResource);
boolean enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
setupTool.getClusterManagementTool().enableResource(clusterName, resourceName, enabled);
} else {
throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.resetResource + "]");
}
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("", e);
}
return null;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ResourceGroupsResource method post.
@Override
public Representation post(Representation entity) {
try {
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
JsonParameters jsonParameters = new JsonParameters(entity);
String command = jsonParameters.getCommand();
if (command.equalsIgnoreCase(ClusterSetup.addResource) || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.addResource).contains(command)) {
jsonParameters.verifyCommand(ClusterSetup.addResource);
String entityName = jsonParameters.getParameter(JsonParameters.RESOURCE_GROUP_NAME);
String stateModelDefRef = jsonParameters.getParameter(JsonParameters.STATE_MODEL_DEF_REF);
int partitions = Integer.parseInt(jsonParameters.getParameter(JsonParameters.PARTITIONS));
String mode = RebalanceMode.SEMI_AUTO.toString();
if (jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE) != null) {
mode = jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE);
}
int bucketSize = 0;
if (jsonParameters.getParameter(JsonParameters.BUCKET_SIZE) != null) {
try {
bucketSize = Integer.parseInt(jsonParameters.getParameter(JsonParameters.BUCKET_SIZE));
} catch (Exception e) {
}
}
int maxPartitionsPerNode = -1;
if (jsonParameters.getParameter(JsonParameters.MAX_PARTITIONS_PER_NODE) != null) {
try {
maxPartitionsPerNode = Integer.parseInt(jsonParameters.getParameter(JsonParameters.MAX_PARTITIONS_PER_NODE));
} catch (Exception e) {
}
}
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
setupTool.addResourceToCluster(clusterName, entityName, partitions, stateModelDefRef, mode, bucketSize, maxPartitionsPerNode);
} else {
throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.addResource + "]");
}
getResponse().setEntity(getHostedEntitiesRepresentation(clusterName));
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;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class SchedulerTasksResource method getSchedulerTasksRepresentation.
StringRepresentation getSchedulerTasksRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
String instanceName = (String) getRequest().getAttributes().get("instanceName");
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
LiveInstance liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
String sessionId = liveInstance.getSessionId();
// (ClusterRepresentationUtil.ObjectToJson(instanceConfigs),
StringRepresentation representation = new StringRepresentation("");
return representation;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class AbstractTestClass method beforeSuite.
@BeforeSuite
public void beforeSuite() throws Exception {
if (!_init) {
// TODO: use logging.properties file to config java.util.logging.Logger levels
java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
topJavaLogger.setLevel(Level.WARNING);
_gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
_gZkClientTestNS = new ZkClient(_zkAddrTestNS, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
_gSetupTool = new ClusterSetup(_gZkClient);
_configAccessor = new ConfigAccessor(_gZkClient);
_baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
_baseAccessorTestNS = new ZkBaseDataAccessor<>(_gZkClientTestNS);
// wait for the web service to start
Thread.sleep(100);
setup();
_init = true;
}
}
Aggregations