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, software
013* distributed under the License is distributed on an "AS IS" BASIS,
014* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015* See the License for the specific language governing permissions and
016* limitations under the License.
017*/
018
019package org.apache.hadoop.yarn.api.records;
020
021import org.apache.hadoop.classification.InterfaceAudience.Private;
022import org.apache.hadoop.classification.InterfaceAudience.Public;
023import org.apache.hadoop.classification.InterfaceStability.Evolving;
024import org.apache.hadoop.classification.InterfaceStability.Stable;
025import org.apache.hadoop.classification.InterfaceStability.Unstable;
026import org.apache.hadoop.yarn.util.Records;
027
028import java.util.List;
029
030/**
031 * {@code ContainerStatus} represents the current status of a
032 * {@code Container}.
033 * <p>
034 * It provides details such as:
035 * <ul>
036 *   <li>{@code ContainerId} of the container.</li>
037 *   <li>{@code ExecutionType} of the container.</li>
038 *   <li>{@code ContainerState} of the container.</li>
039 *   <li><em>Exit status</em> of a completed container.</li>
040 *   <li><em>Diagnostic</em> message for a failed container.</li>
041 *   <li>{@link Resource} allocated to the container.</li>
042 * </ul>
043 */
044@Public
045@Stable
046public abstract class ContainerStatus {
047
048  @Private
049  @Unstable
050  public static ContainerStatus newInstance(ContainerId containerId,
051      ContainerState containerState, String diagnostics, int exitStatus) {
052    return newInstance(containerId, ExecutionType.GUARANTEED, containerState,
053        diagnostics, exitStatus);
054  }
055
056  @Private
057  @Unstable
058  public static ContainerStatus newInstance(ContainerId containerId,
059      ExecutionType executionType, ContainerState containerState,
060      String diagnostics, int exitStatus) {
061    ContainerStatus containerStatus = Records.newRecord(ContainerStatus.class);
062    containerStatus.setExecutionType(executionType);
063    containerStatus.setState(containerState);
064    containerStatus.setContainerId(containerId);
065    containerStatus.setDiagnostics(diagnostics);
066    containerStatus.setExitStatus(exitStatus);
067    return containerStatus;
068  }
069
070  /**
071   * Get the <code>ContainerId</code> of the container.
072   * @return <code>ContainerId</code> of the container
073   */
074  @Public
075  @Stable
076  public abstract ContainerId getContainerId();
077  
078  @Private
079  @Unstable
080  public abstract void setContainerId(ContainerId containerId);
081
082  /**
083   * Get the <code>ExecutionType</code> of the container.
084   * @return <code>ExecutionType</code> of the container
085   */
086  @Public
087  @Evolving
088  public abstract ExecutionType getExecutionType();
089
090  @Private
091  @Unstable
092  public abstract void setExecutionType(ExecutionType executionType);
093
094  /**
095   * Get the <code>ContainerState</code> of the container.
096   * @return <code>ContainerState</code> of the container
097   */
098  @Public
099  @Stable
100  public abstract ContainerState getState();
101  
102  @Private
103  @Unstable
104  public abstract void setState(ContainerState state);
105
106  /**
107   * <p>Get the <em>exit status</em> for the container.</p>
108   *  
109   * <p>Note: This is valid only for completed containers i.e. containers
110   * with state {@link ContainerState#COMPLETE}. 
111   * Otherwise, it returns an ContainerExitStatus.INVALID.
112   * </p>
113   * 
114   * <p>Containers killed by the framework, either due to being released by
115   * the application or being 'lost' due to node failures etc. have a special
116   * exit code of ContainerExitStatus.ABORTED.</p>
117   * 
118   * <p>When threshold number of the nodemanager-local-directories or
119   * threshold number of the nodemanager-log-directories become bad, then
120   * container is not launched and is exited with ContainersExitStatus.DISKS_FAILED.
121   * </p>
122   *  
123   * @return <em>exit status</em> for the container
124   */
125  @Public
126  @Unstable
127  public abstract int getExitStatus();
128  
129  @Private
130  @Unstable
131  public abstract void setExitStatus(int exitStatus);
132
133  /**
134   * Get <em>diagnostic messages</em> for failed containers.
135   * @return <em>diagnostic messages</em> for failed containers
136   */
137  @Public
138  @Stable
139  public abstract String getDiagnostics();
140  
141  @Private
142  @Unstable
143  public abstract void setDiagnostics(String diagnostics);
144
145  /**
146   * Get the <code>Resource</code> allocated to the container.
147   * @return <code>Resource</code> allocated to the container
148   */
149  @Public
150  @Unstable
151  public abstract Resource getCapability();
152
153  @Private
154  @Unstable
155  public abstract void setCapability(Resource capability);
156
157  /**
158   * Get all the IP addresses with which the container run.
159   * @return The IP address where the container runs.
160   */
161  @Public
162  @Unstable
163  public abstract List<String> getIPs();
164
165  @Private
166  @Unstable
167  public abstract void setIPs(List<String> ips);
168
169  /**
170   * Get the hostname where the container runs.
171   * @return The hostname where the container runs.
172   */
173  @Public
174  @Unstable
175  public abstract String getHost();
176
177  @Private
178  @Unstable
179  public abstract void setHost(String host);
180}