Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TestUnmanagedAMLauncher.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args[0].equals("success")) {
    ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf,
        ApplicationMasterProtocol.class);
    client.registerApplicationMaster(RegisterApplicationMasterRequest
        .newInstance(NetUtils.getHostname(), -1, ""));
    Thread.sleep(1000);
    FinishApplicationMasterResponse resp =
        client.finishApplicationMaster(FinishApplicationMasterRequest
          .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null));
    assertTrue(resp.getIsUnregistered());
    System.exit(0);
  } else {
    System.exit(1);
  }
}
 
Example 2
Source Project: big-c   Source File: TestUnmanagedAMLauncher.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args[0].equals("success")) {
    ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf,
        ApplicationMasterProtocol.class);
    client.registerApplicationMaster(RegisterApplicationMasterRequest
        .newInstance(NetUtils.getHostname(), -1, ""));
    Thread.sleep(1000);
    FinishApplicationMasterResponse resp =
        client.finishApplicationMaster(FinishApplicationMasterRequest
          .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null));
    assertTrue(resp.getIsUnregistered());
    System.exit(0);
  } else {
    System.exit(1);
  }
}
 
Example 3
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  RegisterApplicationMasterRequestProto requestProto =
      ((RegisterApplicationMasterRequestPBImpl) request).getProto();
  try {
    return new RegisterApplicationMasterResponsePBImpl(
      proxy.registerApplicationMaster(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 4
Source Project: hadoop   Source File: TestRPCFactories.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  // TODO Auto-generated method stub
  return null;
}
 
Example 5
Source Project: hadoop   Source File: MockAM.java    License: Apache License 2.0 5 votes vote down vote up
public RegisterApplicationMasterResponse registerAppAttempt(boolean wait)
    throws Exception {
  if (wait) {
    waitForState(RMAppAttemptState.LAUNCHED);
  }
  responseId = 0;
  final RegisterApplicationMasterRequest req =
      Records.newRecord(RegisterApplicationMasterRequest.class);
  req.setHost("");
  req.setRpcPort(1);
  req.setTrackingUrl("");
  if (ugi == null) {
    ugi = UserGroupInformation.createRemoteUser(
        attemptId.toString());
    Token<AMRMTokenIdentifier> token =
        context.getRMApps().get(attemptId.getApplicationId())
            .getRMAppAttempt(attemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
  }
  try {
    return ugi
      .doAs(
          new PrivilegedExceptionAction<RegisterApplicationMasterResponse>() {
        @Override
        public RegisterApplicationMasterResponse run() throws Exception {
          return amRMProtocol.registerApplicationMaster(req);
        }
      });
  } catch (UndeclaredThrowableException e) {
    throw (Exception) e.getCause();
  }
}
 
Example 6
Source Project: hadoop   Source File: AMRMClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
private RegisterApplicationMasterResponse registerApplicationMaster()
    throws YarnException, IOException {
  RegisterApplicationMasterRequest request =
      RegisterApplicationMasterRequest.newInstance(this.appHostName,
          this.appHostPort, this.appTrackingUrl);
  RegisterApplicationMasterResponse response =
      rmClient.registerApplicationMaster(request);
  synchronized (this) {
    lastResponseId = 0;
    if (!response.getNMTokensFromPreviousAttempts().isEmpty()) {
      populateNMTokens(response.getNMTokensFromPreviousAttempts());
    }
  }
  return response;
}
 
Example 7
Source Project: hadoop   Source File: ProtocolHATestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  resetStartFailoverFlag(true);
  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());
  return createFakeRegisterApplicationMasterResponse();
}
 
Example 8
@Test(timeout = 15000)
public void testRegisterApplicationMasterOnHA() throws YarnException,
    IOException {
  RegisterApplicationMasterRequest request =
      RegisterApplicationMasterRequest.newInstance("localhost", 0, "");
  RegisterApplicationMasterResponse response =
      amClient.registerApplicationMaster(request);
  Assert.assertEquals(response,
      this.cluster.createFakeRegisterApplicationMasterResponse());
}
 
Example 9
Source Project: hadoop   Source File: RMCommunicator.java    License: Apache License 2.0 5 votes vote down vote up
protected void register() {
  //Register
  InetSocketAddress serviceAddr = null;
  if (clientService != null ) {
    serviceAddr = clientService.getBindAddress();
  }
  try {
    RegisterApplicationMasterRequest request =
      recordFactory.newRecordInstance(RegisterApplicationMasterRequest.class);
    if (serviceAddr != null) {
      request.setHost(serviceAddr.getHostName());
      request.setRpcPort(serviceAddr.getPort());
      request.setTrackingUrl(MRWebAppUtil
          .getAMWebappScheme(getConfig())
          + serviceAddr.getHostName() + ":" + clientService.getHttpPort());
    }
    RegisterApplicationMasterResponse response =
      scheduler.registerApplicationMaster(request);
    isApplicationMasterRegistered = true;
    maxContainerCapability = response.getMaximumResourceCapability();
    this.context.getClusterInfo().setMaxContainerCapability(
        maxContainerCapability);
    if (UserGroupInformation.isSecurityEnabled()) {
      setClientToAMToken(response.getClientToAMTokenMasterKey());        
    }
    this.applicationACLs = response.getApplicationACLs();
    LOG.info("maxContainerCapability: " + maxContainerCapability);
    String queue = response.getQueue();
    LOG.info("queue: " + queue);
    job.setQueueName(queue);
    this.schedulerResourceTypes.addAll(response.getSchedulerResourceTypes());
  } catch (Exception are) {
    LOG.error("Exception while registering", are);
    throw new YarnRuntimeException(are);
  }
}
 
Example 10
Source Project: hadoop   Source File: TestRMContainerAllocator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  return RegisterApplicationMasterResponse.newInstance(
      Resource.newInstance(512, 1),
      Resource.newInstance(512000, 1024),
      Collections.<ApplicationAccessType,String>emptyMap(),
      ByteBuffer.wrap("fake_key".getBytes()),
      Collections.<Container>emptyList(),
      "default",
      Collections.<NMToken>emptyList());
}
 
