use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV100 method resultSetToJobExecutionInfo.
private JobExecutionInfo resultSetToJobExecutionInfo(ResultSet rs) throws SQLException {
JobExecutionInfo jobExecutionInfo = new JobExecutionInfo();
jobExecutionInfo.setJobName(rs.getString("job_name"));
jobExecutionInfo.setJobId(rs.getString("job_id"));
try {
jobExecutionInfo.setStartTime(rs.getTimestamp("start_time").getTime());
} catch (SQLException se) {
jobExecutionInfo.setStartTime(0);
}
try {
jobExecutionInfo.setEndTime(rs.getTimestamp("end_time").getTime());
} catch (SQLException se) {
jobExecutionInfo.setEndTime(0);
}
jobExecutionInfo.setDuration(rs.getLong("duration"));
String state = rs.getString("state");
if (!Strings.isNullOrEmpty(state)) {
jobExecutionInfo.setState(JobStateEnum.valueOf(state));
}
jobExecutionInfo.setLaunchedTasks(rs.getInt("launched_tasks"));
jobExecutionInfo.setCompletedTasks(rs.getInt("completed_tasks"));
String launcherType = rs.getString("launcher_type");
if (!Strings.isNullOrEmpty(launcherType)) {
jobExecutionInfo.setLauncherType(LauncherTypeEnum.valueOf(launcherType));
}
String trackingUrl = rs.getString("tracking_url");
if (!Strings.isNullOrEmpty(trackingUrl)) {
jobExecutionInfo.setTrackingUrl(trackingUrl);
}
return jobExecutionInfo;
}
use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV100 method processQueryByTable.
private List<JobExecutionInfo> processQueryByTable(Connection connection, JobExecutionQuery query) throws SQLException {
Preconditions.checkArgument(query.getId().isTable());
Filter tableFilter = constructTableFilter(query.getId().getTable());
// Construct the query for job names by table definition
String jobNameByTableQuery = String.format(JOB_NAME_QUERY_BY_TABLE_STATEMENT_TEMPLATE, tableFilter);
List<JobExecutionInfo> jobExecutionInfos = Lists.newArrayList();
// Query job names by table definition
try (PreparedStatement queryStatement = connection.prepareStatement(jobNameByTableQuery)) {
if (tableFilter.isPresent()) {
tableFilter.addParameters(queryStatement, 1);
}
try (ResultSet rs = queryStatement.executeQuery()) {
while (rs.next()) {
jobExecutionInfos.addAll(processQueryByJobName(connection, rs.getString(1), query, tableFilter));
}
}
}
return jobExecutionInfos;
}
use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV101 method addPropertiesToJobExecutions.
private void addPropertiesToJobExecutions(Connection connection, JobExecutionQuery query, Map<String, JobExecutionInfo> jobExecutionInfos) throws SQLException {
if (jobExecutionInfos.size() > 0) {
Set<String> propertyKeys = null;
if (query.hasJobProperties()) {
propertyKeys = Sets.newHashSet(Iterables.filter(Arrays.asList(query.getJobProperties().split(",")), new Predicate<String>() {
@Override
public boolean apply(String input) {
return !Strings.isNullOrEmpty(input);
}
}));
}
if (propertyKeys == null || propertyKeys.size() > 0) {
String template = String.format(JOB_PROPERTY_QUERY_STATEMENT_TEMPLATE, getInPredicate(jobExecutionInfos.size()));
if (propertyKeys != null && propertyKeys.size() > 0) {
template += String.format(" AND property_key IN (%s)", getInPredicate(propertyKeys.size()));
}
int index = 1;
try (PreparedStatement jobPropertiesQueryStatement = connection.prepareStatement(template)) {
for (String jobId : jobExecutionInfos.keySet()) {
jobPropertiesQueryStatement.setString(index++, jobId);
}
if (propertyKeys != null && propertyKeys.size() > 0) {
for (String propertyKey : propertyKeys) {
jobPropertiesQueryStatement.setString(index++, propertyKey);
}
}
try (ResultSet jobPropertiesRs = jobPropertiesQueryStatement.executeQuery()) {
while (jobPropertiesRs.next()) {
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());
jobExecutionInfo.setJobProperties(jobProperties);
}
Map.Entry<String, String> property = resultSetToProperty(jobPropertiesRs);
if (propertyKeys == null || propertyKeys.contains(property.getKey())) {
jobProperties.put(property.getKey(), property.getValue());
}
}
}
}
}
}
}
use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV101 method resultSetToJobExecutionInfo.
private JobExecutionInfo resultSetToJobExecutionInfo(ResultSet rs) throws SQLException {
JobExecutionInfo jobExecutionInfo = new JobExecutionInfo();
jobExecutionInfo.setJobName(rs.getString("job_name"));
jobExecutionInfo.setJobId(rs.getString("job_id"));
try {
Timestamp startTime = rs.getTimestamp("start_time");
if (startTime != null) {
jobExecutionInfo.setStartTime(startTime.getTime());
}
} catch (SQLException se) {
jobExecutionInfo.setStartTime(0);
}
try {
Timestamp endTime = rs.getTimestamp("end_time");
if (endTime != null) {
jobExecutionInfo.setEndTime(endTime.getTime());
}
} catch (SQLException se) {
jobExecutionInfo.setEndTime(0);
}
jobExecutionInfo.setDuration(rs.getLong("duration"));
String state = rs.getString("state");
if (!Strings.isNullOrEmpty(state)) {
jobExecutionInfo.setState(JobStateEnum.valueOf(state));
}
jobExecutionInfo.setLaunchedTasks(rs.getInt("launched_tasks"));
jobExecutionInfo.setCompletedTasks(rs.getInt("completed_tasks"));
String launcherType = rs.getString("launcher_type");
if (!Strings.isNullOrEmpty(launcherType)) {
jobExecutionInfo.setLauncherType(LauncherTypeEnum.valueOf(launcherType));
}
String trackingUrl = rs.getString("tracking_url");
if (!Strings.isNullOrEmpty(trackingUrl)) {
jobExecutionInfo.setTrackingUrl(trackingUrl);
}
return jobExecutionInfo;
}
use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV101 method addMetricsToJobExecutions.
private void addMetricsToJobExecutions(Connection connection, JobExecutionQuery query, Map<String, JobExecutionInfo> jobExecutionInfos) throws SQLException {
if (query.isIncludeJobMetrics() && jobExecutionInfos.size() > 0) {
String template = String.format(JOB_METRIC_QUERY_STATEMENT_TEMPLATE, getInPredicate(jobExecutionInfos.size()));
int index = 1;
try (PreparedStatement jobMetricQueryStatement = connection.prepareStatement(template)) {
for (String jobId : jobExecutionInfos.keySet()) {
jobMetricQueryStatement.setString(index++, jobId);
}
try (ResultSet jobMetricRs = jobMetricQueryStatement.executeQuery()) {
while (jobMetricRs.next()) {
String jobId = jobMetricRs.getString("job_id");
JobExecutionInfo jobExecutionInfo = jobExecutionInfos.get(jobId);
MetricArray metricArray = jobExecutionInfo.getMetrics(GetMode.NULL);
if (metricArray == null) {
metricArray = new MetricArray();
jobExecutionInfo.setMetrics(metricArray);
}
metricArray.add(resultSetToMetric(jobMetricRs));
}
}
}
}
}
Aggregations