@GET @Path(RMWSConsts.NODES_NODEID_GETLABELS) @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, @PathParam(RMWSConsts.NODEID) String nodeId) throws IOException { initForReadableEndpoints(); NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId); List<NodeLabel> labels = new ArrayList<NodeLabel>( rm.getRMContext().getNodeLabelManager().getLabelsInfoByNode(nid)); return new NodeLabelsInfo(labels); }
NodeLabelsInfo nlsifo = new NodeLabelsInfo(); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("a")); response = r.path("ws").path("v1").path("cluster") 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()); nlsifo = new NodeLabelsInfo(); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("b", false)); response = r.path("ws").path("v1").path("cluster") response.getType().toString()); nlsifo = response.getEntity(NodeLabelsInfo.class); assertEquals(2, nlsifo.getNodeLabels().size()); for (NodeLabelInfo nl : nlsifo.getNodeLabelsInfo()) { if (nl.getName().equals("b")) { assertFalse(nl.getExclusivity()); response.getType().toString()); nlsifo = response.getEntity(NodeLabelsInfo.class); assertTrue(nlsifo.getNodeLabelsInfo().contains(new NodeLabelInfo("a")));
newNodeToLabels.getNodeToLabels().entrySet()) { nodeIdToLabels.put(ConverterUtils.toNodeIdWithDefaultPort(nitle.getKey()), new HashSet<String>(nitle.getValue().getNodeLabels()));
NodeLabelsInfo nli = new NodeLabelsInfo(); nli.getNodeLabels().add("a"); ntli.getNodeToLabels().put("nid:0", nli); response = ntli = response.getEntity(NodeToLabelsInfo.class); nli = ntli.getNodeToLabels().get("nid:0"); assertEquals(1, nli.getNodeLabels().size()); assertTrue(nli.getNodeLabels().contains("a"));
@Test public void testLabelInvalidAddition() throws UniformInterfaceException, Exception { WebResource r = resource(); ClientResponse response; // Add a invalid 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); String expectedmessage = "java.io.IOException: label name should only contains" + " {0-9, a-z, A-Z, -, _} and should not started with" + " {-,_}, now it is= a&"; validateJsonExceptionContent(response, expectedmessage); }
@POST @Path("/remove-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response removeFromCluserNodeLabels(final NodeLabelsInfo oldNodeLabels, @Context HttpServletRequest hsr) throws Exception { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { String msg = "Unable to obtain user name, user not authenticated for" + " post to .../remove-node-labels"; throw new AuthorizationException(msg); } if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { String msg = "User " + callerUGI.getShortUserName() + " not authorized" + " for post to .../remove-node-labels "; throw new AuthorizationException(msg); } rm.getRMContext().getNodeLabelManager() .removeFromClusterNodeLabels(new HashSet<String>( oldNodeLabels.getNodeLabels())); return Response.status(Status.OK).build(); }
@Test public void testLabelChangeExclusivity() throws Exception, JSONException { WebResource r = resource(); ClientResponse response; NodeLabelsInfo nlsifo = new NodeLabelsInfo(); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("newlabel", true)); 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); // new info and change exclusivity NodeLabelsInfo nlsinfo2 = new NodeLabelsInfo(); nlsinfo2.getNodeLabelsInfo().add(new NodeLabelInfo("newlabel", false)); response = r.path("ws").path("v1").path("cluster").path("add-node-labels") .queryParam("user.name", userName).accept(MediaType.APPLICATION_JSON) .entity(toJson(nlsinfo2, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); String expectedmessage = "java.io.IOException: Exclusivity cannot be modified for an existing" + " label with : <newlabel:exclusivity=false>"; validateJsonExceptionContent(response, expectedmessage); }
@GET @Path("/get-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr) throws IOException { init(); NodeLabelsInfo ret = new NodeLabelsInfo(rm.getRMContext().getNodeLabelManager() .getClusterNodeLabels()); return ret; }
Set<String>>(); newLabelsForNode.put(nid, new HashSet<String>(newNodeLabelsInfo.getNodeLabels()));
@GET @Path(RMWSConsts.GET_NODE_LABELS) @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr) throws IOException { initForReadableEndpoints(); List<NodeLabel> nodeLabels = rm.getRMContext().getNodeLabelManager().getClusterNodeLabels(); NodeLabelsInfo ret = new NodeLabelsInfo(nodeLabels); return ret; }
Set<String>>(); newLabelsForNode.put(nid, new HashSet<String>(newNodeLabelsInfo.getNodeLabels()));
@GET @Path("/get-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr) throws IOException { init(); NodeLabelsInfo ret = new NodeLabelsInfo(rm.getRMContext().getNodeLabelManager() .getClusterNodeLabels()); return ret; }
newNodeToLabels.getNodeToLabels().entrySet()) { nodeIdToLabels.put(ConverterUtils.toNodeIdWithDefaultPort(nitle.getKey()), new HashSet<String>(nitle.getValue().getNodeLabels()));
@GET @Path("/nodes/{nodeId}/get-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) throws IOException { init(); NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId); return new NodeLabelsInfo( rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid)); }
@POST @Path("/add-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response addToClusterNodeLabels(final NodeLabelsInfo newNodeLabels, @Context HttpServletRequest hsr) throws Exception { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { String msg = "Unable to obtain user name, user not authenticated for" + " post to .../add-node-labels"; throw new AuthorizationException(msg); } if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { String msg = "User " + callerUGI.getShortUserName() + " not authorized" + " for post to .../add-node-labels "; throw new AuthorizationException(msg); } rm.getRMContext().getNodeLabelManager() .addToCluserNodeLabels(new HashSet<String>( newNodeLabels.getNodeLabels())); return Response.status(Status.OK).build(); }
@GET @Path("/nodes/{nodeId}/get-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) throws IOException { init(); NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId); return new NodeLabelsInfo( rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid)); }
@POST @Path("/remove-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response removeFromCluserNodeLabels(final NodeLabelsInfo oldNodeLabels, @Context HttpServletRequest hsr) throws Exception { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { String msg = "Unable to obtain user name, user not authenticated for" + " post to .../remove-node-labels"; throw new AuthorizationException(msg); } if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { String msg = "User " + callerUGI.getShortUserName() + " not authorized" + " for post to .../remove-node-labels "; throw new AuthorizationException(msg); } rm.getRMContext().getNodeLabelManager() .removeFromClusterNodeLabels(new HashSet<String>( oldNodeLabels.getNodeLabels())); return Response.status(Status.OK).build(); }
@GET @Path("/get-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr) throws IOException { init(); NodeToLabelsInfo ntl = new NodeToLabelsInfo(); HashMap<String, NodeLabelsInfo> ntlMap = ntl.getNodeToLabels(); Map<NodeId, Set<String>> nodeIdToLabels = rm.getRMContext().getNodeLabelManager().getNodeLabels(); for (Map.Entry<NodeId, Set<String>> nitle : nodeIdToLabels.entrySet()) { ntlMap.put(nitle.getKey().toString(), new NodeLabelsInfo(nitle.getValue())); } return ntl; }
@POST @Path("/add-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response addToClusterNodeLabels(final NodeLabelsInfo newNodeLabels, @Context HttpServletRequest hsr) throws Exception { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { String msg = "Unable to obtain user name, user not authenticated for" + " post to .../add-node-labels"; throw new AuthorizationException(msg); } if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { String msg = "User " + callerUGI.getShortUserName() + " not authorized" + " for post to .../add-node-labels "; throw new AuthorizationException(msg); } rm.getRMContext().getNodeLabelManager() .addToCluserNodeLabels(new HashSet<String>( newNodeLabels.getNodeLabels())); return Response.status(Status.OK).build(); }
@GET @Path("/get-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr) throws IOException { init(); NodeToLabelsInfo ntl = new NodeToLabelsInfo(); HashMap<String, NodeLabelsInfo> ntlMap = ntl.getNodeToLabels(); Map<NodeId, Set<String>> nodeIdToLabels = rm.getRMContext().getNodeLabelManager().getNodeLabels(); for (Map.Entry<NodeId, Set<String>> nitle : nodeIdToLabels.entrySet()) { ntlMap.put(nitle.getKey().toString(), new NodeLabelsInfo(nitle.getValue())); } return ntl; }