Example 11
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  RegisterApplicationMasterRequestProto requestProto =
      ((RegisterApplicationMasterRequestPBImpl) request).getProto();
  try {
    return new RegisterApplicationMasterResponsePBImpl(
      proxy.registerApplicationMaster(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 12
Source Project: big-c   Source File: TestRPCFactories.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  // TODO Auto-generated method stub
  return null;
}
 
Example 13
Source Project: big-c   Source File: MockAM.java    License: Apache License 2.0 5 votes vote down vote up
public RegisterApplicationMasterResponse registerAppAttempt(boolean wait)
    throws Exception {
  if (wait) {
    waitForState(RMAppAttemptState.LAUNCHED);
  }
  responseId = 0;
  final RegisterApplicationMasterRequest req =
      Records.newRecord(RegisterApplicationMasterRequest.class);
  req.setHost("");
  req.setRpcPort(1);
  req.setTrackingUrl("");
  if (ugi == null) {
    ugi = UserGroupInformation.createRemoteUser(
        attemptId.toString());
    Token<AMRMTokenIdentifier> token =
        context.getRMApps().get(attemptId.getApplicationId())
            .getRMAppAttempt(attemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
  }
  try {
    return ugi
      .doAs(
          new PrivilegedExceptionAction<RegisterApplicationMasterResponse>() {
        @Override
        public RegisterApplicationMasterResponse run() throws Exception {
          return amRMProtocol.registerApplicationMaster(req);
        }
      });
  } catch (UndeclaredThrowableException e) {
    throw (Exception) e.getCause();
  }
}
 
Example 14
Source Project: big-c   Source File: AMRMClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
private RegisterApplicationMasterResponse registerApplicationMaster()
    throws YarnException, IOException {
  RegisterApplicationMasterRequest request =
      RegisterApplicationMasterRequest.newInstance(this.appHostName,
          this.appHostPort, this.appTrackingUrl);
  RegisterApplicationMasterResponse response =
      rmClient.registerApplicationMaster(request);
  synchronized (this) {
    lastResponseId = 0;
    if (!response.getNMTokensFromPreviousAttempts().isEmpty()) {
      populateNMTokens(response.getNMTokensFromPreviousAttempts());
    }
  }
  return response;
}
 
Example 15
Source Project: big-c   Source File: ProtocolHATestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  resetStartFailoverFlag(true);
  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());
  return createFakeRegisterApplicationMasterResponse();
}
 
Example 16
@Test(timeout = 15000)
public void testRegisterApplicationMasterOnHA() throws YarnException,
    IOException {
  RegisterApplicationMasterRequest request =
      RegisterApplicationMasterRequest.newInstance("localhost", 0, "");
  RegisterApplicationMasterResponse response =
      amClient.registerApplicationMaster(request);
  Assert.assertEquals(response,
      this.cluster.createFakeRegisterApplicationMasterResponse());
}
 
Example 17
Source Project: big-c   Source File: RMCommunicator.java    License: Apache License 2.0 5 votes vote down vote up
protected void register() {
  //Register
  InetSocketAddress serviceAddr = null;
  if (clientService != null ) {
    serviceAddr = clientService.getBindAddress();
  }
  try {
    RegisterApplicationMasterRequest request =
      recordFactory.newRecordInstance(RegisterApplicationMasterRequest.class);
    if (serviceAddr != null) {
      request.setHost(serviceAddr.getHostName());
      request.setRpcPort(serviceAddr.getPort());
      request.setTrackingUrl(MRWebAppUtil
          .getAMWebappScheme(getConfig())
          + serviceAddr.getHostName() + ":" + clientService.getHttpPort());
    }
    RegisterApplicationMasterResponse response =
      scheduler.registerApplicationMaster(request);
    isApplicationMasterRegistered = true;
    maxContainerCapability = response.getMaximumResourceCapability();
    this.context.getClusterInfo().setMaxContainerCapability(
        maxContainerCapability);
    if (UserGroupInformation.isSecurityEnabled()) {
      setClientToAMToken(response.getClientToAMTokenMasterKey());        
    }
    this.applicationACLs = response.getApplicationACLs();
    LOG.info("maxContainerCapability: " + maxContainerCapability);
    String queue = response.getQueue();
    LOG.info("queue: " + queue);
    job.setQueueName(queue);
    this.schedulerResourceTypes.addAll(response.getSchedulerResourceTypes());
  } catch (Exception are) {
    LOG.error("Exception while registering", are);
    throw new YarnRuntimeException(are);
  }
}
 
Example 18
Source Project: big-c   Source File: TestRMContainerAllocator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  return RegisterApplicationMasterResponse.newInstance(
      Resource.newInstance(512, 1),
      Resource.newInstance(512000, 1024),
      Collections.<ApplicationAccessType,String>emptyMap(),
      ByteBuffer.wrap("fake_key".getBytes()),
      Collections.<Container>emptyList(),
      "default",
      Collections.<NMToken>emptyList());
}
 
