Exemplo n.º 1
0
			/// <exception cref="System.IO.IOException"/>
			public virtual StartContainersResponse StartContainers(StartContainersRequest requests
				)
			{
				StartContainerRequest request = requests.GetStartContainerRequests()[0];
				ContainerTokenIdentifier containerTokenIdentifier = MRApp.NewContainerTokenIdentifier
					(request.GetContainerToken());
				// Validate that the container is what RM is giving.
				NUnit.Framework.Assert.AreEqual(MRApp.NmHost + ":" + MRApp.NmPort, containerTokenIdentifier
					.GetNmHostAddress());
				StartContainersResponse response = TestContainerLauncher.recordFactory.NewRecordInstance
					<StartContainersResponse>();
				this.status = TestContainerLauncher.recordFactory.NewRecordInstance<ContainerStatus
					>();
				try
				{
					// make the thread sleep to look like its not going to respond
					Sharpen.Thread.Sleep(15000);
				}
				catch (Exception e)
				{
					TestContainerLauncher.Log.Error(e);
					throw new UndeclaredThrowableException(e);
				}
				this.status.SetState(ContainerState.Running);
				this.status.SetContainerId(containerTokenIdentifier.GetContainerID());
				this.status.SetExitStatus(0);
				return response;
			}
            /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
            public StartContainersResponse StartContainers(StartContainersRequest requests)
            {
                StartContainerRequest request = requests.GetStartContainerRequests()[0];

                Log.Info("Container started by MyContainerManager: " + request);
                launched = true;
                IDictionary <string, string> env = request.GetContainerLaunchContext().GetEnvironment
                                                       ();
                Token containerToken             = request.GetContainerToken();
                ContainerTokenIdentifier tokenId = null;

                try
                {
                    tokenId = BuilderUtils.NewContainerTokenIdentifier(containerToken);
                }
                catch (IOException e)
                {
                    throw RPCUtil.GetRemoteException(e);
                }
                ContainerId containerId = tokenId.GetContainerID();

                containerIdAtContainerManager = containerId.ToString();
                attemptIdAtContainerManager   = containerId.GetApplicationAttemptId().ToString();
                nmHostAtContainerManager      = tokenId.GetNmHostAddress();
                submitTimeAtContainerManager  = long.Parse(env[ApplicationConstants.AppSubmitTimeEnv
                                                           ]);
                maxAppAttempts = System.Convert.ToInt32(env[ApplicationConstants.MaxAppAttemptsEnv
                                                        ]);
                return(StartContainersResponse.NewInstance(new Dictionary <string, ByteBuffer>(),
                                                           new AList <ContainerId>(), new Dictionary <ContainerId, SerializedException>()));
            }
        public ContainerTokenIdentifierForTest(ContainerTokenIdentifier identifier, string
                                               message)
        {
            YarnSecurityTestTokenProtos.ContainerTokenIdentifierForTestProto.Builder builder =
                YarnSecurityTestTokenProtos.ContainerTokenIdentifierForTestProto.NewBuilder();
            ContainerIdPBImpl containerID = (ContainerIdPBImpl)identifier.GetContainerID();

            if (containerID != null)
            {
                builder.SetContainerId(containerID.GetProto());
            }
            builder.SetNmHostAddr(identifier.GetNmHostAddress());
            builder.SetAppSubmitter(identifier.GetApplicationSubmitter());
            ResourcePBImpl resource = (ResourcePBImpl)identifier.GetResource();

            if (resource != null)
            {
                builder.SetResource(resource.GetProto());
            }
            builder.SetExpiryTimeStamp(identifier.GetExpiryTimeStamp());
            builder.SetMasterKeyId(identifier.GetMasterKeyId());
            builder.SetRmIdentifier(identifier.GetRMIdentifier());
            PriorityPBImpl priority = (PriorityPBImpl)identifier.GetPriority();

            if (priority != null)
            {
                builder.SetPriority(priority.GetProto());
            }
            builder.SetCreationTime(identifier.GetCreationTime());
            builder.SetMessage(message);
            LogAggregationContextPBImpl logAggregationContext = (LogAggregationContextPBImpl)
                                                                identifier.GetLogAggregationContext();

            if (logAggregationContext != null)
            {
                builder.SetLogAggregationContext(logAggregationContext.GetProto());
            }
            proto = ((YarnSecurityTestTokenProtos.ContainerTokenIdentifierForTestProto)builder
                     .Build());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Override of this is to validate ContainerTokens generated by using
 /// different
 /// <see cref="Org.Apache.Hadoop.Yarn.Server.Api.Records.MasterKey"/>
 /// s.
 /// </summary>
 /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
 public override byte[] RetrievePassword(ContainerTokenIdentifier identifier)
 {
     lock (this)
     {
         int           keyId          = identifier.GetMasterKeyId();
         MasterKeyData masterKeyToUse = null;
         if (this.previousMasterKey != null && keyId == this.previousMasterKey.GetMasterKey
                 ().GetKeyId())
         {
             // A container-launch has come in with a token generated off the last
             // master-key
             masterKeyToUse = this.previousMasterKey;
         }
         else
         {
             if (keyId == base.currentMasterKey.GetMasterKey().GetKeyId())
             {
                 // A container-launch has come in with a token generated off the current
                 // master-key
                 masterKeyToUse = base.currentMasterKey;
             }
         }
         if (nodeHostAddr != null && !identifier.GetNmHostAddress().Equals(nodeHostAddr))
         {
             // Valid container token used for incorrect node.
             throw new SecretManager.InvalidToken("Given Container " + identifier.GetContainerID
                                                      ().ToString() + " identifier is not valid for current Node manager. Expected : "
                                                  + nodeHostAddr + " Found : " + identifier.GetNmHostAddress());
         }
         if (masterKeyToUse != null)
         {
             return(RetrievePasswordInternal(identifier, masterKeyToUse));
         }
         // Invalid request. Like startContainer() with token generated off
         // old-master-keys.
         throw new SecretManager.InvalidToken("Given Container " + identifier.GetContainerID
                                                  ().ToString() + " seems to have an illegally generated token.");
     }
 }