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.rmapp; 20 21 import java.util.Collection; 22 import java.util.LinkedHashMap; 23 import java.util.Map; 24 import java.util.Set; 25 26 import org.apache.hadoop.yarn.MockApps; 27 import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; 28 import org.apache.hadoop.yarn.api.records.ApplicationId; 29 import org.apache.hadoop.yarn.api.records.ApplicationReport; 30 import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; 31 import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; 32 import org.apache.hadoop.yarn.api.records.NodeId; 33 import org.apache.hadoop.yarn.api.records.ReservationId; 34 import org.apache.hadoop.yarn.api.records.Resource; 35 import org.apache.hadoop.yarn.api.records.ResourceRequest; 36 import org.apache.hadoop.yarn.api.records.YarnApplicationState; 37 import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationSubmissionContextPBImpl; 38 import org.apache.hadoop.yarn.conf.YarnConfiguration; 39 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; 40 import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; 41 42 public class MockRMApp implements RMApp { 43 static final int DT = 1000000; // ms 44 45 String user = MockApps.newUserName(); 46 String name = MockApps.newAppName(); 47 String queue = MockApps.newQueue(); 48 long start = System.currentTimeMillis() - (int) (Math.random() * DT); 49 long submit = start - (int) (Math.random() * DT); 50 long finish = 0; 51 RMAppState state = RMAppState.NEW; 52 int failCount = 0; 53 ApplicationId id; 54 String url = null; 55 String oUrl = null; 56 StringBuilder diagnostics = new StringBuilder(); 57 RMAppAttempt attempt; 58 int maxAppAttempts = 1; 59 ResourceRequest amReq; 60 MockRMApp(int newid, long time, RMAppState newState)61 public MockRMApp(int newid, long time, RMAppState newState) { 62 finish = time; 63 id = MockApps.newAppID(newid); 64 state = newState; 65 } 66 MockRMApp(int newid, long time, RMAppState newState, String userName)67 public MockRMApp(int newid, long time, RMAppState newState, String userName) { 68 this(newid, time, newState); 69 user = userName; 70 } 71 MockRMApp(int newid, long time, RMAppState newState, String userName, String diag)72 public MockRMApp(int newid, long time, RMAppState newState, String userName, String diag) { 73 this(newid, time, newState, userName); 74 this.diagnostics = new StringBuilder(diag); 75 } 76 77 @Override getApplicationId()78 public ApplicationId getApplicationId() { 79 return id; 80 } 81 82 @Override getApplicationSubmissionContext()83 public ApplicationSubmissionContext getApplicationSubmissionContext() { 84 return new ApplicationSubmissionContextPBImpl(); 85 } 86 87 @Override getState()88 public RMAppState getState() { 89 return state; 90 } 91 setState(RMAppState state)92 public void setState(RMAppState state) { 93 this.state = state; 94 } 95 96 @Override getUser()97 public String getUser() { 98 return user; 99 } 100 setUser(String user)101 public void setUser(String user) { 102 this.user = user; 103 } 104 105 @Override getProgress()106 public float getProgress() { 107 return (float) 0.0; 108 } 109 110 @Override getRMAppAttempt(ApplicationAttemptId appAttemptId)111 public RMAppAttempt getRMAppAttempt(ApplicationAttemptId appAttemptId) { 112 throw new UnsupportedOperationException("Not supported yet."); 113 } 114 115 @Override getQueue()116 public String getQueue() { 117 return queue; 118 } 119 setQueue(String queue)120 public void setQueue(String queue) { 121 this.queue = queue; 122 } 123 124 @Override getName()125 public String getName() { 126 return name; 127 } 128 setName(String name)129 public void setName(String name) { 130 this.name = name; 131 } 132 133 @Override getAppAttempts()134 public Map<ApplicationAttemptId, RMAppAttempt> getAppAttempts() { 135 Map<ApplicationAttemptId, RMAppAttempt> attempts = 136 new LinkedHashMap<ApplicationAttemptId, RMAppAttempt>(); 137 if(attempt != null) { 138 attempts.put(attempt.getAppAttemptId(), attempt); 139 } 140 return attempts; 141 } 142 143 @Override getCurrentAppAttempt()144 public RMAppAttempt getCurrentAppAttempt() { 145 return attempt; 146 } 147 setCurrentAppAttempt(RMAppAttempt attempt)148 public void setCurrentAppAttempt(RMAppAttempt attempt) { 149 this.attempt = attempt; 150 } 151 152 @Override createAndGetApplicationReport( String clientUserName, boolean allowAccess)153 public ApplicationReport createAndGetApplicationReport( 154 String clientUserName, boolean allowAccess) { 155 throw new UnsupportedOperationException("Not supported yet."); 156 } 157 158 @Override getFinishTime()159 public long getFinishTime() { 160 return finish; 161 } 162 setFinishTime(long time)163 public void setFinishTime(long time) { 164 this.finish = time; 165 } 166 167 @Override getStartTime()168 public long getStartTime() { 169 return start; 170 } 171 172 @Override getSubmitTime()173 public long getSubmitTime() { 174 return submit; 175 } 176 setStartTime(long time)177 public void setStartTime(long time) { 178 this.start = time; 179 } 180 181 @Override getTrackingUrl()182 public String getTrackingUrl() { 183 return url; 184 } 185 setTrackingUrl(String url)186 public void setTrackingUrl(String url) { 187 this.url = url; 188 } 189 190 @Override getOriginalTrackingUrl()191 public String getOriginalTrackingUrl() { 192 return oUrl; 193 } 194 setOriginalTrackingUrl(String oUrl)195 public void setOriginalTrackingUrl(String oUrl) { 196 this.oUrl = oUrl; 197 } 198 199 @Override getDiagnostics()200 public StringBuilder getDiagnostics() { 201 return diagnostics; 202 } 203 setDiagnostics(String diag)204 public void setDiagnostics(String diag) { 205 this.diagnostics = new StringBuilder(diag); 206 } 207 208 @Override getMaxAppAttempts()209 public int getMaxAppAttempts() { 210 return maxAppAttempts; 211 } 212 setNumMaxRetries(int maxAppAttempts)213 public void setNumMaxRetries(int maxAppAttempts) { 214 this.maxAppAttempts = maxAppAttempts; 215 } 216 217 @Override handle(RMAppEvent event)218 public void handle(RMAppEvent event) { 219 } 220 221 @Override getFinalApplicationStatus()222 public FinalApplicationStatus getFinalApplicationStatus() { 223 return FinalApplicationStatus.UNDEFINED; 224 } 225 226 @Override pullRMNodeUpdates(Collection<RMNode> updatedNodes)227 public int pullRMNodeUpdates(Collection<RMNode> updatedNodes) { 228 throw new UnsupportedOperationException("Not supported yet."); 229 } 230 231 @Override getApplicationType()232 public String getApplicationType() { 233 return YarnConfiguration.DEFAULT_APPLICATION_TYPE; 234 } 235 236 @Override getApplicationTags()237 public Set<String> getApplicationTags() { 238 return null; 239 } 240 241 @Override isAppFinalStateStored()242 public boolean isAppFinalStateStored() { 243 return true; 244 } 245 246 @Override createApplicationState()247 public YarnApplicationState createApplicationState() { 248 return null; 249 } 250 251 @Override getRanNodes()252 public Set<NodeId> getRanNodes() { 253 return null; 254 } 255 getResourcePreempted()256 public Resource getResourcePreempted() { 257 throw new UnsupportedOperationException("Not supported yet."); 258 } 259 260 @Override getRMAppMetrics()261 public RMAppMetrics getRMAppMetrics() { 262 throw new UnsupportedOperationException("Not supported yet."); 263 } 264 265 @Override getReservationId()266 public ReservationId getReservationId() { 267 throw new UnsupportedOperationException("Not supported yet."); 268 } 269 270 @Override getAMResourceRequest()271 public ResourceRequest getAMResourceRequest() { 272 return this.amReq; 273 } 274 } 275