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 50c450b..d8e5cb7 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 @@ -151,6 +151,7 @@ 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.NodeLabelInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelStatsInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsEntry; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsEntryList; @@ -187,6 +188,7 @@ import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import com.google.common.annotations.VisibleForTesting; +import com.google.common.io.Resources; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -995,7 +997,41 @@ public Response removeFromCluserNodeLabels( return Response.status(Status.OK).build(); } - + + @GET + @Path("/label-stats") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public NodeLabelStatsInfo getLabelStats(@QueryParam("label") String label) + throws IOException, YarnException { + init(); + + NodeLabelStatsInfo nlsi = null; + Map> labelsToNodeId = null; + Set labels = new HashSet(); + + if (label == null) { + throw new YarnException("Requested node label shouldn't be null"); + } + + labels.add(label); + labelsToNodeId = rm.getRMContext().getNodeLabelManager() + .getLabelsInfoToNodes(labels); + + Set nodes = null; + List nodeIdStrList = new ArrayList(); + if ((nodes = labelsToNodeId.get(labels)) != null) { + for (NodeId nodeId : nodes) { + nodeIdStrList.add(nodeId.toString()); + } + } + + Resource labelResource = rm.getRMContext().getNodeLabelManager() + .getResourceByLabel(label, Resource.newInstance(0, 0)); + nlsi = new NodeLabelStatsInfo(label, nodeIdStrList, labelResource); + + return nlsi; + } + @GET @Path("/nodes/{nodeId}/get-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) 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/NodeLabelStatsInfo.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/NodeLabelStatsInfo.java new file mode 100644 index 0000000..5e3dc98 --- /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/NodeLabelStatsInfo.java @@ -0,0 +1,65 @@ +/** + * 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.List; + +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.Resource; + +@XmlRootElement(name = "nodeLabelStatsInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class NodeLabelStatsInfo { + + private String name; + private List nodes; + private long totalResourceMem; + private long totalResourceCores; + + public NodeLabelStatsInfo() { + // JAXB needs this + } + + public NodeLabelStatsInfo(String label, List nodes, + Resource partitionResource) { + this.name = label; + this.nodes = nodes; + this.totalResourceMem = partitionResource.getMemory(); + this.totalResourceCores = partitionResource.getVirtualCores(); + } + + public List getNodes() { + return nodes; + } + + public long getPartitionResourceMemory() { + return totalResourceMem; + } + + public long getPartitionResourceCores() { + return totalResourceCores; + } + + public String getName() { + return name; + } +} -- 2.7.4 (Apple Git-66)