Skip to main content

[glassfish~svn:59898] Allow Jobs to be displayed based on instanceid. Also, convert Date into m

  • From: mk111283@...
  • To: commits@...
  • Subject: [glassfish~svn:59898] Allow Jobs to be displayed based on instanceid. Also, convert Date into m
  • Date: Thu, 28 Feb 2013 04:09:07 +0000

Project:    glassfish
Repository: svn
Revision:   59898
Author:     mk111283
Date:       2013-02-28 04:09:06 UTC
Link:       

Log Message:
------------
Allow Jobs to be displayed based on instanceid. Also, convert Date into 
millis. QL Passed


Revisions:
----------
59898


Modified Paths:
---------------
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobSteps.java
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobExecutions.java
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobs.java


Diffs:
------
Index: 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobExecutions.java
===================================================================
--- 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobExecutions.java
    (revision 59897)
+++ 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobExecutions.java
    (revision 59898)
@@ -94,17 +94,29 @@
 
     private static final String STEP_COUNT = "stepCount";
 
-    @Param(name = "executionid", primary = true)
+    @Param(name = "instanceid", shortName = "i", optional = true)
+    String instanceId;
+
+    @Param(name = "executionid", shortName = "x", optional = true)
     String executionId;
 
     @Override
     protected void executeCommand(AdminCommandContext context, Properties 
extraProps) {
 
+        if (executionId == null && instanceId == null) {
+            context.getActionReport().setMessage("Either executionid OR 
instanceid is required");
+        }
         ColumnFormatter columnFormatter = new 
ColumnFormatter(getDisplayHeaders());
         List<Map<String, Object>> jobExecutions = new ArrayList<>();
         extraProps.put("list-batch-jobs", jobExecutions);
-        for (JobExecution je : findJobExecutions()) {
-            jobExecutions.add(handleJob(je, columnFormatter));
+        if (executionId != null) {
+            for (JobExecution je : 
findJobExecutions(Long.valueOf(executionId))) {
+                jobExecutions.add(handleJob(je, columnFormatter));
+            }
+        } else if (instanceId != null) {
+            for (JobExecution je : 
getJobExecutionForInstance(Long.valueOf(instanceId))) {
+                jobExecutions.add(handleJob(je, columnFormatter));
+            }
         }
         context.getActionReport().setMessage(columnFormatter.toString());
     }
@@ -135,35 +147,42 @@
         return true;
     }
 
-    private List<JobExecution> findJobExecutions() {
+    private List<JobExecution> findJobExecutions(long exeId) {
         List<JobExecution> jobExecutions = new ArrayList<>();
         JobOperator jobOperator = BatchRuntime.getJobOperator();
-        JobExecution jobExecution = 
jobOperator.getJobExecution(Long.valueOf(executionId));
+        JobExecution jobExecution = 
jobOperator.getJobExecution(Long.valueOf(exeId));
         if (jobExecution != null)
             jobExecutions.add(jobExecution);
 
         return jobExecutions;
     }
 
-//    private static List<JobExecution> getJobExecutionForInstance(long 
instId) {
-//        JobOperator jobOperator = BatchRuntime.getJobOperator();
-//        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> jobExecutionList = 
BatchRuntime.getJobOperator().getJobExecutions(jobInstance);
-//        return jobExecutionList == null
-//                ? new ArrayList<JobExecution>() : jobExecutionList;
-//    }
+    private static List<JobExecution> getJobExecutionForInstance(long 
instId) {
+        JobOperator jobOperator = BatchRuntime.getJobOperator();
+        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>();
+        List<JobExecution> lst = 
BatchRuntime.getJobOperator().getJobExecutions(jobInstance);
+        if (lst != null) {
+            for (JobExecution je : lst) {
+                jeList.add(jobOperator.getJobExecution(je.getExecutionId()));
+            }
+        }
+
+        return jeList;
+    }
+
     private Map<String, Object> handleJob(JobExecution je, ColumnFormatter 
columnFormatter) {
         Map<String, Object> jobInfo = new HashMap<>();
 
@@ -175,10 +194,11 @@
             Object data = null;
             switch (getOutputHeaders()[index]) {
                 case JOB_NAME:
-                    data = 
jobOperator.getJobInstance(je.getInstanceId()).getJobName();
+                    data = jobOperator.getJobInstance(
+                            je.getInstanceId() <= 0 ? 
Long.valueOf(instanceId) : je.getInstanceId()).getJobName();
                     break;
                 case EXECUTION_ID:
-                    data = je.getExecutionId();
+                    data = "" + je.getExecutionId();
                     break;
                 case BATCH_STATUS:
                     data = je.getBatchStatus();
@@ -187,10 +207,12 @@
                     data = je.getExitStatus();
                     break;
                 case START_TIME:
-                    data = je.getStartTime();
+                    data = je.getStartTime().getTime();
+                    cfData[index] = je.getStartTime().toString();
                     break;
                 case END_TIME:
-                    data = je.getEndTime();
+                    data = je.getEndTime().getTime();
+                    cfData[index] = je.getEndTime().toString();
                     break;
                 case JOB_PARAMETERS:
                     data = je.getJobParameters() == null ? new Properties() 
: je.getJobParameters();
@@ -201,7 +223,7 @@
                     st = new StringTokenizer(cf.toString(), "\n");
                     break;
                 case STEP_COUNT:
-                    long exeId = Long.valueOf(executionId);
+                    long exeId = executionId == null ? je.getExecutionId() : 
Long.valueOf(executionId);
                     data = jobOperator.getStepExecutions(exeId) == null
                         ? 0 : jobOperator.getStepExecutions(exeId).size();
                     break;
@@ -210,7 +232,7 @@
             }
             jobInfo.put(getOutputHeaders()[index], data);
             cfData[index] = (jobParamIndex != index)
-                    ? data.toString()
+                    ? (cfData[index] == null ? data.toString() : 
cfData[index])
                     : (st.hasMoreTokens()) ? st.nextToken() : "";
         }
         columnFormatter.addRow(cfData);
Index: 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobSteps.java
===================================================================
--- 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobSteps.java
 (revision 59897)
+++ 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobSteps.java
 (revision 59898)
@@ -51,7 +51,6 @@
 
 import javax.batch.operations.JobOperator;
 import javax.batch.runtime.BatchRuntime;
-import javax.batch.runtime.JobExecution;
 import javax.batch.runtime.Metric;
 import javax.batch.runtime.StepExecution;
 import java.util.*;
@@ -79,7 +78,7 @@
 public class ListBatchJobSteps
         extends AbstractListCommand {
 
-    private static final String NAME = "name";
+    private static final String NAME = "stepName";
 
     private static final String STEP_ID = "stepId";
 
@@ -135,32 +134,12 @@
         return stepExecutions;
     }
 
-//    private static List<JobExecution> getJobExecutionForInstance(long 
instId) {
-//        JobOperator jobOperator = BatchRuntime.getJobOperator();
-//        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> jobExecutionList = 
BatchRuntime.getJobOperator().getJobExecutions(jobInstance);
-//        return jobExecutionList == null
-//                ? new ArrayList<JobExecution>() : jobExecutionList;
-//    }
-
     private Map<String, Object> handleJob(StepExecution stepExecution, 
ColumnFormatter columnFormatter) {
         Map<String, Object> jobInfo = new HashMap<>();
 
         int stepMetricsIndex = -1;
         StringTokenizer st = new StringTokenizer("", "");
         String[] cfData = new String[getOutputHeaders().length];
-        JobOperator jobOperator = BatchRuntime.getJobOperator();
         for (int index = 0; index < getOutputHeaders().length; index++) {
             Object data = null;
             switch (getOutputHeaders()[index]) {
@@ -177,10 +156,12 @@
                     data = stepExecution.getExitStatus();
                     break;
                 case START_TIME:
-                    data = stepExecution.getStartTime();
+                    data = stepExecution.getStartTime().getTime();
+                    cfData[index] = stepExecution.getStartTime().toString();
                     break;
                 case END_TIME:
-                    data = stepExecution.getEndTime();
+                    data = stepExecution.getEndTime().getTime();
+                    cfData[index] = stepExecution.getEndTime().toString();
                     break;
                 case STEP_METRICS:
                     stepMetricsIndex = index;
@@ -200,8 +181,8 @@
             }
             jobInfo.put(getOutputHeaders()[index], data);
             cfData[index] = (stepMetricsIndex != index)
-                    ? data.toString()
-                    : (st.hasMoreTokens()) ? st.nextToken() : "";
+                    ? (cfData[index] == null ? data.toString() : 
cfData[index])
+                    : (st.hasMoreTokens() ? st.nextToken() : "");
         }
         columnFormatter.addRow(cfData);
 
Index: 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobs.java
===================================================================
--- 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobs.java
     (revision 59897)
+++ 
trunk/main/appserver/batch/batch-connector/src/main/java/org/glassfish/batch/ListBatchJobs.java
     (revision 59898)
@@ -94,7 +94,7 @@
 
     private static final String END_TIME = "endTime";
 
-    @Param(name = "jobname", optional = true)
+    @Param(name = "jobname", optional = true, primary = true)
     String jobName;
 
 
@@ -229,16 +229,19 @@
                     data = je.getExitStatus();
                     break;
                 case START_TIME:
-                    data = je.getStartTime();
+                    data = je.getStartTime().getTime();
+                    cfData[index] = je.getStartTime().toString();
                     break;
                 case END_TIME:
-                    data = je.getEndTime();
+                    data = je.getEndTime().getTime();
+                    cfData[index] = je.getEndTime().toString();
                     break;
                 default:
                     throw new IllegalArgumentException("Unknown header: " + 
getOutputHeaders()[index]);
             }
             jobInfo.put(getOutputHeaders()[index], data);
-            cfData[index] = data.toString();
+            if (cfData[index] == null)
+                cfData[index] = data.toString();
         }
         columnFormatter.addRow(cfData);
 





[glassfish~svn:59898] Allow Jobs to be displayed based on instanceid. Also, convert Date into m

mk111283 02/28/2013
 
 
Close
loading
Please Confirm
Close