All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aksw.jena_sparql_api.batch.SparqlBatchUtils Maven / Gradle / Ivy

There is a newer version: 3.17.0-1
Show newest version
package org.aksw.jena_sparql_api.batch;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.context.ApplicationContext;

public class SparqlBatchUtils {

    public static void cleanUp(ApplicationContext context) {
            //ApplicationContext context = new AnnotationConfigApplicationContext(ConfigSparqlExportJob.class);
            JobExplorer jobExplorer = context.getBean(JobExplorer.class);
            JobRepository jobRepository = context.getBean(JobRepository.class);
            //JobOperator jobOperator = context.getBean(JobOperator.class);
            //JobLauncher jobLauncher = context.getBean(JobLauncher.class);



    //JobOperator x;
    //
    //x.restart(executionId)

            Date endTime = new Date();


            List jobNames = jobExplorer.getJobNames();
            for(String jobName : jobNames) {
                List jobInstances = jobExplorer.getJobInstances(jobName, 0, 1000000);

                //Set jobExecutions = jobExplorer.findRunningJobExecutions(jobName);

                for(JobInstance jobInstance : jobInstances) {
                    List jobExecutions = jobExplorer.getJobExecutions(jobInstance);

                    for(JobExecution jobExecution : jobExecutions) {


    //                    long jobExecutionId = jobExecution.getId();
    //                    try {
    //                        //jobOperator.restart(jobExecutionId);
    //                    } catch(Exception e) {
    //                        logger.warn("Failed to restart a job", e);
    //                    }
                        Collection stepExecutions = jobExecution.getStepExecutions();
                        for(StepExecution stepExecution : stepExecutions) {
                            BatchStatus stepStatus = stepExecution.getStatus();

                            //if(!BatchStatus.STOPPED.equals(stepStatus)) {
                            if(!BatchStatus.COMPLETED.equals(stepStatus)) {
                                stepExecution.setStatus(BatchStatus.STOPPED);
                                stepExecution.setEndTime(endTime);
                                jobRepository.update(stepExecution);
                            }
                        }

                        BatchStatus jobStatus = jobExecution.getStatus();
                        //jobExecution.isRunning()
                        //if(jobStatus.equals(BatchStatus.STARTED)) {
                        //if(!BatchStatus.STOPPED.equals(jobStatus)) {
                        if(!BatchStatus.COMPLETED.equals(jobStatus)) {
                            jobExecution.setStatus(BatchStatus.STOPPED);
                            jobExecution.setEndTime(endTime);
                            jobRepository.update(jobExecution);
                        }


    //                    if(jobExecution.getExitStatus().isRunning()) {
    //                        JobParameters jobParameters = jobExecution.getJobParameters();
    //
    //                        result = jobLauncher.run();
    //                    }

                    }
                }
            }


            //JobLauncher jobLauncher = context.getBean(JobLauncher.class);
            //jobExplorer.findRunningJobExecutions();
        }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy