Search in sources :

Example 66 with TimelineEntity

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

the class TestRollingLevelDBTimelineStore method testRelatingToEntityInSamePut.

@Test
public void testRelatingToEntityInSamePut() throws IOException {
    TimelineEntity entityToRelate = new TimelineEntity();
    entityToRelate.setEntityType("TEST_ENTITY_TYPE_2");
    entityToRelate.setEntityId("TEST_ENTITY_ID_2");
    entityToRelate.setDomainId("TEST_DOMAIN");
    TimelineEntity entityToStore = new TimelineEntity();
    entityToStore.setEntityType("TEST_ENTITY_TYPE_1");
    entityToStore.setEntityId("TEST_ENTITY_ID_1");
    entityToStore.setDomainId("TEST_DOMAIN");
    entityToStore.addRelatedEntity("TEST_ENTITY_TYPE_2", "TEST_ENTITY_ID_2");
    TimelineEntities entities = new TimelineEntities();
    entities.addEntity(entityToStore);
    entities.addEntity(entityToRelate);
    store.put(entities);
    TimelineEntity entityToGet = store.getEntity("TEST_ENTITY_ID_2", "TEST_ENTITY_TYPE_2", null);
    Assert.assertNotNull(entityToGet);
    Assert.assertEquals("TEST_DOMAIN", 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());
}
Also used : TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Test(org.junit.Test)

Example 67 with TimelineEntity

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

the class TestTimelineDataManager method testUpdatingOldEntityWithoutDomainId.

@Test
public void testUpdatingOldEntityWithoutDomainId() throws Exception {
    // Set the domain to the default domain when updating
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityType("OLD_ENTITY_TYPE_1");
    entity.setEntityId("OLD_ENTITY_ID_1");
    entity.setDomainId(TimelineDataManager.DEFAULT_DOMAIN_ID);
    entity.addOtherInfo("NEW_OTHER_INFO_KEY", "NEW_OTHER_INFO_VALUE");
    TimelineEntities entities = new TimelineEntities();
    entities.addEntity(entity);
    TimelinePutResponse response = dataManaer.postEntities(entities, UserGroupInformation.getCurrentUser());
    Assert.assertEquals(0, response.getErrors().size());
    entity = store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null);
    Assert.assertNotNull(entity);
    // Even in leveldb, the domain is updated to the default domain Id
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID, entity.getDomainId());
    Assert.assertEquals(1, entity.getOtherInfo().size());
    Assert.assertEquals("NEW_OTHER_INFO_KEY", entity.getOtherInfo().keySet().iterator().next());
    Assert.assertEquals("NEW_OTHER_INFO_VALUE", entity.getOtherInfo().values().iterator().next());
    // Set the domain to the non-default domain when updating
    entity = new TimelineEntity();
    entity.setEntityType("OLD_ENTITY_TYPE_1");
    entity.setEntityId("OLD_ENTITY_ID_2");
    entity.setDomainId("NON_DEFAULT");
    entity.addOtherInfo("NEW_OTHER_INFO_KEY", "NEW_OTHER_INFO_VALUE");
    entities = new TimelineEntities();
    entities.addEntity(entity);
    response = dataManaer.postEntities(entities, UserGroupInformation.getCurrentUser());
    Assert.assertEquals(1, response.getErrors().size());
    Assert.assertEquals(TimelinePutResponse.TimelinePutError.ACCESS_DENIED, response.getErrors().get(0).getErrorCode());
    entity = store.getEntity("OLD_ENTITY_ID_2", "OLD_ENTITY_TYPE_1", null);
    Assert.assertNotNull(entity);
    // In leveldb, the domain Id is still null
    Assert.assertNull(entity.getDomainId());
    // Updating is not executed
    Assert.assertEquals(0, entity.getOtherInfo().size());
}
Also used : TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Test(org.junit.Test)

Example 68 with TimelineEntity

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

the class TestTimelineDataManager method testGetOldEntityWithOutDomainId.

