|
@@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -130,7 +131,8 @@ public class TestRMWebServicesNodeLabels extends JerseyTestBase {
|
|
|
r.path("ws").path("v1").path("cluster")
|
|
|
.path("add-node-labels").queryParam("user.name", userName)
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
- .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON)
|
|
|
+ .entity(toJson(nlsifo, NodeLabelsInfo.class),
|
|
|
+ MediaType.APPLICATION_JSON)
|
|
|
.post(ClientResponse.class);
|
|
|
|
|
|
// Verify
|
|
@@ -154,7 +156,8 @@ public class TestRMWebServicesNodeLabels extends JerseyTestBase {
|
|
|
r.path("ws").path("v1").path("cluster")
|
|
|
.path("add-node-labels").queryParam("user.name", userName)
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
- .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON)
|
|
|
+ .entity(toJson(nlsifo, NodeLabelsInfo.class),
|
|
|
+ MediaType.APPLICATION_JSON)
|
|
|
.post(ClientResponse.class);
|
|
|
|
|
|
// Verify
|
|
@@ -690,6 +693,66 @@ public class TestRMWebServicesNodeLabels extends JerseyTestBase {
|
|
|
validateJsonExceptionContent(response, expectedmessage);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testNodeLabelPartitionInfo() throws Exception {
|
|
|
+ WebResource r = resource();
|
|
|
+
|
|
|
+ ClientResponse response;
|
|
|
+
|
|
|
+ // Add a node label
|
|
|
+ NodeLabelsInfo nlsifo = new NodeLabelsInfo();
|
|
|
+ nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("a"));
|
|
|
+ response =
|
|
|
+ r.path("ws").path("v1").path("cluster")
|
|
|
+ .path("add-node-labels").queryParam("user.name", userName)
|
|
|
+ .accept(MediaType.APPLICATION_JSON)
|
|
|
+ .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON)
|
|
|
+ .post(ClientResponse.class);
|
|
|
+
|
|
|
+ // Verify partition info in get-node-labels
|
|
|
+ response =
|
|
|
+ r.path("ws").path("v1").path("cluster")
|
|
|
+ .path("get-node-labels").queryParam("user.name", userName)
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
|
+ assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
|
+ response.getType().toString());
|
|
|
+ nlsifo = response.getEntity(NodeLabelsInfo.class);
|
|
|
+ assertEquals(1, nlsifo.getNodeLabels().size());
|
|
|
+ for (NodeLabelInfo nl : nlsifo.getNodeLabelsInfo()) {
|
|
|
+ assertEquals("a", nl.getName());
|
|
|
+ assertTrue(nl.getExclusivity());
|
|
|
+ assertNotNull(nl.getPartitionInfo());
|
|
|
+ assertNotNull(nl.getPartitionInfo().getResourceAvailable());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add node label to a node
|
|
|
+ MultivaluedMapImpl params = new MultivaluedMapImpl();
|
|
|
+ params.add("labels", "a");
|
|
|
+ response =
|
|
|
+ r.path("ws").path("v1").path("cluster")
|
|
|
+ .path("nodes").path("nodeId:0")
|
|
|
+ .path("replace-labels")
|
|
|
+ .queryParam("user.name", userName)
|
|
|
+ .queryParams(params)
|
|
|
+ .accept(MediaType.APPLICATION_JSON)
|
|
|
+ .post(ClientResponse.class);
|
|
|
+
|
|
|
+ // Verify partition info in label-mappings
|
|
|
+ response =
|
|
|
+ r.path("ws").path("v1").path("cluster")
|
|
|
+ .path("label-mappings").queryParam("user.name", userName)
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
|
+ assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
|
+ response.getType().toString());
|
|
|
+ LabelsToNodesInfo ltni = response.getEntity(LabelsToNodesInfo.class);
|
|
|
+ assertEquals(1, ltni.getLabelsToNodes().size());
|
|
|
+ NodeIDsInfo nodes = ltni.getLabelsToNodes().get(
|
|
|
+ new NodeLabelInfo("a"));
|
|
|
+ assertTrue(nodes.getNodeIDs().contains("nodeId:0"));
|
|
|
+ assertNotNull(nodes.getPartitionInfo());
|
|
|
+ assertNotNull(nodes.getPartitionInfo().getResourceAvailable());
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
private String toJson(Object nsli, Class klass) throws Exception {
|
|
|
StringWriter sw = new StringWriter();
|