Search in sources :

Example 11 with Context

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

the class TestAppLogAggregatorImpl method createAppLogAggregator.

private static AppLogAggregatorInTest createAppLogAggregator(ApplicationId applicationId, String rootLogDir, YarnConfiguration config, long recoveredLogInitedTimeMillis, DeletionService deletionServiceWithFilesToExpect) throws IOException {
    final Dispatcher dispatcher = createNullDispatcher();
    final NodeId nodeId = NodeId.newInstance("localhost", 0);
    final String userId = "AppLogAggregatorTest";
    final UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userId);
    final LocalDirsHandlerService dirsService = createLocalDirsHandlerService(config, rootLogDir);
    final DeletionService deletionService = deletionServiceWithFilesToExpect;
    final LogAggregationContext logAggregationContext = null;
    final Map<ApplicationAccessType, String> appAcls = new HashMap<>();
    final Context context = createContext(config);
    final FileContext fakeLfs = mock(FileContext.class);
    final Path remoteLogDirForApp = new Path(REMOTE_LOG_FILE.getAbsolutePath());
    return new AppLogAggregatorInTest(dispatcher, deletionService, config, applicationId, ugi, nodeId, dirsService, remoteLogDirForApp, appAcls, logAggregationContext, context, fakeLfs, recoveredLogInitedTimeMillis);
}
Also used : FileContext(org.apache.hadoop.fs.FileContext) LogAggregationContext(org.apache.hadoop.yarn.api.records.LogAggregationContext) ContainerLogContext(org.apache.hadoop.yarn.server.api.ContainerLogContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) DeletionService(org.apache.hadoop.yarn.server.nodemanager.DeletionService) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) NodeId(org.apache.hadoop.yarn.api.records.NodeId) LogAggregationContext(org.apache.hadoop.yarn.api.records.LogAggregationContext) FileContext(org.apache.hadoop.fs.FileContext) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 12 with Context

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

the class TestLocalCacheCleanup method createLocService.

private ResourceLocalizationService createLocService(ConcurrentMap<LocalResourceRequest, LocalizedResource> publicRsrcs, ConcurrentMap<String, LocalResourcesTracker> privateRsrcs, long targetCacheSize) {
    Context mockedContext = mock(Context.class);
    when(mockedContext.getNMStateStore()).thenReturn(null);
    ResourceLocalizationService rls = new ResourceLocalizationService(null, null, null, null, mockedContext);
    // We set the following members directly so we don't have to deal with
    // mocking out the service init method.
    rls.publicRsrc = new StubbedLocalResourcesTrackerImpl(null, publicRsrcs);
    rls.cacheTargetSize = targetCacheSize;
    rls.privateRsrc.putAll(privateRsrcs);
    return rls;
}
Also used : Context(org.apache.hadoop.yarn.server.nodemanager.Context)

Example 13 with Context

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

the class TestNMWebServer method testNMWebApp.

