Search in sources :

Example 21 with JobExecution

use of javax.batch.runtime.JobExecution in project Payara by payara.

the class ListBatchJobExecutions method getJobExecutionForInstance.

private static List<JobExecution> getJobExecutionForInstance(long instId) throws JobSecurityException, NoSuchJobException, NoSuchJobInstanceException, NoSuchJobExecutionException {
    JobOperator jobOperator = AbstractListCommand.getJobOperatorFromBatchRuntime();
    JobInstance jobInstance = null;
    for (String jn : jobOperator.getJobNames()) {
        List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
        if (exe != null) {
            for (JobInstance ji : exe) {
                if (ji.getInstanceId() == instId) {
                    jobInstance = ji;
                    break;
                }
            }
        }
    }
    List<JobExecution> jeList = new ArrayList<JobExecution>();
    if (jobInstance == null)
        throw new RuntimeException("No Job Executions found for instanceid = " + instId);
    List<JobExecution> lst = AbstractListCommand.getJobOperatorFromBatchRuntime().getJobExecutions(jobInstance);
    if (lst != null) {
        for (JobExecution je : lst) {
            jeList.add(jobOperator.getJobExecution(je.getExecutionId()));
        }
    }
    return jeList;
}
Also used : JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) JobInstance(javax.batch.runtime.JobInstance)

Example 22 with JobExecution

use of javax.batch.runtime.JobExecution in project Payara by payara.

the class ListBatchJobExecutions method executeCommand.

@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) throws Exception {
    ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
    List<Map<String, Object>> jobExecutions = new ArrayList<>();
    extraProps.put("listBatchJobExecutions", jobExecutions);
    if (executionId != null) {
        JobOperator jobOperator = getJobOperatorFromBatchRuntime();
        JobExecution je = jobOperator.getJobExecution(Long.parseLong(executionId));
        if (instanceId != null) {
            JobInstance ji = jobOperator.getJobInstance(Long.parseLong(executionId));
            if (ji.getInstanceId() != Long.parseLong(instanceId)) {
                throw new RuntimeException("executionid " + executionId + " is not associated with the specified instanceid (" + instanceId + ")" + "; did you mean " + ji.getInstanceId() + " ?");
            }
        }
        try {
            if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                jobExecutions.add(handleJob(je, columnFormatter));
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
            logger.log(Level.FINE, "Exception while getting jobExecution details: ", ex);
        }
    } else if (instanceId != null) {
        for (JobExecution je : getJobExecutionForInstance(Long.parseLong(instanceId))) {
            try {
                if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                    jobExecutions.add(handleJob(je, columnFormatter));
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
                logger.log(Level.FINE, "Exception while getting jobExecution details: ", ex);
            }
        }
    } else {
        JobOperator jobOperator = getJobOperatorFromBatchRuntime();
        Set<String> jobNames = jobOperator.getJobNames();
        if (jobNames != null) {
            for (String jn : jobOperator.getJobNames()) {
                List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
                if (exe != null) {
                    for (JobInstance ji : exe) {
                        for (JobExecution je : jobOperator.getJobExecutions(ji)) {
                            try {
                                if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                                    jobExecutions.add(handleJob(jobOperator.getJobExecution(je.getExecutionId()), columnFormatter));
                            } catch (Exception ex) {
                                logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
                                logger.log(Level.FINE, "Exception while getting jobExecution details: ", ex);
                            }
                        }
                    }
                }
            }
        }
    }
    if (jobExecutions.size() > 0) {
        context.getActionReport().setMessage(columnFormatter.toString());
    } else {
        throw new RuntimeException("No Job Executions found");
    }
}
Also used : JobInstance(javax.batch.runtime.JobInstance) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 23 with JobExecution

use of javax.batch.runtime.JobExecution in project Payara by payara.

the class ListBatchJobs method findSimpleJobInfo.

