org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest Java Examples

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest. 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 File: QueueACLsTestBase.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void verifyKillAppFailure(String submitter, String killer,
    String queueName, boolean setupACLs) throws Exception {

  ApplicationId applicationId =
      submitAppAndGetAppId(submitter, queueName, setupACLs);

  final KillApplicationRequest finishAppRequest =
      KillApplicationRequest.newInstance(applicationId);

  ApplicationClientProtocol killerClient = getRMClientForUser(killer);

  // Kill app as the killer
  try {
    killerClient.forceKillApplication(finishAppRequest);
    Assert.fail("App killing by the enemy should fail!!");
  } catch (YarnException e) {
    LOG.info("Got exception while killing app as the enemy", e);
    Assert.assertTrue(e.getMessage().contains(
      "User " + killer + " cannot perform operation MODIFY_APP on "
          + applicationId));
  }

  getRMClientForUser(submitter).forceKillApplication(finishAppRequest);
}
 
Example #2
Source File: TestYarnClient.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testKillApplication() throws Exception {
  MockRM rm = new MockRM();
  rm.start();
  RMApp app = rm.submitApp(2000);

  Configuration conf = new Configuration();
  @SuppressWarnings("resource")
  final YarnClient client = new MockYarnClient();
  client.init(conf);
  client.start();

  client.killApplication(app.getApplicationId());
  verify(((MockYarnClient) client).getRMClient(), times(2))
    .forceKillApplication(any(KillApplicationRequest.class));
}
 
Example #3
Source File: QueueACLsTestBase.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void verifyKillAppFailure(String submitter, String killer,
    String queueName, boolean setupACLs) throws Exception {

  ApplicationId applicationId =
      submitAppAndGetAppId(submitter, queueName, setupACLs);

  final KillApplicationRequest finishAppRequest =
      KillApplicationRequest.newInstance(applicationId);

  ApplicationClientProtocol killerClient = getRMClientForUser(killer);

  // Kill app as the killer
  try {
    killerClient.forceKillApplication(finishAppRequest);
    Assert.fail("App killing by the enemy should fail!!");
  } catch (YarnException e) {
    LOG.info("Got exception while killing app as the enemy", e);
    Assert.assertTrue(e.getMessage().contains(
      "User " + killer + " cannot perform operation MODIFY_APP on "
          + applicationId));
  }

  getRMClientForUser(submitter).forceKillApplication(finishAppRequest);
}
 
Example #4
Source File: TestClientRMService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testForceKillNonExistingApplication() throws YarnException {
  RMContext rmContext = mock(RMContext.class);
  when(rmContext.getRMApps()).thenReturn(
      new ConcurrentHashMap<ApplicationId, RMApp>());
  ClientRMService rmService = new ClientRMService(rmContext, null, null,
      null, null, null);
  ApplicationId applicationId =
      BuilderUtils.newApplicationId(System.currentTimeMillis(), 0);
  KillApplicationRequest request =
      KillApplicationRequest.newInstance(applicationId);
  try {
    rmService.forceKillApplication(request);
    Assert.fail();
  } catch (ApplicationNotFoundException ex) {
    Assert.assertEquals(ex.getMessage(),
        "Trying to kill an absent " +
            "application " + request.getApplicationId());
  }
}
 
Example #5
Source File: TestYarnClient.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testKillApplication() throws Exception {
  MockRM rm = new MockRM();
  rm.start();
  RMApp app = rm.submitApp(2000);

  Configuration conf = new Configuration();
  @SuppressWarnings("resource")
  final YarnClient client = new MockYarnClient();
  client.init(conf);
  client.start();

  client.killApplication(app.getApplicationId());
  verify(((MockYarnClient) client).getRMClient(), times(2))
    .forceKillApplication(any(KillApplicationRequest.class));
}
 
