use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ClustersResource method getClustersRepresentation.
StringRepresentation getClustersRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> clusters = setupTool.getClusterManagementTool().getClusters();
ZNRecord clustersRecord = new ZNRecord("Clusters Summary");
clustersRecord.setListField("clusters", clusters);
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clustersRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ConfigResource method setConfigs.
/**
* set or remove configs depends on "command" field of jsonParameters in POST body
* @param entity
* @param scopeStr
* @throws Exception
*/
void setConfigs(Representation entity, ConfigScopeProperty type, String scopeArgs) throws Exception {
JsonParameters jsonParameters = new JsonParameters(entity);
String command = jsonParameters.getCommand();
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
if (command.equalsIgnoreCase(ClusterSetup.setConfig)) {
jsonParameters.verifyCommand(ClusterSetup.setConfig);
String propertiesStr = jsonParameters.getParameter(JsonParameters.CONFIGS);
setupTool.setConfig(type, scopeArgs, propertiesStr);
} else if (command.equalsIgnoreCase(ClusterSetup.removeConfig)) {
jsonParameters.verifyCommand(ClusterSetup.removeConfig);
String propertiesStr = jsonParameters.getParameter(JsonParameters.CONFIGS);
setupTool.removeConfig(type, scopeArgs, propertiesStr);
} else {
throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.setConfig + ", " + ClusterSetup.removeConfig + "]");
}
getResponse().setEntity(get());
getResponse().setStatus(Status.SUCCESS_OK);
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ConfigResource method getConfigs.
StringRepresentation getConfigs(ConfigScopeProperty scopeProperty, String... keys) throws Exception {
StringRepresentation representation = null;
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
HelixAdmin admin = setupTool.getClusterManagementTool();
ZNRecord record = new ZNRecord(scopeProperty + " Config");
HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
List<String> configKeys = admin.getConfigKeys(scope);
Map<String, String> configs = admin.getConfig(scope, configKeys);
record.setSimpleFields(configs);
representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ConstraintResource method post.
/**
* Set constraints
* <p>
* Usage:
* <code>curl -d 'jsonParameters={"constraintAttributes":"RESOURCE={resource},CONSTRAINT_VALUE={1}"}'
* -H "Content-Type: application/json" http://{host:port}/clusters/{cluster}/constraints/MESSAGE_CONSTRAINT/{constraintId}
*/
@Override
public Representation post(Representation entity) {
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
String constraintTypeStr = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CONSTRAINT_TYPE);
String constraintId = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CONSTRAINT_ID);
try {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
JsonParameters jsonParameters = new JsonParameters(entity);
String constraintAttrStr = jsonParameters.getParameter(JsonParameters.CONSTRAINT_ATTRIBUTES);
setupTool.setConstraint(clusterName, constraintTypeStr, constraintId, constraintAttrStr);
} catch (Exception e) {
LOG.error("Error in posting " + entity, 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 ConstraintResource method delete.
/**
* Remove constraints
* <p>
* Usage:
* <code>curl -X DELETE http://{host:port}/clusters/{cluster}/constraints/MESSAGE_CONSTRAINT/{constraintId}
*/
@Override
public Representation delete() {
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
String constraintTypeStr = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CONSTRAINT_TYPE);
String constraintId = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CONSTRAINT_ID);
try {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
setupTool.removeConstraint(clusterName, constraintTypeStr, constraintId);
} catch (Exception e) {
LOG.error("Error in delete constraint", e);
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
}
return null;
}
Aggregations