private Map<String, Integer> findSimpleJobInfo(ColumnFormatter columnFormatter) throws JobSecurityException, NoSuchJobException {
    Map<String, Integer> jobToInstanceCountMap = new HashMap<>();
    List<JobExecution> jobExecutions = findJobExecutions();
    for (JobExecution je : jobExecutions) {
        if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName())) {
            String jobName = je.getJobName();
            int count = 0;
            if (jobToInstanceCountMap.containsKey(jobName)) {
                count = jobToInstanceCountMap.get(jobName);
            }
            jobToInstanceCountMap.put(jobName, count + 1);
        }
    }
    for (Map.Entry<String, Integer> e : jobToInstanceCountMap.entrySet()) columnFormatter.addRow(new Object[] { e.getKey(), e.getValue() });
    return jobToInstanceCountMap;
}
Also used : JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution)

Example 24 with JobExecution

use of javax.batch.runtime.JobExecution in project Payara by payara.

the class ListBatchJobs method executeCommand.

@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) throws Exception {
    ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
    if (isSimpleMode()) {
        extraProps.put("simpleMode", true);
        extraProps.put("listBatchJobs", findSimpleJobInfo(columnFormatter));
    } else {
        extraProps.put("simpleMode", false);
        List<Map<String, Object>> jobExecutions = new ArrayList<>();
        extraProps.put("listBatchJobs", jobExecutions);
        for (JobExecution je : findJobExecutions()) {
            try {
                if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                    jobExecutions.add(handleJob(je, columnFormatter));
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
                logger.log(Level.FINE, "Exception while getting jobExecution details ", ex);
            }
        }
    }
    context.getActionReport().setMessage(columnFormatter.toString());
}
Also used : JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 25 with JobExecution

use of javax.batch.runtime.JobExecution in project quickstart by wildfly.

the class BatchController method getJobsExecution.

public Set<JobData> getJobsExecution() {
    Set<JobData> jobsData = new TreeSet<JobData>(new Comparator<JobData>() {

        @Override
        public int compare(JobData o1, JobData o2) {
            return o2.getJobInstanceId().compareTo(o1.getJobInstanceId());
        }
    });
    Map<Long, JobExecution> jobIntances = new HashMap<>();
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    try {
        List<JobInstance> instances = jobOperator.getJobInstances("import-file", 0, jobOperator.getJobInstanceCount("import-file"));
        for (JobInstance ji : instances) {
            List<JobExecution> executions = jobOperator.getJobExecutions(ji);
            for (JobExecution jobExecution : executions) {
                // initialize the map if null
                if (jobIntances.get(ji.getInstanceId()) == null) {
                    jobIntances.put(ji.getInstanceId(), jobExecution);
                }
                // Update the jobExecution if is newer
                JobExecution existing = jobIntances.get(ji.getInstanceId());
                if (jobExecution.getExecutionId() > existing.getExecutionId()) {
                    jobIntances.put(ji.getInstanceId(), jobExecution);
                }
            }
        }
        for (Long instaceId : jobIntances.keySet()) {
            JobExecution jobExecution = jobIntances.get(instaceId);
            JobInstance ji = jobOperator.getJobInstance(jobExecution.getExecutionId());
            Properties parameters = jobOperator.getParameters(jobExecution.getExecutionId());
            jobsData.add(new JobData(ji.getInstanceId(), jobExecution.getExecutionId(), ji.getJobName(), jobExecution.getCreateTime(), jobExecution.getEndTime(), jobExecution.getBatchStatus(), parameters, jobExecution.getExitStatus()));
        }
    } catch (NoSuchJobException e) {
    // It's ok if when doesn't have any jobs yet to show
    }
    return jobsData;
}
Also used : HashMap(java.util.HashMap) JobInstance(javax.batch.runtime.JobInstance) JobOperator(javax.batch.operations.JobOperator) Properties(java.util.Properties) JobExecution(javax.batch.runtime.JobExecution) NoSuchJobException(javax.batch.operations.NoSuchJobException) TreeSet(java.util.TreeSet)

Aggregations

JobExecution (javax.batch.runtime.JobExecution)25 JobOperator (javax.batch.operations.JobOperator)13 Test (org.junit.Test)12 Properties (java.util.Properties)8 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)6 JobInstance (javax.batch.runtime.JobInstance)5 ModelNode (org.jboss.dmr.ModelNode)5 ArrayList (java.util.ArrayList)3 StepExecution (javax.batch.runtime.StepExecution)3 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 NoSuchJobException (javax.batch.operations.NoSuchJobException)1