This content has been marked as final.
Show 4 replies
-
1. Re: JSR 352 - Viewing batch jobs in admin console
jamezp Mar 26, 2014 4:15 PM (in response to cdesjardins)There is currently not a way to do that. It's been on the todo list, but hasn't happened yet. I did create a JIRA to track it though.
That said it would be fairly easy to create a rest endpoint to at least view/list them. For tests I've done something like:
package org.jboss.example.batch.rest; import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.batch.operations.JobOperator; import javax.batch.runtime.JobExecution; import javax.batch.runtime.JobInstance; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.jboss.example.batch.common.BatchExecutionService; @Path("batch") public class BatchResource { @Inject private BatchExecutionService service; @GET @Path("/jobs") @Produces(MediaType.APPLICATION_JSON) public Response listBatchJobs() { final List<JobExecutionEntity> executionEntities = new ArrayList<>(); final JobOperator jobOperator = service.getJobOperator(); final Set<String> names = jobOperator.getJobNames(); for (String name : names) { final int end = jobOperator.getJobInstanceCount(name); final List<JobInstance> jobInstances = jobOperator.getJobInstances(name, 0, end); for (JobInstance jobInstance : jobInstances) { final List<JobExecution> executions = jobOperator.getJobExecutions(jobInstance); for (JobExecution execution : executions) { executionEntities.add(JobExecutionEntity.create(execution)); } } } return Response.ok(executionEntities).build(); } }
Then the simple bean
package org.jboss.example.batch.rest; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; import javax.batch.runtime.BatchStatus; import javax.batch.runtime.JobExecution; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) public class JobExecutionEntity { private long id; private String name; private BatchStatus status; private String exitStatus; private Date createTime; private Date endTime; private Date lastUpdateTime; private Date startTime; private Map<String, String> properties; public JobExecutionEntity() { } static JobExecutionEntity create(final JobExecution jobExecution) { final JobExecutionEntity result = new JobExecutionEntity(); result.id = jobExecution.getExecutionId(); result.name = jobExecution.getJobName(); result.status = jobExecution.getBatchStatus(); result.exitStatus = jobExecution.getExitStatus(); result.createTime = new Date(jobExecution.getCreateTime().getTime()); result.endTime = new Date(jobExecution.getEndTime().getTime()); result.lastUpdateTime = new Date(jobExecution.getLastUpdatedTime().getTime()); result.startTime = new Date(jobExecution.getStartTime().getTime()); result.properties = new LinkedHashMap<>(); final Properties props = jobExecution.getJobParameters(); for (String name : props.stringPropertyNames()) { result.properties.put(name, props.getProperty(name)); } return result; } public long getId() { return id; } public String getName() { return name; } public BatchStatus getStatus() { return status; } public String getExitStatus() { return exitStatus; } public Date getCreateTime() { return createTime; } public Date getEndTime() { return endTime; } public Date getLastUpdateTime() { return lastUpdateTime; } public Date getStartTime() { return startTime; } public Map<String, String> getProperties() { return properties; } }
--
James R. Perkins
-
2. Re: JSR 352 - Viewing batch jobs in admin console
cdesjardins Mar 31, 2014 8:40 AM (in response to jamezp)Thanks for your answer and the JIRA, James.
I will develop a small web app to list those jobs. -
3. Re: JSR 352 - Viewing batch jobs in admin console
xkylex Apr 2, 2014 2:55 AM (in response to cdesjardins)I'm developing such kind of a small web app.
https://pbs.twimg.com/media/Bj3tO-NCUAABjXv.png
If there are anyone know better one, I would be glad if you could share here.
-
4. Re: JSR 352 - Viewing batch jobs in admin console
xkylex Jan 1, 2015 10:50 AM (in response to xkylex)I posted an entry about my app.
http://www.nailedtothex.org/roller/kyle/entry/jberetweb-jberet-job-repository-viewer