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.Map;
023    
024    import org.apache.hadoop.classification.InterfaceAudience.Private;
025    import org.apache.hadoop.classification.InterfaceAudience.Public;
026    import org.apache.hadoop.classification.InterfaceStability.Stable;
027    import org.apache.hadoop.classification.InterfaceStability.Unstable;
028    import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
029    import org.apache.hadoop.yarn.api.records.ApplicationAccessType;
030    import org.apache.hadoop.yarn.api.records.Resource;
031    import org.apache.hadoop.yarn.util.Records;
032    
033    /**
034     * <p>The response sent by the <code>ResourceManager</code> to a new 
035     * <code>ApplicationMaster</code> on registration.</p>
036     * 
037     * <p>The response contains critical details such as:
038     * <ul>
039     *   <li>Maximum capability for allocated resources in the cluster.</li>
040     *   <li><code>ApplicationACL</code>s for the application.</li>
041     *   <li>ClientToAMToken master key.</li>
042     * </ul>
043     * </p>
044     * 
045     * @see ApplicationMasterProtocol#registerApplicationMaster(RegisterApplicationMasterRequest)
046     */
047    @Public
048    @Stable
049    public abstract class RegisterApplicationMasterResponse {
050      @Private
051      @Unstable
052      public static RegisterApplicationMasterResponse newInstance(
053          Resource minCapability, Resource maxCapability,
054          Map<ApplicationAccessType, String> acls, ByteBuffer key,
055          String queue) {
056        RegisterApplicationMasterResponse response =
057            Records.newRecord(RegisterApplicationMasterResponse.class);
058        response.setMaximumResourceCapability(maxCapability);
059        response.setApplicationACLs(acls);
060        response.setClientToAMTokenMasterKey(key);
061        response.setQueue(queue);
062        return response;
063      }
064    
065      /**
066       * Get the maximum capability for any {@link Resource} allocated by the 
067       * <code>ResourceManager</code> in the cluster.
068       * @return maximum capability of allocated resources in the cluster
069       */
070      @Public
071      @Stable
072      public abstract Resource getMaximumResourceCapability();
073      
074      @Private
075      @Unstable
076      public abstract void setMaximumResourceCapability(Resource capability);
077    
078      /**
079       * Get the <code>ApplicationACL</code>s for the application. 
080       * @return all the <code>ApplicationACL</code>s
081       */
082      @Public
083      @Stable
084      public abstract Map<ApplicationAccessType, String> getApplicationACLs();
085    
086      /**
087       * Set the <code>ApplicationACL</code>s for the application. 
088       * @param acls
089       */
090      @Private
091      @Unstable
092      public abstract void setApplicationACLs(Map<ApplicationAccessType, String> acls);
093    
094      /**
095       * <p>Get ClientToAMToken master key.</p>
096       * <p>The ClientToAMToken master key is sent to <code>ApplicationMaster</code>
097       * by <code>ResourceManager</code> via {@link RegisterApplicationMasterResponse}
098       * , used to verify corresponding ClientToAMToken.</p>
099       */
100      @Public
101      @Stable
102      public abstract ByteBuffer getClientToAMTokenMasterKey();
103    
104      /**
105       * Set ClientToAMToken master key.
106       */
107      @Public
108      @Stable
109      public abstract void setClientToAMTokenMasterKey(ByteBuffer key);
110    
111      /**
112       * <p>Get the queue that the application was placed in.<p>
113       */
114      @Public
115      @Stable
116      public abstract String getQueue();
117      
118      /**
119       * <p>Set the queue that the application was placed in.<p>
120       */
121      @Public
122      @Stable
123      public abstract void setQueue(String queue);
124      
125    }