diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java 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 87c895a..0f71586 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java @@ -133,6 +133,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.webapp.BadRequestException; @@ -715,6 +716,216 @@ public Response updateAppState(AppState targetState, return Response.status(Status.OK).entity(ret).build(); } + + @GET + @Path("/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; + } + + @POST + @Path("/node-labels") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response addToCluserNodeLabels(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 .../node-labels"; + throw new AuthorizationException(msg); + } + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for post to .../node-labels "; + throw new AuthorizationException(msg); + } + + rm.getRMContext().getNodeLabelManager() + .addToCluserNodeLabels(new HashSet( + newNodeLabels.getNodeLabels())); + + return Response.status(Status.OK).build(); + + } + + @DELETE + @Path("/node-labels/{nodeLabel}") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public void removeFromClusterNodeLabels(@Context HttpServletRequest hsr, + @PathParam("nodeLabel") String nodeLabel) + throws Exception { + init(); + + UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); + if (callerUGI == null) { + String msg = "Unable to obtain user name, user not authenticated for" + + " delete on .../node-labels"; + throw new AuthorizationException(msg); + } + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for delete on .../node-labels "; + throw new AuthorizationException(msg); + } + + rm.getRMContext().getNodeLabelManager() + .removeFromClusterNodeLabels(Arrays.asList(nodeLabel)); + + } + + @GET + @Path("/nodes/{nodeId}/labels") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, + @PathParam("nodeId") String nodeId) + throws IOException { + init(); + + NodeId nid = ConverterUtils.toNodeId(nodeId); + return new NodeLabelsInfo( + rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid)); + + } + + @POST + @Path("/nodes/{nodeId}/labels") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response addLabelsToNode(NodeLabelsInfo newNodeLabelsInfo, + @Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) + throws Exception { + init(); + + UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); + if (callerUGI == null) { + String msg = "Unable to obtain user name, user not authenticated for" + + " post to .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for post to .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + + NodeId nid = ConverterUtils.toNodeId(nodeId); + + Map> newLabelsForNode = new HashMap>(); + + newLabelsForNode.put(nid, new HashSet(newNodeLabelsInfo.getNodeLabels())); + + rm.getRMContext().getNodeLabelManager().addLabelsToNode(newLabelsForNode); + + return Response.status(Status.OK).build(); + + } + + @DELETE + @Path("/nodes/{nodeId}/labels/{nodeLabel}") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public void removeLabelsFromNode(@Context HttpServletRequest hsr, + @PathParam("nodeId") String nodeId, + @PathParam("nodeLabel") String nodeLabel) + throws Exception { + init(); + + UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); + if (callerUGI == null) { + String msg = "Unable to obtain user name, user not authenticated for" + + " delete on .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for delete on .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + + NodeId nid = ConverterUtils.toNodeId(nodeId); + + Map> rmLabelsFromNode = new HashMap>(); + + rmLabelsFromNode.put(nid, new HashSet(Arrays.asList(nodeLabel))); + + rm.getRMContext().getNodeLabelManager(). + removeLabelsFromNode(rmLabelsFromNode); + + } + + @PUT + @Path("/node-labels/{nodeLabel}") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response addToCluserNodeLabels(@Context HttpServletRequest hsr, + @PathParam("nodeLabel") String nodeLabel) + throws Exception { + init(); + + UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); + if (callerUGI == null) { + String msg = "Unable to obtain user name, user not authenticated for" + + " put to .../node-labels"; + throw new AuthorizationException(msg); + } + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for put to .../node-labels"; + throw new AuthorizationException(msg); + } + + rm.getRMContext().getNodeLabelManager() + .addToCluserNodeLabels(new HashSet(Arrays.asList(nodeLabel))); + + return Response.status(Status.OK).build(); + + } + + @PUT + @Path("/nodes/{nodeId}/labels/{nodeLabel}") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response addLabelsToNode(@Context HttpServletRequest hsr, + @PathParam("nodeId") String nodeId, + @PathParam("nodeLabel") String nodeLabel) + throws Exception { + init(); + + UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); + if (callerUGI == null) { + String msg = "Unable to obtain user name, user not authenticated for" + + " put to .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + + if (!rm.getRMContext().getNodeLabelManager().checkAccess(callerUGI)) { + String msg = "User " + callerUGI.getShortUserName() + " not authorized" + + " for put to .../nodes/nodeid/labels"; + throw new AuthorizationException(msg); + } + + NodeId nid = ConverterUtils.toNodeId(nodeId); + + Map> newLabelsForNode = new HashMap>(); + + newLabelsForNode.put(nid, new HashSet(Arrays.asList(nodeLabel))); + + rm.getRMContext().getNodeLabelManager().addLabelsToNode(newLabelsForNode); + + return Response.status(Status.OK).build(); + + } protected Response killApp(RMApp app, UserGroupInformation callerUGI, HttpServletRequest hsr) throws IOException, InterruptedException { @@ -965,7 +1176,9 @@ protected ApplicationSubmissionContext createAppSubmissionContext( newApp.getCancelTokensWhenComplete(), newApp.getMaxAppAttempts(), createAppSubmissionContextResource(newApp), newApp.getApplicationType(), - newApp.getKeepContainersAcrossApplicationAttempts()); + newApp.getKeepContainersAcrossApplicationAttempts(), + newApp.getAppNodeLabelExpression(), + newApp.getAMContainerNodeLabelExpression()); appContext.setApplicationTags(newApp.getApplicationTags()); return appContext; diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/ApplicationSubmissionContextInfo.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/ApplicationSubmissionContextInfo.java index f7233e6..5278b3e 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/ApplicationSubmissionContextInfo.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/ApplicationSubmissionContextInfo.java @@ -71,6 +71,12 @@ @XmlElementWrapper(name = "application-tags") @XmlElement(name = "tag") Set tags; + + @XmlElement(name = "app-node-label-expression") + String appNodeLabelExpression; + + @XmlElement(name = "am-container-node-label-expression") + String amContainerNodeLabelExpression; public ApplicationSubmissionContextInfo() { applicationId = ""; @@ -83,6 +89,8 @@ public ApplicationSubmissionContextInfo() { keepContainers = false; applicationType = ""; tags = new HashSet(); + appNodeLabelExpression = ""; + amContainerNodeLabelExpression = ""; } public String getApplicationId() { @@ -132,6 +140,14 @@ public boolean getKeepContainersAcrossApplicationAttempts() { public Set getApplicationTags() { return tags; } + + public String getAppNodeLabelExpression() { + return appNodeLabelExpression; + } + + public String getAMContainerNodeLabelExpression() { + return amContainerNodeLabelExpression; + } public void setApplicationId(String applicationId) { this.applicationId = applicationId; @@ -182,5 +198,12 @@ public void setApplicationType(String applicationType) { public void setApplicationTags(Set tags) { this.tags = tags; } + + public void setAppNodeLabelExpression(String appNodeLabelExpression) { + this.appNodeLabelExpression = appNodeLabelExpression; + } + public void setAMContainerNodeLabelExpression(String nodeLabelExpression) { + this.amContainerNodeLabelExpression = nodeLabelExpression; + } }