Exemple #1
0
        public virtual void Setup()
        {
            localFS.Delete(new Path(localDir.GetAbsolutePath()), true);
            localFS.Delete(new Path(tmpDir.GetAbsolutePath()), true);
            localFS.Delete(new Path(localLogDir.GetAbsolutePath()), true);
            localFS.Delete(new Path(remoteLogDir.GetAbsolutePath()), true);
            localDir.Mkdir();
            tmpDir.Mkdir();
            localLogDir.Mkdir();
            remoteLogDir.Mkdir();
            Log.Info("Created localDir in " + localDir.GetAbsolutePath());
            Log.Info("Created tmpDir in " + tmpDir.GetAbsolutePath());
            string bindAddress = "0.0.0.0:12345";

            conf.Set(YarnConfiguration.NmAddress, bindAddress);
            conf.Set(YarnConfiguration.NmLocalDirs, localDir.GetAbsolutePath());
            conf.Set(YarnConfiguration.NmLogDirs, localLogDir.GetAbsolutePath());
            conf.Set(YarnConfiguration.NmRemoteAppLogDir, remoteLogDir.GetAbsolutePath());
            conf.SetLong(YarnConfiguration.NmLogRetainSeconds, 1);
            // Default delSrvc
            delSrvc = CreateDeletionService();
            delSrvc.Init(conf);
            exec = CreateContainerExecutor();
            nodeHealthChecker = new NodeHealthCheckerService();
            nodeHealthChecker.Init(conf);
            dirsHandler      = nodeHealthChecker.GetDiskHandler();
            containerManager = CreateContainerManager(delSrvc);
            ((NodeManager.NMContext)context).SetContainerManager(containerManager);
            nodeStatusUpdater.Init(conf);
            containerManager.Init(conf);
            nodeStatusUpdater.Start();
        }
Exemple #2
0
 public _ContainersLauncher_148(DummyContainerManager _enclosing, Context baseArg1
                                , Dispatcher baseArg2, ContainerExecutor baseArg3, LocalDirsHandlerService baseArg4
                                , ContainerManagerImpl baseArg5)
     : base(baseArg1, baseArg2, baseArg3, baseArg4, baseArg5)
 {
     this._enclosing = _enclosing;
 }
Exemple #3
0
        /// <exception cref="System.Exception"/>
        protected override void ServiceInit(Configuration conf)
        {
            conf.SetBoolean(Dispatcher.DispatcherExitOnErrorKey, true);
            rmWorkPreservingRestartEnabled = conf.GetBoolean(YarnConfiguration.RmWorkPreservingRecoveryEnabled
                                                             , YarnConfiguration.DefaultRmWorkPreservingRecoveryEnabled);
            InitAndStartRecoveryStore(conf);
            NMContainerTokenSecretManager containerTokenSecretManager = new NMContainerTokenSecretManager
                                                                            (conf, nmStore);
            NMTokenSecretManagerInNM nmTokenSecretManager = new NMTokenSecretManagerInNM(nmStore
                                                                                         );

            RecoverTokens(nmTokenSecretManager, containerTokenSecretManager);
            this.aclsManager = new ApplicationACLsManager(conf);
            ContainerExecutor exec = ReflectionUtils.NewInstance(conf.GetClass <ContainerExecutor
                                                                                >(YarnConfiguration.NmContainerExecutor, typeof(DefaultContainerExecutor)), conf
                                                                 );

            try
            {
                exec.Init();
            }
            catch (IOException e)
            {
                throw new YarnRuntimeException("Failed to initialize container executor", e);
            }
            DeletionService del = CreateDeletionService(exec);

            AddService(del);
            // NodeManager level dispatcher
            this.dispatcher   = new AsyncDispatcher();
            nodeHealthChecker = new NodeHealthCheckerService();
            AddService(nodeHealthChecker);
            dirsHandler  = nodeHealthChecker.GetDiskHandler();
            this.context = CreateNMContext(containerTokenSecretManager, nmTokenSecretManager,
                                           nmStore);
            nodeStatusUpdater = CreateNodeStatusUpdater(context, dispatcher, nodeHealthChecker
                                                        );
            NodeResourceMonitor nodeResourceMonitor = CreateNodeResourceMonitor();

            AddService(nodeResourceMonitor);
            containerManager = CreateContainerManager(context, exec, del, nodeStatusUpdater,
                                                      this.aclsManager, dirsHandler);
            AddService(containerManager);
            ((NodeManager.NMContext)context).SetContainerManager(containerManager);
            WebServer webServer = CreateWebServer(context, containerManager.GetContainersMonitor
                                                      (), this.aclsManager, dirsHandler);

            AddService(webServer);
            ((NodeManager.NMContext)context).SetWebServer(webServer);
            dispatcher.Register(typeof(ContainerManagerEventType), containerManager);
            dispatcher.Register(typeof(NodeManagerEventType), this);
            AddService(dispatcher);
            DefaultMetricsSystem.Initialize("NodeManager");
            // StatusUpdater should be added last so that it get started last
            // so that we make sure everything is up before registering with RM.
            AddService(nodeStatusUpdater);
            base.ServiceInit(conf);
        }
