Package org.apache.hadoop.yarn.server.resourcemanager

Examples of org.apache.hadoop.yarn.server.resourcemanager.ResourceManager


  @Test
  public void testUnauthorizedUser() throws IOException, InterruptedException {

    LOG.info("\n\nRunning test for malice user");

    ResourceManager resourceManager = yarnCluster.getResourceManager();

    final YarnRPC yarnRPC = YarnRPC.create(conf);

    // Submit an application
    final ApplicationId appID = resourceManager.getClientRMService()
        .getNewApplication(Records.newRecord(GetNewApplicationRequest.class))
        .getApplicationId();
    AMRMProtocol scheduler = submitAndRegisterApplication(resourceManager,
        yarnRPC, appID);

    // Now request a container.
    final Container allocatedContainer = requestAndGetContainer(scheduler,
        appID);

    // Now talk to the NM for launching the container with modified containerID
    final ContainerId containerID = allocatedContainer.getId();

    /////////// Test calls with illegal containerIDs and illegal Resources
    UserGroupInformation unauthorizedUser = UserGroupInformation
        .createRemoteUser(containerID.toString());
    ContainerToken containerToken = allocatedContainer.getContainerToken();

    byte[] identifierBytes = containerToken.getIdentifier().array();
    DataInputBuffer di = new DataInputBuffer();
    di.reset(identifierBytes, identifierBytes.length);
    final ContainerTokenIdentifier tokenId = new ContainerTokenIdentifier();
    tokenId.readFields(di);

    Token<ContainerTokenIdentifier> token = new Token<ContainerTokenIdentifier>(
        identifierBytes, containerToken.getPassword().array(), new Text(
            containerToken.getKind()), new Text(containerToken.getService()));

    unauthorizedUser.addToken(token);
    ContainerManager client =
        unauthorizedUser.doAs(new PrivilegedAction<ContainerManager>() {
      @Override
      public ContainerManager run() {
        ContainerManager client = (ContainerManager) yarnRPC.getProxy(
            ContainerManager.class, NetUtils
                .createSocketAddr(allocatedContainer.getNodeId().toString()),
            conf);

        LOG.info("Going to contact NM:  unauthorized request");

        callWithIllegalContainerID(client, tokenId);
        callWithIllegalResource(client, tokenId);
        callWithIllegalUserName(client, tokenId);

        return client;
      }
    });
   
    // ///////// End of testing for illegal containerIDs, illegal Resources and
    // illegal users

    /////////// Test calls with expired tokens
    RPC.stopProxy(client);
    unauthorizedUser = UserGroupInformation
        .createRemoteUser(containerID.toString());

    RMContainerTokenSecretManager containerTokenSecreteManager =
      resourceManager.getRMContainerTokenSecretManager();
    final ContainerTokenIdentifier newTokenId =
        new ContainerTokenIdentifier(tokenId.getContainerID(),
          tokenId.getNmHostAddress(), "testUser", tokenId.getResource(),
          System.currentTimeMillis() - 1,
          containerTokenSecreteManager.getCurrentKey().getKeyId());
    byte[] passowrd =
        containerTokenSecreteManager.createPassword(
            newTokenId);
    // Create a valid token by using the key from the RM.
    token = new Token<ContainerTokenIdentifier>(
        newTokenId.getBytes(), passowrd, new Text(
            containerToken.getKind()), new Text(containerToken.getService()));

    unauthorizedUser.addToken(token);
    unauthorizedUser.doAs(new PrivilegedAction<Void>() {
      @Override
      public Void run() {
        ContainerManager client = (ContainerManager) yarnRPC.getProxy(
            ContainerManager.class, NetUtils
                .createSocketAddr(allocatedContainer.getNodeId().toString()),
            conf);

        LOG.info("Going to contact NM with expired token");
        ContainerLaunchContext context = createContainerLaunchContextForTest(newTokenId);
        StartContainerRequest request = Records.newRecord(StartContainerRequest.class);
        request.setContainerLaunchContext(context);

        //Calling startContainer with an expired token.
        try {
          client.startContainer(request);
          fail("Connection initiation with expired "
              + "token is expected to fail.");
        } catch (Throwable t) {
          LOG.info("Got exception : ", t);
          Assert.assertTrue(t.getMessage().contains(
                  "This token is expired. current time is"));
        }

        // Try stopping a container - should not get an expiry error.
        StopContainerRequest stopRequest = Records.newRecord(StopContainerRequest.class);
        stopRequest.setContainerId(newTokenId.getContainerID());
        try {
          client.stopContainer(stopRequest);
        } catch (Throwable t) {
          fail("Stop Container call should have succeeded");
        }
       
        return null;
      }
    });
    /////////// End of testing calls with expired tokens

    KillApplicationRequest request = Records
        .newRecord(KillApplicationRequest.class);
    request.setApplicationId(appID);
    resourceManager.getClientRMService().forceKillApplication(request);
  }
View Full Code Here


  private ResourceManager resourceManager = null;
 
  @Before
  public void setUp() throws Exception {
    Store store = StoreFactory.getStore(new Configuration());
    resourceManager = new ResourceManager(store);
    Configuration conf = new Configuration();
    conf.setClass(YarnConfiguration.RM_SCHEDULER,
        FifoScheduler.class, ResourceScheduler.class);
    resourceManager.init(conf);
  }
