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.sls.nodemanager; 20 21 import java.util.ArrayList; 22 import java.util.List; 23 import java.util.Set; 24 25 import org.apache.hadoop.classification.InterfaceAudience.Private; 26 import org.apache.hadoop.classification.InterfaceStability.Unstable; 27 import org.apache.hadoop.net.Node; 28 import org.apache.hadoop.yarn.api.records.ApplicationId; 29 import org.apache.hadoop.yarn.api.records.ContainerExitStatus; 30 import org.apache.hadoop.yarn.api.records.ContainerId; 31 import org.apache.hadoop.yarn.api.records.ContainerState; 32 import org.apache.hadoop.yarn.api.records.ContainerStatus; 33 import org.apache.hadoop.yarn.api.records.NodeId; 34 import org.apache.hadoop.yarn.api.records.NodeState; 35 import org.apache.hadoop.yarn.api.records.Resource; 36 import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse; 37 import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; 38 import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; 39 import org.apache.hadoop.yarn.server.resourcemanager.rmnode 40 .UpdatedContainerInfo; 41 42 @Private 43 @Unstable 44 public class NodeInfo { 45 private static int NODE_ID = 0; 46 newNodeID(String host, int port)47 public static NodeId newNodeID(String host, int port) { 48 return NodeId.newInstance(host, port); 49 } 50 51 @Private 52 @Unstable 53 private static class FakeRMNodeImpl implements RMNode { 54 private NodeId nodeId; 55 private String hostName; 56 private String nodeAddr; 57 private String httpAddress; 58 private int cmdPort; 59 private volatile Resource perNode; 60 private String rackName; 61 private String healthReport; 62 private NodeState state; 63 private List<ContainerId> toCleanUpContainers; 64 private List<ApplicationId> toCleanUpApplications; 65 FakeRMNodeImpl(NodeId nodeId, String nodeAddr, String httpAddress, Resource perNode, String rackName, String healthReport, int cmdPort, String hostName, NodeState state)66 public FakeRMNodeImpl(NodeId nodeId, String nodeAddr, String httpAddress, 67 Resource perNode, String rackName, String healthReport, 68 int cmdPort, String hostName, NodeState state) { 69 this.nodeId = nodeId; 70 this.nodeAddr = nodeAddr; 71 this.httpAddress = httpAddress; 72 this.perNode = perNode; 73 this.rackName = rackName; 74 this.healthReport = healthReport; 75 this.cmdPort = cmdPort; 76 this.hostName = hostName; 77 this.state = state; 78 toCleanUpApplications = new ArrayList<ApplicationId>(); 79 toCleanUpContainers = new ArrayList<ContainerId>(); 80 } 81 getNodeID()82 public NodeId getNodeID() { 83 return nodeId; 84 } 85 getHostName()86 public String getHostName() { 87 return hostName; 88 } 89 getCommandPort()90 public int getCommandPort() { 91 return cmdPort; 92 } 93 getHttpPort()94 public int getHttpPort() { 95 return 0; 96 } 97 getNodeAddress()98 public String getNodeAddress() { 99 return nodeAddr; 100 } 101 getHttpAddress()102 public String getHttpAddress() { 103 return httpAddress; 104 } 105 getHealthReport()106 public String getHealthReport() { 107 return healthReport; 108 } 109 getLastHealthReportTime()110 public long getLastHealthReportTime() { 111 return 0; 112 } 113 getTotalCapability()114 public Resource getTotalCapability() { 115 return perNode; 116 } 117 getRackName()118 public String getRackName() { 119 return rackName; 120 } 121 getNode()122 public Node getNode() { 123 throw new UnsupportedOperationException("Not supported yet."); 124 } 125 getState()126 public NodeState getState() { 127 return state; 128 } 129 getContainersToCleanUp()130 public List<ContainerId> getContainersToCleanUp() { 131 return toCleanUpContainers; 132 } 133 getAppsToCleanup()134 public List<ApplicationId> getAppsToCleanup() { 135 return toCleanUpApplications; 136 } 137 updateNodeHeartbeatResponseForCleanup( NodeHeartbeatResponse response)138 public void updateNodeHeartbeatResponseForCleanup( 139 NodeHeartbeatResponse response) { 140 } 141 getLastNodeHeartBeatResponse()142 public NodeHeartbeatResponse getLastNodeHeartBeatResponse() { 143 return null; 144 } 145 resetLastNodeHeartBeatResponse()146 public void resetLastNodeHeartBeatResponse() { 147 } 148 pullContainerUpdates()149 public List<UpdatedContainerInfo> pullContainerUpdates() { 150 ArrayList<UpdatedContainerInfo> list = new ArrayList<UpdatedContainerInfo>(); 151 152 ArrayList<ContainerStatus> list2 = new ArrayList<ContainerStatus>(); 153 for(ContainerId cId : this.toCleanUpContainers) { 154 list2.add(ContainerStatus.newInstance(cId, ContainerState.RUNNING, "", 155 ContainerExitStatus.SUCCESS)); 156 } 157 list.add(new UpdatedContainerInfo(new ArrayList<ContainerStatus>(), 158 list2)); 159 return list; 160 } 161 162 @Override getNodeManagerVersion()163 public String getNodeManagerVersion() { 164 return null; 165 } 166 167 @Override getNodeLabels()168 public Set<String> getNodeLabels() { 169 return RMNodeLabelsManager.EMPTY_STRING_SET; 170 } 171 } 172 newNodeInfo(String rackName, String hostName, final Resource resource, int port)173 public static RMNode newNodeInfo(String rackName, String hostName, 174 final Resource resource, int port) { 175 final NodeId nodeId = newNodeID(hostName, port); 176 final String nodeAddr = hostName + ":" + port; 177 final String httpAddress = hostName; 178 179 return new FakeRMNodeImpl(nodeId, nodeAddr, httpAddress, 180 resource, rackName, "Me good", 181 port, hostName, null); 182 } 183 newNodeInfo(String rackName, String hostName, final Resource resource)184 public static RMNode newNodeInfo(String rackName, String hostName, 185 final Resource resource) { 186 return newNodeInfo(rackName, hostName, resource, NODE_ID++); 187 } 188 } 189