request.setEntity(JsonParameters.JSON_PARAMETERS + "="
+ ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
ObjectMapper mapper = new ObjectMapper();
TypeReference<ArrayList<ZNRecord>> typeRef = new TypeReference<ArrayList<ZNRecord>>()
{
};
List<ZNRecord> znList = mapper.readValue(new StringReader(sw.toString()), typeRef);
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);
client = new Client(Protocol.HTTP);
response = client.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
mapper = new ObjectMapper();