Java Code Examples for org.apache.hadoop.yarn.api.records.timeline.TimelineEntities#addEntity()

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelineEntities#addEntity() . 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: TestTimelineWebServices.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithPrimaryFilter() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  Map<String, Set<Object>> filters = new HashMap<String, Set<Object>>();
  filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(),
      new HashSet<Object>());
  entity.setPrimaryFilters(filters);
  entity.setEntityId("test id 6");
  entity.setEntityType("test type 6");
  entity.setStartTime(System.currentTimeMillis());
  entities.addEntity(entity);
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertEquals(0, putResposne.getErrors().size());
}
 
Example 2
Source File: TestLeveldbTimelineStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelatingToNonExistingEntity() throws IOException {
  TimelineEntity entityToStore = new TimelineEntity();
  entityToStore.setEntityType("TEST_ENTITY_TYPE_1");
  entityToStore.setEntityId("TEST_ENTITY_ID_1");
  entityToStore.setDomainId(TimelineDataManager.DEFAULT_DOMAIN_ID);
  entityToStore.addRelatedEntity("TEST_ENTITY_TYPE_2", "TEST_ENTITY_ID_2");
  TimelineEntities entities = new TimelineEntities();
  entities.addEntity(entityToStore);
  store.put(entities);
  TimelineEntity entityToGet =
      store.getEntity("TEST_ENTITY_ID_2", "TEST_ENTITY_TYPE_2", null);
  Assert.assertNotNull(entityToGet);
  Assert.assertEquals("DEFAULT", entityToGet.getDomainId());
  Assert.assertEquals("TEST_ENTITY_TYPE_1",
      entityToGet.getRelatedEntities().keySet().iterator().next());
  Assert.assertEquals("TEST_ENTITY_ID_1",
      entityToGet.getRelatedEntities().values().iterator().next()
          .iterator().next());
}
 
Example 3
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithPrimaryFilter() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  Map<String, Set<Object>> filters = new HashMap<String, Set<Object>>();
  filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(),
      new HashSet<Object>());
  entity.setPrimaryFilters(filters);
  entity.setEntityId("test id 6");
  entity.setEntityType("test type 6");
  entity.setStartTime(System.currentTimeMillis());
  entities.addEntity(entity);
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertEquals(0, putResposne.getErrors().size());
}
 
Example 4
Source File: TestLeveldbTimelineStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelatingToNonExistingEntity() throws IOException {
  TimelineEntity entityToStore = new TimelineEntity();
  entityToStore.setEntityType("TEST_ENTITY_TYPE_1");
  entityToStore.setEntityId("TEST_ENTITY_ID_1");
  entityToStore.setDomainId(TimelineDataManager.DEFAULT_DOMAIN_ID);
  entityToStore.addRelatedEntity("TEST_ENTITY_TYPE_2", "TEST_ENTITY_ID_2");
  TimelineEntities entities = new TimelineEntities();
  entities.addEntity(entityToStore);
  store.put(entities);
  TimelineEntity entityToGet =
      store.getEntity("TEST_ENTITY_ID_2", "TEST_ENTITY_TYPE_2", null);
  Assert.assertNotNull(entityToGet);
  Assert.assertEquals("DEFAULT", entityToGet.getDomainId());
  Assert.assertEquals("TEST_ENTITY_TYPE_1",
      entityToGet.getRelatedEntities().keySet().iterator().next());
  Assert.assertEquals("TEST_ENTITY_ID_1",
      entityToGet.getRelatedEntities().values().iterator().next()
          .iterator().next());
}
 
Example 5
Source File: TestApplicationHistoryManagerOnTimelineStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void prepareStore() throws Exception {
  store = createStore(SCALE);
  TimelineEntities entities = new TimelineEntities();
  entities.addEntity(createApplicationTimelineEntity(
      ApplicationId.newInstance(0, SCALE + 1), true, true, false));
  entities.addEntity(createApplicationTimelineEntity(
      ApplicationId.newInstance(0, SCALE + 2), true, false, true));
  store.put(entities);
}
 