Example 19
Source Project: hadoop   Source File: TestAMAuthorization.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testAuthorizedAccess() throws Exception {
  MyContainerManager containerManager = new MyContainerManager();
  rm =
      new MockRMWithAMS(conf, containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(2);
  acls.put(ApplicationAccessType.VIEW_APP, "*");
  RMApp app = rm.submitApp(1024, "appname", "appuser", acls);

  nm1.nodeHeartbeat(true);

  int waitCount = 0;
  while (containerManager.containerTokens == null && waitCount++ < 20) {
    LOG.info("Waiting for AM Launch to happen..");
    Thread.sleep(1000);
  }
  Assert.assertNotNull(containerManager.containerTokens);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  // Create a client to the RM.
  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);

  UserGroupInformation currentUser = UserGroupInformation
      .createRemoteUser(applicationAttemptId.toString());
  Credentials credentials = containerManager.getContainerCredentials();
  final InetSocketAddress rmBindAddress =
      rm.getApplicationMasterService().getBindAddress();
  Token<? extends TokenIdentifier> amRMToken =
      MockRMWithAMS.setupAndReturnAMRMToken(rmBindAddress,
        credentials.getAllTokens());
  currentUser.addToken(amRMToken);
  ApplicationMasterProtocol client = currentUser
      .doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(ApplicationMasterProtocol.class, rm
            .getApplicationMasterService().getBindAddress(), conf);
        }
      });

  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  RegisterApplicationMasterResponse response =
      client.registerApplicationMaster(request);
  Assert.assertNotNull(response.getClientToAMTokenMasterKey());
  if (UserGroupInformation.isSecurityEnabled()) {
    Assert
      .assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
  }
  Assert.assertEquals("Register response has bad ACLs", "*",
      response.getApplicationACLs().get(ApplicationAccessType.VIEW_APP));
}
 
