FileSystemTimelineReaderImpl extends AbstractService implements TimelineReader { @Override public TimelineEntity getEntity(TimelineReaderContext context, TimelineDataToRetrieve dataToRetrieve) throws IOException { String flowRunPath = getFlowRunPath(context.getUserId(), context.getClusterId(), context.getFlowName(), context.getFlowRunId(), context.getAppId()); File dir = new File(new File(rootPath, ENTITIES_DIR), context.getClusterId() + File.separator + flowRunPath + File.separator + context.getAppId() + File.separator + context.getEntityType()); File entityFile = new File( dir, context.getEntityId() + TIMELINE_SERVICE_STORAGE_EXTENSION); try (BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(entityFile), Charset.forName("UTF-8")))) { TimelineEntity entity = readEntityFromFile(reader); return createEntityToBeReturned( entity, dataToRetrieve.getFieldsToRetrieve()); } catch (FileNotFoundException e) { LOG.info("Cannot find entity {id:" + context.getEntityId() + " , type:" + context.getEntityType() + "}. Will send HTTP 404 in response."); return null; } } FileSystemTimelineReaderImpl(); static T getTimelineRecordFromJSON(
      String jsonString, Class<T> clazz); @Override void serviceInit(Configuration conf); @Override TimelineEntity getEntity(TimelineReaderContext context,
      TimelineDataToRetrieve dataToRetrieve); @Override Set<TimelineEntity> getEntities(TimelineReaderContext context,
      TimelineEntityFilters filters, TimelineDataToRetrieve dataToRetrieve); @Override Set<String> getEntityTypes(TimelineReaderContext context); static final String TIMELINE_SERVICE_STORAGE_DIR_ROOT; }
@Test public void testGetEntityDefaultView() throws Exception { TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
@Test public void testGetEntityByClusterAndApp() throws Exception { TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
@Test public void testAppFlowMappingCsv() throws Exception { TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app2", "app", "id_5"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_5")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502050L, result.getCreatedTime()); }
@Test public void testGetEntityCustomFields() throws Exception { TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO, Field.CONFIGS, Field.METRICS), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); Assert.assertEquals(2, result.getInfo().size()); Assert.assertEquals(0, result.getEvents().size()); }
@Test public void testGetEntityAllFields() throws Exception { TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.ALL), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); Assert.assertEquals(2, result.getEvents().size()); }