Example 6
Source File: TestTimelineWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  entity.setEntityId("test id 1");
  entity.setEntityType("test type 1");
  entity.setStartTime(System.currentTimeMillis());
  entity.setDomainId("domain_id_1");
  entities.addEntity(entity);
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertNotNull(putResposne);
  Assert.assertEquals(0, putResposne.getErrors().size());
  // verify the entity exists in the store
  response = r.path("ws").path("v1").path("timeline")
      .path("test type 1").path("test id 1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  entity = response.getEntity(TimelineEntity.class);
  Assert.assertNotNull(entity);
  Assert.assertEquals("test id 1", entity.getEntityId());
  Assert.assertEquals("test type 1", entity.getEntityType());
}
 
Example 7
Source File: TestTimelineWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntitiesToDefaultDomain() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 7");
    entity.setEntityType("test type 7");
    entity.setStartTime(System.currentTimeMillis());
    entities.addEntity(entity);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .queryParam("user.name", "anybody_1")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    TimelinePutResponse putResposne =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertNotNull(putResposne);
    Assert.assertEquals(0, putResposne.getErrors().size());
    // verify the entity exists in the store
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 7").path("test id 7")
        .queryParam("user.name", "any_body_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNotNull(entity);
    Assert.assertEquals("test id 7", entity.getEntityId());
    Assert.assertEquals("test type 7", entity.getEntityType());
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID,
        entity.getDomainId());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 8
Source File: TestApplicationHistoryManagerOnTimelineStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void prepareStore() throws Exception {
  store = createStore(SCALE);
  TimelineEntities entities = new TimelineEntities();
  entities.addEntity(createApplicationTimelineEntity(
      ApplicationId.newInstance(0, SCALE + 1), true, true, false));
  entities.addEntity(createApplicationTimelineEntity(
      ApplicationId.newInstance(0, SCALE + 2), true, false, true));
  store.put(entities);
}
 
Example 9
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  entity.setEntityId("test id 1");
  entity.setEntityType("test type 1");
  entity.setStartTime(System.currentTimeMillis());
  entity.setDomainId("domain_id_1");
  entities.addEntity(entity);
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertNotNull(putResposne);
  Assert.assertEquals(0, putResposne.getErrors().size());
  // verify the entity exists in the store
  response = r.path("ws").path("v1").path("timeline")
      .path("test type 1").path("test id 1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  entity = response.getEntity(TimelineEntity.class);
  Assert.assertNotNull(entity);
  Assert.assertEquals("test id 1", entity.getEntityId());
  Assert.assertEquals("test type 1", entity.getEntityType());
}
 
Example 10
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntitiesToDefaultDomain() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 7");
    entity.setEntityType("test type 7");
    entity.setStartTime(System.currentTimeMillis());
    entities.addEntity(entity);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .queryParam("user.name", "anybody_1")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    TimelinePutResponse putResposne =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertNotNull(putResposne);
    Assert.assertEquals(0, putResposne.getErrors().size());
    // verify the entity exists in the store
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 7").path("test id 7")
        .queryParam("user.name", "any_body_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNotNull(entity);
    Assert.assertEquals("test id 7", entity.getEntityId());
    Assert.assertEquals("test type 7", entity.getEntityType());
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID,
        entity.getDomainId());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 11
Source File: TestTimelineWebServices.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetEntityWithYarnACLsEnabled() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 3");
    entity.setEntityType("test type 3");
    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_TYPE, response.getType());
    TimelinePutResponse putResponse =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertEquals(0, putResponse.getErrors().size());
    // verify the system data will not be exposed
    // 1. No field specification
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 2. other field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "relatedentities")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 3. primaryfilters field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "primaryfilters")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));

    // get entity with other user
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    assertEquals(ClientResponse.Status.NOT_FOUND,
        response.getClientResponseStatus());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 12
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetEntityWithYarnACLsEnabled() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 3");
    entity.setEntityType("test type 3");
    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_TYPE, response.getType());
    TimelinePutResponse putResponse =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertEquals(0, putResponse.getErrors().size());
    // verify the system data will not be exposed
    // 1. No field specification
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 2. other field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "relatedentities")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 3. primaryfilters field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "primaryfilters")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));

    // get entity with other user
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    assertEquals(ClientResponse.Status.NOT_FOUND,
        response.getClientResponseStatus());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}