diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java index 4ce2b54..0581994 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java @@ -93,6 +93,7 @@ import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; import org.apache.hadoop.yarn.api.records.LocalResource; import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.api.records.NodeLabel; import org.apache.hadoop.yarn.api.records.NodeState; import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.QueueACL; @@ -136,7 +137,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NewApplication; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo; -import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsName; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsName; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerInfo; @@ -796,18 +798,18 @@ public Response updateAppState(AppState targetState, @GET @Path("/get-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr) + public NodeToLabelsName getNodeToLabels(@Context HttpServletRequest hsr) throws IOException { init(); - NodeToLabelsInfo ntl = new NodeToLabelsInfo(); - HashMap ntlMap = ntl.getNodeToLabels(); + NodeToLabelsName ntl = new NodeToLabelsName(); + HashMap ntlMap = ntl.getNodeToLabels(); Map> nodeIdToLabels = rm.getRMContext().getNodeLabelManager().getNodeLabels(); for (Map.Entry> nitle : nodeIdToLabels.entrySet()) { ntlMap.put(nitle.getKey().toString(), - new NodeLabelsInfo(nitle.getValue())); + new NodeLabelsName(nitle.getValue())); } return ntl; @@ -844,12 +846,12 @@ public LabelsToNodesInfo getLabelsToNodes( @POST @Path("/replace-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public Response replaceLabelsOnNodes(final NodeToLabelsInfo newNodeToLabels, + public Response replaceLabelsOnNodes(final NodeToLabelsName newNodeToLabels, @Context HttpServletRequest hsr) throws IOException { Map> nodeIdToLabels = new HashMap>(); - for (Map.Entry nitle : newNodeToLabels + for (Map.Entry nitle : newNodeToLabels .getNodeToLabels().entrySet()) { nodeIdToLabels.put( ConverterUtils.toNodeIdWithDefaultPort(nitle.getKey()), @@ -862,14 +864,14 @@ public Response replaceLabelsOnNodes(final NodeToLabelsInfo newNodeToLabels, @POST @Path("/nodes/{nodeId}/replace-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public Response replaceLabelsOnNode(NodeLabelsInfo newNodeLabelsInfo, + public Response replaceLabelsOnNode(NodeLabelsName newNodeLabelsName, @Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) throws Exception { NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId); Map> newLabelsForNode = new HashMap>(); newLabelsForNode.put(nid, - new HashSet(newNodeLabelsInfo.getNodeLabels())); + new HashSet(newNodeLabelsName.getNodeLabels())); return replaceLabelsOnNode(newLabelsForNode, hsr, "/nodes/nodeid/replace-labels"); } @@ -909,9 +911,9 @@ public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr) throws IOException { init(); - NodeLabelsInfo ret = - new NodeLabelsInfo(rm.getRMContext().getNodeLabelManager() - .getClusterNodeLabelNames()); + List nodeLabels = rm.getRMContext().getNodeLabelManager() + .getClusterNodeLabels(); + NodeLabelsInfo ret = new NodeLabelsInfo(nodeLabels); return ret; } @@ -937,8 +939,7 @@ public Response addToClusterNodeLabels(final NodeLabelsInfo newNodeLabels, } rm.getRMContext().getNodeLabelManager() - .addToCluserNodeLabelsWithDefaultExclusivity(new HashSet( - newNodeLabels.getNodeLabels())); + .addToCluserNodeLabels(newNodeLabels.getNodeLabels()); return Response.status(Status.OK).build(); @@ -947,7 +948,7 @@ public Response addToClusterNodeLabels(final NodeLabelsInfo newNodeLabels, @POST @Path("/remove-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public Response removeFromCluserNodeLabels(final NodeLabelsInfo oldNodeLabels, + public Response removeFromCluserNodeLabels(final NodeLabelsName oldNodeLabels, @Context HttpServletRequest hsr) throws Exception { init(); @@ -975,13 +976,13 @@ public Response removeFromCluserNodeLabels(final NodeLabelsInfo oldNodeLabels, @GET @Path("/nodes/{nodeId}/get-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, + public NodeLabelsName getLabelsOnNode(@Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) throws IOException { init(); NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId); - return new NodeLabelsInfo( + return new NodeLabelsName( rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelInfo.java new file mode 100644 index 0000000..2ce9c67 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelInfo.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.hadoop.yarn.api.records.NodeLabel; + +@XmlRootElement(name = "nodeLabelInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class NodeLabelInfo { + + protected String name; + protected boolean exclusity; + + public NodeLabelInfo() { + } // JAXB needs this + + public NodeLabelInfo(String name) { + this.name = name; + this.exclusity = true; + } + + public NodeLabelInfo(String name, boolean exclusity) { + this.name = name; + this.exclusity = exclusity; + } + + public NodeLabelInfo(NodeLabel label) { + this.name = label.getName(); + this.exclusity = label.isExclusive(); + } + + public String getName() { + return name; + } + + public boolean getExclusity() { + return exclusity; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsInfo.java index 1cb895a..87c749a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsInfo.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsInfo.java @@ -22,31 +22,47 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.apache.hadoop.yarn.api.records.NodeLabel; + @XmlRootElement(name = "nodeLabelsInfo") @XmlAccessorType(XmlAccessType.FIELD) public class NodeLabelsInfo { - protected ArrayList nodeLabels = new ArrayList(); + @XmlElement(name = "nodeLabels") + protected ArrayList nodeLabelsInfo = new ArrayList(); public NodeLabelsInfo() { } // JAXB needs this - - public NodeLabelsInfo(ArrayList nodeLabels) { - this.nodeLabels = nodeLabels; + + public NodeLabelsInfo(ArrayList nodeLabels) { + this.nodeLabelsInfo = nodeLabels; + } + + public NodeLabelsInfo(List nodeLabels) { + this.nodeLabelsInfo = new ArrayList(); + for (NodeLabel label : nodeLabels) { + this.nodeLabelsInfo.add(new NodeLabelInfo(label)); + } } - - public NodeLabelsInfo(Set nodeLabelsSet) { - this.nodeLabels = new ArrayList(nodeLabelsSet); + + public ArrayList getNodeLabelsInfo() { + return nodeLabelsInfo; } - - public ArrayList getNodeLabels() { + + public Set getNodeLabels() { + Set nodeLabels = new HashSet(); + for (NodeLabelInfo label : nodeLabelsInfo) { + nodeLabels.add(NodeLabel.newInstance(label.getName(), + label.getExclusity())); + } return nodeLabels; } - - public void setNodeLabels(ArrayList nodeLabels) { - this.nodeLabels = nodeLabels; + + public void setNodeLabelsInfo(ArrayList nodeLabelsInfo) { + this.nodeLabelsInfo = nodeLabelsInfo; } - + } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsName.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsName.java new file mode 100644 index 0000000..9d28f33 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsName.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; + +import java.util.*; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "nodeLabelsName") +@XmlAccessorType(XmlAccessType.FIELD) +public class NodeLabelsName { + + protected ArrayList nodeLabels = new ArrayList(); + + public NodeLabelsName() { + } // JAXB needs this + + public NodeLabelsName(ArrayList nodeLabels) { + this.nodeLabels = nodeLabels; + } + + public NodeLabelsName(Set nodeLabelsSet) { + this.nodeLabels = new ArrayList(nodeLabelsSet); + } + + public ArrayList getNodeLabels() { + return nodeLabels; + } + + public void setNodeLabels(ArrayList nodeLabels) { + this.nodeLabels = nodeLabels; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsInfo.java deleted file mode 100644 index f2e6441..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsInfo.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; - -import java.util.*; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "nodeToLabelsInfo") -@XmlAccessorType(XmlAccessType.FIELD) -public class NodeToLabelsInfo { - - protected HashMap nodeToLabels = - new HashMap(); - - public NodeToLabelsInfo() { - } // JAXB needs this - - public HashMap getNodeToLabels() { - return nodeToLabels; - } - -} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsName.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsName.java new file mode 100644 index 0000000..b259b25 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeToLabelsName.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; + +import java.util.*; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "nodeToLabelsInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class NodeToLabelsName { + + protected HashMap nodeToLabels = + new HashMap(); + + public NodeToLabelsName() { + } // JAXB needs this + + public HashMap getNodeToLabels() { + return nodeToLabels; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java index 48d6602..5dae402 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java @@ -138,7 +138,6 @@ private void checkTaskContainersHost(ApplicationAttemptId attemptId, return set; } - @Test (timeout = 300000) public void testContainerAllocationWithSingleUserLimits() throws Exception { final RMNodeLabelsManager mgr = new NullRMNodeLabelsManager(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodeLabels.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodeLabels.java index 2d5518d..1342d3d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodeLabels.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodeLabels.java @@ -34,11 +34,12 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LabelsToNodesInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo; -import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsName; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsName; import org.apache.hadoop.yarn.webapp.GenericExceptionHandler; import org.apache.hadoop.yarn.webapp.JerseyTestBase; -import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.junit.Test; @@ -114,31 +115,35 @@ public void testNodeLabels() throws JSONException, Exception { ClientResponse response; JSONObject json; - JSONArray jarr; - + // Add a 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("{\"nodeLabels\":\"a\"}", MediaType.APPLICATION_JSON) + .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); // Verify response = r.path("ws").path("v1").path("cluster") .path("get-node-labels").queryParam("user.name", userName) - .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); + .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - json = response.getEntity(JSONObject.class); - assertEquals("a", json.getString("nodeLabels")); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals("a", nlsifo.getNodeLabelsInfo().get(0).getName()); + assertEquals(1, nlsifo.getNodeLabels().size()); // Add another + nlsifo = new NodeLabelsInfo(); + nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("b")); response = r.path("ws").path("v1").path("cluster") .path("add-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON) - .entity("{\"nodeLabels\":\"b\"}", MediaType.APPLICATION_JSON) + .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); // Verify @@ -147,9 +152,8 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - json = response.getEntity(JSONObject.class); - jarr = json.getJSONArray("nodeLabels"); - assertEquals(2, jarr.length()); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals(2, nlsifo.getNodeLabels().size()); // Add labels to a node response = @@ -249,8 +253,8 @@ public void testNodeLabels() throws JSONException, Exception { assertEquals("b", json.getString("nodeLabels")); // Replace labels using node-to-labels - NodeToLabelsInfo ntli = new NodeToLabelsInfo(); - NodeLabelsInfo nli = new NodeLabelsInfo(); + NodeToLabelsName ntli = new NodeToLabelsName(); + NodeLabelsName nli = new NodeLabelsName(); nli.getNodeLabels().add("a"); ntli.getNodeToLabels().put("nid:0", nli); response = @@ -258,7 +262,7 @@ public void testNodeLabels() throws JSONException, Exception { .path("replace-node-to-labels") .queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON) - .entity(toJson(ntli, NodeToLabelsInfo.class), + .entity(toJson(ntli, NodeToLabelsName.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); @@ -268,7 +272,7 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-to-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - ntli = response.getEntity(NodeToLabelsInfo.class); + ntli = response.getEntity(NodeToLabelsName.class); nli = ntli.getNodeToLabels().get("nid:0"); assertEquals(1, nli.getNodeLabels().size()); assertTrue(nli.getNodeLabels().contains("a")); @@ -349,9 +353,8 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - json = response.getEntity(JSONObject.class); - jarr = json.getJSONArray("nodeLabels"); - assertEquals(2, jarr.length()); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals(2, nlsifo.getNodeLabels().size()); // Remove cluster label (succeed, we no longer need it) response = @@ -367,9 +370,9 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - json = response.getEntity(JSONObject.class); - assertEquals("a", json.getString("nodeLabels")); - + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals("a", nlsifo.getNodeLabelsInfo().get(0).getName()); + assertEquals(1, nlsifo.getNodeLabels().size()); // Remove cluster label with post response = @@ -385,12 +388,15 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - String res = response.getEntity(String.class); - assertTrue(res.equals("null")); - + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals(0, nlsifo.getNodeLabels().size()); + // Following test cases are to test replace when distributed node label // configuration is on // Reset for testing : add cluster labels + nlsifo = new NodeLabelsInfo(); + nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("x")); + nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("y")); response = r.path("ws") .path("v1") @@ -398,7 +404,7 @@ public void testNodeLabels() throws JSONException, Exception { .path("add-node-labels") .queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON) - .entity("{\"nodeLabels\":[\"x\",\"y\"]}", + .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON).post(ClientResponse.class); // Reset for testing : Add labels to a node response = @@ -413,8 +419,8 @@ public void testNodeLabels() throws JSONException, Exception { rmWebService.isDistributedNodeLabelConfiguration = true; // Case1 : Replace labels using node-to-labels - ntli = new NodeToLabelsInfo(); - nli = new NodeLabelsInfo(); + ntli = new NodeToLabelsName(); + nli = new NodeLabelsName(); nli.getNodeLabels().add("x"); ntli.getNodeToLabels().put("nid:0", nli); response = @@ -424,7 +430,7 @@ public void testNodeLabels() throws JSONException, Exception { .path("replace-node-to-labels") .queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON) - .entity(toJson(ntli, NodeToLabelsInfo.class), + .entity(toJson(ntli, NodeToLabelsName.class), MediaType.APPLICATION_JSON).post(ClientResponse.class); // Verify, using node-to-labels that previous operation has failed @@ -433,7 +439,7 @@ public void testNodeLabels() throws JSONException, Exception { .queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - ntli = response.getEntity(NodeToLabelsInfo.class); + ntli = response.getEntity(NodeToLabelsName.class); nli = ntli.getNodeToLabels().get("nid:0"); assertEquals(1, nli.getNodeLabels().size()); assertFalse(nli.getNodeLabels().contains("x")); @@ -453,7 +459,7 @@ public void testNodeLabels() throws JSONException, Exception { .queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - ntli = response.getEntity(NodeToLabelsInfo.class); + ntli = response.getEntity(NodeToLabelsName.class); nli = ntli.getNodeToLabels().get("nid:0"); assertEquals(1, nli.getNodeLabels().size()); assertFalse(nli.getNodeLabels().contains("x")); @@ -472,8 +478,50 @@ public void testNodeLabels() throws JSONException, Exception { .path("get-node-labels").queryParam("user.name", userName) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); - json = response.getEntity(JSONObject.class); - assertEquals("y", json.getString("nodeLabels")); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals("y", nlsifo.getNodeLabelsInfo().get(0).getName()); + + // Remove y + response = + r.path("ws").path("v1").path("cluster") + .path("remove-node-labels") + .queryParam("user.name", userName) + .accept(MediaType.APPLICATION_JSON) + .entity("{\"nodeLabels\":\"y\"}", MediaType.APPLICATION_JSON) + .post(ClientResponse.class); + + // Verify + 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, response.getType()); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertTrue(nlsifo.getNodeLabelsInfo().isEmpty()); + + // add a new nodelabel with exclusity + nlsifo = new NodeLabelsInfo(); + nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("z", false)); + 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 + 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, response.getType()); + nlsifo = response.getEntity(NodeLabelsInfo.class); + assertEquals("z", nlsifo.getNodeLabelsInfo().get(0).getName()); + assertEquals(false, nlsifo.getNodeLabelsInfo().get(0).getExclusity()); + assertEquals(1, nlsifo.getNodeLabels().size()); } @SuppressWarnings("rawtypes") -- 1.9.4.msysgit.1