Example 20
Source Project: hadoop   Source File: TestAMAuthorization.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testUnauthorizedAccess() throws Exception {
  MyContainerManager containerManager = new MyContainerManager();
  rm = new MockRMWithAMS(conf, containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  RMApp app = rm.submitApp(1024);

  nm1.nodeHeartbeat(true);

  int waitCount = 0;
  while (containerManager.containerTokens == null && waitCount++ < 40) {
    LOG.info("Waiting for AM Launch to happen..");
    Thread.sleep(1000);
  }
  Assert.assertNotNull(containerManager.containerTokens);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);
  final InetSocketAddress serviceAddr = conf.getSocketAddr(
      YarnConfiguration.RM_SCHEDULER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT);

  UserGroupInformation currentUser = UserGroupInformation
      .createRemoteUser(applicationAttemptId.toString());

  // First try contacting NM without tokens
  ApplicationMasterProtocol client = currentUser
      .doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(ApplicationMasterProtocol.class,
              serviceAddr, conf);
        }
      });
  
  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  try {
    client.registerApplicationMaster(request);
    Assert.fail("Should fail with authorization error");
  } catch (Exception e) {
    if (isCause(AccessControlException.class, e)) {
      // Because there are no tokens, the request should be rejected as the
      // server side will assume we are trying simple auth.
      String expectedMessage = "";
      if (UserGroupInformation.isSecurityEnabled()) {
        expectedMessage = "Client cannot authenticate via:[TOKEN]";
      } else {
        expectedMessage =
            "SIMPLE authentication is not enabled.  Available:[TOKEN]";
      }
      Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage)); 
    } else {
      throw e;
    }
  }

  // TODO: Add validation of invalid authorization when there's more data in
  // the AMRMToken
}
 
Example 21
Source Project: hadoop   Source File: TestSchedulerUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testValidateResourceBlacklistRequest() throws Exception {

  MyContainerManager containerManager = new MyContainerManager();
  final MockRMWithAMS rm =
      new MockRMWithAMS(new YarnConfiguration(), containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(2);
  acls.put(ApplicationAccessType.VIEW_APP, "*");
  RMApp app = rm.submitApp(1024, "appname", "appuser", acls);

  nm1.nodeHeartbeat(true);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  // Create a client to the RM.
  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);

  UserGroupInformation currentUser = 
      UserGroupInformation.createRemoteUser(applicationAttemptId.toString());
  Credentials credentials = containerManager.getContainerCredentials();
  final InetSocketAddress rmBindAddress =
      rm.getApplicationMasterService().getBindAddress();
  Token<? extends TokenIdentifier> amRMToken =
      MockRMWithAMS.setupAndReturnAMRMToken(rmBindAddress,
        credentials.getAllTokens());
  currentUser.addToken(amRMToken);
  ApplicationMasterProtocol client =
      currentUser.doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(
            ApplicationMasterProtocol.class, rmBindAddress, conf);
        }
      });

  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  client.registerApplicationMaster(request);

  ResourceBlacklistRequest blacklistRequest =
      ResourceBlacklistRequest.newInstance(
          Collections.singletonList(ResourceRequest.ANY), null);

  AllocateRequest allocateRequest =
      AllocateRequest.newInstance(0, 0.0f, null, null, blacklistRequest);
  boolean error = false;
  try {
    client.allocate(allocateRequest);
  } catch (InvalidResourceBlacklistRequestException e) {
    error = true;
  }

  rm.stop();
  
  Assert.assertTrue(
      "Didn't not catch InvalidResourceBlacklistRequestException", error);
}
 