Example #6
Source File: TestClientRMService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testForceKillNonExistingApplication() throws YarnException {
  RMContext rmContext = mock(RMContext.class);
  when(rmContext.getRMApps()).thenReturn(
      new ConcurrentHashMap<ApplicationId, RMApp>());
  ClientRMService rmService = new ClientRMService(rmContext, null, null,
      null, null, null);
  ApplicationId applicationId =
      BuilderUtils.newApplicationId(System.currentTimeMillis(), 0);
  KillApplicationRequest request =
      KillApplicationRequest.newInstance(applicationId);
  try {
    rmService.forceKillApplication(request);
    Assert.fail();
  } catch (ApplicationNotFoundException ex) {
    Assert.assertEquals(ex.getMessage(),
        "Trying to kill an absent " +
            "application " + request.getApplicationId());
  }
}
 
Example #7
Source File: ApplicationClientProtocolPBClientImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException, IOException {
  KillApplicationRequestProto requestProto =
      ((KillApplicationRequestPBImpl) request).getProto();
  try {
    return new KillApplicationResponsePBImpl(proxy.forceKillApplication(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example #8
Source File: TestApplicationACLs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyFriendAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    ApplicationClientProtocol friendClient = getRMClientForUser(FRIEND);

    // View as the friend
    friendClient.getApplicationReport(appReportRequest);

    // List apps as friend
    Assert.assertEquals("App view by a friend should list the apps!!", 3,
        friendClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as the friend
    friendClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #9
Source File: TestApplicationACLs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifySuperUserAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    ApplicationClientProtocol superUserClient = getRMClientForUser(SUPER_USER);

    // View as the superUser
    superUserClient.getApplicationReport(appReportRequest);

    // List apps as superUser
    Assert.assertEquals("App view by super-user should list the apps!!", 2,
        superUserClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as the superUser
    superUserClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #10
Source File: TestApplicationACLs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyOwnerAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    // View as owner
    rmClient.getApplicationReport(appReportRequest);

    // List apps as owner
    Assert.assertEquals("App view by owner should list the apps!!", 1,
        rmClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as owner
    rmClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #11
Source File: QueueACLsTestBase.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyKillAppSuccess(String submitter, String killer,
    String queueName, boolean setupACLs) throws Exception {
  ApplicationId applicationId =
      submitAppAndGetAppId(submitter, queueName, setupACLs);

  final KillApplicationRequest finishAppRequest =
      KillApplicationRequest.newInstance(applicationId);

  ApplicationClientProtocol ownerClient = getRMClientForUser(killer);

  // Kill app as killer
  ownerClient.forceKillApplication(finishAppRequest);
  resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
 
Example #12
Source File: TestApplicationACLs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyAdministerQueueUserAccess() throws Exception {
  isQueueUser = true;
  AccessControlList viewACL = new AccessControlList("");
  viewACL.addGroup(FRIENDLY_GROUP);
  AccessControlList modifyACL = new AccessControlList("");
  modifyACL.addUser(FRIEND);
  ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

  final GetApplicationReportRequest appReportRequest = recordFactory
      .newRecordInstance(GetApplicationReportRequest.class);
  appReportRequest.setApplicationId(applicationId);
  final KillApplicationRequest finishAppRequest = recordFactory
      .newRecordInstance(KillApplicationRequest.class);
  finishAppRequest.setApplicationId(applicationId);

  ApplicationClientProtocol administerQueueUserRmClient =
      getRMClientForUser(QUEUE_ADMIN_USER);

  // View as the administerQueueUserRmClient
  administerQueueUserRmClient.getApplicationReport(appReportRequest);

  // List apps as administerQueueUserRmClient
  Assert.assertEquals("App view by queue-admin-user should list the apps!!",
      5, administerQueueUserRmClient.getApplications(
             recordFactory.newRecordInstance(GetApplicationsRequest.class))
             .getApplicationList().size());

  // Kill app as the administerQueueUserRmClient
  administerQueueUserRmClient.forceKillApplication(finishAppRequest);
  resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
 
Example #13
Source File: ApplicationClientProtocolPBClientImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException, IOException {
  KillApplicationRequestProto requestProto =
      ((KillApplicationRequestPBImpl) request).getProto();
  try {
    return new KillApplicationResponsePBImpl(proxy.forceKillApplication(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example #14
Source File: TestKillApplicationWithRMHA.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException {
  ApplicationId applicationId = request.getApplicationId();
  RMApp application = this.rmContext.getRMApps().get(applicationId);
  if (application.isAppFinalStateStored()) {
    return KillApplicationResponse.newInstance(true);
  } else {
    return KillApplicationResponse.newInstance(false);
  }
}
 
Example #15
Source File: TestMoveApplication.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 10000)
public void testMoveTooLate() throws Exception {
  // Submit application
  Application application = new Application("user1", resourceManager);
  ApplicationId appId = application.getApplicationId();
  application.submit();
  
  ClientRMService clientRMService = resourceManager.getClientRMService();
  // Kill the application
  clientRMService.forceKillApplication(
      KillApplicationRequest.newInstance(appId));
  RMApp rmApp = resourceManager.getRMContext().getRMApps().get(appId);
  // wait until it's dead
  while (rmApp.getState() != RMAppState.KILLED) {
    Thread.sleep(100);
  }
  
  try {
    clientRMService.moveApplicationAcrossQueues(
        MoveApplicationAcrossQueuesRequest.newInstance(appId, "newqueue"));
    fail("Should have hit exception");
  } catch (YarnException ex) {
    assertEquals(YarnException.class,
        ex.getClass());
    assertEquals("App in KILLED state cannot be moved.", ex.getMessage());
  }
}
 
Example #16
Source File: ProtocolHATestBase.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException {
  resetStartFailoverFlag(true);

  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());

  return KillApplicationResponse.newInstance(true);
}
 
Example #17
Source File: YarnClientImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void killApplication(ApplicationId applicationId)
    throws YarnException, IOException {
  KillApplicationRequest request =
      Records.newRecord(KillApplicationRequest.class);
  request.setApplicationId(applicationId);

  try {
    int pollCount = 0;
    long startTime = System.currentTimeMillis();

    while (true) {
      KillApplicationResponse response =
          rmClient.forceKillApplication(request);
      if (response.getIsKillCompleted()) {
        LOG.info("Killed application " + applicationId);
        break;
      }

      long elapsedMillis = System.currentTimeMillis() - startTime;
      if (enforceAsyncAPITimeout() &&
          elapsedMillis >= this.asyncApiPollTimeoutMillis) {
        throw new YarnException("Timed out while waiting for application " +
          applicationId + " to be killed.");
      }

      if (++pollCount % 10 == 0) {
        LOG.info("Waiting for application " + applicationId + " to be killed.");
      }
      Thread.sleep(asyncApiPollIntervalMillis);
    }
  } catch (InterruptedException e) {
    LOG.error("Interrupted while waiting for application " + applicationId
        + " to be killed.");
  }
}
 
Example #18
Source File: TestMoveApplication.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 10000)
public void testMoveTooLate() throws Exception {
  // Submit application
  Application application = new Application("user1", resourceManager);
  ApplicationId appId = application.getApplicationId();
  application.submit();
  
  ClientRMService clientRMService = resourceManager.getClientRMService();
  // Kill the application
  clientRMService.forceKillApplication(
      KillApplicationRequest.newInstance(appId));
  RMApp rmApp = resourceManager.getRMContext().getRMApps().get(appId);
  // wait until it's dead
  while (rmApp.getState() != RMAppState.KILLED) {
    Thread.sleep(100);
  }
  
  try {
    clientRMService.moveApplicationAcrossQueues(
        MoveApplicationAcrossQueuesRequest.newInstance(appId, "newqueue"));
    fail("Should have hit exception");
  } catch (YarnException ex) {
    assertEquals(YarnException.class,
        ex.getClass());
    assertEquals("App in KILLED state cannot be moved.", ex.getMessage());
  }
}
 
Example #19
Source File: TestKillApplicationWithRMHA.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException {
  ApplicationId applicationId = request.getApplicationId();
  RMApp application = this.rmContext.getRMApps().get(applicationId);
  if (application.isAppFinalStateStored()) {
    return KillApplicationResponse.newInstance(true);
  } else {
    return KillApplicationResponse.newInstance(false);
  }
}
 
Example #20
Source File: YarnClientImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void killApplication(ApplicationId applicationId)
    throws YarnException, IOException {
  KillApplicationRequest request =
      Records.newRecord(KillApplicationRequest.class);
  request.setApplicationId(applicationId);

  try {
    int pollCount = 0;
    long startTime = System.currentTimeMillis();

    while (true) {
      KillApplicationResponse response =
          rmClient.forceKillApplication(request);
      if (response.getIsKillCompleted()) {
        LOG.info("Killed application " + applicationId);
        break;
      }

      long elapsedMillis = System.currentTimeMillis() - startTime;
      if (enforceAsyncAPITimeout() &&
          elapsedMillis >= this.asyncApiPollTimeoutMillis) {
        throw new YarnException("Timed out while waiting for application " +
          applicationId + " to be killed.");
      }

      if (++pollCount % 10 == 0) {
        LOG.info("Waiting for application " + applicationId + " to be killed.");
      }
      Thread.sleep(asyncApiPollIntervalMillis);
    }
  } catch (InterruptedException e) {
    LOG.error("Interrupted while waiting for application " + applicationId
        + " to be killed.");
  }
}
 
Example #21
Source File: TestApplicationACLs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyAdministerQueueUserAccess() throws Exception {
  isQueueUser = true;
  AccessControlList viewACL = new AccessControlList("");
  viewACL.addGroup(FRIENDLY_GROUP);
  AccessControlList modifyACL = new AccessControlList("");
  modifyACL.addUser(FRIEND);
  ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

  final GetApplicationReportRequest appReportRequest = recordFactory
      .newRecordInstance(GetApplicationReportRequest.class);
  appReportRequest.setApplicationId(applicationId);
  final KillApplicationRequest finishAppRequest = recordFactory
      .newRecordInstance(KillApplicationRequest.class);
  finishAppRequest.setApplicationId(applicationId);

  ApplicationClientProtocol administerQueueUserRmClient =
      getRMClientForUser(QUEUE_ADMIN_USER);

  // View as the administerQueueUserRmClient
  administerQueueUserRmClient.getApplicationReport(appReportRequest);

  // List apps as administerQueueUserRmClient
  Assert.assertEquals("App view by queue-admin-user should list the apps!!",
      5, administerQueueUserRmClient.getApplications(
             recordFactory.newRecordInstance(GetApplicationsRequest.class))
             .getApplicationList().size());

  // Kill app as the administerQueueUserRmClient
  administerQueueUserRmClient.forceKillApplication(finishAppRequest);
  resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
 
Example #22
Source File: ProtocolHATestBase.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException {
  resetStartFailoverFlag(true);

  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());

  return KillApplicationResponse.newInstance(true);
}
 
Example #23
Source File: TestApplicationACLs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyFriendAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    ApplicationClientProtocol friendClient = getRMClientForUser(FRIEND);

    // View as the friend
    friendClient.getApplicationReport(appReportRequest);

    // List apps as friend
    Assert.assertEquals("App view by a friend should list the apps!!", 3,
        friendClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as the friend
    friendClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #24
Source File: TestApplicationACLs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifySuperUserAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    ApplicationClientProtocol superUserClient = getRMClientForUser(SUPER_USER);

    // View as the superUser
    superUserClient.getApplicationReport(appReportRequest);

    // List apps as superUser
    Assert.assertEquals("App view by super-user should list the apps!!", 2,
        superUserClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as the superUser
    superUserClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #25
Source File: TestApplicationACLs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyOwnerAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    // View as owner
    rmClient.getApplicationReport(appReportRequest);

    // List apps as owner
    Assert.assertEquals("App view by owner should list the apps!!", 1,
        rmClient.getApplications(
            recordFactory.newRecordInstance(GetApplicationsRequest.class))
            .getApplicationList().size());

    // Kill app as owner
    rmClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
  }
 
Example #26
Source File: QueueACLsTestBase.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyKillAppSuccess(String submitter, String killer,
    String queueName, boolean setupACLs) throws Exception {
  ApplicationId applicationId =
      submitAppAndGetAppId(submitter, queueName, setupACLs);

  final KillApplicationRequest finishAppRequest =
      KillApplicationRequest.newInstance(applicationId);

  ApplicationClientProtocol ownerClient = getRMClientForUser(killer);

  // Kill app as killer
  ownerClient.forceKillApplication(finishAppRequest);
  resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
 
Example #27
Source File: TestClientRMService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testForceKillApplication() throws Exception {
  YarnConfiguration conf = new YarnConfiguration();
  MockRM rm = new MockRM();
  rm.init(conf);
  rm.start();

  ClientRMService rmService = rm.getClientRMService();
  GetApplicationsRequest getRequest = GetApplicationsRequest.newInstance(
      EnumSet.of(YarnApplicationState.KILLED));

  RMApp app1 = rm.submitApp(1024);
  RMApp app2 = rm.submitApp(1024, true);

  assertEquals("Incorrect number of apps in the RM", 0,
      rmService.getApplications(getRequest).getApplicationList().size());

  KillApplicationRequest killRequest1 =
      KillApplicationRequest.newInstance(app1.getApplicationId());
  KillApplicationRequest killRequest2 =
      KillApplicationRequest.newInstance(app2.getApplicationId());

  int killAttemptCount = 0;
  for (int i = 0; i < 100; i++) {
    KillApplicationResponse killResponse1 =
        rmService.forceKillApplication(killRequest1);
    killAttemptCount++;
    if (killResponse1.getIsKillCompleted()) {
      break;
    }
    Thread.sleep(10);
  }
  assertTrue("Kill attempt count should be greater than 1 for managed AMs",
      killAttemptCount > 1);
  assertEquals("Incorrect number of apps in the RM", 1,
      rmService.getApplications(getRequest).getApplicationList().size());

  KillApplicationResponse killResponse2 =
      rmService.forceKillApplication(killRequest2);
  assertTrue("Killing UnmanagedAM should falsely acknowledge true",
      killResponse2.getIsKillCompleted());
  for (int i = 0; i < 100; i++) {
    if (2 ==
        rmService.getApplications(getRequest).getApplicationList().size()) {
      break;
    }
    Thread.sleep(10);
  }
  assertEquals("Incorrect number of apps in the RM", 2,
      rmService.getApplications(getRequest).getApplicationList().size());
}
 
Example #28
Source File: MockRM.java    From big-c with Apache License 2.0 4 votes vote down vote up
public KillApplicationResponse killApp(ApplicationId appId) throws Exception {
  ApplicationClientProtocol client = getClientRMService();
  KillApplicationRequest req = KillApplicationRequest.newInstance(appId);
  return client.forceKillApplication(req);
}
 
Example #29
Source File: TestApplicationACLs.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void verifyEnemyAccess() throws Exception {

    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);

    final GetApplicationReportRequest appReportRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory
        .newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);

    ApplicationClientProtocol enemyRmClient = getRMClientForUser(ENEMY);

    // View as the enemy
    ApplicationReport appReport = enemyRmClient.getApplicationReport(
        appReportRequest).getApplicationReport();
    verifyEnemyAppReport(appReport);

    // List apps as enemy
    List<ApplicationReport> appReports = enemyRmClient
        .getApplications(recordFactory
            .newRecordInstance(GetApplicationsRequest.class))
        .getApplicationList();
    Assert.assertEquals("App view by enemy should list the apps!!", 4,
        appReports.size());
    for (ApplicationReport report : appReports) {
      verifyEnemyAppReport(report);
    }

    // Kill app as the enemy
    try {
      enemyRmClient.forceKillApplication(finishAppRequest);
      Assert.fail("App killing by the enemy should fail!!");
    } catch (YarnException e) {
      LOG.info("Got exception while killing app as the enemy", e);
      Assert
          .assertTrue(e.getMessage().contains(
              "User enemy cannot perform operation MODIFY_APP on "
                  + applicationId));
    }

    rmClient.forceKillApplication(finishAppRequest);
  }
 
Example #30
Source File: TestYARNRunner.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout=20000)
public void testResourceMgrDelegate() throws Exception {
  /* we not want a mock of resource mgr delegate */
  final ApplicationClientProtocol clientRMProtocol = mock(ApplicationClientProtocol.class);
  ResourceMgrDelegate delegate = new ResourceMgrDelegate(conf) {
    @Override
    protected void serviceStart() throws Exception {
      assertTrue(this.client instanceof YarnClientImpl);
      ((YarnClientImpl) this.client).setRMClient(clientRMProtocol);
    }
  };
  /* make sure kill calls finish application master */
  when(clientRMProtocol.forceKillApplication(any(KillApplicationRequest.class)))
  .thenReturn(KillApplicationResponse.newInstance(true));
  delegate.killApplication(appId);
  verify(clientRMProtocol).forceKillApplication(any(KillApplicationRequest.class));

  /* make sure getalljobs calls get all applications */
  when(clientRMProtocol.getApplications(any(GetApplicationsRequest.class))).
  thenReturn(recordFactory.newRecordInstance(GetApplicationsResponse.class));
  delegate.getAllJobs();
  verify(clientRMProtocol).getApplications(any(GetApplicationsRequest.class));

  /* make sure getapplication report is called */
  when(clientRMProtocol.getApplicationReport(any(GetApplicationReportRequest.class)))
  .thenReturn(recordFactory.newRecordInstance(GetApplicationReportResponse.class));
  delegate.getApplicationReport(appId);
  verify(clientRMProtocol).getApplicationReport(any(GetApplicationReportRequest.class));

  /* make sure metrics is called */
  GetClusterMetricsResponse clusterMetricsResponse = recordFactory.newRecordInstance
      (GetClusterMetricsResponse.class);
  clusterMetricsResponse.setClusterMetrics(recordFactory.newRecordInstance(
      YarnClusterMetrics.class));
  when(clientRMProtocol.getClusterMetrics(any(GetClusterMetricsRequest.class)))
  .thenReturn(clusterMetricsResponse);
  delegate.getClusterMetrics();
  verify(clientRMProtocol).getClusterMetrics(any(GetClusterMetricsRequest.class));

  when(clientRMProtocol.getClusterNodes(any(GetClusterNodesRequest.class))).
  thenReturn(recordFactory.newRecordInstance(GetClusterNodesResponse.class));
  delegate.getActiveTrackers();
  verify(clientRMProtocol).getClusterNodes(any(GetClusterNodesRequest.class));
  
  GetNewApplicationResponse newAppResponse = recordFactory.newRecordInstance(
      GetNewApplicationResponse.class);
  newAppResponse.setApplicationId(appId);
  when(clientRMProtocol.getNewApplication(any(GetNewApplicationRequest.class))).
  thenReturn(newAppResponse);
  delegate.getNewJobID();
  verify(clientRMProtocol).getNewApplication(any(GetNewApplicationRequest.class));
  
  GetQueueInfoResponse queueInfoResponse = recordFactory.newRecordInstance(
      GetQueueInfoResponse.class);
  queueInfoResponse.setQueueInfo(recordFactory.newRecordInstance(QueueInfo.class));
  when(clientRMProtocol.getQueueInfo(any(GetQueueInfoRequest.class))).
  thenReturn(queueInfoResponse);
  delegate.getQueues();
  verify(clientRMProtocol).getQueueInfo(any(GetQueueInfoRequest.class));

  GetQueueUserAclsInfoResponse aclResponse = recordFactory.newRecordInstance(
      GetQueueUserAclsInfoResponse.class);
  when(clientRMProtocol.getQueueUserAcls(any(GetQueueUserAclsInfoRequest.class)))
  .thenReturn(aclResponse);
  delegate.getQueueAclsForCurrentUser();
  verify(clientRMProtocol).getQueueUserAcls(any(GetQueueUserAclsInfoRequest.class));
}