/** * Store job execution information into the job history store. */ void storeJobExecutionInfo() { if (this.jobHistoryStoreOptional.isPresent()) { try { this.logger.info("Writing job execution information to the job history store"); this.jobHistoryStoreOptional.get().put(this.jobState.toJobExecutionInfo()); } catch (IOException ioe) { this.logger.error("Failed to write job execution information to the job history store: " + ioe, ioe); } } }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { if (this.jobHistoryStore != null) { this.jobHistoryStore.close(); } if (this.testMetastoreDatabase != null) { this.testMetastoreDatabase.close(); } }
@Test(dependsOnMethods = {"testUpdate"}) public void testQueryByJobId() throws IOException { JobExecutionQuery queryByJobId = new JobExecutionQuery(); queryByJobId.setIdType(QueryIdTypeEnum.JOB_ID); queryByJobId.setId(JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(0).getJobId())); List<JobExecutionInfo> result = this.jobHistoryStore.get(queryByJobId); Assert.assertEquals(result.size(), 1); JobExecutionInfo actual = result.get(0); JobExecutionInfo expected = this.expectedJobExecutionInfos.get(0); assertJobExecution(actual, expected); }
@Test(dependsOnMethods = {"testUpdate"}) public void testQueryByJobName() throws IOException { JobExecutionQuery queryByJobName = new JobExecutionQuery(); queryByJobName.setIdType(QueryIdTypeEnum.JOB_NAME); queryByJobName.setId(JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(0).getJobName())); List<JobExecutionInfo> result = this.jobHistoryStore.get(queryByJobName); Assert.assertEquals(result.size(), 1); JobExecutionInfo actual = result.get(0); JobExecutionInfo expected = this.expectedJobExecutionInfos.get(0); assertJobExecution(actual, expected); }
@Override public JobExecutionQueryResult get(ComplexResourceKey<JobExecutionQuery, EmptyRecord> key) { JobExecutionQuery query = key.getKey(); JobExecutionInfoArray jobExecutionInfos = new JobExecutionInfoArray(); try { for (JobExecutionInfo jobExecutionInfo : this.jobHistoryStore.get(query)) { jobExecutionInfos.add(jobExecutionInfo); } } catch (Throwable t) { LOGGER .error(String.format("Failed to execute query [id = %s, type = %s]", query.getId(), query.getIdType().name()), t); return null; } JobExecutionQueryResult result = new JobExecutionQueryResult(); result.setJobExecutions(jobExecutionInfos); ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return result; }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { if (this.client != null) { this.client.close(); } if (this.server != null) { this.server.shutDown(); } if (this.jobHistoryStore != null) { this.jobHistoryStore.close(); } if (this.testMetastoreDatabase != null) { this.testMetastoreDatabase.close(); } }
@BeforeClass public void setUp() throws Exception { testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_HISTORY_STORE_URL_KEY, testMetastoreDatabase.getJdbcUrl()); int randomPort = chooseRandomPort(); properties.setProperty(ConfigurationKeys.REST_SERVER_PORT_KEY, Integer.toString(randomPort)); Injector injector = Guice.createInjector(new MetaStoreModule(properties)); this.jobHistoryStore = injector.getInstance(JobHistoryStore.class); this.client = new JobExecutionInfoClient(String.format("http://%s:%s/", "localhost", randomPort)); this.server = new JobExecutionInfoServer(properties); this.server.startUp(); this.expected1 = createJobExecutionInfo(1); this.expected2 = createJobExecutionInfo(2); this.jobHistoryStore.put(this.expected1); this.jobHistoryStore.put(this.expected2); }
JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(0).getTaskExecutions().get(0).getTable())); List<JobExecutionInfo> result = this.jobHistoryStore.get(queryByTable); Assert.assertEquals(result.size(), 2); JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(1).getTaskExecutions().get(1).getTable())); result = this.jobHistoryStore.get(queryByTable); Assert.assertEquals(result.size(), 1);
@Test(dependsOnMethods = {"testInsert"}) public void testUpdate() throws IOException { for (JobExecutionInfo jobExecutionInfo : this.expectedJobExecutionInfos) { jobExecutionInfo.setEndTime(System.currentTimeMillis()); jobExecutionInfo.setDuration(jobExecutionInfo.getEndTime() - jobExecutionInfo.getStartTime()); jobExecutionInfo.setState(JobStateEnum.COMMITTED); jobExecutionInfo.setCompletedTasks(jobExecutionInfo.getLaunchedTasks()); for (TaskExecutionInfo taskExecutionInfo : jobExecutionInfo.getTaskExecutions()) { taskExecutionInfo.setEndTime(jobExecutionInfo.getEndTime()); taskExecutionInfo.setDuration(taskExecutionInfo.getEndTime() - taskExecutionInfo.getStartTime()); taskExecutionInfo.setState(TaskStateEnum.COMMITTED); } this.jobHistoryStore.put(jobExecutionInfo); } }
@Override public JobExecutionQueryResult get(ComplexResourceKey<JobExecutionQuery, EmptyRecord> key) { JobExecutionQuery query = key.getKey(); JobExecutionInfoArray jobExecutionInfos = new JobExecutionInfoArray(); try { for (JobExecutionInfo jobExecutionInfo : this.jobHistoryStore.get(query)) { jobExecutionInfos.add(jobExecutionInfo); } } catch (Throwable t) { LOGGER .error(String.format("Failed to execute query [id = %s, type = %s]", query.getId(), query.getIdType().name()), t); return null; } JobExecutionQueryResult result = new JobExecutionQueryResult(); result.setJobExecutions(jobExecutionInfos); ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return result; }
/** * Store job execution information into the job history store. */ void storeJobExecutionInfo() { if (this.jobHistoryStoreOptional.isPresent()) { try { this.logger.info("Writing job execution information to the job history store"); this.jobHistoryStoreOptional.get().put(this.jobState.toJobExecutionInfo()); } catch (IOException ioe) { this.logger.error("Failed to write job execution information to the job history store: " + ioe, ioe); } } }