private AppLogs getAndSetActiveLog(ApplicationId appId, Path appDirPath) { AppLogs appLogs = appIdLogMap.get(appId); if (appLogs == null) { appLogs = new AppLogs(appId, appDirPath, AppState.ACTIVE); AppLogs oldAppLogs = appIdLogMap.putIfAbsent(appId, appLogs); if (oldAppLogs != null) { appLogs = oldAppLogs; } } return appLogs; }
private AppLogs createAndPutAppLogsIfAbsent(ApplicationId appId, Path appDirPath, AppState appState) { AppLogs appLogs = new AppLogs(appId, appDirPath, appState); AppLogs oldAppLogs = appIdLogMap.putIfAbsent(appId, appLogs); if (oldAppLogs != null) { appLogs = oldAppLogs; } return appLogs; }
private AppLogs getAndSetAppLogs(ApplicationId applicationId) throws IOException { LOG.debug("Looking for app logs mapped for app id {}", applicationId); AppLogs appLogs = appIdLogMap.get(applicationId); if (appLogs == null) { AppState appState = AppState.UNKNOWN; Path appDirPath = getDoneAppPath(applicationId); if (fs.exists(appDirPath)) { appState = AppState.COMPLETED; } else { appDirPath = getActiveAppPath(applicationId); if (fs.exists(appDirPath)) { appState = AppState.ACTIVE; } } if (appState != AppState.UNKNOWN) { appLogs = new AppLogs(applicationId, appDirPath, appState); LOG.debug("Create and try to add new appLogs to appIdLogMap for {}", applicationId); AppLogs oldAppLogs = appIdLogMap.putIfAbsent(applicationId, appLogs); if (oldAppLogs != null) { appLogs = oldAppLogs; } } } return appLogs; }
store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); EntityCacheItem cacheItem = new EntityCacheItem(
@Test public void testSummaryRead() throws Exception { // Load data EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); MutableCounterLong summaryLogEntityRead = store.metrics.getGetEntityToSummaryOps(); long numEntityReadBefore = summaryLogEntityRead.value(); TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithStore(config, store); appLogs.scanForLogs(); appLogs.parseSummaryLogs(tdm); // Verify single entity read PluginStoreTestUtils.verifyTestEntities(tdm); // Verify multiple entities read TimelineEntities entities = tdm.getEntities("type_1", null, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser()); assertEquals(entities.getEntities().size(), 1); for (TimelineEntity entity : entities.getEntities()) { assertEquals((Long) 123L, entity.getStartTime()); } // Verify metrics assertEquals(numEntityReadBefore + 5L, summaryLogEntityRead.value()); }
@Test public void testAppLogsScanLogs() throws Exception { EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); appLogs.scanForLogs(); List<LogInfo> summaryLogs = appLogs.getSummaryLogs(); List<LogInfo> detailLogs = appLogs.getDetailLogs(); assertEquals(2, summaryLogs.size()); assertEquals(1, detailLogs.size()); for (LogInfo log : summaryLogs) { String fileName = log.getFilename(); assertTrue(fileName.equals(TEST_SUMMARY_LOG_FILE_NAME) || fileName.equals(TEST_DOMAIN_LOG_FILE_NAME)); } for (LogInfo log : detailLogs) { String fileName = log.getFilename(); assertEquals(fileName, mainEntityLogFileName); } }
@Test public void testParseSummaryLogs() throws Exception { TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithMemStore(config); MutableCounterLong scanned = store.metrics.getEntitiesReadToSummary(); long beforeScan = scanned.value(); EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); appLogs.scanForLogs(); appLogs.parseSummaryLogs(tdm); PluginStoreTestUtils.verifyTestEntities(tdm); assertEquals(beforeScan + 2L, scanned.value()); }
@Test public void testMoveToDone() throws Exception { EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); Path pathBefore = appLogs.getAppDirPath(); appLogs.moveToDone(); Path pathAfter = appLogs.getAppDirPath(); assertNotEquals(pathBefore, pathAfter); assertTrue(pathAfter.toString().contains(testDoneDirPath.toString())); }