Example 22
Source Project: hadoop   Source File: TestLocalContainerAllocator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  return null;
}
 
Example 23
Source Project: big-c   Source File: TestAMAuthorization.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testAuthorizedAccess() throws Exception {
  MyContainerManager containerManager = new MyContainerManager();
  rm =
      new MockRMWithAMS(conf, containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(2);
  acls.put(ApplicationAccessType.VIEW_APP, "*");
  RMApp app = rm.submitApp(1024, "appname", "appuser", acls);

  nm1.nodeHeartbeat(true);

  int waitCount = 0;
  while (containerManager.containerTokens == null && waitCount++ < 20) {
    LOG.info("Waiting for AM Launch to happen..");
    Thread.sleep(1000);
  }
  Assert.assertNotNull(containerManager.containerTokens);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  // Create a client to the RM.
  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);

  UserGroupInformation currentUser = UserGroupInformation
      .createRemoteUser(applicationAttemptId.toString());
  Credentials credentials = containerManager.getContainerCredentials();
  final InetSocketAddress rmBindAddress =
      rm.getApplicationMasterService().getBindAddress();
  Token<? extends TokenIdentifier> amRMToken =
      MockRMWithAMS.setupAndReturnAMRMToken(rmBindAddress,
        credentials.getAllTokens());
  currentUser.addToken(amRMToken);
  ApplicationMasterProtocol client = currentUser
      .doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(ApplicationMasterProtocol.class, rm
            .getApplicationMasterService().getBindAddress(), conf);
        }
      });

  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  RegisterApplicationMasterResponse response =
      client.registerApplicationMaster(request);
  Assert.assertNotNull(response.getClientToAMTokenMasterKey());
  if (UserGroupInformation.isSecurityEnabled()) {
    Assert
      .assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
  }
  Assert.assertEquals("Register response has bad ACLs", "*",
      response.getApplicationACLs().get(ApplicationAccessType.VIEW_APP));
}
 
Example 24
Source Project: big-c   Source File: TestAMAuthorization.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testUnauthorizedAccess() throws Exception {
  MyContainerManager containerManager = new MyContainerManager();
  rm = new MockRMWithAMS(conf, containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  RMApp app = rm.submitApp(1024);

  nm1.nodeHeartbeat(true);

  int waitCount = 0;
  while (containerManager.containerTokens == null && waitCount++ < 40) {
    LOG.info("Waiting for AM Launch to happen..");
    Thread.sleep(1000);
  }
  Assert.assertNotNull(containerManager.containerTokens);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);
  final InetSocketAddress serviceAddr = conf.getSocketAddr(
      YarnConfiguration.RM_SCHEDULER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT);

  UserGroupInformation currentUser = UserGroupInformation
      .createRemoteUser(applicationAttemptId.toString());

  // First try contacting NM without tokens
  ApplicationMasterProtocol client = currentUser
      .doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(ApplicationMasterProtocol.class,
              serviceAddr, conf);
        }
      });
  
  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  try {
    client.registerApplicationMaster(request);
    Assert.fail("Should fail with authorization error");
  } catch (Exception e) {
    if (isCause(AccessControlException.class, e)) {
      // Because there are no tokens, the request should be rejected as the
      // server side will assume we are trying simple auth.
      String expectedMessage = "";
      if (UserGroupInformation.isSecurityEnabled()) {
        expectedMessage = "Client cannot authenticate via:[TOKEN]";
      } else {
        expectedMessage =
            "SIMPLE authentication is not enabled.  Available:[TOKEN]";
      }
      Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage)); 
    } else {
      throw e;
    }
  }

  // TODO: Add validation of invalid authorization when there's more data in
  // the AMRMToken
}
 
