Search in sources :

Example 11 with ClientToAMTokenSecretManagerInRM

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

the class TestRMWebApp method mockCapacityScheduler.

public static CapacityScheduler mockCapacityScheduler() throws IOException {
    // stolen from TestCapacityScheduler
    CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
    setupQueueConfiguration(conf);
    CapacityScheduler cs = new CapacityScheduler();
    cs.setConf(new YarnConfiguration());
    RMContext rmContext = new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), null);
    rmContext.setNodeLabelManager(new NullRMNodeLabelsManager());
    cs.setRMContext(rmContext);
    cs.init(conf);
    return cs;
}
Also used : RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) ClientToAMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) RMContainerTokenSecretManager(org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager) NMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM) NullRMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) RMContextImpl(org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl)

Example 12 with ClientToAMTokenSecretManagerInRM

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

the class TestCapacityScheduler method testRefreshQueuesWithQueueDelete.

/**
   * Test for queue deletion.
   * @throws Exception
   */
@Test
public void testRefreshQueuesWithQueueDelete() throws Exception {
    CapacityScheduler cs = new CapacityScheduler();
    CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
    RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), null);
    setupQueueConfiguration(conf);
    cs.setConf(new YarnConfiguration());
    cs.setRMContext(resourceManager.getRMContext());
    cs.init(conf);
    cs.start();
    cs.reinitialize(conf, rmContext);
    checkQueueCapacities(cs, A_CAPACITY, B_CAPACITY);
    // test delete leaf queue when there is application running.
    Map<String, CSQueue> queues = cs.getCapacitySchedulerQueueManager().getQueues();
    String b1QTobeDeleted = "b1";
    LeafQueue csB1Queue = Mockito.spy((LeafQueue) queues.get(b1QTobeDeleted));
    when(csB1Queue.getState()).thenReturn(QueueState.DRAINING).thenReturn(QueueState.STOPPED);
    queues.put(b1QTobeDeleted, csB1Queue);
    conf = new CapacitySchedulerConfiguration();
    setupQueueConfigurationWithOutB1(conf);
    try {
        cs.reinitialize(conf, mockContext);
        fail("Expected to throw exception when refresh queue tries to delete a" + " queue with running apps");
    } catch (IOException e) {
    // ignore
    }
    // test delete leaf queue(root.b.b1) when there is no application running.
    conf = new CapacitySchedulerConfiguration();
    setupQueueConfigurationWithOutB1(conf);
    try {
        cs.reinitialize(conf, mockContext);
    } catch (IOException e) {
        fail("Expected to NOT throw exception when refresh queue tries to delete" + " a queue WITHOUT running apps");
    }
    CSQueue rootQueue = cs.getRootQueue();
    CSQueue queueB = findQueue(rootQueue, B);
    CSQueue queueB3 = findQueue(queueB, B1);
    assertNull("Refresh needs to support delete of leaf queue ", queueB3);
    // reset back to default configuration for testing parent queue delete
    conf = new CapacitySchedulerConfiguration();
    setupQueueConfiguration(conf);
    cs.reinitialize(conf, rmContext);
    checkQueueCapacities(cs, A_CAPACITY, B_CAPACITY);
    // set the configurations such that it fails once but should be successfull
    // next time
    queues = cs.getCapacitySchedulerQueueManager().getQueues();
    CSQueue bQueue = Mockito.spy((ParentQueue) queues.get("b"));
    when(bQueue.getState()).thenReturn(QueueState.DRAINING).thenReturn(QueueState.STOPPED);
    queues.put("b", bQueue);
    bQueue = Mockito.spy((LeafQueue) queues.get("b1"));
    when(bQueue.getState()).thenReturn(QueueState.STOPPED);
    queues.put("b1", bQueue);
    bQueue = Mockito.spy((LeafQueue) queues.get("b2"));
    when(bQueue.getState()).thenReturn(QueueState.STOPPED);
    queues.put("b2", bQueue);
    bQueue = Mockito.spy((LeafQueue) queues.get("b3"));
    when(bQueue.getState()).thenReturn(QueueState.STOPPED);
    queues.put("b3", bQueue);
    // test delete Parent queue when there is application running.
    conf = new CapacitySchedulerConfiguration();
    setupQueueConfigurationWithOutB(conf);
    try {
        cs.reinitialize(conf, mockContext);
        fail("Expected to throw exception when refresh queue tries to delete a" + " parent queue with running apps in children queue");
    } catch (IOException e) {
    // ignore
    }
    // test delete Parent queue when there is no application running.
    conf = new CapacitySchedulerConfiguration();
    setupQueueConfigurationWithOutB(conf);
    try {
        cs.reinitialize(conf, mockContext);
    } catch (IOException e) {
        fail("Expected to not throw exception when refresh queue tries to delete" + " a queue without running apps");
    }
    rootQueue = cs.getRootQueue();
    queueB = findQueue(rootQueue, B);
    String message = "Refresh needs to support delete of Parent queue and its children.";
    assertNull(message, queueB);
    assertNull(message, cs.getCapacitySchedulerQueueManager().getQueues().get("b"));
    assertNull(message, cs.getCapacitySchedulerQueueManager().getQueues().get("b1"));
    assertNull(message, cs.getCapacitySchedulerQueueManager().getQueues().get("b2"));
    cs.stop();
}
Also used : ClientToAMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) RMContainerTokenSecretManager(org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager) IOException(java.io.IOException) NMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM) RMContextImpl(org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl) Test(org.junit.Test)