View Full Code Here

    @Override
    public synchronized void start() {
      try {
        Store store = StoreFactory.getStore(getConfig());
        resourceManager = new ResourceManager(store) {
          @Override
          protected void doSecureLogin() throws IOException {
            // Don't try to login using keytab in the testcase.
          };
        };
View Full Code Here

    UserGroupInformation.setConfiguration(conf);
    // Default rolling and activation intervals are large enough, no need to
    // intervene

    final DrainDispatcher dispatcher = new DrainDispatcher();
    ResourceManager rm = new ResourceManager(null) {
      @Override
      protected void doSecureLogin() throws IOException {
        // Do nothing.
      }

      @Override
      protected Dispatcher createDispatcher() {
        return dispatcher;
      }
    };
    rm.init(conf);
    rm.start();

    MockNM nm = new MockNM("host:1234", 3072, rm.getResourceTrackerService());
    RegistrationResponse registrationResponse = nm.registerNode();
    MasterKey masterKey = registrationResponse.getMasterKey();
    Assert.assertNotNull("Registration should cause a key-update!", masterKey);
    dispatcher.await();

    HeartbeatResponse response = nm.nodeHeartbeat(true);
    Assert.assertNull(
      "First heartbeat after registration shouldn't get any key updates!",
      response.getMasterKey());
    dispatcher.await();

    response = nm.nodeHeartbeat(true);
    Assert
      .assertNull(
        "Even second heartbeat after registration shouldn't get any key updates!",
        response.getMasterKey());
    dispatcher.await();

    // Let's force a roll-over
    RMContainerTokenSecretManager secretManager =
        rm.getRMContainerTokenSecretManager();
    secretManager.rollMasterKey();

    // Heartbeats after roll-over and before activation should be fine.
    response = nm.nodeHeartbeat(true);
    Assert.assertNotNull(
      "Heartbeats after roll-over and before activation should not err out.",
      response.getMasterKey());
    Assert.assertEquals(
      "Roll-over should have incremented the key-id only by one!",
      masterKey.getKeyId() + 1, response.getMasterKey().getKeyId());
    dispatcher.await();

    response = nm.nodeHeartbeat(true);
    Assert.assertNull(
      "Second heartbeat after roll-over shouldn't get any key updates!",
      response.getMasterKey());
    dispatcher.await();

    // Let's force activation
    secretManager.activateNextMasterKey();

    response = nm.nodeHeartbeat(true);
    Assert.assertNull("Activation shouldn't cause any key updates!",
      response.getMasterKey());
    dispatcher.await();

    response = nm.nodeHeartbeat(true);
    Assert.assertNull(
      "Even second heartbeat after activation shouldn't get any key updates!",
      response.getMasterKey());
    dispatcher.await();

    rm.stop();
  }
View Full Code Here

  private ResourceManager resourceManager = null;
 
  @Before
  public void setUp() throws Exception {
    Store store = StoreFactory.getStore(new Configuration());
    resourceManager = new ResourceManager(store);
    CapacitySchedulerConfiguration csConf
       = new CapacitySchedulerConfiguration();
    setupQueueConfiguration(csConf);
    YarnConfiguration conf = new YarnConfiguration(csConf);
    conf.setClass(YarnConfiguration.RM_SCHEDULER,
View Full Code Here

        RMAppState.NEW.toString(),
        RMAppState.SUBMITTED.toString(),
        RMAppState.ACCEPTED.toString(),
        RMAppState.RUNNING.toString()));

    ResourceManager rm = getInstance(ResourceManager.class);
    ResourceScheduler rs = rm.getResourceScheduler();
    if (rs == null || rs instanceof CapacityScheduler) {
      setTitle("Capacity Scheduler");
      render(CapacitySchedulerPage.class);
      return;
    }
View Full Code Here

        RMAppState.NEW.toString(),
        RMAppState.SUBMITTED.toString(),
        RMAppState.ACCEPTED.toString(),
        RMAppState.RUNNING.toString()));

    ResourceManager rm = getInstance(ResourceManager.class);
    ResourceScheduler rs = rm.getResourceScheduler();
    if (rs == null || rs instanceof CapacityScheduler) {
      setTitle("Capacity Scheduler");
      render(CapacitySchedulerPage.class);
      return;
    }
View Full Code Here

              MiniYARNCluster.getHostname() + ":0");
          getConfig().set(YarnConfiguration.RM_WEBAPP_ADDRESS,
              MiniYARNCluster.getHostname() + ":0");
        }
        Store store = StoreFactory.getStore(getConfig());
        resourceManager = new ResourceManager(store) {
          @Override
          protected void doSecureLogin() throws IOException {
            // Don't try to login using keytab in the testcase.
          };
        };
View Full Code Here

  private ResourceManager resourceManager = null;
 
  @Before
  public void setUp() throws Exception {
    Store store = StoreFactory.getStore(new Configuration());
    resourceManager = new ResourceManager(store);
    CapacitySchedulerConfiguration csConf
       = new CapacitySchedulerConfiguration();
    setupQueueConfiguration(csConf);
    YarnConfiguration conf = new YarnConfiguration(csConf);
    conf.setClass(YarnConfiguration.RM_SCHEDULER,
View Full Code Here

          getConfig().set(YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS,
              hostname + ":0");
          getConfig().set(YarnConfiguration.RM_WEBAPP_ADDRESS,
              hostname + ":0");
        }
        resourceManager = new ResourceManager() {
          @Override
          protected void doSecureLogin() throws IOException {
            // Don't try to login using keytab in the testcase.
          };
        };
View Full Code Here

TOP

Related Classes of org.apache.hadoop.yarn.server.resourcemanager.ResourceManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.