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.records;
020    
021    import org.apache.hadoop.classification.InterfaceAudience.Private;
022    import org.apache.hadoop.classification.InterfaceAudience.Public;
023    import org.apache.hadoop.classification.InterfaceStability.Stable;
024    import org.apache.hadoop.classification.InterfaceStability.Unstable;
025    import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
026    import org.apache.hadoop.yarn.util.Records;
027    
028    /**
029     * <p>The NMToken is used for authenticating communication with
030     * <code>NodeManager</code></p>
031     * <p>It is issued by <code>ResourceMananger</code> when <code>ApplicationMaster</code>
032     * negotiates resource with <code>ResourceManager</code> and
033     * validated on <code>NodeManager</code> side.</p>
034     * @see  AllocateResponse#getNMTokens()
035     */
036    @Public
037    @Stable
038    public abstract class NMToken {
039    
040      @Private
041      @Unstable
042      public static NMToken newInstance(NodeId nodeId, Token token) {
043        NMToken nmToken = Records.newRecord(NMToken.class);
044        nmToken.setNodeId(nodeId);
045        nmToken.setToken(token);
046        return nmToken;
047      }
048    
049      /**
050       * Get the {@link NodeId} of the <code>NodeManager</code> for which the NMToken
051       * is used to authenticate.
052       * @return the {@link NodeId} of the <code>NodeManager</code> for which the
053       * NMToken is used to authenticate.
054       */
055      @Public
056      @Stable
057      public abstract NodeId getNodeId();
058      
059      @Public
060      @Stable
061      public abstract void setNodeId(NodeId nodeId);
062    
063      /**
064       * Get the {@link Token} used for authenticating with <code>NodeManager</code>
065       * @return the {@link Token} used for authenticating with <code>NodeManager</code>
066       */
067      @Public
068      @Stable
069      public abstract Token getToken();
070      
071      @Public
072      @Stable
073      public abstract void setToken(Token token);
074    
075    }