@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 = BatchRuntime.getJobOperator();
JobExecution je = jobOperator.getJobExecution(Long.valueOf(executionId));
if (instanceId != null) {
JobInstance ji = jobOperator.getJobInstance(Long.valueOf(executionId));
if (ji.getInstanceId() != Long.valueOf(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.valueOf(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 = BatchRuntime.getJobOperator();
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");
}
}