Exemple #4
0
 public ContainersLauncher(Context context, Dispatcher dispatcher, ContainerExecutor
                           exec, LocalDirsHandlerService dirsHandler, ContainerManagerImpl containerManager
                           )
     : base("containers-launcher")
 {
     this.exec             = exec;
     this.context          = context;
     this.dispatcher       = dispatcher;
     this.dirsHandler      = dirsHandler;
     this.containerManager = containerManager;
 }
Exemple #5
0
        /// <exception cref="System.Exception"/>
        protected internal virtual void WaitForNMToReceiveNMTokenKey(NMTokenSecretManagerInNM
                                                                     nmTokenSecretManagerNM, NodeManager nm)
        {
            int attempt             = 60;
            ContainerManagerImpl cm = ((ContainerManagerImpl)nm.GetNMContext().GetContainerManager
                                           ());

            while ((cm.GetBlockNewContainerRequestsStatus() || nmTokenSecretManagerNM.GetNodeId
                        () == null) && attempt-- > 0)
            {
                Sharpen.Thread.Sleep(2000);
            }
        }
Exemple #6
0
        /// <exception cref="System.Exception"/>
        internal static void WaitForApplicationState(ContainerManagerImpl containerManager
                                                     , ApplicationId appID, ApplicationState finalState)
        {
            // Wait for app-finish
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app     = containerManager.GetContext().GetApplications()[appID];
            int timeout = 0;

            while (!(app.GetApplicationState().Equals(finalState)) && timeout++ < 15)
            {
                Log.Info("Waiting for app to reach " + finalState + ".. Current state is " + app.
                         GetApplicationState());
                Sharpen.Thread.Sleep(1000);
            }
            NUnit.Framework.Assert.IsTrue("App is not in " + finalState + " yet!! Timedout!!"
                                          , app.GetApplicationState().Equals(finalState));
        }
 public ContainerLaunch(Context context, Configuration configuration, Dispatcher dispatcher
                        , ContainerExecutor exec, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                        app, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                        container, LocalDirsHandlerService dirsHandler, ContainerManagerImpl containerManager
                        )
 {
     this.context                 = context;
     this.conf                    = configuration;
     this.app                     = app;
     this.exec                    = exec;
     this.container               = container;
     this.dispatcher              = dispatcher;
     this.dirsHandler             = dirsHandler;
     this.containerManager        = containerManager;
     this.sleepDelayBeforeSigKill = conf.GetLong(YarnConfiguration.NmSleepDelayBeforeSigkillMs
                                                 , YarnConfiguration.DefaultNmSleepDelayBeforeSigkillMs);
     this.maxKillWaitTime = conf.GetLong(YarnConfiguration.NmProcessKillWaitMs, YarnConfiguration
                                         .DefaultNmProcessKillWaitMs);
 }
        /// <exception cref="System.Exception"/>
        private StartContainersResponse StartContainer(Context context, ContainerManagerImpl
                                                       cm, ContainerId cid, ContainerLaunchContext clc, LogAggregationContext logAggregationContext
                                                       )
        {
            UserGroupInformation user = UserGroupInformation.CreateRemoteUser(cid.GetApplicationAttemptId
                                                                                  ().ToString());
            StartContainerRequest scReq = StartContainerRequest.NewInstance(clc, TestContainerManager
                                                                            .CreateContainerToken(cid, 0, context.GetNodeId(), user.GetShortUserName(), context
                                                                                                  .GetContainerTokenSecretManager(), logAggregationContext));
            IList <StartContainerRequest> scReqList = new AList <StartContainerRequest>();

            scReqList.AddItem(scReq);
            NMTokenIdentifier nmToken = new NMTokenIdentifier(cid.GetApplicationAttemptId(),
                                                              context.GetNodeId(), user.GetShortUserName(), context.GetNMTokenSecretManager().
                                                              GetCurrentKey().GetKeyId());

            user.AddTokenIdentifier(nmToken);
            return(user.DoAs(new _PrivilegedExceptionAction_264(cm, scReqList)));
        }
        public virtual void TestApplicationRecovery()
        {
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetBoolean(YarnConfiguration.NmRecoveryEnabled, true);
            conf.Set(YarnConfiguration.NmAddress, "localhost:1234");
            conf.SetBoolean(YarnConfiguration.YarnAclEnable, true);
            conf.Set(YarnConfiguration.YarnAdminAcl, "yarn_admin_user");
            NMStateStoreService stateStore = new NMMemoryStateStoreService();

            stateStore.Init(conf);
            stateStore.Start();
            Context context = new NodeManager.NMContext(new NMContainerTokenSecretManager(conf
                                                                                          ), new NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), stateStore
                                                        );
            ContainerManagerImpl cm = CreateContainerManager(context);

            cm.Init(conf);
            cm.Start();
            // simulate registration with RM
            MasterKey masterKey = new MasterKeyPBImpl();

            masterKey.SetKeyId(123);
            masterKey.SetBytes(ByteBuffer.Wrap(new byte[] { 123 }));
            context.GetContainerTokenSecretManager().SetMasterKey(masterKey);
            context.GetNMTokenSecretManager().SetMasterKey(masterKey);
            // add an application by starting a container
            string               appUser   = "******";
            string               modUser   = "******";
            string               viewUser  = "******";
            string               enemyUser = "******";
            ApplicationId        appId     = ApplicationId.NewInstance(0, 1);
            ApplicationAttemptId attemptId = ApplicationAttemptId.NewInstance(appId, 1);
            ContainerId          cid       = ContainerId.NewContainerId(attemptId, 1);
            IDictionary <string, LocalResource> localResources = Collections.EmptyMap();
            IDictionary <string, string>        containerEnv   = Sharpen.Collections.EmptyMap();
            IList <string> containerCmds = Sharpen.Collections.EmptyList();
            IDictionary <string, ByteBuffer> serviceData = Sharpen.Collections.EmptyMap();
            Credentials      containerCreds = new Credentials();
            DataOutputBuffer dob            = new DataOutputBuffer();

            containerCreds.WriteTokenStorageToStream(dob);
            ByteBuffer containerTokens = ByteBuffer.Wrap(dob.GetData(), 0, dob.GetLength());
            IDictionary <ApplicationAccessType, string> acls = new Dictionary <ApplicationAccessType
                                                                               , string>();

            acls[ApplicationAccessType.ModifyApp] = modUser;
            acls[ApplicationAccessType.ViewApp]   = viewUser;
            ContainerLaunchContext clc = ContainerLaunchContext.NewInstance(localResources, containerEnv
                                                                            , containerCmds, serviceData, containerTokens, acls);
            // create the logAggregationContext
            LogAggregationContext logAggregationContext = LogAggregationContext.NewInstance("includePattern"
                                                                                            , "excludePattern", "includePatternInRollingAggregation", "excludePatternInRollingAggregation"
                                                                                            );
            StartContainersResponse startResponse = StartContainer(context, cm, cid, clc, logAggregationContext
                                                                   );

            NUnit.Framework.Assert.IsTrue(startResponse.GetFailedRequests().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, context.GetApplications().Count);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = context.GetApplications()[appId];
            NUnit.Framework.Assert.IsNotNull(app);
            WaitForAppState(app, ApplicationState.Initing);
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(modUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(viewUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(viewUser), ApplicationAccessType.ViewApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(enemyUser), ApplicationAccessType.ViewApp, appUser, appId));
            // reset container manager and verify app recovered with proper acls
            cm.Stop();
            context = new NodeManager.NMContext(new NMContainerTokenSecretManager(conf), new
                                                NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), stateStore);
            cm = CreateContainerManager(context);
            cm.Init(conf);
            cm.Start();
            NUnit.Framework.Assert.AreEqual(1, context.GetApplications().Count);
            app = context.GetApplications()[appId];
            NUnit.Framework.Assert.IsNotNull(app);
            // check whether LogAggregationContext is recovered correctly
            LogAggregationContext recovered = ((ApplicationImpl)app).GetLogAggregationContext
                                                  ();

            NUnit.Framework.Assert.IsNotNull(recovered);
            NUnit.Framework.Assert.AreEqual(logAggregationContext.GetIncludePattern(), recovered
                                            .GetIncludePattern());
            NUnit.Framework.Assert.AreEqual(logAggregationContext.GetExcludePattern(), recovered
                                            .GetExcludePattern());
            NUnit.Framework.Assert.AreEqual(logAggregationContext.GetRolledLogsIncludePattern
                                                (), recovered.GetRolledLogsIncludePattern());
            NUnit.Framework.Assert.AreEqual(logAggregationContext.GetRolledLogsExcludePattern
                                                (), recovered.GetRolledLogsExcludePattern());
            WaitForAppState(app, ApplicationState.Initing);
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(modUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(viewUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(viewUser), ApplicationAccessType.ViewApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(enemyUser), ApplicationAccessType.ViewApp, appUser, appId));
            // simulate application completion
            IList <ApplicationId> finishedApps = new AList <ApplicationId>();

            finishedApps.AddItem(appId);
            cm.Handle(new CMgrCompletedAppsEvent(finishedApps, CMgrCompletedAppsEvent.Reason.
                                                 ByResourcemanager));
            WaitForAppState(app, ApplicationState.ApplicationResourcesCleaningup);
            // restart and verify app is marked for finishing
            cm.Stop();
            context = new NodeManager.NMContext(new NMContainerTokenSecretManager(conf), new
                                                NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), stateStore);
            cm = CreateContainerManager(context);
            cm.Init(conf);
            cm.Start();
            NUnit.Framework.Assert.AreEqual(1, context.GetApplications().Count);
            app = context.GetApplications()[appId];
            NUnit.Framework.Assert.IsNotNull(app);
            WaitForAppState(app, ApplicationState.ApplicationResourcesCleaningup);
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(modUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(viewUser), ApplicationAccessType.ModifyApp, appUser, appId));
            NUnit.Framework.Assert.IsTrue(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                          .CreateRemoteUser(viewUser), ApplicationAccessType.ViewApp, appUser, appId));
            NUnit.Framework.Assert.IsFalse(context.GetApplicationACLsManager().CheckAccess(UserGroupInformation
                                                                                           .CreateRemoteUser(enemyUser), ApplicationAccessType.ViewApp, appUser, appId));
            // simulate log aggregation completion
            app.Handle(new ApplicationEvent(app.GetAppId(), ApplicationEventType.ApplicationResourcesCleanedup
                                            ));
            NUnit.Framework.Assert.AreEqual(app.GetApplicationState(), ApplicationState.Finished
                                            );
            app.Handle(new ApplicationEvent(app.GetAppId(), ApplicationEventType.ApplicationLogHandlingFinished
                                            ));
            // restart and verify app is no longer present after recovery
            cm.Stop();
            context = new NodeManager.NMContext(new NMContainerTokenSecretManager(conf), new
                                                NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), stateStore);
            cm = CreateContainerManager(context);
            cm.Init(conf);
            cm.Start();
            NUnit.Framework.Assert.IsTrue(context.GetApplications().IsEmpty());
            cm.Stop();
        }
 public _ContainersLauncher_309(Context baseArg1, Dispatcher baseArg2, ContainerExecutor
                                baseArg3, LocalDirsHandlerService baseArg4, ContainerManagerImpl baseArg5)
     : base(baseArg1, baseArg2, baseArg3, baseArg4, baseArg5)
 {
 }
 public _PrivilegedExceptionAction_264(ContainerManagerImpl cm, IList <StartContainerRequest
                                                                       > scReqList)
 {
     this.cm        = cm;
     this.scReqList = scReqList;
 }
 public RecoveredContainerLaunch(Context context, Configuration configuration, Dispatcher
                                 dispatcher, ContainerExecutor exec, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                                 app, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                                 container, LocalDirsHandlerService dirsHandler, ContainerManagerImpl containerManager
                                 )
     : base(context, configuration, dispatcher, exec, app, container, dirsHandler, containerManager
            )
 {
     this.shouldLaunchContainer.Set(true);
 }