details:   https://code.openbravo.com/erp/devel/pi/rev/b83ebb9b59bb
changeset: 30663:b83ebb9b59bb
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Nov 16 16:55:58 2016 +0100
summary:   fixed issue 34542: instance activation/refresh in a node not 
detected in others

  When activating/refreshing instance in a node of a cluster, other nodes didn't
  get refreshed maintaing already cached information.

  Even there was a mechanism to reload activation when AD_System was updated, it
  didn't work correctly because strPublicKey was not getting updated which was
  later checked to actually reload the license.

  The fix:
    - Removes code duplication so this same flow is invoked from different 
places
      centrally maintained
    - Small code clean up for better readability

details:   https://code.openbravo.com/erp/devel/pi/rev/b07ef157bb90
changeset: 30664:b07ef157bb90
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Nov 17 10:17:26 2016 +0100
summary:   fixed bug 34550: incorrect message killing process if no executing 
bg processes

  When trying to kill a process in a node that does not execute background 
processes,
  an incorrect message was displayed in UI and an error was logged in 
openbravo.log.

diffstat:

 src-db/database/sourcedata/AD_MESSAGE.xml                   |   2 +-
 src/org/openbravo/common/actionhandler/KillProcess.java     |  10 +-
 src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java |   7 +-
 src/org/openbravo/erpCommon/obps/ActivationKey.java         |  74 ++++++------
 src/org/openbravo/scheduling/OBScheduler.java               |  20 ++-
 5 files changed, 62 insertions(+), 51 deletions(-)

diffs (246 lines):

