{
String clusterName = (String) getRequest().getAttributes().get("clusterName");
String resourceName = (String) getRequest().getAttributes().get("resourceName");
ZkClient zkClient =
(ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
JsonParameters jsonParameters = new JsonParameters(entity);
String command = jsonParameters.getCommand();
if (command.equalsIgnoreCase(ClusterSetup.addIdealState))
{
ZNRecord newIdealState = jsonParameters.getExtraParameter(JsonParameters.NEW_IDEAL_STATE);
HelixDataAccessor accessor =
ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
accessor.setProperty(accessor.keyBuilder().idealStates(resourceName),
new IdealState(newIdealState));
}
else if (command.equalsIgnoreCase(ClusterSetup.rebalance))
{
int replicas =
Integer.parseInt(jsonParameters.getParameter(JsonParameters.REPLICAS));
if (jsonParameters.getParameter(JsonParameters.RESOURCE_KEY_PREFIX) != null)
{
setupTool.rebalanceStorageCluster(clusterName,
resourceName,
replicas,
jsonParameters.getParameter(JsonParameters.RESOURCE_KEY_PREFIX));
}
else
{
setupTool.rebalanceStorageCluster(clusterName, resourceName, replicas);
}
}
else if (command.equalsIgnoreCase(ClusterSetup.expandResource))
{
setupTool.expandResource(clusterName, resourceName);
}
else if (command.equalsIgnoreCase(ClusterSetup.addResourceProperty))
{
Map<String, String> parameterMap = jsonParameters.cloneParameterMap();
parameterMap.remove(JsonParameters.MANAGEMENT_COMMAND);
for (String key : parameterMap.keySet())
{
setupTool.addResourceProperty(clusterName,
resourceName,
key,
parameterMap.get(key));
}
}