1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package org.apache.hadoop.yarn.api.protocolrecords;
20 
21 import java.util.List;
22 
23 import org.apache.hadoop.classification.InterfaceAudience.Public;
24 import org.apache.hadoop.classification.InterfaceStability.Stable;
25 import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
26 import org.apache.hadoop.yarn.api.records.Container;
27 import org.apache.hadoop.yarn.api.records.ContainerId;
28 import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest;
29 import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest;
30 import org.apache.hadoop.yarn.api.records.ResourceRequest;
31 import org.apache.hadoop.yarn.util.Records;
32 
33 /**
34  * <p>The core request sent by the <code>ApplicationMaster</code> to the
35  * <code>ResourceManager</code> to obtain resources in the cluster.</p>
36  *
37  * <p>The request includes:
38  * <ul>
39  *   <li>A response id to track duplicate responses.</li>
40  *   <li>Progress information.</li>
41  *   <li>
42  *     A list of {@link ResourceRequest} to inform the
43  *     <code>ResourceManager</code> about the application's
44  *     resource requirements.
45  *   </li>
46  *   <li>
47  *     A list of unused {@link Container} which are being returned.
48  *   </li>
49  * </ul>
50  *
51  * @see ApplicationMasterProtocol#allocate(AllocateRequest)
52  */
53 @Public
54 @Stable
55 public abstract class AllocateRequest {
56 
57   @Public
58   @Stable
newInstance(int responseID, float appProgress, List<ResourceRequest> resourceAsk, List<ContainerId> containersToBeReleased, ResourceBlacklistRequest resourceBlacklistRequest)59   public static AllocateRequest newInstance(int responseID, float appProgress,
60       List<ResourceRequest> resourceAsk,
61       List<ContainerId> containersToBeReleased,
62       ResourceBlacklistRequest resourceBlacklistRequest) {
63     return newInstance(responseID, appProgress, resourceAsk,
64         containersToBeReleased, resourceBlacklistRequest, null);
65   }
66 
67   @Public
68   @Stable
newInstance(int responseID, float appProgress, List<ResourceRequest> resourceAsk, List<ContainerId> containersToBeReleased, ResourceBlacklistRequest resourceBlacklistRequest, List<ContainerResourceIncreaseRequest> increaseRequests)69   public static AllocateRequest newInstance(int responseID, float appProgress,
70       List<ResourceRequest> resourceAsk,
71       List<ContainerId> containersToBeReleased,
72       ResourceBlacklistRequest resourceBlacklistRequest,
73       List<ContainerResourceIncreaseRequest> increaseRequests) {
74     AllocateRequest allocateRequest = Records.newRecord(AllocateRequest.class);
75     allocateRequest.setResponseId(responseID);
76     allocateRequest.setProgress(appProgress);
77     allocateRequest.setAskList(resourceAsk);
78     allocateRequest.setReleaseList(containersToBeReleased);
79     allocateRequest.setResourceBlacklistRequest(resourceBlacklistRequest);
80     allocateRequest.setIncreaseRequests(increaseRequests);
81     return allocateRequest;
82   }
83 
84   /**
85    * Get the <em>response id</em> used to track duplicate responses.
86    * @return <em>response id</em>
87    */
88   @Public
89   @Stable
getResponseId()90   public abstract int getResponseId();
91 
92   /**
93    * Set the <em>response id</em> used to track duplicate responses.
94    * @param id <em>response id</em>
95    */
96   @Public
97   @Stable
setResponseId(int id)98   public abstract void setResponseId(int id);
99 
100   /**
101    * Get the <em>current progress</em> of application.
102    * @return <em>current progress</em> of application
103    */
104   @Public
105   @Stable
getProgress()106   public abstract float getProgress();
107 
108   /**
109    * Set the <em>current progress</em> of application
110    * @param progress <em>current progress</em> of application
111    */
112   @Public
113   @Stable
setProgress(float progress)114   public abstract void setProgress(float progress);
115 
116   /**
117    * Get the list of <code>ResourceRequest</code> to update the
118    * <code>ResourceManager</code> about the application's resource requirements.
119    * @return the list of <code>ResourceRequest</code>
120    * @see ResourceRequest
121    */
122   @Public
123   @Stable
getAskList()124   public abstract List<ResourceRequest> getAskList();
125 
126   /**
127    * Set list of <code>ResourceRequest</code> to update the
128    * <code>ResourceManager</code> about the application's resource requirements.
129    * @param resourceRequests list of <code>ResourceRequest</code> to update the
130    *                        <code>ResourceManager</code> about the application's
131    *                        resource requirements
132    * @see ResourceRequest
133    */
134   @Public
135   @Stable
setAskList(List<ResourceRequest> resourceRequests)136   public abstract void setAskList(List<ResourceRequest> resourceRequests);
137 
138   /**
139    * Get the list of <code>ContainerId</code> of containers being
140    * released by the <code>ApplicationMaster</code>.
141    * @return list of <code>ContainerId</code> of containers being
142    *         released by the <code>ApplicationMaster</code>
143    */
144   @Public
145   @Stable
getReleaseList()146   public abstract List<ContainerId> getReleaseList();
147 
148   /**
149    * Set the list of <code>ContainerId</code> of containers being
150    * released by the <code>ApplicationMaster</code>
151    * @param releaseContainers list of <code>ContainerId</code> of
152    *                          containers being released by the
153    *                          <code>ApplicationMaster</code>
154    */
155   @Public
156   @Stable
setReleaseList(List<ContainerId> releaseContainers)157   public abstract void setReleaseList(List<ContainerId> releaseContainers);
158 
159   /**
160    * Get the <code>ResourceBlacklistRequest</code> being sent by the
161    * <code>ApplicationMaster</code>.
162    * @return the <code>ResourceBlacklistRequest</code> being sent by the
163    *         <code>ApplicationMaster</code>
164    * @see ResourceBlacklistRequest
165    */
166   @Public
167   @Stable
getResourceBlacklistRequest()168   public abstract ResourceBlacklistRequest getResourceBlacklistRequest();
169 
170   /**
171    * Set the <code>ResourceBlacklistRequest</code> to inform the
172    * <code>ResourceManager</code> about the blacklist additions and removals
173    * per the <code>ApplicationMaster</code>.
174    *
175    * @param resourceBlacklistRequest the <code>ResourceBlacklistRequest</code>
176    *                         to inform the <code>ResourceManager</code> about
177    *                         the blacklist additions and removals
178    *                         per the <code>ApplicationMaster</code>
179    * @see ResourceBlacklistRequest
180    */
181   @Public
182   @Stable
setResourceBlacklistRequest( ResourceBlacklistRequest resourceBlacklistRequest)183   public abstract void setResourceBlacklistRequest(
184       ResourceBlacklistRequest resourceBlacklistRequest);
185 
186   /**
187    * Get the <code>ContainerResourceIncreaseRequest</code> being sent by the
188    * <code>ApplicationMaster</code>
189    */
190   @Public
191   @Stable
getIncreaseRequests()192   public abstract List<ContainerResourceIncreaseRequest> getIncreaseRequests();
193 
194   /**
195    * Set the <code>ContainerResourceIncreaseRequest</code> to inform the
196    * <code>ResourceManager</code> about some container's resources need to be
197    * increased
198    */
199   @Public
200   @Stable
setIncreaseRequests( List<ContainerResourceIncreaseRequest> increaseRequests)201   public abstract void setIncreaseRequests(
202       List<ContainerResourceIncreaseRequest> increaseRequests);
203 }
204