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.nio.ByteBuffer;
022    import java.util.List;
023    import java.util.Map;
024    
025    import org.apache.hadoop.classification.InterfaceAudience.Private;
026    import org.apache.hadoop.classification.InterfaceAudience.Public;
027    import org.apache.hadoop.classification.InterfaceStability.Stable;
028    import org.apache.hadoop.classification.InterfaceStability.Unstable;
029    import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
030    import org.apache.hadoop.yarn.api.records.ApplicationAccessType;
031    import org.apache.hadoop.yarn.api.records.Container;
032    import org.apache.hadoop.yarn.api.records.NMToken;
033    import org.apache.hadoop.yarn.api.records.Resource;
034    import org.apache.hadoop.yarn.util.Records;
035    
036    /**
037     * <p>The response sent by the <code>ResourceManager</code> to a new 
038     * <code>ApplicationMaster</code> on registration.</p>
039     * 
040     * <p>The response contains critical details such as:
041     * <ul>
042     *   <li>Maximum capability for allocated resources in the cluster.</li>
043     *   <li><code>ApplicationACL</code>s for the application.</li>
044     *   <li>ClientToAMToken master key.</li>
045     * </ul>
046     * </p>
047     * 
048     * @see ApplicationMasterProtocol#registerApplicationMaster(RegisterApplicationMasterRequest)
049     */
050    @Public
051    @Stable
052    public abstract class RegisterApplicationMasterResponse {
053    
054      @Private
055      @Unstable
056      public static RegisterApplicationMasterResponse newInstance(
057          Resource minCapability, Resource maxCapability,
058          Map<ApplicationAccessType, String> acls, ByteBuffer key,
059          List<Container> containersFromPreviousAttempt, String queue,
060          List<NMToken> nmTokensFromPreviousAttempts) {
061        RegisterApplicationMasterResponse response =
062            Records.newRecord(RegisterApplicationMasterResponse.class);
063        response.setMaximumResourceCapability(maxCapability);
064        response.setApplicationACLs(acls);
065        response.setClientToAMTokenMasterKey(key);
066        response.setContainersFromPreviousAttempts(containersFromPreviousAttempt);
067        response.setNMTokensFromPreviousAttempts(nmTokensFromPreviousAttempts);
068        response.setQueue(queue);
069        return response;
070      }
071    
072      /**
073       * Get the maximum capability for any {@link Resource} allocated by the 
074       * <code>ResourceManager</code> in the cluster.
075       * @return maximum capability of allocated resources in the cluster
076       */
077      @Public
078      @Stable
079      public abstract Resource getMaximumResourceCapability();
080      
081      @Private
082      @Unstable
083      public abstract void setMaximumResourceCapability(Resource capability);
084    
085      /**
086       * Get the <code>ApplicationACL</code>s for the application. 
087       * @return all the <code>ApplicationACL</code>s
088       */
089      @Public
090      @Stable
091      public abstract Map<ApplicationAccessType, String> getApplicationACLs();
092    
093      /**
094       * Set the <code>ApplicationACL</code>s for the application. 
095       * @param acls
096       */
097      @Private
098      @Unstable
099      public abstract void setApplicationACLs(Map<ApplicationAccessType, String> acls);
100    
101      /**
102       * <p>Get ClientToAMToken master key.</p>
103       * <p>The ClientToAMToken master key is sent to <code>ApplicationMaster</code>
104       * by <code>ResourceManager</code> via {@link RegisterApplicationMasterResponse}
105       * , used to verify corresponding ClientToAMToken.</p>
106       */
107      @Public
108      @Stable
109      public abstract ByteBuffer getClientToAMTokenMasterKey();
110    
111      /**
112       * Set ClientToAMToken master key.
113       */
114      @Public
115      @Stable
116      public abstract void setClientToAMTokenMasterKey(ByteBuffer key);
117    
118      /**
119       * <p>Get the queue that the application was placed in.<p>
120       */
121      @Public
122      @Stable
123      public abstract String getQueue();
124      
125      /**
126       * <p>Set the queue that the application was placed in.<p>
127       */
128      @Public
129      @Stable
130      public abstract void setQueue(String queue);
131      
132      /**
133       * <p>
134       * Get the list of running containers as viewed by
135       * <code>ResourceManager</code> from previous application attempts.
136       * </p>
137       * 
138       * @return the list of running containers as viewed by
139       *         <code>ResourceManager</code> from previous application attempts
140       * @see RegisterApplicationMasterResponse#getNMTokensFromPreviousAttempts()
141       */
142      @Public
143      @Unstable
144      public abstract List<Container> getContainersFromPreviousAttempts();
145    
146      /**
147       * Set the list of running containers as viewed by
148       * <code>ResourceManager</code> from previous application attempts.
149       * 
150       * @param containersFromPreviousAttempt
151       *          the list of running containers as viewed by
152       *          <code>ResourceManager</code> from previous application attempts.
153       */
154      @Private
155      @Unstable
156      public abstract void setContainersFromPreviousAttempts(
157          List<Container> containersFromPreviousAttempt);
158    
159      /**
160       * Get the list of NMTokens for communicating with the NMs where the
161       * containers of previous application attempts are running.
162       * 
163       * @return the list of NMTokens for communicating with the NMs where the
164       *         containers of previous application attempts are running.
165       * 
166       * @see RegisterApplicationMasterResponse#getContainersFromPreviousAttempts()
167       */
168      @Public
169      @Stable
170      public abstract List<NMToken> getNMTokensFromPreviousAttempts();
171    
172      /**
173       * Set the list of NMTokens for communicating with the NMs where the the
174       * containers of previous application attempts are running.
175       * 
176       * @param nmTokens
177       *          the list of NMTokens for communicating with the NMs where the
178       *          containers of previous application attempts are running.
179       */
180      @Private
181      @Unstable
182      public abstract void setNMTokensFromPreviousAttempts(List<NMToken> nmTokens);
183    }