Example 13 with ClientToAMTokenSecretManagerInRM

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

the class RMAppAttemptImpl method createClientToken.

@Override
public Token<ClientToAMTokenIdentifier> createClientToken(String client) {
    this.readLock.lock();
    try {
        Token<ClientToAMTokenIdentifier> token = null;
        ClientToAMTokenSecretManagerInRM secretMgr = this.rmContext.getClientToAMTokenSecretManager();
        if (client != null && secretMgr.getMasterKey(this.applicationAttemptId) != null) {
            token = new Token<ClientToAMTokenIdentifier>(new ClientToAMTokenIdentifier(this.applicationAttemptId, client), secretMgr);
        }
        return token;
    } finally {
        this.readLock.unlock();
    }
}
Also used : ClientToAMTokenIdentifier(org.apache.hadoop.yarn.security.client.ClientToAMTokenIdentifier) ClientToAMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM)

Example 14 with ClientToAMTokenSecretManagerInRM

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

the class TestUtils method getMockRMContext.

/**
   * Get a mock {@link RMContext} for use in test cases.
   * @return a mock {@link RMContext} for use in test cases
   */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static RMContext getMockRMContext() {
    // Null dispatcher
    Dispatcher nullDispatcher = new Dispatcher() {

        private final EventHandler handler = new EventHandler() {

            @Override
            public void handle(Event event) {
            }
        };

        @Override
        public void register(Class<? extends Enum> eventType, EventHandler handler) {
        }

        @Override
        public EventHandler<Event> getEventHandler() {
            return handler;
        }
    };
    // No op
    ContainerAllocationExpirer cae = new ContainerAllocationExpirer(nullDispatcher);
    Configuration conf = new Configuration();
    RMApplicationHistoryWriter writer = mock(RMApplicationHistoryWriter.class);
    RMContextImpl rmContext = new RMContextImpl(nullDispatcher, cae, null, null, null, new AMRMTokenSecretManager(conf, null), new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM());
    RMNodeLabelsManager nlm = mock(RMNodeLabelsManager.class);
    when(nlm.getQueueResource(any(String.class), any(Set.class), any(Resource.class))).thenAnswer(new Answer<Resource>() {

        @Override
        public Resource answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Resource) args[2];
        }
    });
    when(nlm.getResourceByLabel(any(String.class), any(Resource.class))).thenAnswer(new Answer<Resource>() {

        @Override
        public Resource answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Resource) args[1];
        }
    });
    rmContext.setNodeLabelManager(nlm);
    rmContext.setSystemMetricsPublisher(mock(SystemMetricsPublisher.class));
    rmContext.setRMApplicationHistoryWriter(mock(RMApplicationHistoryWriter.class));
    ResourceScheduler mockScheduler = mock(ResourceScheduler.class);
    when(mockScheduler.getResourceCalculator()).thenReturn(new DefaultResourceCalculator());
    rmContext.setScheduler(mockScheduler);
    return rmContext;
}
Also used : ClientToAMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM) Set(java.util.Set) Configuration(org.apache.hadoop.conf.Configuration) ContainerAllocationExpirer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.ContainerAllocationExpirer) Resource(org.apache.hadoop.yarn.api.records.Resource) EventHandler(org.apache.hadoop.yarn.event.EventHandler) RMApplicationHistoryWriter(org.apache.hadoop.yarn.server.resourcemanager.ahs.RMApplicationHistoryWriter) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) AMRMTokenSecretManager(org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager) NMTokenSecretManagerInRM(org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM) DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) SystemMetricsPublisher(org.apache.hadoop.yarn.server.resourcemanager.metrics.SystemMetricsPublisher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Event(org.apache.hadoop.yarn.event.Event) ResourceScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler) RMContainerTokenSecretManager(org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager) RMContextImpl(org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl) RMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager)

Example 15 with ClientToAMTokenSecretManagerInRM

use of org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM 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)

Aggregations

ClientToAMTokenSecretManagerInRM (org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM)30 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)25 RMContextImpl (org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl)24 NMTokenSecretManagerInRM (org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM)24 RMContainerTokenSecretManager (org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager)24 Test (org.junit.Test)21 RMNodeLabelsManager (org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager)6 RMContext (org.apache.hadoop.yarn.server.resourcemanager.RMContext)5 NullRMNodeLabelsManager (org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager)5 Configuration (org.apache.hadoop.conf.Configuration)4 ResourceScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler)4 AMRMTokenSecretManager (org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager)4 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)3 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 SecretKey (javax.crypto.SecretKey)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 Resource (org.apache.hadoop.yarn.api.records.Resource)2 ApplicationSubmissionContextPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ApplicationSubmissionContextPBImpl)2 RMApplicationHistoryWriter (org.apache.hadoop.yarn.server.resourcemanager.ahs.RMApplicationHistoryWriter)2