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;
020
021import java.io.IOException;
022
023import org.apache.hadoop.classification.InterfaceAudience.Public;
024import org.apache.hadoop.classification.InterfaceStability.Stable;
025import org.apache.hadoop.classification.InterfaceStability.Unstable;
026import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest;
027import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse;
028import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest;
029import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse;
030import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationRequest;
031import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationResponse;
032import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerRequest;
033import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerResponse;
034import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest;
035import org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest;
036import org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse;
037import org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest;
038import org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse;
039import org.apache.hadoop.yarn.api.records.Container;
040import org.apache.hadoop.yarn.api.records.ContainerId;
041import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
042import org.apache.hadoop.yarn.api.records.ContainerStatus;
043import org.apache.hadoop.yarn.exceptions.NMNotYetReadyException;
044import org.apache.hadoop.yarn.exceptions.YarnException;
045
046/**
047 * <p>The protocol between an <code>ApplicationMaster</code> and a 
048 * <code>NodeManager</code> to start/stop and increase resource of containers
049 * and to get status of running containers.</p>
050 *
051 * <p>If security is enabled the <code>NodeManager</code> verifies that the
052 * <code>ApplicationMaster</code> has truly been allocated the container
053 * by the <code>ResourceManager</code> and also verifies all interactions such 
054 * as stopping the container or obtaining status information for the container.
055 * </p>
056 */
057@Public
058@Stable
059public interface ContainerManagementProtocol {
060
061  /**
062   * <p>
063   * The <code>ApplicationMaster</code> provides a list of
064   * {@link StartContainerRequest}s to a <code>NodeManager</code> to
065   * <em>start</em> {@link Container}s allocated to it using this interface.
066   * </p>
067   * 
068   * <p>
069   * The <code>ApplicationMaster</code> has to provide details such as allocated
070   * resource capability, security tokens (if enabled), command to be executed
071   * to start the container, environment for the process, necessary
072   * binaries/jar/shared-objects etc. via the {@link ContainerLaunchContext} in
073   * the {@link StartContainerRequest}.
074   * </p>
075   * 
076   * <p>
077   * The <code>NodeManager</code> sends a response via
078   * {@link StartContainersResponse} which includes a list of
079   * {@link Container}s of successfully launched {@link Container}s, a
080   * containerId-to-exception map for each failed {@link StartContainerRequest} in
081   * which the exception indicates errors from per container and a
082   * allServicesMetaData map between the names of auxiliary services and their
083   * corresponding meta-data. Note: None-container-specific exceptions will
084   * still be thrown by the API method itself.
085   * </p>
086   * <p>
087   * The <code>ApplicationMaster</code> can use
088   * {@link #getContainerStatuses(GetContainerStatusesRequest)} to get updated
089   * statuses of the to-be-launched or launched containers.
090   * </p>
091   * 
092   * @param request
093   *          request to start a list of containers
094   * @return response including conatinerIds of all successfully launched
095   *         containers, a containerId-to-exception map for failed requests and
096   *         a allServicesMetaData map.
097   * @throws YarnException
098   * @throws IOException
099   * @throws NMNotYetReadyException
100   *           This exception is thrown when NM starts from scratch but has not
101   *           yet connected with RM.
102   */
103  @Public
104  @Stable
105  StartContainersResponse startContainers(StartContainersRequest request)
106      throws YarnException, IOException;
107
108  /**
109   * <p>
110   * The <code>ApplicationMaster</code> requests a <code>NodeManager</code> to
111   * <em>stop</em> a list of {@link Container}s allocated to it using this
112   * interface.
113   * </p>
114   * 
115   * <p>
116   * The <code>ApplicationMaster</code> sends a {@link StopContainersRequest}
117   * which includes the {@link ContainerId}s of the containers to be stopped.
118   * </p>
119   * 
120   * <p>
121   * The <code>NodeManager</code> sends a response via
122   * {@link StopContainersResponse} which includes a list of {@link ContainerId}
123   * s of successfully stopped containers, a containerId-to-exception map for
124   * each failed request in which the exception indicates errors from per
125   * container. Note: None-container-specific exceptions will still be thrown by
126   * the API method itself. <code>ApplicationMaster</code> can use
127   * {@link #getContainerStatuses(GetContainerStatusesRequest)} to get updated
128   * statuses of the containers.
129   * </p>
130   * 
131   * @param request
132   *          request to stop a list of containers
133   * @return response which includes a list of containerIds of successfully
134   *         stopped containers, a containerId-to-exception map for failed
135   *         requests.
136   * @throws YarnException
137   * @throws IOException
138   */
139  @Public
140  @Stable
141  StopContainersResponse stopContainers(StopContainersRequest request)
142      throws YarnException, IOException;
143
144  /**
145   * <p>
146   * The API used by the <code>ApplicationMaster</code> to request for current
147   * statuses of <code>Container</code>s from the <code>NodeManager</code>.
148   * </p>
149   * 
150   * <p>
151   * The <code>ApplicationMaster</code> sends a
152   * {@link GetContainerStatusesRequest} which includes the {@link ContainerId}s
153   * of all containers whose statuses are needed.
154   * </p>
155   * 
156   * <p>
157   * The <code>NodeManager</code> responds with
158   * {@link GetContainerStatusesResponse} which includes a list of
159   * {@link ContainerStatus} of the successfully queried containers and a
160   * containerId-to-exception map for each failed request in which the exception
161   * indicates errors from per container. Note: None-container-specific
162   * exceptions will still be thrown by the API method itself.
163   * </p>
164   * 
165   * @param request
166   *          request to get <code>ContainerStatus</code>es of containers with
167   *          the specified <code>ContainerId</code>s
168   * @return response containing the list of <code>ContainerStatus</code> of the
169   *         successfully queried containers and a containerId-to-exception map
170   *         for failed requests.
171   * 
172   * @throws YarnException
173   * @throws IOException
174   */
175  @Public
176  @Stable
177  GetContainerStatusesResponse getContainerStatuses(
178      GetContainerStatusesRequest request) throws YarnException,
179      IOException;
180
181  /**
182   * <p>
183   * The API used by the <code>ApplicationMaster</code> to request for
184   * resource increase of running containers on the <code>NodeManager</code>.
185   * </p>
186   *
187   * @param request
188   *         request to increase resource of a list of containers
189   * @return response which includes a list of containerIds of containers
190   *         whose resource has been successfully increased and a
191   *         containerId-to-exception map for failed requests.
192   *
193   * @throws YarnException
194   * @throws IOException
195   */
196  @Public
197  @Unstable
198  IncreaseContainersResourceResponse increaseContainersResource(
199      IncreaseContainersResourceRequest request) throws YarnException,
200      IOException;
201
202  SignalContainerResponse signalToContainer(SignalContainerRequest request)
203      throws YarnException, IOException;
204
205  /**
206   * Localize resources required by the container.
207   * Currently, this API only works for running containers.
208   *
209   * @param request Specify the resources to be localized.
210   * @return Response that the localize request is accepted.
211   * @throws YarnException Exception specific to YARN
212   * @throws IOException IOException thrown from the RPC layer.
213   */
214  @Public
215  @Unstable
216  ResourceLocalizationResponse localize(ResourceLocalizationRequest request)
217    throws YarnException, IOException;
218}