4 Replies Latest reply on Jan 1, 2015 10:50 AM by Kohei Nozaki

    JSR 352 - Viewing batch jobs in admin console

    Cedric Desjardins Newbie

      Hello,

       

      I'm looking for an easy way to view, run, restart my jobs (JSR 352) with Wildfly 8.

      It seems that Glassfish has this feature in the admin console (http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/1965492.gif), and Spring Batch had it too (Spring Batch Admin).

       

      Do you know if Wildfly will have soon a same page in its admin console ?

       

      Thanks.

       

      Cedric

        • 1. Re: JSR 352 - Viewing batch jobs in admin console
          James Perkins Master

          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
            Cedric Desjardins Newbie

            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
              Kohei Nozaki Newbie

              I'm developing such kind of a small web app.

              lbtc-xxx/jberetweb · GitHub

              https://pbs.twimg.com/media/Bj3tO-NCUAABjXv.png

               

              If there are anyone know better one, I would be glad if you could share here.