use of org.restlet.Request 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.Request 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.Request 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"));
}
use of org.restlet.Request in project helix by apache.
the class TestClusterManagementWebapp method verifyEnableCluster.
void verifyEnableCluster() throws Exception {
System.out.println("START: verifyEnableCluster()");
String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/Controller";
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableCluster);
paramMap.put(JsonParameters.ENABLED, "" + false);
Reference resourceRef = new Reference(httpUrlBase);
Request request = new Request(Method.POST, resourceRef);
request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paramMap), MediaType.APPLICATION_ALL);
Response response = _gClient.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
System.out.println(sw.toString());
// verify pause znode exists
String pausePath = PropertyPathBuilder.pause(clusterName);
System.out.println("pausePath: " + pausePath);
boolean exists = _gZkClient.exists(pausePath);
Assert.assertTrue(exists, pausePath + " should exist");
// Then enable it
paramMap.put(JsonParameters.ENABLED, "" + true);
request = new Request(Method.POST, resourceRef);
request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paramMap), MediaType.APPLICATION_ALL);
response = _gClient.handle(request);
result = response.getEntity();
sw = new StringWriter();
result.write(sw);
System.out.println(sw.toString());
// verify pause znode doesn't exist
exists = _gZkClient.exists(pausePath);
Assert.assertFalse(exists, pausePath + " should be removed");
System.out.println("END: verifyEnableCluster()");
}
use of org.restlet.Request in project helix by apache.
the class TestHelixAdminScenariosRest method testGetInstances.
@Test
public void testGetInstances() throws IOException {
final String clusterName = "TestTagAwareness_testGetResources";
final String[] TAGS = { "tag1", "tag2" };
final String URL_BASE = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances";
_gSetupTool.addCluster(clusterName, true);
HelixAdmin admin = _gSetupTool.getClusterManagementTool();
// Add 4 participants, each with differint tag characteristics
InstanceConfig instance1 = new InstanceConfig("localhost_1");
instance1.addTag(TAGS[0]);
admin.addInstance(clusterName, instance1);
InstanceConfig instance2 = new InstanceConfig("localhost_2");
instance2.addTag(TAGS[1]);
admin.addInstance(clusterName, instance2);
InstanceConfig instance3 = new InstanceConfig("localhost_3");
instance3.addTag(TAGS[0]);
instance3.addTag(TAGS[1]);
admin.addInstance(clusterName, instance3);
InstanceConfig instance4 = new InstanceConfig("localhost_4");
admin.addInstance(clusterName, instance4);
// Now make a REST call for all resources
Reference resourceRef = new Reference(URL_BASE);
Request request = new Request(Method.GET, resourceRef);
Response response = _gClient.handle(request);
ListInstancesWrapper responseWrapper = ClusterRepresentationUtil.JsonToObject(ListInstancesWrapper.class, response.getEntityAsText());
Map<String, List<String>> tagInfo = responseWrapper.tagInfo;
// Ensure tag ownership is reported correctly
Assert.assertTrue(tagInfo.containsKey(TAGS[0]));
Assert.assertTrue(tagInfo.containsKey(TAGS[1]));
Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_1"));
Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_2"));
Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_3"));
Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_4"));
Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_1"));
Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_2"));
Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_3"));
Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_4"));
}
Aggregations