Request request = new Request(Method.POST, resourceRef);
request.setEntity(
JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap),
MediaType.APPLICATION_ALL);
Response response = _gClient.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
ObjectMapper mapper = new ObjectMapper();
TypeReference<ListInstancesWrapper> typeRef = new TypeReference<ListInstancesWrapper>() {
};
ListInstancesWrapper wrapper = mapper.readValue(new StringReader(sw.toString()), typeRef);
List<ZNRecord> znList = wrapper.instanceInfo;
AssertJUnit.assertTrue(znList.get(0).getId().equals(instance1 + "_" + instancePort));
// the case to add more than 1 instances
paraMap.clear();
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
String[] instances = {
"test2", "test3", "test4", "test5"
};
String instanceNames = "";
boolean first = true;
for (String instance : instances) {
if (first == true) {
first = false;
} else {
instanceNames += ";";
}
instanceNames += (instance + ":" + instancePort);
}
paraMap.put(JsonParameters.INSTANCE_NAMES, instanceNames);
request = new Request(Method.POST, resourceRef);
request.setEntity(
JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap),
MediaType.APPLICATION_ALL);
response = _gClient.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());