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    
019    package org.apache.hadoop.yarn.api.protocolrecords;
020    
021    import java.util.EnumSet;
022    import java.util.Set;
023    
024    import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
025    import org.apache.commons.lang.math.LongRange;
026    import org.apache.hadoop.classification.InterfaceAudience.Private;
027    import org.apache.hadoop.classification.InterfaceAudience.Public;
028    import org.apache.hadoop.classification.InterfaceStability.Stable;
029    import org.apache.hadoop.classification.InterfaceStability.Unstable;
030    import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
031    import org.apache.hadoop.yarn.api.records.YarnApplicationState;
032    import org.apache.hadoop.yarn.util.Records;
033    
034    /**
035     * <p>The request from clients to get a report of Applications
036     * in the cluster from the <code>ResourceManager</code>.</p>
037     *
038     *
039     * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
040     */
041    @Public
042    @Stable
043    public abstract class GetApplicationsRequest {
044      @Public
045      @Stable
046      public static GetApplicationsRequest newInstance() {
047        GetApplicationsRequest request =
048            Records.newRecord(GetApplicationsRequest.class);
049        return request;
050      }
051    
052      /**
053       * <p>
054       * The request from clients to get a report of Applications matching the
055       * giving application types in the cluster from the
056       * <code>ResourceManager</code>.
057       * </p>
058       *
059       *
060       * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
061       */
062      @Public
063      @Stable
064      public static GetApplicationsRequest
065          newInstance(Set<String> applicationTypes) {
066        GetApplicationsRequest request =
067            Records.newRecord(GetApplicationsRequest.class);
068        request.setApplicationTypes(applicationTypes);
069        return request;
070      }
071    
072      /**
073       * <p>
074       * The request from clients to get a report of Applications matching the
075       * giving application states in the cluster from the
076       * <code>ResourceManager</code>.
077       * </p>
078       *
079       *
080       * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
081       */
082      @Public
083      @Stable
084      public static GetApplicationsRequest newInstance(
085          EnumSet<YarnApplicationState> applicationStates) {
086        GetApplicationsRequest request =
087            Records.newRecord(GetApplicationsRequest.class);
088        request.setApplicationStates(applicationStates);
089        return request;
090      }
091    
092      /**
093       * <p>
094       * The request from clients to get a report of Applications matching the
095       * giving and application types and application types in the cluster from the
096       * <code>ResourceManager</code>.
097       * </p>
098       *
099       *
100       * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
101       */
102      @Public
103      @Stable
104      public static GetApplicationsRequest newInstance(
105          Set<String> applicationTypes,
106          EnumSet<YarnApplicationState> applicationStates) {
107        GetApplicationsRequest request =
108            Records.newRecord(GetApplicationsRequest.class);
109        request.setApplicationTypes(applicationTypes);
110        request.setApplicationStates(applicationStates);
111        return request;
112      }
113    
114      /**
115       * Get the application types to filter applications on
116       *
117       * @return Set of Application Types to filter on
118       */
119      @Public
120      @Stable
121      public abstract Set<String> getApplicationTypes();
122    
123      /**
124       * Set the application types to filter applications on
125       *
126       * @param applicationTypes
127       * A Set of Application Types to filter on.
128       * If not defined, match all applications
129       */
130      @Private
131      @Unstable
132      public abstract void
133          setApplicationTypes(Set<String> applicationTypes);
134    
135      /**
136       * Get the application states to filter applications on
137       *
138       * @return Set of Application states to filter on
139       */
140      @Public
141      @Stable
142      public abstract EnumSet<YarnApplicationState> getApplicationStates();
143    
144      /**
145       * Set the application states to filter applications on
146       *
147       * @param applicationStates
148       * A Set of Application states to filter on.
149       * If not defined, match all running applications
150       */
151      @Private
152      @Unstable
153      public abstract void
154          setApplicationStates(EnumSet<YarnApplicationState> applicationStates);
155    
156      /**
157       * Set the application states to filter applications on
158       *
159       * @param applicationStates all lower-case string representation of the
160       *                          application states to filter on
161       */
162      @Private
163      @Unstable
164      public abstract void setApplicationStates(Set<String> applicationStates);
165    
166      /**
167       * Get the users to filter applications on
168       *
169       * @return set of users to filter applications on
170       */
171      @Private
172      @Unstable
173      public abstract Set<String> getUsers();
174    
175      /**
176       * Set the users to filter applications on
177       *
178       * @param users set of users to filter applications on
179       */
180      @Private
181      @Unstable
182      public abstract void setUsers(Set<String> users);
183    
184      /**
185       * Get the queues to filter applications on
186       *
187       * @return set of queues to filter applications on
188       */
189      @Private
190      @Unstable
191      public abstract Set<String> getQueues();
192    
193      /**
194       * Set the queue to filter applications on
195       *
196       * @param queue user to filter applications on
197       */
198      @Private
199      @Unstable
200      public abstract void setQueues(Set<String> queue);
201    
202      /**
203       * Get the limit on the number applications to return
204       *
205       * @return number of applications to limit to
206       */
207      @Private
208      @Unstable
209      public abstract long getLimit();
210    
211      /**
212       * Limit the number applications to return
213       *
214       * @param limit number of applications to limit to
215       */
216      @Private
217      @Unstable
218      public abstract void setLimit(long limit);
219    
220      /**
221       * Get the range of start times to filter applications on
222       *
223       * @return {@link LongRange} of start times to filter applications on
224       */
225      @Private
226      @Unstable
227      public abstract LongRange getStartRange();
228    
229      /**
230       * Set the range of start times to filter applications on
231       *
232       * @param begin beginning of the range
233       * @param end end of the range
234       * @throws IllegalArgumentException
235       */
236      @Private
237      @Unstable
238      public abstract void setStartRange(long begin, long end)
239          throws IllegalArgumentException;
240    
241      /**
242       * Get the range of finish times to filter applications on
243       *
244       * @return {@link LongRange} of finish times to filter applications on
245       */
246      @Private
247      @Unstable
248      public abstract LongRange getFinishRange();
249    
250      /**
251       * Set the range of finish times to filter applications on
252       *
253       * @param begin beginning of the range
254       * @param end end of the range
255       * @throws IllegalArgumentException
256       */
257      @Private
258      @Unstable
259      public abstract void setFinishRange(long begin, long end);
260    }