details:   https://code.openbravo.com/erp/devel/pi/rev/59aad1232b89
changeset: 26636:59aad1232b89
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu May 14 14:59:55 2015 +0200
summary:   ted to issue 29751: Killable processes

  Few minor enhacements:
    - When a process is killed, its status in process monitor is shown as 
"Killed
      by User"
    - When user clicks on "Kill Process" button change the message from "Process
      killed successfully" to "Kill signal sent to process" as sending the kill
      signal doesn't imply necessaryly the process to be successfully killed
    - Changed UI message levels when "Kill Process" button is clicked:
        - If signal is sent: from success to info
        - If process does not implement KillableProcess: from info to warn
    - Added ProcessBundle to KillableProcess.kill method so process instance's
      information can be accessed (ie. allows to add extra log when killing the
      process)

diffstat:

 src-db/database/sourcedata/AD_MESSAGE.xml               |   2 +-
 src-db/database/sourcedata/AD_REF_LIST.xml              |  11 ++++++++
 src/org/openbravo/common/actionhandler/KillProcess.java |   9 ++++---
 src/org/openbravo/scheduling/DefaultJob.java            |  21 +++++++++++++++-
 src/org/openbravo/scheduling/KillableProcess.java       |  11 +++++---
 src/org/openbravo/scheduling/Process.java               |   2 +
 src/org/openbravo/scheduling/ProcessMonitor.java        |  21 ++++++++++++----
 7 files changed, 60 insertions(+), 17 deletions(-)

diffs (206 lines):

diff -r 14775af5b6a0 -r 59aad1232b89 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Wed May 13 12:11:18 2015 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Thu May 14 14:59:55 2015 +0200
@@ -17593,7 +17593,7 @@
 <!--29F703C6919C4631B4C2BF24484691AF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--29F703C6919C4631B4C2BF24484691AF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--29F703C6919C4631B4C2BF24484691AF-->  
<VALUE><![CDATA[ProcessKilled]]></VALUE>
-<!--29F703C6919C4631B4C2BF24484691AF-->  <MSGTEXT><![CDATA[Process killed 
succesfully]]></MSGTEXT>
+<!--29F703C6919C4631B4C2BF24484691AF-->  <MSGTEXT><![CDATA[Kill signal sent to 
process]]></MSGTEXT>
 <!--29F703C6919C4631B4C2BF24484691AF-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--29F703C6919C4631B4C2BF24484691AF-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--29F703C6919C4631B4C2BF24484691AF-->  
<ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
diff -r 14775af5b6a0 -r 59aad1232b89 src-db/database/sourcedata/AD_REF_LIST.xml
--- a/src-db/database/sourcedata/AD_REF_LIST.xml        Wed May 13 12:11:18 
2015 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml        Thu May 14 14:59:55 
2015 +0200
@@ -9120,6 +9120,17 @@
 <!--45987EAE3290457E98F2317B8807B963-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--45987EAE3290457E98F2317B8807B963--></AD_REF_LIST>
 
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C--><AD_REF_LIST>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  
<AD_REF_LIST_ID><![CDATA[459BC70B105C4AD9A23D3B69B7AB0E6C]]></AD_REF_LIST_ID>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  <VALUE><![CDATA[KIL]]></VALUE>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  <NAME><![CDATA[Killed by 
User]]></NAME>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  
<AD_REFERENCE_ID><![CDATA[7DB6D4792CDC4ED297C70A4F4282A52E]]></AD_REFERENCE_ID>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--459BC70B105C4AD9A23D3B69B7AB0E6C--></AD_REF_LIST>
+
 <!--4653221C958347A2A3423AFAAE983E48--><AD_REF_LIST>
 <!--4653221C958347A2A3423AFAAE983E48-->  
<AD_REF_LIST_ID><![CDATA[4653221C958347A2A3423AFAAE983E48]]></AD_REF_LIST_ID>
 <!--4653221C958347A2A3423AFAAE983E48-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 14775af5b6a0 -r 59aad1232b89 
src/org/openbravo/common/actionhandler/KillProcess.java
--- a/src/org/openbravo/common/actionhandler/KillProcess.java   Wed May 13 
12:11:18 2015 +0200
+++ b/src/org/openbravo/common/actionhandler/KillProcess.java   Thu May 14 
14:59:55 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2014 Openbravo SLU 
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -71,11 +71,12 @@
               .getProcessInstance();
           if (process instanceof KillableProcess) {
             // Kill Process
-            ((KillableProcess) process).kill();
-            return buildResult("success", "OBUIAPP_Success", "ProcessKilled");
+            ((KillableProcess) process).kill(jobInstance.getBundle());
+            jobInstance.setKilled(true);
+            return buildResult("info", "Info", "ProcessKilled");
           } else {
             // KillableProcess not implemented
-            return buildResult("info", "Info", 
"KillableProcessNotImplemented");
+            return buildResult("warning", "Info", 
"KillableProcessNotImplemented");
           }
 
         }
