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; 20 21 import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES_ID; 22 23 import org.apache.hadoop.yarn.nodelabels.NodeLabel; 24 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; 25 import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; 26 import org.apache.hadoop.yarn.webapp.SubView; 27 import org.apache.hadoop.yarn.webapp.YarnWebParams; 28 import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; 29 import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE; 30 import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TBODY; 31 import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TR; 32 import org.apache.hadoop.yarn.webapp.view.HtmlBlock; 33 34 import com.google.inject.Inject; 35 36 public class NodeLabelsPage extends RmView { 37 static class NodeLabelsBlock extends HtmlBlock { 38 final ResourceManager rm; 39 40 @Inject NodeLabelsBlock(ResourceManager rm, ViewContext ctx)41 NodeLabelsBlock(ResourceManager rm, ViewContext ctx) { 42 super(ctx); 43 this.rm = rm; 44 } 45 46 @Override render(Block html)47 protected void render(Block html) { 48 TBODY<TABLE<Hamlet>> tbody = html.table("#nodelabels"). 49 thead(). 50 tr(). 51 th(".name", "Label Name"). 52 th(".numOfActiveNMs", "Num Of Active NMs"). 53 th(".totalResource", "Total Resource"). 54 _()._(). 55 tbody(); 56 57 RMNodeLabelsManager nlm = rm.getRMContext().getNodeLabelManager(); 58 for (NodeLabel info : nlm.pullRMNodeLabelsInfo()) { 59 TR<TBODY<TABLE<Hamlet>>> row = 60 tbody.tr().td( 61 info.getLabelName().isEmpty() ? "<NO_LABEL>" : info 62 .getLabelName()); 63 int nActiveNMs = info.getNumActiveNMs(); 64 if (nActiveNMs > 0) { 65 row = row.td() 66 .a(url("nodes", 67 "?" + YarnWebParams.NODE_LABEL + "=" + info.getLabelName()), 68 String.valueOf(nActiveNMs)) 69 ._(); 70 } else { 71 row = row.td(String.valueOf(nActiveNMs)); 72 } 73 row.td(info.getResource().toString())._(); 74 } 75 tbody._()._(); 76 } 77 } 78 preHead(Page.HTML<_> html)79 @Override protected void preHead(Page.HTML<_> html) { 80 commonPreHead(html); 81 String title = "Node labels of the cluster"; 82 setTitle(title); 83 set(DATATABLES_ID, "nodelabels"); 84 setTableStyles(html, "nodelabels", ".healthStatus {width:10em}", 85 ".healthReport {width:10em}"); 86 } 87 content()88 @Override protected Class<? extends SubView> content() { 89 return NodeLabelsBlock.class; 90 } 91 } 92