Search in sources :

Example 6 with TimelineEvents

use of org.apache.hadoop.yarn.api.records.timeline.TimelineEvents in project hadoop by apache.

the class TestTimelineWebServices method testGetEvents.

@Test
public void testGetEvents() throws Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline").path("type_1").path("events").queryParam("entityId", "id_1").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
    TimelineEvents events = response.getEntity(TimelineEvents.class);
    Assert.assertNotNull(events);
    Assert.assertEquals(1, events.getAllEvents().size());
    TimelineEvents.EventsOfOneEntity partEvents = events.getAllEvents().get(0);
    Assert.assertEquals(2, partEvents.getEvents().size());
    TimelineEvent event1 = partEvents.getEvents().get(0);
    Assert.assertEquals(456l, event1.getTimestamp());
    Assert.assertEquals("end_event", event1.getEventType());
    Assert.assertEquals(1, event1.getEventInfo().size());
    TimelineEvent event2 = partEvents.getEvents().get(1);
    Assert.assertEquals(123l, event2.getTimestamp());
    Assert.assertEquals("start_event", event2.getEventType());
    Assert.assertEquals(0, event2.getEventInfo().size());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) TimelineEvents(org.apache.hadoop.yarn.api.records.timeline.TimelineEvents) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 7 with TimelineEvents

use of org.apache.hadoop.yarn.api.records.timeline.TimelineEvents in project hadoop by apache.

the class TestTimelineWebServices method testGetEventsWithYarnACLsEnabled.

@Test
public void testGetEventsWithYarnACLsEnabled() {
    AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager);
    try {
        // Put entity [5, 5] in domain 1
        TimelineEntities entities = new TimelineEntities();
        TimelineEntity entity = new TimelineEntity();
        entity.setEntityId("test id 5");
        entity.setEntityType("test type 5");
        entity.setStartTime(System.currentTimeMillis());
        entity.setDomainId("domain_id_1");
        TimelineEvent event = new TimelineEvent();
        event.setEventType("event type 1");
        event.setTimestamp(System.currentTimeMillis());
        entity.addEvent(event);
        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 [5, 6] in domain 2
        entities = new TimelineEntities();
        entity = new TimelineEntity();
        entity.setEntityId("test id 6");
        entity.setEntityType("test type 5");
        entity.setStartTime(System.currentTimeMillis());
        entity.setDomainId("domain_id_2");
        event = new TimelineEvent();
        event.setEventType("event type 2");
        event.setTimestamp(System.currentTimeMillis());
        entity.addEvent(event);
        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 events belonging to the entities of type 4
        response = r.path("ws").path("v1").path("timeline").path("test type 5").path("events").queryParam("user.name", "reader_user_1").queryParam("entityId", "test id 5,test id 6").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        TimelineEvents events = response.getEntity(TimelineEvents.class);
        // Reader 1 should just have the access to the events of entity [5, 5]
        assertEquals(1, events.getAllEvents().size());
        assertEquals("test id 5", events.getAllEvents().get(0).getEntityId());
    } finally {
        timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) ClientResponse(com.sun.jersey.api.client.ClientResponse) AdminACLsManager(org.apache.hadoop.yarn.security.AdminACLsManager) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) TimelineEvents(org.apache.hadoop.yarn.api.records.timeline.TimelineEvents) 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

TimelineEvents (org.apache.hadoop.yarn.api.records.timeline.TimelineEvents)7 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)4 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 EventsOfOneEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEvents.EventsOfOneEntity)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)1 KeyBuilder (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyBuilder)1 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)1 DB (org.iq80.leveldb.DB)1 DBIterator (org.iq80.leveldb.DBIterator)1