001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.runtime.hdinsight.client.yarnrest; 020 021import org.codehaus.jackson.annotate.JsonIgnoreProperties; 022import org.codehaus.jackson.annotate.JsonProperty; 023import org.codehaus.jackson.map.ObjectMapper; 024 025import java.io.IOException; 026import java.io.StringWriter; 027 028/** 029 * An object representing the state of an application, 030 * used to deserialize queries for an application/list of applications 031 * to the Resource Manager on HDInsight via the YARN REST API. 032 * For detailed information, please refer to 033 * https://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html 034 */ 035@JsonIgnoreProperties(ignoreUnknown = true) 036public final class ApplicationState { 037 038 private static final String APPLICATION_STATE = "applicationState"; 039 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 040 041 private String progress; 042 private String queue; 043 private String trackingUI; 044 private String state; 045 private String amContainerLogs; 046 private int runningContainers; 047 private int allocatedMB; 048 private long elapsedTime; 049 private String amHostHttpAddress; 050 private String id; 051 private String finalStatus; 052 private String trackingUrl; 053 private int allocatedVCores; 054 private long finishedTime; 055 private String name; 056 private String applicationType; 057 private String clusterId; 058 private String user; 059 private String diagnostics; 060 private long startedTime; 061 private long memorySeconds; 062 private long vCoreSeconds; 063 064 @JsonProperty(Constants.FINISHED_TIME) 065 public long getFinishedTime() { 066 return finishedTime; 067 } 068 069 public void setFinishedTime(final long finishedTime) { 070 this.finishedTime = finishedTime; 071 } 072 073 @JsonProperty(Constants.AM_CONTAINER_LOGS) 074 public String getAmContainerLogs() { 075 return amContainerLogs; 076 } 077 078 public void setAmContainerLogs(final String amContainerLogs) { 079 this.amContainerLogs = amContainerLogs; 080 } 081 082 @JsonProperty(Constants.TRACKING_UI) 083 public String getTrackingUI() { 084 return trackingUI; 085 } 086 087 public void setTrackingUI(final String trackingUI) { 088 this.trackingUI = trackingUI; 089 } 090 091 @JsonProperty(Constants.STATE) 092 public String getState() { 093 return state; 094 } 095 096 public void setState(final String state) { 097 this.state = state; 098 } 099 100 @JsonProperty(Constants.USER) 101 public String getUser() { 102 return user; 103 } 104 105 public void setUser(final String user) { 106 this.user = user; 107 } 108 109 @JsonProperty(Constants.ID) 110 public String getId() { 111 return id; 112 } 113 114 public void setId(final String id) { 115 this.id = id; 116 } 117 118 @JsonProperty(Constants.CLUSTER_ID) 119 public String getClusterId() { 120 return clusterId; 121 } 122 123 public void setClusterId(final String clusterId) { 124 this.clusterId = clusterId; 125 } 126 127 @JsonProperty(Constants.FINAL_STATUS) 128 public String getFinalStatus() { 129 return finalStatus; 130 } 131 132 public void setFinalStatus(final String finalStatus) { 133 this.finalStatus = finalStatus; 134 } 135 136 @JsonProperty(Constants.AM_HOST_HTTP_ADDRESS) 137 public String getAmHostHttpAddress() { 138 return amHostHttpAddress; 139 } 140 141 public void setAmHostHttpAddress(final String amHostHttpAddress) { 142 this.amHostHttpAddress = amHostHttpAddress; 143 } 144 145 @JsonProperty(Constants.PROGRESS) 146 public String getProgress() { 147 return progress; 148 } 149 150 public void setProgress(final String progress) { 151 this.progress = progress; 152 } 153 154 @JsonProperty(Constants.NAME) 155 public String getName() { 156 return name; 157 } 158 159 public void setName(final String name) { 160 this.name = name; 161 } 162 163 @JsonProperty(Constants.RESPONSE_APPLICATION_TYPE) 164 public String getApplicationType() { 165 return applicationType; 166 } 167 168 public void setApplicationType(final String applicationType) { 169 this.applicationType = applicationType; 170 } 171 172 @JsonProperty(Constants.STARTED_TIME) 173 public long getStartedTime() { 174 return startedTime; 175 } 176 177 public void setStartedTime(final long startedTime) { 178 this.startedTime = startedTime; 179 } 180 181 @JsonProperty(Constants.ELAPSED_TIME) 182 public long getElapsedTime() { 183 return elapsedTime; 184 } 185 186 public void setElapsedTime(final long elapsedTime) { 187 this.elapsedTime = elapsedTime; 188 } 189 190 @JsonProperty(Constants.DIAGNOSTICS) 191 public String getDiagnostics() { 192 return diagnostics; 193 } 194 195 public void setDiagnostics(final String diagnostics) { 196 this.diagnostics = diagnostics; 197 } 198 199 @JsonProperty(Constants.TRACKING_URL) 200 public String getTrackingUrl() { 201 return trackingUrl; 202 } 203 204 public void setTrackingUrl(final String trackingUrl) { 205 this.trackingUrl = trackingUrl; 206 } 207 208 @JsonProperty(Constants.QUEUE) 209 public String getQueue() { 210 return queue; 211 } 212 213 public void setQueue(final String queue) { 214 this.queue = queue; 215 } 216 217 @JsonProperty(Constants.ALLOCATED_MB) 218 public int getAllocatedMB() { 219 return allocatedMB; 220 } 221 222 public void setAllocatedMB(final int allocatedMB) { 223 this.allocatedMB = allocatedMB; 224 } 225 226 @JsonProperty(Constants.ALLOCATED_VCORES) 227 public int getAllocatedVCores() { 228 return allocatedVCores; 229 } 230 231 public void setAllocatedVCores(final int allocatedVCores) { 232 this.allocatedVCores = allocatedVCores; 233 } 234 235 @JsonProperty(Constants.RUNNING_CONTAINERS) 236 public int getRunningContainers() { 237 return runningContainers; 238 } 239 240 public void setRunningContainers(final int runningContainers) { 241 this.runningContainers = runningContainers; 242 } 243 244 @JsonProperty(Constants.MEMORY_SECONDS) 245 public long getMemorySeconds() { 246 return memorySeconds; 247 } 248 249 public void setMemorySeconds(final long memorySeconds) { 250 this.memorySeconds = memorySeconds; 251 } 252 253 @JsonProperty(Constants.VCORE_SECONDS) 254 public long getVCoreSeconds() { 255 return vCoreSeconds; 256 } 257 258 @SuppressWarnings("checkstyle:hiddenfield") 259 public void setVCoreSeconds(final long vCoreSeconds) { 260 this.vCoreSeconds = vCoreSeconds; 261 } 262 263 @Override 264 public String toString() { 265 final StringWriter writer = new StringWriter(); 266 final String objectString; 267 try { 268 OBJECT_MAPPER.writeValue(writer, this); 269 objectString = writer.toString(); 270 } catch (final IOException e) { 271 throw new RuntimeException("Exception while serializing ApplicationState: " + e); 272 } 273 274 return APPLICATION_STATE + objectString; 275 } 276}