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.Stable;
024import org.apache.hadoop.classification.InterfaceStability.Unstable;
025import org.apache.hadoop.yarn.util.Records;
026
027/**
028 * <p><code>ContainerStatus</code> represents the current status of a 
029 * <code>Container</code>.</p>
030 * 
031 * <p>It provides details such as:
032 *   <ul>
033 *     <li><code>ContainerId</code> of the container.</li>
034 *     <li><code>ContainerState</code> of the container.</li>
035 *     <li><em>Exit status</em> of a completed container.</li>
036 *     <li><em>Diagnostic</em> message for a failed container.</li>
037 *   </ul>
038 * </p>
039 */
040@Public
041@Stable
042public abstract class ContainerStatus {
043
044  @Private
045  @Unstable
046  public static ContainerStatus newInstance(ContainerId containerId,
047      ContainerState containerState, String diagnostics, int exitStatus) {
048    ContainerStatus containerStatus = Records.newRecord(ContainerStatus.class);
049    containerStatus.setState(containerState);
050    containerStatus.setContainerId(containerId);
051    containerStatus.setDiagnostics(diagnostics);
052    containerStatus.setExitStatus(exitStatus);
053    return containerStatus;
054  }
055
056  /**
057   * Get the <code>ContainerId</code> of the container.
058   * @return <code>ContainerId</code> of the container
059   */
060  @Public
061  @Stable
062  public abstract ContainerId getContainerId();
063  
064  @Private
065  @Unstable
066  public abstract void setContainerId(ContainerId containerId);
067
068  /**
069   * Get the <code>ContainerState</code> of the container.
070   * @return <code>ContainerState</code> of the container
071   */
072  @Public
073  @Stable
074  public abstract ContainerState getState();
075  
076  @Private
077  @Unstable
078  public abstract void setState(ContainerState state);
079
080  /**
081   * <p>Get the <em>exit status</em> for the container.</p>
082   *  
083   * <p>Note: This is valid only for completed containers i.e. containers
084   * with state {@link ContainerState#COMPLETE}. 
085   * Otherwise, it returns an ContainerExitStatus.INVALID.
086   * </p>
087   * 
088   * <p>Containers killed by the framework, either due to being released by
089   * the application or being 'lost' due to node failures etc. have a special
090   * exit code of ContainerExitStatus.ABORTED.</p>
091   * 
092   * <p>When threshold number of the nodemanager-local-directories or
093   * threshold number of the nodemanager-log-directories become bad, then
094   * container is not launched and is exited with ContainersExitStatus.DISKS_FAILED.
095   * </p>
096   *  
097   * @return <em>exit status</em> for the container
098   */
099  @Public
100  @Unstable
101  public abstract int getExitStatus();
102  
103  @Private
104  @Unstable
105  public abstract void setExitStatus(int exitStatus);
106
107  /**
108   * Get <em>diagnostic messages</em> for failed containers.
109   * @return <em>diagnostic messages</em> for failed containers
110   */
111  @Public
112  @Stable
113  public abstract String getDiagnostics();
114  
115  @Private
116  @Unstable
117  public abstract void setDiagnostics(String diagnostics);
118}