Search in sources :

Example 6 with ContainerManagerImpl

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl in project hadoop by apache.

the class TestNodeStatusUpdater method testStopReentrant.

@Test
public void testStopReentrant() throws Exception {
    final AtomicInteger numCleanups = new AtomicInteger(0);
    nm = new NodeManager() {

        @Override
        protected NodeStatusUpdater createNodeStatusUpdater(Context context, Dispatcher dispatcher, NodeHealthCheckerService healthChecker) {
            MyNodeStatusUpdater myNodeStatusUpdater = new MyNodeStatusUpdater(context, dispatcher, healthChecker, metrics);
            MyResourceTracker2 myResourceTracker2 = new MyResourceTracker2();
            myResourceTracker2.heartBeatNodeAction = NodeAction.SHUTDOWN;
            myNodeStatusUpdater.resourceTracker = myResourceTracker2;
            return myNodeStatusUpdater;
        }

        @Override
        protected ContainerManagerImpl createContainerManager(Context context, ContainerExecutor exec, DeletionService del, NodeStatusUpdater nodeStatusUpdater, ApplicationACLsManager aclsManager, LocalDirsHandlerService dirsHandler) {
            return new ContainerManagerImpl(context, exec, del, nodeStatusUpdater, metrics, dirsHandler) {

                @Override
                public void cleanUpApplicationsOnNMShutDown() {
                    super.cleanUpApplicationsOnNMShutDown();
                    numCleanups.incrementAndGet();
                }
            };
        }
    };
    YarnConfiguration conf = createNMConfig();
    nm.init(conf);
    nm.start();
    int waitCount = 0;
    while (heartBeatID < 1 && waitCount++ != 200) {
        Thread.sleep(500);
    }
    Assert.assertFalse(heartBeatID < 1);
    // Meanwhile call stop directly as the shutdown hook would
    nm.stop();
    // NM takes a while to reach the STOPPED state.
    waitCount = 0;
    while (nm.getServiceState() != STATE.STOPPED && waitCount++ != 20) {
        LOG.info("Waiting for NM to stop..");
        Thread.sleep(1000);
    }
    Assert.assertEquals(STATE.STOPPED, nm.getServiceState());
    // It further takes a while after NM reached the STOPPED state.
    waitCount = 0;
    while (numCleanups.get() == 0 && waitCount++ != 20) {
        LOG.info("Waiting for NM shutdown..");
        Thread.sleep(1000);
    }
    Assert.assertEquals(1, numCleanups.get());
}
Also used : FileContext(org.apache.hadoop.fs.FileContext) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) ContainerManagerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Test(org.junit.Test)

Example 7 with ContainerManagerImpl

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl in project hadoop by apache.

the class TestContainerSchedulerQueuing method createContainerManager.

@Override
protected ContainerManagerImpl createContainerManager(DeletionService delSrvc) {
    return new ContainerManagerImpl(context, exec, delSrvc, nodeStatusUpdater, metrics, dirsHandler) {

        @Override
        public void setBlockNewContainerRequests(boolean blockNewContainerRequests) {
        // do nothing
        }

        @Override
        protected UserGroupInformation getRemoteUgi() throws YarnException {
            ApplicationId appId = ApplicationId.newInstance(0, 0);
            ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
            UserGroupInformation ugi = UserGroupInformation.createRemoteUser(appAttemptId.toString());
            ugi.addTokenIdentifier(new NMTokenIdentifier(appAttemptId, context.getNodeId(), user, context.getNMTokenSecretManager().getCurrentKey().getKeyId()));
            return ugi;
        }

        @Override
        protected ContainersMonitor createContainersMonitor(ContainerExecutor exec) {
            return new ContainersMonitorImpl(exec, dispatcher, this.context) {

                // Define resources available for containers to be executed.
                @Override
                public long getPmemAllocatedForContainers() {
                    return 2048 * 1024 * 1024L;
                }

                @Override
                public long getVmemAllocatedForContainers() {
                    float pmemRatio = getConfig().getFloat(YarnConfiguration.NM_VMEM_PMEM_RATIO, YarnConfiguration.DEFAULT_NM_VMEM_PMEM_RATIO);
                    return (long) (pmemRatio * getPmemAllocatedForContainers());
                }

                @Override
                public long getVCoresAllocatedForContainers() {
                    return 4;
                }
            };
        }
    };
}
Also used : ContainerManagerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl) NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) DefaultContainerExecutor(org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor) ContainerExecutor(org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor) ContainersMonitorImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitorImpl) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

ContainerManagerImpl (org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl)7 FileContext (org.apache.hadoop.fs.FileContext)4 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)4 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)4 NMContext (org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext)4 ApplicationACLsManager (org.apache.hadoop.yarn.server.security.ApplicationACLsManager)4 Test (org.junit.Test)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 IOException (java.io.IOException)1 ApplicationMasterProtocol (org.apache.hadoop.yarn.api.ApplicationMasterProtocol)1 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 AMRMTokenIdentifier (org.apache.hadoop.yarn.security.AMRMTokenIdentifier)1 NMTokenIdentifier (org.apache.hadoop.yarn.security.NMTokenIdentifier)1 ContainerExecutor (org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor)1