Search in sources :

Example 1 with AzkabanJobStatusUtil

use of com.linkedin.drelephant.clients.azkaban.AzkabanJobStatusUtil in project dr-elephant by linkedin.

the class AzkabanJobCompleteDetector method getCompletedExecutions.

/**
 * Returns the list of completed executions
 * @param jobExecutions Started Execution list
 * @return List of completed executions
 * @throws MalformedURLException
 * @throws URISyntaxException
 */
protected List<TuningJobExecution> getCompletedExecutions(List<TuningJobExecution> jobExecutions) throws MalformedURLException, URISyntaxException {
    logger.info("Fetching the list of executions completed since last iteration");
    List<TuningJobExecution> completedExecutions = new ArrayList<TuningJobExecution>();
    try {
        for (TuningJobExecution tuningJobExecution : jobExecutions) {
            JobExecution jobExecution = tuningJobExecution.jobExecution;
            logger.info("Checking current status of started execution: " + tuningJobExecution.jobExecution.jobExecId);
            if (_azkabanJobStatusUtil == null) {
                logger.info("Initializing  AzkabanJobStatusUtil");
                _azkabanJobStatusUtil = new AzkabanJobStatusUtil();
            }
            try {
                Map<String, String> jobStatus = _azkabanJobStatusUtil.getJobsFromFlow(jobExecution.flowExecution.flowExecId);
                if (jobStatus != null) {
                    for (Map.Entry<String, String> job : jobStatus.entrySet()) {
                        logger.info("Job Found:" + job.getKey() + ". Status: " + job.getValue());
                        if (job.getKey().equals(jobExecution.job.jobName)) {
                            if (job.getValue().equals(AzkabanJobStatus.FAILED.toString())) {
                                tuningJobExecution.paramSetState = ParamSetStatus.EXECUTED;
                                jobExecution.executionState = ExecutionState.FAILED;
                            }
                            if (job.getValue().equals(AzkabanJobStatus.CANCELLED.toString()) || job.getValue().equals(AzkabanJobStatus.KILLED.toString())) {
                                tuningJobExecution.paramSetState = ParamSetStatus.EXECUTED;
                                jobExecution.executionState = ExecutionState.CANCELLED;
                            }
                            if (job.getValue().equals(AzkabanJobStatus.SUCCEEDED.toString())) {
                                tuningJobExecution.paramSetState = ParamSetStatus.EXECUTED;
                                jobExecution.executionState = ExecutionState.SUCCEEDED;
                            }
                            if (tuningJobExecution.paramSetState.equals(ParamSetStatus.EXECUTED)) {
                                completedExecutions.add(tuningJobExecution);
                                logger.info("Execution " + tuningJobExecution.jobExecution.jobExecId + " is completed");
                            } else {
                                logger.info("Execution " + tuningJobExecution.jobExecution.jobExecId + " is still in running state");
                            }
                        }
                    }
                } else {
                    logger.info("No jobs found for flow execution: " + jobExecution.flowExecution.flowExecId);
                }
            } catch (Exception e) {
                logger.error("Error in checking status of execution: " + jobExecution.jobExecId, e);
            }
        }
    } catch (Exception e) {
        logger.error("Error in fetching list of completed executions", e);
        e.printStackTrace();
    }
    logger.info("Number of executions completed since last iteration: " + completedExecutions.size());
    return completedExecutions;
}
Also used : TuningJobExecution(models.TuningJobExecution) JobExecution(models.JobExecution) AzkabanJobStatusUtil(com.linkedin.drelephant.clients.azkaban.AzkabanJobStatusUtil) ArrayList(java.util.ArrayList) TuningJobExecution(models.TuningJobExecution) Map(java.util.Map) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException)

Aggregations

AzkabanJobStatusUtil (com.linkedin.drelephant.clients.azkaban.AzkabanJobStatusUtil)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JobExecution (models.JobExecution)1 TuningJobExecution (models.TuningJobExecution)1