@Test
public void testNMWebApp() throws IOException, YarnException {
    Configuration conf = new Configuration();
    Context nmContext = new NodeManager.NMContext(null, null, null, null, null, false, conf);
    ResourceView resourceView = new ResourceView() {

        @Override
        public long getVmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getPmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getVCoresAllocatedForContainers() {
            return 0;
        }

        @Override
        public boolean isVmemCheckEnabled() {
            return true;
        }

        @Override
        public boolean isPmemCheckEnabled() {
            return true;
        }
    };
    conf.set(YarnConfiguration.NM_LOCAL_DIRS, testRootDir.getAbsolutePath());
    conf.set(YarnConfiguration.NM_LOG_DIRS, testLogDir.getAbsolutePath());
    NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
    healthChecker.init(conf);
    LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
    WebServer server = new WebServer(nmContext, resourceView, new ApplicationACLsManager(conf), dirsHandler);
    server.init(conf);
    server.start();
    // Add an application and the corresponding containers
    RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(conf);
    Dispatcher dispatcher = new AsyncDispatcher();
    String user = "nobody";
    long clusterTimeStamp = 1234;
    ApplicationId appId = BuilderUtils.newApplicationId(recordFactory, clusterTimeStamp, 1);
    Application app = mock(Application.class);
    when(app.getUser()).thenReturn(user);
    when(app.getAppId()).thenReturn(appId);
    nmContext.getApplications().put(appId, app);
    ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(appId, 1);
    ContainerId container1 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 0);
    ContainerId container2 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 1);
    NodeManagerMetrics metrics = mock(NodeManagerMetrics.class);
    NMStateStoreService stateStore = new NMNullStateStoreService();
    for (ContainerId containerId : new ContainerId[] { container1, container2 }) {
        // TODO: Use builder utils
        ContainerLaunchContext launchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class);
        long currentTime = System.currentTimeMillis();
        Token containerToken = BuilderUtils.newContainerToken(containerId, 0, "127.0.0.1", 1234, user, BuilderUtils.newResource(1024, 1), currentTime + 10000L, 123, "password".getBytes(), currentTime);
        Context context = mock(Context.class);
        Container container = new ContainerImpl(conf, dispatcher, launchContext, null, metrics, BuilderUtils.newContainerTokenIdentifier(containerToken), context) {

            @Override
            public ContainerState getContainerState() {
                return ContainerState.RUNNING;
            }

            ;
        };
        nmContext.getContainers().put(containerId, container);
        //TODO: Gross hack. Fix in code.
        ApplicationId applicationId = containerId.getApplicationAttemptId().getApplicationId();
        nmContext.getApplications().get(applicationId).getContainers().put(containerId, container);
        writeContainerLogs(nmContext, containerId, dirsHandler);
    }
// TODO: Pull logs and test contents.
//    Thread.sleep(1000000);
}
Also used : ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) NodeHealthCheckerService(org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService) Token(org.apache.hadoop.yarn.api.records.Token) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) NMStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService) ResourceView(org.apache.hadoop.yarn.server.nodemanager.ResourceView) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl) NodeManagerMetrics(org.apache.hadoop.yarn.server.nodemanager.metrics.NodeManagerMetrics) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 14 with Context

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

the class TestNMWebServer method startNMWebAppServer.

private int startNMWebAppServer(String webAddr) {
    Configuration conf = new Configuration();
    Context nmContext = new NodeManager.NMContext(null, null, null, null, null, false, conf);
    ResourceView resourceView = new ResourceView() {

        @Override
        public long getVmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getPmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getVCoresAllocatedForContainers() {
            return 0;
        }

        @Override
        public boolean isVmemCheckEnabled() {
            return true;
        }

        @Override
        public boolean isPmemCheckEnabled() {
            return true;
        }
    };
    conf.set(YarnConfiguration.NM_LOCAL_DIRS, testRootDir.getAbsolutePath());
    conf.set(YarnConfiguration.NM_LOG_DIRS, testLogDir.getAbsolutePath());
    NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
    healthChecker.init(conf);
    LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
    conf.set(YarnConfiguration.NM_WEBAPP_ADDRESS, webAddr);
    WebServer server = new WebServer(nmContext, resourceView, new ApplicationACLsManager(conf), dirsHandler);
    try {
        server.init(conf);
        server.start();
        return server.getPort();
    } finally {
        server.stop();
        healthChecker.stop();
    }
}
Also used : ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) ResourceView(org.apache.hadoop.yarn.server.nodemanager.ResourceView) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) NodeHealthCheckerService(org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)

Aggregations

Context (org.apache.hadoop.yarn.server.nodemanager.Context)14 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)8 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)8 Test (org.junit.Test)8 Configuration (org.apache.hadoop.conf.Configuration)7 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)7 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)7 FileContext (org.apache.hadoop.fs.FileContext)6 LogAggregationContext (org.apache.hadoop.yarn.api.records.LogAggregationContext)6 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)6 NMContext (org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext)6 ByteBuffer (java.nio.ByteBuffer)5 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)5 HashMap (java.util.HashMap)4 StartContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse)4 ApplicationAccessType (org.apache.hadoop.yarn.api.records.ApplicationAccessType)4 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)4 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)4 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)4 NMMemoryStateStoreService (org.apache.hadoop.yarn.server.nodemanager.recovery.NMMemoryStateStoreService)4