1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; 20 21 import javax.xml.bind.annotation.XmlAccessType; 22 import javax.xml.bind.annotation.XmlAccessorType; 23 import javax.xml.bind.annotation.XmlRootElement; 24 import javax.xml.bind.annotation.XmlTransient; 25 import javax.xml.bind.annotation.XmlType; 26 27 import org.apache.hadoop.yarn.api.records.QueueInfo; 28 import org.apache.hadoop.yarn.api.records.QueueState; 29 import org.apache.hadoop.yarn.server.resourcemanager.RMContext; 30 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; 31 import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; 32 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNodeReport; 33 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; 34 35 @XmlRootElement(name = "fifoScheduler") 36 @XmlType(name = "fifoScheduler") 37 @XmlAccessorType(XmlAccessType.FIELD) 38 public class FifoSchedulerInfo extends SchedulerInfo { 39 40 protected float capacity; 41 protected float usedCapacity; 42 protected QueueState qstate; 43 protected int minQueueMemoryCapacity; 44 protected int maxQueueMemoryCapacity; 45 protected int numNodes; 46 protected int usedNodeCapacity; 47 protected int availNodeCapacity; 48 protected int totalNodeCapacity; 49 protected int numContainers; 50 51 @XmlTransient 52 protected String qstateFormatted; 53 54 @XmlTransient 55 protected String qName; 56 FifoSchedulerInfo()57 public FifoSchedulerInfo() { 58 } // JAXB needs this 59 FifoSchedulerInfo(final ResourceManager rm)60 public FifoSchedulerInfo(final ResourceManager rm) { 61 62 RMContext rmContext = rm.getRMContext(); 63 64 FifoScheduler fs = (FifoScheduler) rm.getResourceScheduler(); 65 qName = fs.getQueueInfo("", false, false).getQueueName(); 66 QueueInfo qInfo = fs.getQueueInfo(qName, true, true); 67 68 this.usedCapacity = qInfo.getCurrentCapacity(); 69 this.capacity = qInfo.getCapacity(); 70 this.minQueueMemoryCapacity = fs.getMinimumResourceCapability().getMemory(); 71 this.maxQueueMemoryCapacity = fs.getMaximumResourceCapability().getMemory(); 72 this.qstate = qInfo.getQueueState(); 73 74 this.numNodes = rmContext.getRMNodes().size(); 75 this.usedNodeCapacity = 0; 76 this.availNodeCapacity = 0; 77 this.totalNodeCapacity = 0; 78 this.numContainers = 0; 79 80 for (RMNode ni : rmContext.getRMNodes().values()) { 81 SchedulerNodeReport report = fs.getNodeReport(ni.getNodeID()); 82 this.usedNodeCapacity += report.getUsedResource().getMemory(); 83 this.availNodeCapacity += report.getAvailableResource().getMemory(); 84 this.totalNodeCapacity += ni.getTotalCapability().getMemory(); 85 this.numContainers += fs.getNodeReport(ni.getNodeID()).getNumContainers(); 86 } 87 } 88 getNumNodes()89 public int getNumNodes() { 90 return this.numNodes; 91 } 92 getUsedNodeCapacity()93 public int getUsedNodeCapacity() { 94 return this.usedNodeCapacity; 95 } 96 getAvailNodeCapacity()97 public int getAvailNodeCapacity() { 98 return this.availNodeCapacity; 99 } 100 getTotalNodeCapacity()101 public int getTotalNodeCapacity() { 102 return this.totalNodeCapacity; 103 } 104 getNumContainers()105 public int getNumContainers() { 106 return this.numContainers; 107 } 108 getState()109 public String getState() { 110 return this.qstate.toString(); 111 } 112 getQueueName()113 public String getQueueName() { 114 return this.qName; 115 } 116 getMinQueueMemoryCapacity()117 public int getMinQueueMemoryCapacity() { 118 return this.minQueueMemoryCapacity; 119 } 120 getMaxQueueMemoryCapacity()121 public int getMaxQueueMemoryCapacity() { 122 return this.maxQueueMemoryCapacity; 123 } 124 getCapacity()125 public float getCapacity() { 126 return this.capacity; 127 } 128 getUsedCapacity()129 public float getUsedCapacity() { 130 return this.usedCapacity; 131 } 132 133 } 134