Search in sources :

Example 11 with AdminACLsManager

use of org.apache.hadoop.yarn.security.AdminACLsManager in project hadoop by apache.

the class TestTimelineWebServices method testGetEntitiesWithYarnACLsEnabled.

@Test
public void testGetEntitiesWithYarnACLsEnabled() {
    AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager);
    try {
        // Put entity [4, 4] in domain 1
        TimelineEntities entities = new TimelineEntities();
        TimelineEntity entity = new TimelineEntity();
        entity.setEntityId("test id 4");
        entity.setEntityType("test type 4");
        entity.setStartTime(System.currentTimeMillis());
        entity.setDomainId("domain_id_1");
        entities.addEntity(entity);
        WebResource r = resource();
        ClientResponse response = r.path("ws").path("v1").path("timeline").queryParam("user.name", "writer_user_1").accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, entities);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        TimelinePutResponse putResponse = response.getEntity(TimelinePutResponse.class);
        Assert.assertEquals(0, putResponse.getErrors().size());
        // Put entity [4, 5] in domain 2
        entities = new TimelineEntities();
        entity = new TimelineEntity();
        entity.setEntityId("test id 5");
        entity.setEntityType("test type 4");
        entity.setStartTime(System.currentTimeMillis());
        entity.setDomainId("domain_id_2");
        entities.addEntity(entity);
        r = resource();
        response = r.path("ws").path("v1").path("timeline").queryParam("user.name", "writer_user_3").accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, entities);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        putResponse = response.getEntity(TimelinePutResponse.class);
        Assert.assertEquals(0, putResponse.getErrors().size());
        // Query entities of type 4
        response = r.path("ws").path("v1").path("timeline").queryParam("user.name", "reader_user_1").path("test type 4").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        entities = response.getEntity(TimelineEntities.class);
        // Reader 1 should just have the access to entity [4, 4]
        assertEquals(1, entities.getEntities().size());
        assertEquals("test type 4", entities.getEntities().get(0).getEntityType());
        assertEquals("test id 4", entities.getEntities().get(0).getEntityId());
    } finally {
        timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) AdminACLsManager(org.apache.hadoop.yarn.security.AdminACLsManager) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) WebResource(com.sun.jersey.api.client.WebResource) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Test(org.junit.Test)

Aggregations

AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)11 Test (org.junit.Test)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 WebResource (com.sun.jersey.api.client.WebResource)8 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)6 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)5 TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)5 TimelineDomain (org.apache.hadoop.yarn.api.records.timeline.TimelineDomain)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 Private (org.apache.hadoop.classification.InterfaceAudience.Private)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 TimelineDomains (org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)1 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)1 TimelineEvents (org.apache.hadoop.yarn.api.records.timeline.TimelineEvents)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 TimelineACLsManager (org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager)1 Before (org.junit.Before)1