diff -r dcce34325eae -r b07ef157bb90 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Thu Nov 17 09:26:43 2016 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Thu Nov 17 10:17:26 2016 +0100
@@ -21197,7 +21197,7 @@
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  
<VALUE><![CDATA[BackgroundPolicyNoExecuteMsg]]></VALUE>
-<!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTEXT><![CDATA[This instance's 
policy for background processes is not to execute them, therefore it is not 
allowed to schedule or unschedule processes here. There should be another 
instance allowing background process execution, it is in that instance where 
this action should be performed.]]></MSGTEXT>
+<!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTEXT><![CDATA[This instance's 
policy for background processes is not to execute them, therefore it is not 
allowed to schedule, unschedule nor kill processes here. There should be 
another instance allowing background process execution, it is in that instance 
where this action should be performed.]]></MSGTEXT>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  
<ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
diff -r dcce34325eae -r b07ef157bb90 
src/org/openbravo/common/actionhandler/KillProcess.java
--- a/src/org/openbravo/common/actionhandler/KillProcess.java   Thu Nov 17 
09:26:43 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/KillProcess.java   Thu Nov 17 
10:17:26 2016 +0100
@@ -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-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2014-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -46,10 +46,12 @@
 
   @Override
   protected JSONObject doExecute(Map<String, Object> parameters, String 
content) {
+    JSONObject result = new JSONObject();
+    try {
+      if (OBScheduler.isNoExecuteBackgroundPolicy()) {
+        return buildResult("error", "Error", "BackgroundPolicyNoExecuteMsg");
+      }
 
-    JSONObject result = new JSONObject();
-
-    try {
       JSONObject request = new JSONObject(content);
       String strProcessRunId = request.getString("inpadProcessRunId");
 
diff -r dcce34325eae -r b07ef157bb90 
src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java
--- a/src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java       Thu Nov 
17 09:26:43 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java       Thu Nov 
17 10:17:26 2016 +0100
@@ -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-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,7 +28,6 @@
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -52,9 +51,7 @@
   @Override
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
-    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
-        .getProperty("background.policy", "default");
-    if ("no-execute".equals(policy)) {
+    if (OBScheduler.isNoExecuteBackgroundPolicy()) {
       log.info("Not scheduling process because current context background 
policy is 'no-execute'");
       advisePopUp(request, response, "ERROR",
           OBMessageUtils.messageBD("BackgroundPolicyNoExecuteTitle"),
diff -r dcce34325eae -r b07ef157bb90 
src/org/openbravo/erpCommon/obps/ActivationKey.java
--- a/src/org/openbravo/erpCommon/obps/ActivationKey.java       Thu Nov 17 
09:26:43 2016 +0100
+++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java       Thu Nov 17 
10:17:26 2016 +0100
@@ -292,11 +292,7 @@
    */
   public static synchronized ActivationKey reload() {
     ActivationKey ak = getInstance();
-    org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
-        org.openbravo.model.ad.system.System.class, "0");
-    ak.loadInfo(sys.getActivationKey());
-    ak.loadRestrictions();
-    ak.lastUpdateTimestamp = sys.getUpdated();
+    ak.loadFromDB();
     return ak;
   }
 
@@ -311,18 +307,21 @@
   public ActivationKey() {
     OBContext.setAdminMode();
     try {
-      org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
-          org.openbravo.model.ad.system.System.class, "0");
-      strPublicKey = sys.getInstanceKey();
-      lastUpdateTimestamp = sys.getUpdated();
-      String activationKey = sys.getActivationKey();
-      loadInfo(activationKey);
-      loadRestrictions();
+      loadFromDB();
     } finally {
       OBContext.restorePreviousMode();
     }
   }
 
+  private void loadFromDB() {
+    org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
+        org.openbravo.model.ad.system.System.class, "0");
+    strPublicKey = sys.getInstanceKey();
+    lastUpdateTimestamp = sys.getUpdated();
+    loadInfo(sys.getActivationKey());
+    loadRestrictions();
+  }
+
   public ActivationKey(String publicKey, String activationKey) {
     strPublicKey = publicKey;
     loadInfo(activationKey);
@@ -330,29 +329,7 @@
   }
 
   private void loadInfo(String activationKey) {
-    // Reset
-    isActive = false;
-    hasActivationKey = false;
-    errorMessage = "";
-    messageType = "Error";
-    instanceProperties = null;
-    hasExpired = false;
-    subscriptionConvertedProperty = false;
-    subscriptionActuallyConverted = false;
-    tier1Artifacts = null;
-    tier2Artifacts = null;
-    goldenExcludedArtifacts = null;
-    trial = false;
-    golden = false;
-    licenseClass = LicenseClass.COMMUNITY;
-    licenseType = null;
-    startDate = null;
-    endDate = null;
-    pendingTime = null;
-    limitedWsAccess = false;
-    limitNamedUsers = false;
-    outOfPlatform = false;
-    maxUsers = null;
+    reset();
 
     if (strPublicKey == null || activationKey == null || 
strPublicKey.equals("")
         || activationKey.equals("")) {
@@ -543,6 +520,31 @@
     checkDates();
   }
 
+  private void reset() {
+    isActive = false;
+    hasActivationKey = false;
+    errorMessage = "";
+    messageType = "Error";
+    instanceProperties = null;
+    hasExpired = false;
+    subscriptionConvertedProperty = false;
+    subscriptionActuallyConverted = false;
+    tier1Artifacts = null;
+    tier2Artifacts = null;
+    goldenExcludedArtifacts = null;
+    trial = false;
+    golden = false;
+    licenseClass = LicenseClass.COMMUNITY;
+    licenseType = null;
+    startDate = null;
+    endDate = null;
+    pendingTime = null;
+    limitedWsAccess = false;
+    limitNamedUsers = false;
+    outOfPlatform = false;
+    maxUsers = null;
+  }
+
   private boolean checkInOnDemandPlatform() {
     InputStream is = null;
     BufferedReader in = null;
@@ -1511,7 +1513,7 @@
         if (lastUpdateTimestamp == null
             || !lastUpdateTimestamp.equals(OBDal.getInstance()
                 .get(org.openbravo.model.ad.system.System.class, 
"0").getUpdated())) {
-          instance = ActivationKey.reload();
+          loadFromDB();
         }
       } catch (Exception e) {
         log.error("Error checking if activation key should be refreshed", e);
diff -r dcce34325eae -r b07ef157bb90 
src/org/openbravo/scheduling/OBScheduler.java
--- a/src/org/openbravo/scheduling/OBScheduler.java     Thu Nov 17 09:26:43 
2016 +0100
+++ b/src/org/openbravo/scheduling/OBScheduler.java     Thu Nov 17 10:17:26 
2016 +0100
@@ -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-2015 Openbravo SLU
+ * All portions are Copyright (C) 2008-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -52,7 +52,6 @@
  * 
  */
 public class OBScheduler {
-
   private static final OBScheduler INSTANCE = new OBScheduler();
 
   private static Logger log = LoggerFactory.getLogger(OBScheduler.class);
@@ -69,6 +68,9 @@
 
   public static String sqlDateTimeFormat;
 
+  private static final String BACKGROUND_POLICY = "background.policy";
+  private static final String NO_EXECUTE_POLICY = "no-execute";
+
   private OBScheduler() {
   }
 
@@ -182,9 +184,7 @@
    */
   public void schedule(String requestId, ProcessBundle bundle, Class<? extends 
Job> jobClass)
       throws SchedulerException, ServletException {
-    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
-        .getProperty("background.policy", "default");
-    if ("no-execute".equals(policy)) {
+    if (isNoExecuteBackgroundPolicy()) {
       log.info("Not scheduling process because current context background 
policy is 'no-execute'");
       return;
     }
@@ -204,6 +204,16 @@
   }
 
   /**
+   * Returns whether current node is set with no-execute background policy, 
which should prevent any
+   * process scheduling.
+   */
+  public static boolean isNoExecuteBackgroundPolicy() {
+    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty(BACKGROUND_POLICY, "default");
+    return NO_EXECUTE_POLICY.equals(policy);
+  }
+
+  /**
    * @param requestId
    * @param bundle
    * @throws SchedulerException

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to