Example usage for org.apache.hadoop.yarn.server.resourcemanager ClientRMService getApplications

List of usage examples for org.apache.hadoop.yarn.server.resourcemanager ClientRMService getApplications

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.server.resourcemanager ClientRMService getApplications.

Prototype

@Override
public GetApplicationsResponse getApplications(GetApplicationsRequest request) throws YarnException 

Source Link

Document

Get applications matching the GetApplicationsRequest .

Usage

From source file:io.hops.metadata.util.TestHopYarnAPIUtilities.java

License:Apache License

@Test(timeout = 60000)
public void testAppSubmissionAndNodeUpdate() throws Exception {
    MockRM rm = new MockRM(conf);
    rm.start();/*w w w  . j a v a  2  s.  co m*/

    ClientRMService rmService = rm.getClientRMService();

    GetApplicationsRequest getRequest = GetApplicationsRequest
            .newInstance(EnumSet.of(YarnApplicationState.KILLED));

    ApplicationId appId1 = getApplicationId(100);
    ApplicationId appId2 = getApplicationId(101);

    ApplicationACLsManager mockAclsManager = mock(ApplicationACLsManager.class);
    when(mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(), ApplicationAccessType.VIEW_APP,
            null, appId1)).thenReturn(true);

    SubmitApplicationRequest submitRequest1 = mockSubmitAppRequest(appId1, null, null);

    SubmitApplicationRequest submitRequest2 = mockSubmitAppRequest(appId2, null, null);

    try {
        rmService.submitApplication(submitRequest1);
        rmService.submitApplication(submitRequest2);

    } catch (YarnException e) {
        Assert.fail("Exception is not expected.");
    }

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

    //test persistance of schedulerapplication
    Map<String, SchedulerApplication> schedulerApplications = RMUtilities.getSchedulerApplications();
    assertEquals("db does not contain good number of schedulerApplications", 2, schedulerApplications.size());

    MockNM nm1 = rm.registerNode("host1:1234", 5120);
    MockNM nm2 = rm.registerNode("host2:5678", 10240);

    NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
    Assert.assertEquals(4000, nodeHeartbeat.getNextHeartBeatInterval());

    NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true);
    Assert.assertEquals(4000, nodeHeartbeat2.getNextHeartBeatInterval());

    Thread.sleep(2000);
    rm.stop();
    Thread.sleep(2000);
}

From source file:io.hops.metadata.util.TestHopYarnAPIUtilities.java

License:Apache License

@Test(timeout = 30000)
public void testForceKillApplication() throws Exception {
    MockRM rm = new MockRM(conf);
    rm.start();/*from  w ww  .  j a v  a2  s.c  om*/

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

    ApplicationId appId1 = getApplicationId(100);

    ApplicationACLsManager mockAclsManager = mock(ApplicationACLsManager.class);
    when(mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(), ApplicationAccessType.VIEW_APP,
            null, appId1)).thenReturn(true);

    SubmitApplicationRequest submitRequest1 = mockSubmitAppRequest(appId1, null, null);

    try {
        rmService.submitApplication(submitRequest1);

    } catch (YarnException e) {
        Assert.fail("Exception is not expected.");
    }

    assertEquals("Incorrect number of apps in the RM", 0,
            rmService.getApplications(getRequest).getApplicationList().size());
    Thread.sleep(1000);
    //TODO: check what have to be present in the db
    Thread.sleep(2000);
    rm.stop();
    Thread.sleep(2000);
}