[wsas-java-dev] svn commit r1719 - trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering

svn at wso2.org svn at wso2.org
Tue Apr 3 02:21:40 PDT 2007


Author: azeez
Date: Tue Apr  3 02:21:29 2007
New Revision: 1719

Modified:
   trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManager.java
   trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/WSASConfigManagerListener.java
Log:
Some minor improvements to Configuration Management code



Modified: trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManager.java
==============================================================================
--- trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManager.java	(original)
+++ trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManager.java	Tue Apr  3 02:21:29 2007
@@ -1,30 +1,32 @@
-/*                                                                             
- * Copyright 2004,2005 The Apache Software Foundation.                         
- *                                                                             
- * Licensed under the Apache License, Version 2.0 (the "License");             
- * you may not use this file except in compliance with the License.            
- * You may obtain a copy of the License at                                     
- *                                                                             
- *      http://www.apache.org/licenses/LICENSE-2.0                             
- *                                                                             
- * Unless required by applicable law or agreed to in writing, software         
- * distributed under the License is distributed on an "AS IS" BASIS,           
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
- * See the License for the specific language governing permissions and         
- * limitations under the License.                                              
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.wso2.wsas.clustering;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.cluster.ClusterManager;
-import org.apache.axis2.cluster.ClusteringFault;
 import org.apache.axis2.cluster.configuration.ConfigurationManager;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * 
+ *
  */
 public class NodeManager {
     private Log log = LogFactory.getLog(NodeManager.class);
@@ -32,60 +34,59 @@
             "ConfigurationManager is null. Please properly set the 'cluster' element in the axis2.xml file";
     private static final String CLUSTER_MANAGER_NULL =
             "ClusterManager is null. Please properly set the 'cluster' element in the axis2.xml file";
+    public static final String OPERATION_FAILED = "nodemanager.operation.failed";
 
-    public boolean loadServiceGroup(String serviceGroupName) throws ClusteringFault {
+    public boolean loadServiceGroup(String serviceGroupName) throws AxisFault {
+        init();
         ConfigurationManager configMan = getConfigurationManager();
         if (configMan != null) {
             configMan.loadServiceGroup(serviceGroupName);
-            configMan.prepare();
-            return true;
+            return isPrepareSuccessful(configMan);
         } else {
-            throw new ClusteringFault(CONFIG_MANAGER_NULL);
+            throw new AxisFault(CONFIG_MANAGER_NULL);
         }
     }
 
-    public boolean unloadServiceGroup(String serviceGroupName) throws ClusteringFault {
+    public boolean unloadServiceGroup(String serviceGroupName) throws AxisFault {
+        init();
         ConfigurationManager configMan = getConfigurationManager();
         if (configMan != null) {
             configMan.unloadServiceGroup(serviceGroupName);
-            configMan.prepare();
-            return true;
+            return isPrepareSuccessful(configMan);
         } else {
-            throw new ClusteringFault(CONFIG_MANAGER_NULL);
+            throw new AxisFault(CONFIG_MANAGER_NULL);
         }
     }
 
-    public boolean applyPolicy(String serviceName, String policyId) throws ClusteringFault {
+    public boolean applyPolicy(String serviceName, String policyId) throws AxisFault {
+        init();
         ConfigurationManager configMan = getConfigurationManager();
         if (configMan != null) {
 //            configMan.applyPolicy(serviceName, policyId);
 
-            configMan.prepare();
-            return true;
+            return isPrepareSuccessful(configMan);
         } else {
-            throw new ClusteringFault(CONFIG_MANAGER_NULL);
+            throw new AxisFault(CONFIG_MANAGER_NULL);
         }
     }
 
-    public boolean reloadConfiguration() throws ClusteringFault {
+    public boolean reloadConfiguration() throws AxisFault {
+        init();
         ConfigurationManager configMan = getConfigurationManager();
         if (configMan != null) {
             configMan.reloadConfiguration();
-
-            //TODO: Check the reload state and return the state
-            // TODO: Need to call prepare only after all nodes have loaded the config
-
-            configMan.prepare();
-            return true;
+            return isPrepareSuccessful(configMan);
         } else {
-            throw new ClusteringFault(CONFIG_MANAGER_NULL);
+            throw new AxisFault(CONFIG_MANAGER_NULL);
         }
     }
 
-    public boolean commit() throws ClusteringFault {
+    public boolean commit() throws AxisFault {
+        init();
         ConfigurationManager configMan = getConfigurationManager();
         if (configMan != null) {
             configMan.commit();
+//            return commitSuccessful(configMan);
         }
         return true;
     }
@@ -108,4 +109,66 @@
         }
         return null;
     }
+
+    private boolean commitSuccessful(ConfigurationManager configMan) throws AxisFault {
+        delay(); // Wait for sometime, so that the failures on other nodes can be detected
+        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
+        AxisService axisService = msgCtx.getAxisService();
+        Parameter opFailed = axisService.getParameter(OPERATION_FAILED);
+        boolean result;
+        if (opFailed == null) {
+            configMan.commit();
+            delay(); // Wait for sometime, so that the failures on other nodes can be detected
+            opFailed = axisService.getParameter(OPERATION_FAILED);
+            result = (opFailed == null);
+        } else {
+            result = false;
+        }
+        if (opFailed != null) {
+            axisService.removeParameter(opFailed);
+        }
+        return result;
+    }
+
+    private void init() throws AxisFault {
+        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
+        AxisService axisService = msgCtx.getAxisService();
+        Parameter opFailed = axisService.getParameter(OPERATION_FAILED);
+        if (opFailed != null) {
+            axisService.removeParameter(opFailed);
+        }
+    }
+
+    /**
+     * @param configMan
+     * @return true if the operation succeeded & prepare succeeded
+     * @throws AxisFault
+     */
+    private boolean isPrepareSuccessful(ConfigurationManager configMan) throws AxisFault {
+        delay(); // Wait for sometime, so that the failures on other nodes can be detected
+        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
+        AxisService axisService = msgCtx.getAxisService();
+        Parameter opFailed = axisService.getParameter(OPERATION_FAILED);
+        boolean result;
+        if (opFailed == null) {
+            configMan.prepare(); // Wait for sometime, so that the failures on other nodes can be detected
+            delay();
+            opFailed = axisService.getParameter(OPERATION_FAILED);
+            result = (opFailed == null);
+        } else {
+            result = false;
+        }
+        if (opFailed != null) {
+            axisService.removeParameter(opFailed);
+        }
+        return result;
+    }
+
+    private void delay() {
+        try {
+            Thread.sleep(3000);
+        } catch (InterruptedException e) {
+            log.error(e);
+        }
+    }
 }

Modified: trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/WSASConfigManagerListener.java
==============================================================================
--- trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/WSASConfigManagerListener.java	(original)
+++ trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/WSASConfigManagerListener.java	Tue Apr  3 02:21:29 2007
@@ -15,9 +15,7 @@
  */
 package org.wso2.wsas.clustering;
 
-import org.apache.axis2.Constants;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.cluster.ClusteringFault;
 import org.apache.axis2.cluster.configuration.ConfigurationEvent;
 import org.apache.axis2.cluster.configuration.ConfigurationManagerListener;
 import org.apache.axis2.context.ConfigurationContext;
@@ -31,6 +29,7 @@
 import org.wso2.wsas.ServerConstants;
 import org.wso2.wsas.deployment.ServerConfigurator;
 import org.wso2.wsas.util.Controllable;
+import org.wso2.wsas.util.Utils;
 
 import java.util.Iterator;
 import java.util.List;
@@ -159,11 +158,7 @@
         ServerConfiguration config = ServerConfiguration.getInstance();
         String repoLocation =
                 config.getFirstProperty(ServerConfiguration.AXIS2_CONFIG_REPO_LOCATION);
-        String axis2XML = System.getProperty(Constants.AXIS2_CONF);
-        if (axis2XML == null) {
-            axis2XML = ServerConfiguration.getInstance().
-                    getFirstProperty("Axis2Config.ConfigurationFile");
-        }
+        String axis2XML = Utils.getAxis2Xml();
         try {
             ServerConfigurator.getInstance().init(repoLocation,
                                                   axis2XML,
@@ -180,9 +175,8 @@
             try {
                 configurationContext.getAxisConfiguration().
                         getClusterManager().getConfigurationManager().exceptionOccurred(e);
-                pendingCommits.remove(LOAD_CONFIGURATION_EVENT);
-            } catch (ClusteringFault ignored) {
-                ignored.printStackTrace();
+            } catch (Exception e1) {
+                log.error(e1);
             }
             log.error("Could not reload new configuration", e);
         }




More information about the Wsas-java-dev mailing list