Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest#newInstance()

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest#newInstance() . 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: 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 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: 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 6
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 7
Source File: TestRM.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Validate killing an application when it is at accepted state.
 * @throws Exception exception
 */
@Test (timeout = 60000)
public void testApplicationKillAtAcceptedState() throws Exception {

  final Dispatcher dispatcher = new AsyncDispatcher() {
    @Override
    public EventHandler getEventHandler() {

      class EventArgMatcher extends ArgumentMatcher<AbstractEvent> {
        @Override
        public boolean matches(Object argument) {
          if (argument instanceof RMAppAttemptEvent) {
            if (((RMAppAttemptEvent) argument).getType().equals(
              RMAppAttemptEventType.KILL)) {
              return true;
            }
          }
          return false;
        }
      }

      EventHandler handler = spy(super.getEventHandler());
      doNothing().when(handler).handle(argThat(new EventArgMatcher()));
      return handler;
    }
  };

  MockRM rm = new MockRM(conf) {
    @Override
    protected Dispatcher createDispatcher() {
      return dispatcher;
    }
  };

  // test metrics
  QueueMetrics metrics = rm.getResourceScheduler().getRootQueueMetrics();
  int appsKilled = metrics.getAppsKilled();
  int appsSubmitted = metrics.getAppsSubmitted();

  rm.start();
  
  MockNM nm1 =
      new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
  nm1.registerNode();

  // a failed app
  RMApp application = rm.submitApp(200);
  MockAM am = MockRM.launchAM(application, rm, nm1);
  am.waitForState(RMAppAttemptState.LAUNCHED);
  nm1.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.RUNNING);
  rm.waitForState(application.getApplicationId(), RMAppState.ACCEPTED);

  // Now kill the application before new attempt is launched, the app report
  // returns the invalid AM host and port.
  KillApplicationRequest request =
      KillApplicationRequest.newInstance(application.getApplicationId());
  rm.getClientRMService().forceKillApplication(request);

  // Specific test for YARN-1689 follows
  // Now let's say a race causes AM to register now. This should not crash RM.
  am.registerAppAttempt(false);

  // We explicitly intercepted the kill-event to RMAppAttempt, so app should
  // still be in KILLING state.
  rm.waitForState(application.getApplicationId(), RMAppState.KILLING);
  // AM should now be in running
  rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.RUNNING);

  // Simulate that appAttempt is killed.
  rm.getRMContext().getDispatcher().getEventHandler().handle(
      new RMAppEvent(application.getApplicationId(),
        RMAppEventType.ATTEMPT_KILLED));
  rm.waitForState(application.getApplicationId(), RMAppState.KILLED);

  // test metrics
  metrics = rm.getResourceScheduler().getRootQueueMetrics();
  Assert.assertEquals(appsKilled + 1, metrics.getAppsKilled());
  Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted());
}
 
Example 8
Source File: MockRM.java    From hadoop 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 9
Source File: TestClientRMService.java    From hadoop 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 10
Source File: TestRM.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Validate killing an application when it is at accepted state.
 * @throws Exception exception
 */
@Test (timeout = 60000)
public void testApplicationKillAtAcceptedState() throws Exception {

  final Dispatcher dispatcher = new AsyncDispatcher() {
    @Override
    public EventHandler getEventHandler() {

      class EventArgMatcher extends ArgumentMatcher<AbstractEvent> {
        @Override
        public boolean matches(Object argument) {
          if (argument instanceof RMAppAttemptEvent) {
            if (((RMAppAttemptEvent) argument).getType().equals(
              RMAppAttemptEventType.KILL)) {
              return true;
            }
          }
          return false;
        }
      }

      EventHandler handler = spy(super.getEventHandler());
      doNothing().when(handler).handle(argThat(new EventArgMatcher()));
      return handler;
    }
  };

  MockRM rm = new MockRM(conf) {
    @Override
    protected Dispatcher createDispatcher() {
      return dispatcher;
    }
  };

  // test metrics
  QueueMetrics metrics = rm.getResourceScheduler().getRootQueueMetrics();
  int appsKilled = metrics.getAppsKilled();
  int appsSubmitted = metrics.getAppsSubmitted();

  rm.start();
  
  MockNM nm1 =
      new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
  nm1.registerNode();

  // a failed app
  RMApp application = rm.submitApp(200);
  MockAM am = MockRM.launchAM(application, rm, nm1);
  am.waitForState(RMAppAttemptState.LAUNCHED);
  nm1.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.RUNNING);
  rm.waitForState(application.getApplicationId(), RMAppState.ACCEPTED);

  // Now kill the application before new attempt is launched, the app report
  // returns the invalid AM host and port.
  KillApplicationRequest request =
      KillApplicationRequest.newInstance(application.getApplicationId());
  rm.getClientRMService().forceKillApplication(request);

  // Specific test for YARN-1689 follows
  // Now let's say a race causes AM to register now. This should not crash RM.
  am.registerAppAttempt(false);

  // We explicitly intercepted the kill-event to RMAppAttempt, so app should
  // still be in KILLING state.
  rm.waitForState(application.getApplicationId(), RMAppState.KILLING);
  // AM should now be in running
  rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.RUNNING);

  // Simulate that appAttempt is killed.
  rm.getRMContext().getDispatcher().getEventHandler().handle(
      new RMAppEvent(application.getApplicationId(),
        RMAppEventType.ATTEMPT_KILLED));
  rm.waitForState(application.getApplicationId(), RMAppState.KILLED);

  // test metrics
  metrics = rm.getResourceScheduler().getRootQueueMetrics();
  Assert.assertEquals(appsKilled + 1, metrics.getAppsKilled());
  Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted());
}
 
Example 11
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 12
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());
}