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;
}
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");
}
}
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;
}
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());
}
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;
}
Aggregations