Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        private void SetupTokens(ContainerLaunchContext container, ContainerId containerID
                                 )
        {
            IDictionary <string, string> environment = container.GetEnvironment();

            environment[ApplicationConstants.ApplicationWebProxyBaseEnv] = application.GetWebProxyBase
                                                                               ();
            // Set AppSubmitTime and MaxAppAttempts to be consumable by the AM.
            ApplicationId applicationId = application.GetAppAttemptId().GetApplicationId();

            environment[ApplicationConstants.AppSubmitTimeEnv] = rmContext.GetRMApps()[applicationId
                                                                 ].GetSubmitTime().ToString();
            environment[ApplicationConstants.MaxAppAttemptsEnv] = rmContext.GetRMApps()[applicationId
                                                                  ].GetMaxAppAttempts().ToString();
            Credentials         credentials = new Credentials();
            DataInputByteBuffer dibb        = new DataInputByteBuffer();

            if (container.GetTokens() != null)
            {
                // TODO: Don't do this kind of checks everywhere.
                dibb.Reset(container.GetTokens());
                credentials.ReadTokenStorageStream(dibb);
            }
            // Add AMRMToken
            Org.Apache.Hadoop.Security.Token.Token <AMRMTokenIdentifier> amrmToken = CreateAndSetAMRMToken
                                                                                         ();
            if (amrmToken != null)
            {
                credentials.AddToken(amrmToken.GetService(), amrmToken);
            }
            DataOutputBuffer dob = new DataOutputBuffer();

            credentials.WriteTokenStorageToStream(dob);
            container.SetTokens(ByteBuffer.Wrap(dob.GetData(), 0, dob.GetLength()));
        }
Exemplo n.º 2
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private void AddTimelineDelegationToken(ContainerLaunchContext clc)
        {
            Credentials         credentials = new Credentials();
            DataInputByteBuffer dibb        = new DataInputByteBuffer();
            ByteBuffer          tokens      = clc.GetTokens();

            if (tokens != null)
            {
                dibb.Reset(tokens);
                credentials.ReadTokenStorageStream(dibb);
                tokens.Rewind();
            }
            // If the timeline delegation token is already in the CLC, no need to add
            // one more
            foreach (Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> token in credentials
                     .GetAllTokens())
            {
                if (token.GetKind().Equals(TimelineDelegationTokenIdentifier.KindName))
                {
                    return;
                }
            }
            Org.Apache.Hadoop.Security.Token.Token <TimelineDelegationTokenIdentifier> timelineDelegationToken
                = GetTimelineDelegationToken();
            if (timelineDelegationToken == null)
            {
                return;
            }
            credentials.AddToken(timelineService, timelineDelegationToken);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Add timline delegation token into credentials: " + timelineDelegationToken
                          );
            }
            DataOutputBuffer dob = new DataOutputBuffer();

            credentials.WriteTokenStorageToStream(dob);
            tokens = ByteBuffer.Wrap(dob.GetData(), 0, dob.GetLength());
            clc.SetTokens(tokens);
        }
Exemplo n.º 3
0
        public virtual void TestAttemptContainerRequest()
        {
            Text SecretKeyAlias = new Text("secretkeyalias");

            byte[] SecretKey = Sharpen.Runtime.GetBytesForString(("secretkey"));
            IDictionary <ApplicationAccessType, string> acls = new Dictionary <ApplicationAccessType
                                                                               , string>(1);

            acls[ApplicationAccessType.ViewApp] = "otheruser";
            ApplicationId       appId        = ApplicationId.NewInstance(1, 1);
            JobId               jobId        = MRBuilderUtils.NewJobId(appId, 1);
            TaskId              taskId       = MRBuilderUtils.NewTaskId(jobId, 1, TaskType.Map);
            Path                jobFile      = Org.Mockito.Mockito.Mock <Path>();
            EventHandler        eventHandler = Org.Mockito.Mockito.Mock <EventHandler>();
            TaskAttemptListener taListener   = Org.Mockito.Mockito.Mock <TaskAttemptListener>();

            Org.Mockito.Mockito.When(taListener.GetAddress()).ThenReturn(new IPEndPoint("localhost"
                                                                                        , 0));
            JobConf jobConf = new JobConf();

            jobConf.SetClass("fs.file.impl", typeof(TestTaskAttemptContainerRequest.StubbedFS
                                                    ), typeof(FileSystem));
            jobConf.SetBoolean("fs.file.impl.disable.cache", true);
            jobConf.Set(JobConf.MapredMapTaskEnv, string.Empty);
            // setup UGI for security so tokens and keys are preserved
            jobConf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kerberos"
                        );
            UserGroupInformation.SetConfiguration(jobConf);
            Credentials credentials = new Credentials();

            credentials.AddSecretKey(SecretKeyAlias, SecretKey);
            Org.Apache.Hadoop.Security.Token.Token <JobTokenIdentifier> jobToken = new Org.Apache.Hadoop.Security.Token.Token
                                                                                   <JobTokenIdentifier>(Sharpen.Runtime.GetBytesForString(("tokenid")), Sharpen.Runtime.GetBytesForString
                                                                                                            (("tokenpw")), new Text("tokenkind"), new Text("tokenservice"));
            TaskAttemptImpl taImpl = new MapTaskAttemptImpl(taskId, 1, eventHandler, jobFile,
                                                            1, Org.Mockito.Mockito.Mock <JobSplit.TaskSplitMetaInfo>(), jobConf, taListener,
                                                            jobToken, credentials, new SystemClock(), null);

            jobConf.Set(MRJobConfig.ApplicationAttemptId, taImpl.GetID().ToString());
            ContainerLaunchContext launchCtx = TaskAttemptImpl.CreateContainerLaunchContext(acls
                                                                                            , jobConf, jobToken, taImpl.CreateRemoteTask(), TypeConverter.FromYarn(jobId), Org.Mockito.Mockito.Mock
                                                                                            <WrappedJvmID>(), taListener, credentials);

            NUnit.Framework.Assert.AreEqual("ACLs mismatch", acls, launchCtx.GetApplicationACLs
                                                ());
            Credentials         launchCredentials = new Credentials();
            DataInputByteBuffer dibb = new DataInputByteBuffer();

            dibb.Reset(launchCtx.GetTokens());
            launchCredentials.ReadTokenStorageStream(dibb);
            // verify all tokens specified for the task attempt are in the launch context
            foreach (Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> token in credentials
                     .GetAllTokens())
            {
                Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> launchToken = launchCredentials
                                                                                       .GetToken(token.GetService());
                NUnit.Framework.Assert.IsNotNull("Token " + token.GetService() + " is missing", launchToken
                                                 );
                NUnit.Framework.Assert.AreEqual("Token " + token.GetService() + " mismatch", token
                                                , launchToken);
            }
            // verify the secret key is in the launch context
            NUnit.Framework.Assert.IsNotNull("Secret key missing", launchCredentials.GetSecretKey
                                                 (SecretKeyAlias));
            NUnit.Framework.Assert.IsTrue("Secret key mismatch", Arrays.Equals(SecretKey, launchCredentials
                                                                               .GetSecretKey(SecretKeyAlias)));
        }