Example usage for org.apache.hadoop.yarn.server.security ApplicationACLsManager checkAccess

List of usage examples for org.apache.hadoop.yarn.server.security ApplicationACLsManager checkAccess

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.server.security ApplicationACLsManager checkAccess.

Prototype

public boolean checkAccess(UserGroupInformation callerUGI, ApplicationAccessType applicationAccessType,
        String applicationOwner, ApplicationId applicationId) 

Source Link

Document

If authorization is enabled, checks whether the user (in the callerUGI) is authorized to perform the access specified by 'applicationAccessType' on the application by checking if the user is applicationOwner or part of application ACL for the specific access-type.

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();//from   w  ww .  ja  v a  2  s.c o 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();/* w ww .j a  va 2  s. c o m*/

    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);
}