Search in sources :

Example 16 with ApplicationACLsManager

use of org.apache.hadoop.yarn.server.security.ApplicationACLsManager in project hadoop by apache.

the class TestNodeStatusUpdater method testNoRegistrationWhenNMServicesFail.

/**
   * Verifies that if for some reason NM fails to start ContainerManager RPC
   * server, RM is oblivious to NM's presence. The behaviour is like this
   * because otherwise, NM will report to RM even if all its servers are not
   * started properly, RM will think that the NM is alive and will retire the NM
   * only after NM_EXPIRY interval. See MAPREDUCE-2749.
   */
@Test
public void testNoRegistrationWhenNMServicesFail() throws Exception {
    nm = new NodeManager() {

        @Override
        protected NodeStatusUpdater createNodeStatusUpdater(Context context, Dispatcher dispatcher, NodeHealthCheckerService healthChecker) {
            return new MyNodeStatusUpdater(context, dispatcher, healthChecker, metrics);
        }

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

                @Override
                protected void serviceStart() {
                    // Simulating failure of starting RPC server
                    throw new YarnRuntimeException("Starting of RPC Server failed");
                }
            };
        }
    };
    verifyNodeStartFailure("Starting of RPC Server failed");
}
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) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) Test(org.junit.Test)

Example 17 with ApplicationACLsManager

use of org.apache.hadoop.yarn.server.security.ApplicationACLsManager in project hadoop by apache.

the class TestAppManager method testRMAppSubmitMaxAppAttempts.

@Test(timeout = 30000)
public void testRMAppSubmitMaxAppAttempts() throws Exception {
    int[] globalMaxAppAttempts = new int[] { 10, 1 };
    int[][] individualMaxAppAttempts = new int[][] { new int[] { 9, 10, 11, 0 }, new int[] { 1, 10, 0, -1 } };
    int[][] expectedNums = new int[][] { new int[] { 9, 10, 10, 10 }, new int[] { 1, 1, 1, 1 } };
    for (int i = 0; i < globalMaxAppAttempts.length; ++i) {
        for (int j = 0; j < individualMaxAppAttempts.length; ++j) {
            ResourceScheduler scheduler = mockResourceScheduler();
            Configuration conf = new Configuration();
            conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, globalMaxAppAttempts[i]);
            ApplicationMasterService masterService = new ApplicationMasterService(rmContext, scheduler);
            TestRMAppManager appMonitor = new TestRMAppManager(rmContext, new ClientToAMTokenSecretManagerInRM(), scheduler, masterService, new ApplicationACLsManager(conf), conf);
            ApplicationId appID = MockApps.newAppID(i * 4 + j + 1);
            asContext.setApplicationId(appID);
            if (individualMaxAppAttempts[i][j] != 0) {
                asContext.setMaxAppAttempts(individualMaxAppAttempts[i][j]);
            }
            appMonitor.submitApplication(asContext, "test");
            RMApp app = rmContext.getRMApps().get(appID);
            Assert.assertEquals("max application attempts doesn't match", expectedNums[i][j], app.getMaxAppAttempts());
            // wait for event to be processed
            int timeoutSecs = 0;
            while ((getAppEventType() == RMAppEventType.KILL) && timeoutSecs++ < 20) {
                Thread.sleep(1000);
            }
            setAppEventType(RMAppEventType.KILL);
        }
    }
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockRMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.MockRMApp) ClientToAMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ResourceScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 18 with ApplicationACLsManager

use of org.apache.hadoop.yarn.server.security.ApplicationACLsManager in project hadoop by apache.

the class TestRMWebApp method mockRm.

public static ResourceManager mockRm(RMContext rmContext) throws IOException {
    ResourceManager rm = mock(ResourceManager.class);
    ResourceScheduler rs = mockCapacityScheduler();
    ApplicationACLsManager aclMgr = mockAppACLsManager();
    ClientRMService clientRMService = mockClientRMService(rmContext);
    when(rm.getResourceScheduler()).thenReturn(rs);
    when(rm.getRMContext()).thenReturn(rmContext);
    when(rm.getApplicationACLsManager()).thenReturn(aclMgr);
    when(rm.getClientRMService()).thenReturn(clientRMService);
    return rm;
}
Also used : ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) ResourceScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) ClientRMService(org.apache.hadoop.yarn.server.resourcemanager.ClientRMService)

Example 19 with ApplicationACLsManager

use of org.apache.hadoop.yarn.server.security.ApplicationACLsManager in project hadoop by apache.

the class TestRMWebServices method testDumpingSchedulerLogs.