@Test
public void testGetOldEntityWithOutDomainId() throws Exception {
    TimelineEntity entity = dataManaer.getEntity("OLD_ENTITY_TYPE_1", "OLD_ENTITY_ID_1", null, UserGroupInformation.getCurrentUser());
    Assert.assertNotNull(entity);
    Assert.assertEquals("OLD_ENTITY_ID_1", entity.getEntityId());
    Assert.assertEquals("OLD_ENTITY_TYPE_1", entity.getEntityType());
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID, entity.getDomainId());
}
Also used : TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Test(org.junit.Test)

Example 69 with TimelineEntity

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

the class TimelineStoreTestUtils method createEntity.

/**
   * Create a test entity
   */
protected static TimelineEntity createEntity(String entityId, String entityType, Long startTime, List<TimelineEvent> events, Map<String, Set<String>> relatedEntities, Map<String, Set<Object>> primaryFilters, Map<String, Object> otherInfo, String domainId) {
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId(entityId);
    entity.setEntityType(entityType);
    entity.setStartTime(startTime);
    entity.setEvents(events);
    if (relatedEntities != null) {
        for (Entry<String, Set<String>> e : relatedEntities.entrySet()) {
            for (String v : e.getValue()) {
                entity.addRelatedEntity(e.getKey(), v);
            }
        }
    } else {
        entity.setRelatedEntities(null);
    }
    entity.setPrimaryFilters(primaryFilters);
    entity.setOtherInfo(otherInfo);
    entity.setDomainId(domainId);
    return entity;
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)

Example 70 with TimelineEntity

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

the class TestTimelineACLsManager method testYarnACLsEnabledForEntity.

@Test
public void testYarnACLsEnabledForEntity() throws Exception {
    Configuration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
    conf.set(YarnConfiguration.YARN_ADMIN_ACL, "admin");
    TimelineACLsManager timelineACLsManager = new TimelineACLsManager(conf);
    timelineACLsManager.setTimelineStore(new TestTimelineStore());
    TimelineEntity entity = new TimelineEntity();
    entity.addPrimaryFilter(TimelineStore.SystemFilter.ENTITY_OWNER.toString(), "owner");
    entity.setDomainId("domain_id_1");
    Assert.assertTrue("Owner should be allowed to view", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("owner"), ApplicationAccessType.VIEW_APP, entity));
    Assert.assertTrue("Reader should be allowed to view", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("reader"), ApplicationAccessType.VIEW_APP, entity));
    Assert.assertFalse("Other shouldn't be allowed to view", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("other"), ApplicationAccessType.VIEW_APP, entity));
    Assert.assertTrue("Admin should be allowed to view", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("admin"), ApplicationAccessType.VIEW_APP, entity));
    Assert.assertTrue("Owner should be allowed to modify", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("owner"), ApplicationAccessType.MODIFY_APP, entity));
    Assert.assertTrue("Writer should be allowed to modify", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("writer"), ApplicationAccessType.MODIFY_APP, entity));
    Assert.assertFalse("Other shouldn't be allowed to modify", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("other"), ApplicationAccessType.MODIFY_APP, entity));
    Assert.assertTrue("Admin should be allowed to modify", timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("admin"), ApplicationAccessType.MODIFY_APP, entity));
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Test(org.junit.Test)

Aggregations

TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)98 Test (org.junit.Test)37 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)32 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)30 TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)20 HashMap (java.util.HashMap)16 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)16 IOException (java.io.IOException)15 ClientResponse (com.sun.jersey.api.client.ClientResponse)12 WebResource (com.sun.jersey.api.client.WebResource)11 Configuration (org.apache.hadoop.conf.Configuration)9 HashSet (java.util.HashSet)8 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)7 Field (org.apache.hadoop.yarn.server.timeline.TimelineReader.Field)6 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5 Path (org.apache.hadoop.fs.Path)5 AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)5 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)4 ArrayList (java.util.ArrayList)4