@Override public TimelineEntity getEntity(String entityId, String entityType, EnumSet<Field> fieldsToRetrieve) throws IOException { LOG.debug("getEntity type={} id={}", entityType, entityId); TimelineStore store = getTimelineStoreForRead(entityType, entityId); return store.getEntity(entityId, entityType, fieldsToRetrieve); }
TimelineEvents.EventsOfOneEntity eventsOfOneEntity = eventsItr.next(); try { TimelineEntity entity = store.getEntity( eventsOfOneEntity.getEntityId(), eventsOfOneEntity.getEntityType(),
@Override public TimelineEntity getEntity(String entityId, String entityType, EnumSet<Field> fieldsToRetrieve) throws IOException { LOG.debug("getEntity type={} id={}", entityType, entityId); List<TimelineStore> stores = getTimelineStoresForRead(entityId, entityType); for (TimelineStore store : stores) { LOG.debug("Try timeline store {}:{} for the request", store.getName(), store.toString()); TimelineEntity e = store.getEntity(entityId, entityType, fieldsToRetrieve); if (e != null) { return e; } } LOG.debug("getEntity: Found nothing"); return null; }
@Override public TimelineEntity getEntity(String entityId, String entityType, EnumSet<Field> fieldsToRetrieve) throws IOException { LOG.debug("getEntity type={} id={}", entityType, entityId); List<EntityCacheItem> relatedCacheItems = new ArrayList<>(); List<TimelineStore> stores = getTimelineStoresForRead(entityId, entityType, relatedCacheItems); for (TimelineStore store : stores) { LOG.debug("Try timeline store {}:{} for the request", store.getName(), store.toString()); TimelineEntity e = store.getEntity(entityId, entityType, fieldsToRetrieve); if (e != null) { return e; } } LOG.debug("getEntity: Found nothing"); return null; }
/** * Get the single timeline entity that the given user has access to. The * meaning of each argument has been documented with * {@link TimelineReader#getEntity}. * * @see TimelineReader#getEntity */ public TimelineEntity getEntity( String entityType, String entityId, EnumSet<Field> fields, UserGroupInformation callerUGI) throws YarnException, IOException { TimelineEntity entity = null; entity = store.getEntity(entityId, entityType, fields); if (entity != null) { addDefaultDomainIdIfAbsent(entity); // check ACLs if (!timelineACLsManager.checkAccess( callerUGI, ApplicationAccessType.VIEW_APP, entity)) { entity = null; } } return entity; }
/** * Get the single timeline entity that the given user has access to. The * meaning of each argument has been documented with * {@link TimelineReader#getEntity}. * * @see TimelineReader#getEntity */ public TimelineEntity getEntity( String entityType, String entityId, EnumSet<Field> fields, UserGroupInformation callerUGI) throws YarnException, IOException { TimelineEntity entity = null; entity = store.getEntity(entityId, entityType, fields); if (entity != null) { addDefaultDomainIdIfAbsent(entity); // check ACLs if (!timelineACLsManager.checkAccess( callerUGI, ApplicationAccessType.VIEW_APP, entity)) { entity = null; } } return entity; }
private TimelineEntity doGetEntity( String entityType, String entityId, EnumSet<Field> fields, UserGroupInformation callerUGI) throws YarnException, IOException { TimelineEntity entity = null; entity = store.getEntity(entityId, entityType, fields); if (entity != null) { addDefaultDomainIdIfAbsent(entity); // check ACLs if (!timelineACLsManager.checkAccess( callerUGI, ApplicationAccessType.VIEW_APP, entity)) { final String user = callerUGI != null ? callerUGI.getShortUserName(): null; throw new YarnException( user + " is not allowed to get the timeline entity " + "{ id: " + entity.getEntityId() + ", type: " + entity.getEntityType() + " }."); } } return entity; }
store.getEntity("id_1", "type_2", EnumSet.allOf(Field.class)), domainId1); primaryFilters, otherInfo, 123l, store.getEntity(entityId1, entityType1, EnumSet.allOf(Field.class)), domainId1); primaryFilters, otherInfo, 123l, store.getEntity(entityId1b, entityType1, EnumSet.allOf(Field.class)), domainId1); EMPTY_PRIMARY_FILTERS, EMPTY_MAP, 0l, store.getEntity(entityId2, entityType2, EnumSet.allOf(Field.class)), domainId1); EMPTY_PRIMARY_FILTERS, EMPTY_MAP, 42l, store.getEntity(entityId4, entityType4, EnumSet.allOf(Field.class)), domainId1); EMPTY_PRIMARY_FILTERS, EMPTY_MAP, 42l, store.getEntity(entityId5, entityType5, EnumSet.allOf(Field.class)), domainId1); store.getEntity(entityId1, entityType1, EnumSet.of(Field.EVENTS)), domainId1); null, null, null, store.getEntity(entityId1, entityType1, EnumSet.of(Field.LAST_EVENT_ONLY)), domainId1); primaryFilters, otherInfo, store.getEntity(entityId1b, entityType1, null), domainId1); store.getEntity(entityId1, entityType1, EnumSet.of(Field.PRIMARY_FILTERS)), domainId1);
@Test(timeout = 10000) public void testPublishAppAttemptMetricsForUnmanagedAM() throws Exception { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1); RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId,true); metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L); RMApp app = mock(RMApp.class); when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED); metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app, Integer.MAX_VALUE + 2L); TimelineEntity entity = null; do { entity = store.getEntity(appAttemptId.toString(), AppAttemptMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); // ensure two events are both published before leaving the loop } while (entity == null || entity.getEvents().size() < 2); }
@Test(timeout = 10000) public void testPublishAppAttemptMetricsForUnmanagedAM() throws Exception { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1); RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId,true); metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L); RMApp app = mock(RMApp.class); when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED); metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app, Integer.MAX_VALUE + 2L); TimelineEntity entity = null; do { entity = store.getEntity(appAttemptId.toString(), AppAttemptMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); // ensure two events are both published before leaving the loop } while (entity == null || entity.getEvents().size() < 2); }
@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()); }
@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()); }
@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()); }
store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null); Assert.assertNotNull(entityToGet); Assert.assertEquals("DEFAULT", entityToGet.getDomainId()); response.getErrors().get(0).getErrorCode()); entityToGet = store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null); Assert.assertNotNull(entityToGet); Assert.assertEquals("DEFAULT", entityToGet.getDomainId());
store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null); Assert.assertNotNull(entityToGet); Assert.assertNull(entityToGet.getDomainId()); response.getErrors().get(0).getErrorCode()); entityToGet = store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null); Assert.assertNotNull(entityToGet); Assert.assertNull(entityToGet.getDomainId());
@Test(timeout = 10000) public void testPublishHostPortInfoOnContainerFinished() throws Exception { ContainerId containerId = ContainerId.newContainerId(ApplicationAttemptId.newInstance( ApplicationId.newInstance(0, 1), 1), 1); RMContainer container = createRMContainer(containerId); metricsPublisher.containerFinished(container, container.getFinishTime()); TimelineEntity entity = null; do { entity = store.getEntity(containerId.toString(), ContainerMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); } while (entity == null || entity.getEvents().size() < 1); Assert.assertNotNull(entity.getOtherInfo()); Assert.assertEquals(2, entity.getOtherInfo().size()); Assert.assertNotNull(entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_HOST_INFO)); Assert.assertNotNull(entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_PORT_INFO)); Assert.assertEquals( container.getAllocatedNode().getHost(), entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_HOST_INFO)); Assert.assertEquals( container.getAllocatedNode().getPort(), entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_PORT_INFO)); }
entities, UserGroupInformation.getCurrentUser()); Assert.assertEquals(0, response.getErrors().size()); entity = store.getEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null); Assert.assertNotNull(entity); 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);
@Test(timeout = 10000) public void testPublishHostPortInfoOnContainerFinished() throws Exception { ContainerId containerId = ContainerId.newContainerId(ApplicationAttemptId.newInstance( ApplicationId.newInstance(0, 1), 1), 1); RMContainer container = createRMContainer(containerId); metricsPublisher.containerFinished(container, container.getFinishTime()); TimelineEntity entity = null; do { entity = store.getEntity(containerId.toString(), ContainerMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); } while (entity == null || entity.getEvents().size() < 1); Assert.assertNotNull(entity.getOtherInfo()); Assert.assertEquals(2, entity.getOtherInfo().size()); Assert.assertNotNull(entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO)); Assert.assertNotNull(entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO)); Assert.assertEquals( container.getAllocatedNode().getHost(), entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO)); Assert.assertEquals( container.getAllocatedNode().getPort(), entity.getOtherInfo().get( ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO)); }
@Test public void testPutEntities() throws Exception { TestTimelineClient client = new TestTimelineClient(); try { client.init(conf); client.start(); TimelineEntity expectedEntity = new TimelineEntity(); expectedEntity.setEntityType("test entity type"); expectedEntity.setEntityId("test entity id"); expectedEntity.setDomainId("test domain id"); TimelineEvent event = new TimelineEvent(); event.setEventType("test event type"); event.setTimestamp(0L); expectedEntity.addEvent(event); TimelinePutResponse response = client.putEntities(expectedEntity); Assert.assertEquals(0, response.getErrors().size()); Assert.assertTrue(client.resp.toString().contains("https")); TimelineEntity actualEntity = store.getEntity( expectedEntity.getEntityId(), expectedEntity.getEntityType(), EnumSet.allOf(Field.class)); Assert.assertNotNull(actualEntity); Assert.assertEquals( expectedEntity.getEntityId(), actualEntity.getEntityId()); Assert.assertEquals( expectedEntity.getEntityType(), actualEntity.getEntityType()); } finally { client.stop(); client.close(); } }