use of org.restlet.representation.Representation in project helix by apache.
the class TestClusterManagementWebapp method postConfig.
private void postConfig(Client client, String url, ObjectMapper mapper, String command, String configs) throws Exception {
Map<String, String> params = new HashMap<String, String>();
params.put(JsonParameters.MANAGEMENT_COMMAND, command);
params.put(JsonParameters.CONFIGS, configs);
Request request = new Request(Method.POST, new Reference(url));
request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(params), MediaType.APPLICATION_ALL);
Response response = client.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
String responseStr = sw.toString();
Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
}
use of org.restlet.representation.Representation in project helix by apache.
the class TestClusterManagementWebapp method verifyEnableInstance.
void verifyEnableInstance() throws JsonGenerationException, JsonMappingException, IOException {
String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances/" + instance1 + "_" + instancePort;
Map<String, String> paraMap = new HashMap<String, String>();
// Add 1 instance
paraMap.put(JsonParameters.ENABLED, "" + false);
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance);
Reference resourceRef = new Reference(httpUrlBase);
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();
ZNRecord r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
AssertJUnit.assertTrue(r.getSimpleField(InstanceConfigProperty.HELIX_ENABLED.toString()).equals("" + false));
// Then enable it
paraMap.put(JsonParameters.ENABLED, "" + true);
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());
mapper = new ObjectMapper();
r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
AssertJUnit.assertTrue(r.getSimpleField(InstanceConfigProperty.HELIX_ENABLED.toString()).equals("" + true));
}
use of org.restlet.representation.Representation in project helix by apache.
the class TestClusterManagementWebapp method verifyAddHostedEntity.
void verifyAddHostedEntity() throws JsonGenerationException, JsonMappingException, IOException {
String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
Map<String, String> paraMap = new HashMap<String, String>();
paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, resourceGroupName);
paraMap.put(JsonParameters.PARTITIONS, "" + partitions);
paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource);
Reference resourceRef = new Reference(httpUrlBase);
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();
ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
AssertJUnit.assertTrue(zn.getListField("ResourceGroups").contains(resourceGroupName));
httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/" + resourceGroupName;
resourceRef = new Reference(httpUrlBase);
request = new Request(Method.GET, resourceRef);
response = _gClient.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
}
use of org.restlet.representation.Representation in project helix by apache.
the class TestClusterManagementWebapp method verifyAlterIdealState.
void verifyAlterIdealState() throws IOException {
String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/" + resourceGroupName + "/idealState";
Reference resourceRef = new Reference(httpUrlBase);
Request request = new Request(Method.GET, resourceRef);
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();
ZNRecord r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
String partitionName = "new-entity-12345_3";
r.getMapFields().remove(partitionName);
Map<String, String> paraMap = new HashMap<String, String>();
// Add 1 instance
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addIdealState);
resourceRef = new Reference(httpUrlBase);
request = new Request(Method.POST, resourceRef);
request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap) + "&" + JsonParameters.NEW_IDEAL_STATE + "=" + ClusterRepresentationUtil.ZNRecordToJson(r), MediaType.APPLICATION_ALL);
response = _gClient.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
mapper = new ObjectMapper();
ZNRecord r2 = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
AssertJUnit.assertTrue(!r2.getMapFields().containsKey(partitionName));
for (String key : r2.getMapFields().keySet()) {
AssertJUnit.assertTrue(r.getMapFields().containsKey(key));
}
}
use of org.restlet.representation.Representation in project helix by apache.
the class TestClusterManagementWebapp method verifyAddStateModel.
void verifyAddStateModel() throws JsonGenerationException, JsonMappingException, IOException {
String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs/MasterSlave";
Reference resourceRef = new Reference(httpUrlBase);
Request request = new Request(Method.GET, resourceRef);
Response response = _gClient.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
ObjectMapper mapper = new ObjectMapper();
ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
Map<String, String> paraMap = new HashMap<String, String>();
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addStateModelDef);
ZNRecord r = new ZNRecord("Test");
r.merge(zn);
httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs";
resourceRef = new Reference(httpUrlBase);
request = new Request(Method.POST, resourceRef);
request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap) + "&" + JsonParameters.NEW_STATE_MODEL_DEF + "=" + ClusterRepresentationUtil.ZNRecordToJson(r), MediaType.APPLICATION_ALL);
response = _gClient.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
// System.out.println(sw.toString());
AssertJUnit.assertTrue(sw.toString().contains("Test"));
}
Aggregations