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