@Test
public void testDumpingSchedulerLogs() throws Exception {
    ResourceManager mockRM = mock(ResourceManager.class);
    Configuration conf = new YarnConfiguration();
    HttpServletRequest mockHsr = mock(HttpServletRequest.class);
    ApplicationACLsManager aclsManager = new ApplicationACLsManager(conf);
    when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager);
    RMWebServices webSvc = new RMWebServices(mockRM, conf, mock(HttpServletResponse.class));
    // nothing should happen
    webSvc.dumpSchedulerLogs("1", mockHsr);
    waitforLogDump(50);
    checkSchedulerLogFileAndCleanup();
    conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
    conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "admin");
    aclsManager = new ApplicationACLsManager(conf);
    when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager);
    webSvc = new RMWebServices(mockRM, conf, mock(HttpServletResponse.class));
    boolean exceptionThrown = false;
    try {
        webSvc.dumpSchedulerLogs("1", mockHsr);
        fail("Dumping logs should fail");
    } catch (ForbiddenException ae) {
        exceptionThrown = true;
    }
    assertTrue("ForbiddenException expected", exceptionThrown);
    exceptionThrown = false;
    when(mockHsr.getUserPrincipal()).thenReturn(new Principal() {

        @Override
        public String getName() {
            return "testuser";
        }
    });
    try {
        webSvc.dumpSchedulerLogs("1", mockHsr);
        fail("Dumping logs should fail");
    } catch (ForbiddenException ae) {
        exceptionThrown = true;
    }
    assertTrue("ForbiddenException expected", exceptionThrown);
    when(mockHsr.getUserPrincipal()).thenReturn(new Principal() {

        @Override
        public String getName() {
            return "admin";
        }
    });
    webSvc.dumpSchedulerLogs("1", mockHsr);
    waitforLogDump(50);
    checkSchedulerLogFileAndCleanup();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) Principal(java.security.Principal) Test(org.junit.Test)

Example 20 with ApplicationACLsManager

use of org.apache.hadoop.yarn.server.security.ApplicationACLsManager in project hadoop by apache.

the class TestRMRestart method testAppRecoveredInOrderOnRMRestart.

@Test(timeout = 20000)
public void testAppRecoveredInOrderOnRMRestart() throws Exception {
    MemoryRMStateStore memStore = new MemoryRMStateStore();
    memStore.init(conf);
    for (int i = 10; i > 0; i--) {
        ApplicationStateData appState = mock(ApplicationStateData.class);
        ApplicationSubmissionContext context = mock(ApplicationSubmissionContext.class);
        when(appState.getApplicationSubmissionContext()).thenReturn(context);
        when(context.getApplicationId()).thenReturn(ApplicationId.newInstance(1234, i));
        memStore.getState().getApplicationState().put(appState.getApplicationSubmissionContext().getApplicationId(), appState);
    }
    MockRM rm1 = new MockRM(conf, memStore) {

        @Override
        protected RMAppManager createRMAppManager() {
            return new TestRMAppManager(this.rmContext, this.scheduler, this.masterService, this.applicationACLsManager, conf);
        }

        class TestRMAppManager extends RMAppManager {

            ApplicationId prevId = ApplicationId.newInstance(1234, 0);

            public TestRMAppManager(RMContext context, YarnScheduler scheduler, ApplicationMasterService masterService, ApplicationACLsManager applicationACLsManager, Configuration conf) {
                super(context, scheduler, masterService, applicationACLsManager, conf);
            }

            @Override
            protected void recoverApplication(ApplicationStateData appState, RMState rmState) throws Exception {
                // check application is recovered in order.
                Assert.assertTrue(rmState.getApplicationState().size() > 0);
                Assert.assertTrue(appState.getApplicationSubmissionContext().getApplicationId().compareTo(prevId) > 0);
                prevId = appState.getApplicationSubmissionContext().getApplicationId();
            }
        }
    };
    try {
        rm1.start();
    } finally {
        rm1.stop();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationStateData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData) IOException(java.io.IOException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) MemoryRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore) AbstractYarnScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler) YarnScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) RMState(org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore.RMState) Test(org.junit.Test)

Aggregations

ApplicationACLsManager (org.apache.hadoop.yarn.server.security.ApplicationACLsManager)35 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)22 Test (org.junit.Test)21 Configuration (org.apache.hadoop.conf.Configuration)18 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)16 NMContext (org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext)11 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)10 QueueACLsManager (org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager)7 Matchers.anyString (org.mockito.Matchers.anyString)7 NMNullStateStoreService (org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService)6 NMContainerTokenSecretManager (org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager)6 NMTokenSecretManagerInNM (org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM)6 IOException (java.io.IOException)5 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)5 YarnScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 QueueACL (org.apache.hadoop.yarn.api.records.QueueACL)4 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)4 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)4 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)4