Example 25
Source Project: big-c   Source File: TestSchedulerUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testValidateResourceBlacklistRequest() throws Exception {

  MyContainerManager containerManager = new MyContainerManager();
  final MockRMWithAMS rm =
      new MockRMWithAMS(new YarnConfiguration(), containerManager);
  rm.start();

  MockNM nm1 = rm.registerNode("localhost:1234", 5120);

  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(2);
  acls.put(ApplicationAccessType.VIEW_APP, "*");
  RMApp app = rm.submitApp(1024, "appname", "appuser", acls);

  nm1.nodeHeartbeat(true);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId();
  waitForLaunchedState(attempt);

  // Create a client to the RM.
  final Configuration conf = rm.getConfig();
  final YarnRPC rpc = YarnRPC.create(conf);

  UserGroupInformation currentUser = 
      UserGroupInformation.createRemoteUser(applicationAttemptId.toString());
  Credentials credentials = containerManager.getContainerCredentials();
  final InetSocketAddress rmBindAddress =
      rm.getApplicationMasterService().getBindAddress();
  Token<? extends TokenIdentifier> amRMToken =
      MockRMWithAMS.setupAndReturnAMRMToken(rmBindAddress,
        credentials.getAllTokens());
  currentUser.addToken(amRMToken);
  ApplicationMasterProtocol client =
      currentUser.doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
          return (ApplicationMasterProtocol) rpc.getProxy(
            ApplicationMasterProtocol.class, rmBindAddress, conf);
        }
      });

  RegisterApplicationMasterRequest request = Records
      .newRecord(RegisterApplicationMasterRequest.class);
  client.registerApplicationMaster(request);

  ResourceBlacklistRequest blacklistRequest =
      ResourceBlacklistRequest.newInstance(
          Collections.singletonList(ResourceRequest.ANY), null);

  AllocateRequest allocateRequest =
      AllocateRequest.newInstance(0, 0.0f, null, null, blacklistRequest);
  boolean error = false;
  try {
    client.allocate(allocateRequest);
  } catch (InvalidResourceBlacklistRequestException e) {
    error = true;
  }

  rm.stop();
  
  Assert.assertTrue(
      "Didn't not catch InvalidResourceBlacklistRequestException", error);
}
 
Example 26
Source Project: big-c   Source File: TestLocalContainerAllocator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) throws YarnException,
    IOException {
  return null;
}
 
Example 27
Source Project: hadoop   Source File: ApplicationMasterProtocol.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The interface used by a new <code>ApplicationMaster</code> to register with
 * the <code>ResourceManager</code>.
 * </p>
 * 
 * <p>
 * The <code>ApplicationMaster</code> needs to provide details such as RPC
 * Port, HTTP tracking url etc. as specified in
 * {@link RegisterApplicationMasterRequest}.
 * </p>
 * 
 * <p>
 * The <code>ResourceManager</code> responds with critical details such as
 * maximum resource capabilities in the cluster as specified in
 * {@link RegisterApplicationMasterResponse}.
 * </p>
 * 
 * @param request
 *          registration request
 * @return registration respose
 * @throws YarnException
 * @throws IOException
 * @throws InvalidApplicationMasterRequestException
 *           The exception is thrown when an ApplicationMaster tries to
 *           register more then once.
 * @see RegisterApplicationMasterRequest
 * @see RegisterApplicationMasterResponse
 */
@Public
@Stable
@Idempotent
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) 
throws YarnException, IOException;
 
Example 28
Source Project: big-c   Source File: ApplicationMasterProtocol.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The interface used by a new <code>ApplicationMaster</code> to register with
 * the <code>ResourceManager</code>.
 * </p>
 * 
 * <p>
 * The <code>ApplicationMaster</code> needs to provide details such as RPC
 * Port, HTTP tracking url etc. as specified in
 * {@link RegisterApplicationMasterRequest}.
 * </p>
 * 
 * <p>
 * The <code>ResourceManager</code> responds with critical details such as
 * maximum resource capabilities in the cluster as specified in
 * {@link RegisterApplicationMasterResponse}.
 * </p>
 * 
 * @param request
 *          registration request
 * @return registration respose
 * @throws YarnException
 * @throws IOException
 * @throws InvalidApplicationMasterRequestException
 *           The exception is thrown when an ApplicationMaster tries to
 *           register more then once.
 * @see RegisterApplicationMasterRequest
 * @see RegisterApplicationMasterResponse
 */
@Public
@Stable
@Idempotent
public RegisterApplicationMasterResponse registerApplicationMaster(
    RegisterApplicationMasterRequest request) 
throws YarnException, IOException;