Ejemplo n.º 1
0
        public virtual void TestAuthorizedAccess()
        {
            TestAMAuthorization.MyContainerManager containerManager = new TestAMAuthorization.MyContainerManager
                                                                          ();
            rm = new TestAMAuthorization.MockRMWithAMS(conf, containerManager);
            rm.Start();
            MockNM nm1 = rm.RegisterNode("localhost:1234", 5120);
            IDictionary <ApplicationAccessType, string> acls = new Dictionary <ApplicationAccessType
                                                                               , string>(2);

            acls[ApplicationAccessType.ViewApp] = "*";
            RMApp app = rm.SubmitApp(1024, "appname", "appuser", acls);

            nm1.NodeHeartbeat(true);
            int waitCount = 0;

            while (containerManager.containerTokens == null && waitCount++ < 20)
            {
                Log.Info("Waiting for AM Launch to happen..");
                Sharpen.Thread.Sleep(1000);
            }
            NUnit.Framework.Assert.IsNotNull(containerManager.containerTokens);
            RMAppAttempt         attempt = app.GetCurrentAppAttempt();
            ApplicationAttemptId applicationAttemptId = attempt.GetAppAttemptId();

            WaitForLaunchedState(attempt);
            // Create a client to the RM.
            Configuration        conf        = rm.GetConfig();
            YarnRPC              rpc         = YarnRPC.Create(conf);
            UserGroupInformation currentUser = UserGroupInformation.CreateRemoteUser(applicationAttemptId
                                                                                     .ToString());
            Credentials credentials   = containerManager.GetContainerCredentials();
            IPEndPoint  rmBindAddress = rm.GetApplicationMasterService().GetBindAddress();

            Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> amRMToken = TestAMAuthorization.MockRMWithAMS
                                                                                 .SetupAndReturnAMRMToken(rmBindAddress, credentials.GetAllTokens());
            currentUser.AddToken(amRMToken);
            ApplicationMasterProtocol client = currentUser.DoAs(new _PrivilegedAction_206(this
                                                                                          , rpc, conf));
            RegisterApplicationMasterRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord
                                                       <RegisterApplicationMasterRequest>();
            RegisterApplicationMasterResponse response = client.RegisterApplicationMaster(request
                                                                                          );

            NUnit.Framework.Assert.IsNotNull(response.GetClientToAMTokenMasterKey());
            if (UserGroupInformation.IsSecurityEnabled())
            {
                NUnit.Framework.Assert.IsTrue(((byte[])response.GetClientToAMTokenMasterKey().Array
                                                   ()).Length > 0);
            }
            NUnit.Framework.Assert.AreEqual("Register response has bad ACLs", "*", response.GetApplicationACLs
                                                ()[ApplicationAccessType.ViewApp]);
        }
Ejemplo n.º 2
0
        protected internal virtual void Register()
        {
            //Register
            IPEndPoint serviceAddr = null;

            if (clientService != null)
            {
                serviceAddr = clientService.GetBindAddress();
            }
            try
            {
                RegisterApplicationMasterRequest request = recordFactory.NewRecordInstance <RegisterApplicationMasterRequest
                                                                                            >();
                if (serviceAddr != null)
                {
                    request.SetHost(serviceAddr.GetHostName());
                    request.SetRpcPort(serviceAddr.Port);
                    request.SetTrackingUrl(MRWebAppUtil.GetAMWebappScheme(GetConfig()) + serviceAddr.
                                           GetHostName() + ":" + clientService.GetHttpPort());
                }
                RegisterApplicationMasterResponse response = scheduler.RegisterApplicationMaster(
                    request);
                isApplicationMasterRegistered = true;
                maxContainerCapability        = response.GetMaximumResourceCapability();
                this.context.GetClusterInfo().SetMaxContainerCapability(maxContainerCapability);
                if (UserGroupInformation.IsSecurityEnabled())
                {
                    SetClientToAMToken(response.GetClientToAMTokenMasterKey());
                }
                this.applicationACLs = response.GetApplicationACLs();
                Log.Info("maxContainerCapability: " + maxContainerCapability);
                string queue = response.GetQueue();
                Log.Info("queue: " + queue);
                job.SetQueueName(queue);
                Sharpen.Collections.AddAll(this.schedulerResourceTypes, response.GetSchedulerResourceTypes
                                               ());
            }
            catch (Exception are)
            {
                Log.Error("Exception while registering", are);
                throw new YarnRuntimeException(are);
            }
        }