38
38
import org .apache .hadoop .classification .InterfaceAudience .Private ;
39
39
import org .apache .hadoop .classification .InterfaceStability .Unstable ;
40
40
import org .apache .hadoop .conf .Configuration ;
41
+ import org .apache .hadoop .yarn .api .records .ApplicationId ;
41
42
import org .apache .hadoop .yarn .conf .YarnConfiguration ;
42
43
import org .apache .hadoop .yarn .server .resourcemanager .scheduler .fair .policies .FifoPolicy ;
43
44
import org .xml .sax .SAXException ;
@@ -71,7 +72,7 @@ private void execute() {
71
72
Boolean removed =
72
73
removeEmptyIncompatibleQueues (queueToCreate , queueType ).orElse (null );
73
74
if (Boolean .TRUE .equals (removed )) {
74
- FSQueue queue = getQueue (queueToCreate , true , queueType , false );
75
+ FSQueue queue = getQueue (queueToCreate , true , queueType , false , null );
75
76
if (queue != null &&
76
77
// if queueToCreate is present in the allocation config, set it
77
78
// to static
@@ -124,30 +125,49 @@ public void initialize(Configuration conf) throws IOException,
124
125
125
126
/**
126
127
* Get a leaf queue by name, creating it if the create param is
127
- * true and is necessary .
128
- * If the queue is not or can not be a leaf queue, i.e. it already exists as a
129
- * parent queue, or one of the parents in its name is already a leaf queue,
130
- * null is returned.
128
+ * <code> true</code> and the queue does not exist .
129
+ * If the queue is not or can not be a leaf queue, i.e. it already exists as
130
+ * a parent queue, or one of the parents in its name is already a leaf queue,
131
+ * <code> null</code> is returned.
131
132
*
132
133
* The root part of the name is optional, so a queue underneath the root
133
134
* named "queue1" could be referred to as just "queue1", and a queue named
134
135
* "queue2" underneath a parent named "parent1" that is underneath the root
135
136
* could be referred to as just "parent1.queue2".
137
+ * @param name name of the queue
138
+ * @param create <code>true</code> if the queue must be created if it does
139
+ * not exist, <code>false</code> otherwise
140
+ * @return the leaf queue or <code>null</code> if the queue cannot be found
136
141
*/
137
142
public FSLeafQueue getLeafQueue (String name , boolean create ) {
138
- return getLeafQueue (name , create , true );
143
+ return getLeafQueue (name , create , null , true );
139
144
}
140
145
141
- private FSLeafQueue getLeafQueue (
142
- String name ,
143
- boolean create ,
144
- boolean recomputeSteadyShares ) {
145
- FSQueue queue = getQueue (
146
- name ,
147
- create ,
148
- FSQueueType .LEAF ,
149
- recomputeSteadyShares
150
- );
146
+ /**
147
+ * Get a leaf queue by name, creating it if the create param is
148
+ * <code>true</code> and the queue does not exist.
149
+ * If the queue is not or can not be a leaf queue, i.e. it already exists as
150
+ * a parent queue, or one of the parents in its name is already a leaf queue,
151
+ * <code>null</code> is returned.
152
+ *
153
+ * If the application will be assigned to the queue if the applicationId is
154
+ * not <code>null</code>
155
+ * @param name name of the queue
156
+ * @param create <code>true</code> if the queue must be created if it does
157
+ * not exist, <code>false</code> otherwise
158
+ * @param applicationId the application ID to assign to the queue
159
+ * @return the leaf queue or <code>null</code> if teh queue cannot be found
160
+ */
161
+ public FSLeafQueue getLeafQueue (String name , boolean create ,
162
+ ApplicationId applicationId ) {
163
+ return getLeafQueue (name , create , applicationId , true );
164
+ }
165
+
166
+ private FSLeafQueue getLeafQueue (String name , boolean create ,
167
+ ApplicationId applicationId ,
168
+ boolean recomputeSteadyShares ) {
169
+ FSQueue queue = getQueue (name , create , FSQueueType .LEAF ,
170
+ recomputeSteadyShares , applicationId );
151
171
if (queue instanceof FSParentQueue ) {
152
172
return null ;
153
173
}
@@ -168,42 +188,55 @@ public boolean removeLeafQueue(String name) {
168
188
169
189
/**
170
190
* Get a parent queue by name, creating it if the create param is
171
- * true and is necessary.
172
- * If the queue is not or can not be a parent queue,
173
- * i.e. it already exists as a
174
- * leaf queue, or one of the parents in its name is already a leaf queue,
175
- * null is returned.
191
+ * <code>true</code> and the queue does not exist.
192
+ * If the queue is not or can not be a parent queue, i.e. it already exists
193
+ * as a leaf queue, or one of the parents in its name is already a leaf
194
+ * queue, <code>null</code> is returned.
176
195
*
177
196
* The root part of the name is optional, so a queue underneath the root
178
197
* named "queue1" could be referred to as just "queue1", and a queue named
179
198
* "queue2" underneath a parent named "parent1" that is underneath the root
180
199
* could be referred to as just "parent1.queue2".
200
+ * @param name name of the queue
201
+ * @param create <code>true</code> if the queue must be created if it does
202
+ * not exist, <code>false</code> otherwise
203
+ * @return the parent queue or <code>null</code> if the queue cannot be found
181
204
*/
182
205
public FSParentQueue getParentQueue (String name , boolean create ) {
183
206
return getParentQueue (name , create , true );
184
207
}
185
208
186
- public FSParentQueue getParentQueue (
187
- String name ,
188
- boolean create ,
209
+ /**
210
+ * Get a parent queue by name, creating it if the create param is
211
+ * <code>true</code> and the queue does not exist.
212
+ * If the queue is not or can not be a parent queue, i.e. it already exists
213
+ * as a leaf queue, or one of the parents in its name is already a leaf
214
+ * queue, <code>null</code> is returned.
215
+ *
216
+ * The root part of the name is optional, so a queue underneath the root
217
+ * named "queue1" could be referred to as just "queue1", and a queue named
218
+ * "queue2" underneath a parent named "parent1" that is underneath the root
219
+ * could be referred to as just "parent1.queue2".
220
+ * @param name name of the queue
221
+ * @param create <code>true</code> if the queue must be created if it does
222
+ * not exist, <code>false</code> otherwise
223
+ * @param recomputeSteadyShares <code>true</code> if the steady fair share
224
+ * should be recalculated when a queue is added,
225
+ * <code>false</code> otherwise
226
+ * @return the parent queue or <code>null</code> if the queue cannot be found
227
+ */
228
+ public FSParentQueue getParentQueue (String name , boolean create ,
189
229
boolean recomputeSteadyShares ) {
190
- FSQueue queue = getQueue (
191
- name ,
192
- create ,
193
- FSQueueType .PARENT ,
194
- recomputeSteadyShares
195
- );
230
+ FSQueue queue = getQueue (name , create , FSQueueType .PARENT ,
231
+ recomputeSteadyShares , null );
196
232
if (queue instanceof FSLeafQueue ) {
197
233
return null ;
198
234
}
199
235
return (FSParentQueue ) queue ;
200
236
}
201
237
202
- private FSQueue getQueue (
203
- String name ,
204
- boolean create ,
205
- FSQueueType queueType ,
206
- boolean recomputeSteadyShares ) {
238
+ private FSQueue getQueue (String name , boolean create , FSQueueType queueType ,
239
+ boolean recomputeSteadyShares , ApplicationId applicationId ) {
207
240
boolean recompute = recomputeSteadyShares ;
208
241
name = ensureRootPrefix (name );
209
242
FSQueue queue ;
@@ -215,8 +248,14 @@ private FSQueue getQueue(
215
248
} else {
216
249
recompute = false ;
217
250
}
251
+ // At this point the queue exists and we need to assign the app if to the
252
+ // but only to a leaf queue
253
+ if (applicationId != null && queue instanceof FSLeafQueue ) {
254
+ ((FSLeafQueue )queue ).addAssignedApp (applicationId );
255
+ }
218
256
}
219
- if (recompute ) {
257
+ // Don't recompute if it is an existing queue or no change was made
258
+ if (recompute && queue != null ) {
220
259
rootQueue .recomputeSteadyShares ();
221
260
}
222
261
return queue ;
@@ -614,7 +653,7 @@ private void ensureQueueExistsAndIsCompatibleAndIsStatic(
614
653
incompatibleQueuesPendingRemoval .add (
615
654
new IncompatibleQueueRemovalTask (name , queueType ));
616
655
} else {
617
- FSQueue queue = getQueue (name , true , queueType , false );
656
+ FSQueue queue = getQueue (name , true , queueType , false , null );
618
657
if (queue != null ) {
619
658
queue .setDynamic (false );
620
659
}
0 commit comments