private void upsertJobProperties(Connection connection, JobExecutionInfo jobExecutionInfo) throws SQLException { if (jobExecutionInfo.hasJobProperties()) { Optional<PreparedStatement> upsertStatement = Optional.absent(); int batchSize = 0; for (Map.Entry<String, String> property : jobExecutionInfo.getJobProperties().entrySet()) { if (!upsertStatement.isPresent()) { upsertStatement = Optional.of(connection.prepareStatement(JOB_PROPERTY_UPSERT_STATEMENT_TEMPLATE)); } addPropertyToBatch(upsertStatement.get(), property.getKey(), property.getValue(), jobExecutionInfo.getJobId()); if (batchSize++ > 1000) { executeBatches(upsertStatement); upsertStatement = Optional.absent(); batchSize = 0; } } executeBatches(upsertStatement); } }
String jobId = jobPropertiesRs.getString("job_id"); JobExecutionInfo jobExecutionInfo = jobExecutionInfos.get(jobId); StringMap jobProperties = jobExecutionInfo.getJobProperties(GetMode.NULL); if (jobProperties == null) { jobProperties = new StringMap(Maps.<String, String>newHashMap());
/** * Print properties of a specific job * @param jobExecutionInfoOptional */ public static void printJobProperties(Optional<JobExecutionInfo> jobExecutionInfoOptional) { if (!jobExecutionInfoOptional.isPresent()) { System.err.println("Job not found."); return; } List<List<String>> data = new ArrayList<>(); List<String> flags = Arrays.asList("", "-"); List<String> labels = Arrays.asList("Property Key", "Property Value"); for (Map.Entry<String, String> entry : jobExecutionInfoOptional.get().getJobProperties().entrySet()) { data.add(Arrays.asList(entry.getKey(), entry.getValue())); } new CliTablePrinter.Builder() .labels(labels) .data(data) .flags(flags) .delimiterWidth(2) .build() .printTable(); }
Optional<StringMap> jobProperties = Optional.absent(); if (jobExecutionInfo.hasJobProperties()) { jobProperties = Optional.of(jobExecutionInfo.getJobProperties());
/** * Extracts the schedule from a job execution. * <p/> * If the job was in run once mode, it will return that, otherwise it will return the schedule. * * @param jobInfo A job execution info to extract from * @return "RUN_ONCE", the Quartz schedule string, or "UNKNOWN" if there were no job properties */ public static String extractJobSchedule(JobExecutionInfo jobInfo) { if (jobInfo.hasJobProperties() && jobInfo.getJobProperties().size() > 0) { StringMap props = jobInfo.getJobProperties(); if (props.containsKey(ConfigurationKeys.JOB_RUN_ONCE_KEY) || !props.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { return "RUN_ONCE"; } else if (props.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { return props.get(ConfigurationKeys.JOB_SCHEDULE_KEY); } } return "UNKNOWN"; }
for (Map.Entry<String, String> entry : jobExecutionInfo.getJobProperties().entrySet()) { boolean insert = !existsProperty(connection, JOB_PROPERTY_EXIST_QUERY_STATEMENT_TEMPLATE, jobExecutionInfo.getJobId(), entry.getKey());
@Test(dependsOnMethods = {"testSetAndGet"}) public void testToJobExecutionInfo() { JobExecutionInfo jobExecutionInfo = this.jobState.toJobExecutionInfo(); Assert.assertEquals(jobExecutionInfo.getJobName(), "TestJob"); Assert.assertEquals(jobExecutionInfo.getJobId(), "TestJob-1"); Assert.assertEquals(jobExecutionInfo.getStartTime().longValue(), this.startTime); Assert.assertEquals(jobExecutionInfo.getEndTime().longValue(), this.startTime + 1000); Assert.assertEquals(jobExecutionInfo.getDuration().longValue(), 1000L); Assert.assertEquals(jobExecutionInfo.getState().name(), JobState.RunningState.COMMITTED.name()); Assert.assertEquals(jobExecutionInfo.getLaunchedTasks().intValue(), 3); Assert.assertEquals(jobExecutionInfo.getCompletedTasks().intValue(), 3); Assert.assertEquals(jobExecutionInfo.getJobProperties().get("foo"), "bar"); List<String> taskStateIds = Lists.newArrayList(); for (TaskExecutionInfo taskExecutionInfo : jobExecutionInfo.getTaskExecutions()) { Assert.assertEquals(taskExecutionInfo.getJobId(), "TestJob-1"); Assert.assertEquals(taskExecutionInfo.getStartTime().longValue(), this.startTime); Assert.assertEquals(taskExecutionInfo.getEndTime().longValue(), this.startTime + 1000); Assert.assertEquals(taskExecutionInfo.getDuration().longValue(), 1000); Assert.assertEquals(taskExecutionInfo.getState().name(), WorkUnitState.WorkingState.COMMITTED.name()); Assert.assertEquals(taskExecutionInfo.getTaskProperties().get("foo"), "bar"); taskStateIds.add(taskExecutionInfo.getTaskId()); } Collections.sort(taskStateIds); Assert.assertEquals(taskStateIds, Lists.newArrayList("TestTask-0", "TestTask-1", "TestTask-2")); } }
private static void assertJobExecution(JobExecutionInfo actual, JobExecutionInfo expected) { Assert.assertEquals(actual.getJobName(), expected.getJobName()); Assert.assertEquals(actual.getJobId(), expected.getJobId()); if (expected.hasDuration()) { Assert.assertEquals(actual.getDuration(), expected.getDuration()); } else { Assert.assertEquals(actual.getDuration().longValue(), -1L); } Assert.assertEquals(actual.getState(), expected.getState()); Assert.assertEquals(actual.getLaunchedTasks(), expected.getLaunchedTasks()); Assert.assertEquals(actual.getCompletedTasks(), expected.getCompletedTasks()); Assert.assertEquals(actual.getMetrics(), expected.getMetrics()); for (int i = 0; i < actual.getMetrics().size(); i++) { assertMetric(actual.getMetrics().get(i), expected.getMetrics().get(i)); } Assert.assertEquals(actual.getJobProperties(), expected.getJobProperties()); Assert.assertEquals(actual.getTaskExecutions().size(), expected.getTaskExecutions().size()); for (int i = 0; i < actual.getTaskExecutions().size(); i++) { assertTaskExecution(actual.getTaskExecutions().get(i), expected.getTaskExecutions().get(i)); } }
private void assertJobExecution(JobExecutionInfo actual, JobExecutionInfo expected) { Assert.assertEquals(actual.getJobName(), expected.getJobName()); Assert.assertEquals(actual.getJobId(), expected.getJobId()); if (expected.hasDuration()) { Assert.assertEquals(actual.getDuration(), expected.getDuration()); } else { Assert.assertEquals(actual.getDuration().longValue(), 0L); } Assert.assertEquals(actual.getState(), expected.getState()); Assert.assertEquals(actual.getLaunchedTasks(), expected.getLaunchedTasks()); Assert.assertEquals(actual.getCompletedTasks(), expected.getCompletedTasks()); Assert.assertEquals(actual.getLauncherType(), expected.getLauncherType()); Assert.assertEquals(actual.getTrackingUrl(), expected.getTrackingUrl()); Assert.assertEquals(actual.getMetrics(), expected.getMetrics()); for (int i = 0; i < actual.getMetrics().size(); i++) { assertMetric(actual.getMetrics().get(i), expected.getMetrics().get(i)); } Assert.assertEquals(actual.getJobProperties(), expected.getJobProperties()); Assert.assertEquals(actual.getTaskExecutions().size(), expected.getTaskExecutions().size()); for (int i = 0; i < actual.getTaskExecutions().size(); i++) { assertTaskExecution(actual.getTaskExecutions().get(i), expected.getTaskExecutions().get(i)); } }
private void upsertJobProperties(Connection connection, JobExecutionInfo jobExecutionInfo) throws SQLException { if (jobExecutionInfo.hasJobProperties()) { Optional<PreparedStatement> upsertStatement = Optional.absent(); int batchSize = 0; for (Map.Entry<String, String> property : jobExecutionInfo.getJobProperties().entrySet()) { if (!upsertStatement.isPresent()) { upsertStatement = Optional.of(connection.prepareStatement(JOB_PROPERTY_UPSERT_STATEMENT_TEMPLATE)); } addPropertyToBatch(upsertStatement.get(), property.getKey(), property.getValue(), jobExecutionInfo.getJobId()); if (batchSize++ > 1000) { executeBatches(upsertStatement); upsertStatement = Optional.absent(); batchSize = 0; } } executeBatches(upsertStatement); } }
String jobId = jobPropertiesRs.getString("job_id"); JobExecutionInfo jobExecutionInfo = jobExecutionInfos.get(jobId); StringMap jobProperties = jobExecutionInfo.getJobProperties(GetMode.NULL); if (jobProperties == null) { jobProperties = new StringMap(Maps.<String, String>newHashMap());
/** * Print properties of a specific job * @param jobExecutionInfoOptional */ public static void printJobProperties(Optional<JobExecutionInfo> jobExecutionInfoOptional) { if (!jobExecutionInfoOptional.isPresent()) { System.err.println("Job not found."); return; } List<List<String>> data = new ArrayList<>(); List<String> flags = Arrays.asList("", "-"); List<String> labels = Arrays.asList("Property Key", "Property Value"); for (Map.Entry<String, String> entry : jobExecutionInfoOptional.get().getJobProperties().entrySet()) { data.add(Arrays.asList(entry.getKey(), entry.getValue())); } new CliTablePrinter.Builder() .labels(labels) .data(data) .flags(flags) .delimiterWidth(2) .build() .printTable(); }
/** * Extracts the schedule from a job execution. * <p/> * If the job was in run once mode, it will return that, otherwise it will return the schedule. * * @param jobInfo A job execution info to extract from * @return "RUN_ONCE", the Quartz schedule string, or "UNKNOWN" if there were no job properties */ public static String extractJobSchedule(JobExecutionInfo jobInfo) { if (jobInfo.hasJobProperties() && jobInfo.getJobProperties().size() > 0) { StringMap props = jobInfo.getJobProperties(); if (props.containsKey(ConfigurationKeys.JOB_RUN_ONCE_KEY) || !props.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { return "RUN_ONCE"; } else if (props.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { return props.get(ConfigurationKeys.JOB_SCHEDULE_KEY); } } return "UNKNOWN"; }
Optional<StringMap> jobProperties = Optional.absent(); if (jobExecutionInfo.hasJobProperties()) { jobProperties = Optional.of(jobExecutionInfo.getJobProperties());
for (Map.Entry<String, String> entry : jobExecutionInfo.getJobProperties().entrySet()) { boolean insert = !existsProperty(connection, JOB_PROPERTY_EXIST_QUERY_STATEMENT_TEMPLATE, jobExecutionInfo.getJobId(), entry.getKey());