diff -r 14775af5b6a0 -r 59aad1232b89 
src/org/openbravo/scheduling/DefaultJob.java
--- a/src/org/openbravo/scheduling/DefaultJob.java      Wed May 13 12:11:18 
2015 +0200
+++ b/src/org/openbravo/scheduling/DefaultJob.java      Thu May 14 14:59:55 
2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -39,12 +39,14 @@
   static Logger log = Logger.getLogger(DefaultJob.class);
 
   private Process processInstance;
+  private ProcessBundle bundle;
+  private boolean killed = false;
 
   /**
    * See the execute method of the Quartz Job class.
    */
   public void execute(JobExecutionContext jec) throws JobExecutionException {
-    final ProcessBundle bundle = (ProcessBundle) 
jec.getMergedJobDataMap().get(ProcessBundle.KEY);
+    bundle = (ProcessBundle) jec.getMergedJobDataMap().get(ProcessBundle.KEY);
     try {
       processInstance = bundle.getProcessClass().newInstance();
       bundle.setConnection((ConnectionProvider) 
jec.get(ProcessBundle.CONNECTION));
@@ -73,4 +75,19 @@
   public Process getProcessInstance() {
     return processInstance;
   }
+
+  /** Returns the bundle associated to current execution */
+  public ProcessBundle getBundle() {
+    return bundle;
+  }
+
+  /** Returns whether kill signal has been sent to current execution */
+  public boolean isKilled() {
+    return killed;
+  }
+
+  /** Flags current execution as killed */
+  public void setKilled(boolean killed) {
+    this.killed = killed;
+  }
 }
diff -r 14775af5b6a0 -r 59aad1232b89 
src/org/openbravo/scheduling/KillableProcess.java
--- a/src/org/openbravo/scheduling/KillableProcess.java Wed May 13 12:11:18 
2015 +0200
+++ b/src/org/openbravo/scheduling/KillableProcess.java Thu May 14 14:59:55 
2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2014 Openbravo SLU 
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,9 +24,12 @@
  */
 public interface KillableProcess {
 
-  /*
-   * Method to implement on background processes for execute the kill action
+  /**
+   * Method to implement on background processes to execute the kill action
+   * 
+   * @param processBundle
+   *          bundle of the current execution, can be used to add log
    */
-  public void kill() throws Exception;
+  public void kill(ProcessBundle processBundle) throws Exception;
 
 }
diff -r 14775af5b6a0 -r 59aad1232b89 src/org/openbravo/scheduling/Process.java
--- a/src/org/openbravo/scheduling/Process.java Wed May 13 12:11:18 2015 +0200
+++ b/src/org/openbravo/scheduling/Process.java Thu May 14 14:59:55 2015 +0200
@@ -45,6 +45,8 @@
 
   public static final String SYSTEM_RESTART = "SYR";
 
+  public static final String KILLED = "KIL";
+
   public static final String PREVENT_CONCURRENT_EXECUTIONS = "PCE";
   public static final String PROCESS_NAME = "name";
   public static final String PROCESS_ID = "id";
diff -r 14775af5b6a0 -r 59aad1232b89 
src/org/openbravo/scheduling/ProcessMonitor.java
--- a/src/org/openbravo/scheduling/ProcessMonitor.java  Wed May 13 12:11:18 
2015 +0200
+++ b/src/org/openbravo/scheduling/ProcessMonitor.java  Thu May 14 14:59:55 
2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -21,6 +21,7 @@
 import static org.openbravo.scheduling.Process.COMPLETE;
 import static org.openbravo.scheduling.Process.ERROR;
 import static org.openbravo.scheduling.Process.EXECUTION_ID;
+import static org.openbravo.scheduling.Process.KILLED;
 import static org.openbravo.scheduling.Process.PROCESSING;
 import static org.openbravo.scheduling.Process.SCHEDULED;
 import static org.openbravo.scheduling.Process.SUCCESS;
@@ -37,6 +38,7 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.database.SessionInfo;
 import org.openbravo.erpCommon.utility.SequenceIdData;
+import org.quartz.Job;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -152,16 +154,23 @@
     final ProcessContext ctx = bundle.getContext();
     try {
       final String executionId = (String) jec.get(EXECUTION_ID);
+      Job jobInstance = jec.getJobInstance();
+
       final String executionLog = bundle.getLog().length() >= 4000 ? 
bundle.getLog().substring(0,
           3999) : bundle.getLog();
-      if (jee == null) {
-        ProcessRunData.update(getConnection(), ctx.getUser(), SUCCESS,
-            getDuration(jec.getJobRunTime()), executionLog, executionId);
+      String executionStatus;
+
+      if (jee != null) {
+        executionStatus = ERROR;
+      } else if (jobInstance instanceof DefaultJob && ((DefaultJob) 
jobInstance).isKilled()) {
+        executionStatus = KILLED;
       } else {
-        ProcessRunData.update(getConnection(), ctx.getUser(), ERROR,
-            getDuration(jec.getJobRunTime()), executionLog, executionId);
+        executionStatus = ERROR;
       }
 
+      ProcessRunData.update(getConnection(), ctx.getUser(), executionStatus,
+          getDuration(jec.getJobRunTime()), executionLog, executionId);
+
       if (bundle.getGroupInfo() != null) {
         // Manage Process Group
         manageGroup(bundle, (jee == null ? SUCCESS : ERROR), executionId);

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to