Search in sources :

Example 1 with JobExecutionInfo

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;
}
Also used : SQLException(java.sql.SQLException) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo)

Example 2 with 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;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo)

Example 3 with JobExecutionInfo

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());
                        }
                    }
                }
            }
        }
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap) AbstractMap(java.util.AbstractMap)

Example 4 with JobExecutionInfo

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;
}
Also used : SQLException(java.sql.SQLException) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) Timestamp(java.sql.Timestamp)

Example 5 with 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));
                }
            }
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MetricArray(org.apache.gobblin.rest.MetricArray) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo)

Aggregations

JobExecutionInfo (org.apache.gobblin.rest.JobExecutionInfo)19 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 StringMap (com.linkedin.data.template.StringMap)5 SQLException (java.sql.SQLException)5 TaskExecutionInfo (org.apache.gobblin.rest.TaskExecutionInfo)5 Test (org.testng.annotations.Test)5 Map (java.util.Map)4 MetricArray (org.apache.gobblin.rest.MetricArray)4 TaskExecutionInfoArray (org.apache.gobblin.rest.TaskExecutionInfoArray)4 AbstractMap (java.util.AbstractMap)3 JobExecutionQuery (org.apache.gobblin.rest.JobExecutionQuery)3 ParseException (java.text.ParseException)2 Metric (org.apache.gobblin.rest.Metric)2 Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Meter (com.codahale.metrics.Meter)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1