ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sath...@apache.org
Subject [02/30] ode git commit: second commit
Date Fri, 06 Nov 2015 10:50:57 GMT
second commit


Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/79c0b16a
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/79c0b16a
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/79c0b16a

Branch: refs/heads/ODE-563
Commit: 79c0b16a694d9a8a25d9ecd8a05272e5e34d8a7f
Parents: 50c4dfe
Author: suba <suba.11@cse.mrt.ac.lk>
Authored: Sun Jun 7 20:44:02 2015 +0530
Committer: suba <suba.11@cse.mrt.ac.lk>
Committed: Sun Jun 7 20:44:02 2015 +0530

----------------------------------------------------------------------
 .../ode/axis2/deploy/DeploymentPoller.java      | 94 +++++++++++++-------
 .../ode/axis2/service/DeploymentWebService.java | 80 ++++++++++-------
 .../ode/il/config/OdeConfigProperties.java      |  6 ++
 .../hazelcast/HazelcastClusterImpl.java         | 22 ++---
 4 files changed, 122 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/79c0b16a/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java b/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
index 6f82385..057c0fb 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
@@ -54,6 +54,8 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import  org.apache.ode.clustering.hazelcast.HazelcastClusterImpl;
+
 /**
  * Polls a directory for the deployment of a new deployment unit.
  */
@@ -74,6 +76,8 @@ public class DeploymentPoller {
 
     private SystemSchedulesConfig _systemSchedulesConf;
 
+    private boolean clusterEnabled;
+
     @SuppressWarnings("unchecked")
     private Map<String, WatchDog> dDWatchDogsByPath = new HashMap<String, WatchDog>();
     @SuppressWarnings("unchecked")
@@ -96,6 +100,7 @@ public class DeploymentPoller {
     public DeploymentPoller(File deployDir, final ODEServer odeServer) {
         _odeServer = odeServer;
         _deployDir = deployDir;
+        clusterEnabled = _odeServer.getClusteringState();
         if (!_deployDir.exists()) {
             boolean isDeployDirCreated = _deployDir.mkdir();
             if (!isDeployDirCreated) {
@@ -130,50 +135,58 @@ public class DeploymentPoller {
     @SuppressWarnings("unchecked")
     private void check() {
         File[] files = _deployDir.listFiles(_fileFilter);
+        boolean duLocked;
 
         // Checking for new deployment directories
         if (isDeploymentFromODEFileSystemAllowed() && files != null) {
             for (File file : files) {
-                File deployXml = new File(file, "deploy.xml");
-                File deployedMarker = new File(_deployDir, file.getName() + ".deployed");
-
-                if (!deployXml.exists()) {
-                    // Skip if deploy.xml is abset
-                    if (__log.isDebugEnabled()) {
-                        __log.debug("Not deploying " + file + " (missing deploy.xml)");
-                    }
-                }
+                duLocked = lock(file.getName());
+                try {
+                    if (duLocked) {
+                        File deployXml = new File(file, "deploy.xml");
+                        File deployedMarker = new File(_deployDir, file.getName() + ".deployed");
+
+                        if (!deployXml.exists()) {
+                            // Skip if deploy.xml is abset
+                            if (__log.isDebugEnabled()) {
+                                __log.debug("Not deploying " + file + " (missing deploy.xml)");
+                            }
+                        }
 
-                WatchDog ddWatchDog = ensureDeployXmlWatchDog(file, deployXml);
+                        WatchDog ddWatchDog = ensureDeployXmlWatchDog(file, deployXml);
 
-                if (deployedMarker.exists()) {
-                    checkDeployXmlWatchDog(ddWatchDog);
-                    continue;
-                }
+                        if (deployedMarker.exists()) {
+                            checkDeployXmlWatchDog(ddWatchDog);
+                            continue;
+                        }
 
-                try {
-                    boolean isCreated = deployedMarker.createNewFile();
-                    if (!isCreated) {
-                        __log.error("Error while creating  file "
+                        try {
+                            boolean isCreated = deployedMarker.createNewFile();
+                            if (!isCreated) {
+                                __log.error("Error while creating  file "
                                         + file.getName()
                                         + ".deployed ,deployment could be inconsistent");
-                    }
-                } catch (IOException e1) {
-                    __log.error("Error creating deployed marker file, " + file + " will not
be deployed");
-                    continue;
-                }
+                            }
+                        } catch (IOException e1) {
+                            __log.error("Error creating deployed marker file, " + file +
" will not be deployed");
+                            continue;
+                        }
 
-                try {
-                    _odeServer.getProcessStore().undeploy(file);
-                } catch (Exception ex) {
-                    __log.error("Error undeploying " + file.getName());
-                }
+                        try {
+                            _odeServer.getProcessStore().undeploy(file);
+                        } catch (Exception ex) {
+                            __log.error("Error undeploying " + file.getName());
+                        }
 
-                try {
-                    Collection<QName> deployed = _odeServer.getProcessStore().deploy(file);
-                    __log.info("Deployment of artifact " + file.getName() + " successful:
" + deployed );
-                } catch (Exception e) {
-                    __log.error("Deployment of " + file.getName() + " failed, aborting for
now.", e);
+                        try {
+                            Collection<QName> deployed = _odeServer.getProcessStore().deploy(file);
+                            __log.info("Deployment of artifact " + file.getName() + " successful:
" + deployed);
+                        } catch (Exception e) {
+                            __log.error("Deployment of " + file.getName() + " failed, aborting
for now.", e);
+                        }
+                    }
+                } finally {
+                    unlock(file.getName());
                 }
             }
         }
@@ -324,4 +337,19 @@ public class DeploymentPoller {
             _odeServer.getProcessStore().refreshSchedules(deploymentPakage);
         }
     }
+
+    //Implementation of IMap key Lock
+    public boolean lock(String key) {
+        if(clusterEnabled) {
+            _odeServer.getBpelServer().getContexts().hazelcastClusterImpl.lock(key);
+        }
+        return true;
+    }
+
+    public boolean unlock(String key) {
+        if(clusterEnabled) {
+            _odeServer.getBpelServer().getContexts().hazelcastClusterImpl.unlock(key);
+        }
+        return true;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ode/blob/79c0b16a/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java b/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
index aa769ed..1c09bb3 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
@@ -109,6 +109,7 @@ public class DeploymentWebService {
             String operation = messageContext.getAxisOperation().getName().getLocalPart();
             SOAPFactory factory = getSOAPFactory(messageContext);
             boolean unknown = false;
+            boolean duLocked;
 
             try {
                 if (operation.equals("deploy")) {
@@ -166,43 +167,54 @@ public class DeploymentWebService {
                         _poller.hold();
 
                         File dest = new File(_deployPath, bundleName + "-" + _store.getCurrentVersion());
-                        boolean createDir = dest.mkdir();
-                        if(!createDir){
-                        	throw new OdeFault("Error while creating file " + dest.getName());
-                        }
-                        unzip(dest, (DataHandler) binaryNode.getDataHandler());
-
-                        // Check that we have a deploy.xml
-                        File deployXml = new File(dest, "deploy.xml");
-                        if (!deployXml.exists())
-                            throw new OdeFault("The deployment doesn't appear to contain
a deployment " +
-                                    "descriptor in its root directory named deploy.xml, aborting.");
-
-                        Collection<QName> deployed = _store.deploy(dest);
-
-                        File deployedMarker = new File(_deployPath, dest.getName() + ".deployed");
-                        if(!deployedMarker.createNewFile()) {
-                        	throw new OdeFault("Error while creating file " + deployedMarker.getName()
+ "deployment failed");
-                        }
 
-                        // Telling the poller what we deployed so that it doesn't try to
deploy it again
-                        _poller.markAsDeployed(dest);
-                        __log.info("Deployment of artifact " + dest.getName() + " successful.");
+                        //lock on deployment unit directory name
+                        duLocked = _poller.lock(dest.getName());
 
-                        OMElement response = factory.createOMElement("response", null);
-
-                        if (__log.isDebugEnabled()) __log.debug("Deployed package: "+dest.getName());
-                        OMElement d = factory.createOMElement("name", _deployapi);
-                        d.setText(dest.getName());
-                        response.addChild(d);
-
-                        for (QName pid : deployed) {
-                            if (__log.isDebugEnabled()) __log.debug("Deployed PID: "+pid);
-                            d = factory.createOMElement("id", _deployapi);
-                            d.setText(pid);
-                            response.addChild(d);
+                        if (duLocked) {
+                            boolean createDir = dest.mkdir();
+                            if (!createDir) {
+                                throw new OdeFault("Error while creating file " + dest.getName());
+                            }
+                            try {
+                                unzip(dest, (DataHandler) binaryNode.getDataHandler());
+
+                                // Check that we have a deploy.xml
+                                File deployXml = new File(dest, "deploy.xml");
+                                if (!deployXml.exists())
+                                    throw new OdeFault("The deployment doesn't appear to
contain a deployment " +
+                                            "descriptor in its root directory named deploy.xml,
aborting.");
+
+                                Collection<QName> deployed = _store.deploy(dest);
+
+                                File deployedMarker = new File(_deployPath, dest.getName()
+ ".deployed");
+                                if (!deployedMarker.createNewFile()) {
+                                    throw new OdeFault("Error while creating file " + deployedMarker.getName()
+ "deployment failed");
+                                }
+
+                                // Telling the poller what we deployed so that it doesn't
try to deploy it again
+                                _poller.markAsDeployed(dest);
+                                __log.info("Deployment of artifact " + dest.getName() + "
successful.");
+
+
+                                OMElement response = factory.createOMElement("response",
null);
+
+                                if (__log.isDebugEnabled()) __log.debug("Deployed package:
" + dest.getName());
+                                OMElement d = factory.createOMElement("name", _deployapi);
+                                d.setText(dest.getName());
+                                response.addChild(d);
+
+                                for (QName pid : deployed) {
+                                    if (__log.isDebugEnabled()) __log.debug("Deployed PID:
" + pid);
+                                    d = factory.createOMElement("id", _deployapi);
+                                    d.setText(pid);
+                                    response.addChild(d);
+                                }
+                                sendResponse(factory, messageContext, "deployResponse", response);
+                            } finally {
+                                _poller.unlock(dest.getName());
+                            }
                         }
-                        sendResponse(factory, messageContext, "deployResponse", response);
                     } finally {
                         _poller.release();
                     }

http://git-wip-us.apache.org/repos/asf/ode/blob/79c0b16a/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java b/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
index 39ca2b0..cef3b74 100644
--- a/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
+++ b/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
@@ -106,6 +106,8 @@ public class OdeConfigProperties {
 
     public static final String DEFAULT_TX_FACTORY_CLASS_NAME = "org.apache.ode.il.EmbeddedGeronimoFactory";
 
+    public static final String PROP_HAZELCAST_CLUSTERING = "hazelcast.clustering.enabled";
+
     private File _cfgFile;
 
     private String _prefix;
@@ -289,6 +291,10 @@ public class OdeConfigProperties {
         return getProperty(OdeConfigProperties.PROP_DEPLOY_DIR);
     }
 
+    public String getClusteringState() {
+        return getProperty(OdeConfigProperties.PROP_HAZELCAST_CLUSTERING);
+    }
+
     public String getTxFactoryClass() {
         return getProperty(OdeConfigProperties.PROP_TX_FACTORY_CLASS, DEFAULT_TX_FACTORY_CLASS_NAME);
     }

http://git-wip-us.apache.org/repos/asf/ode/blob/79c0b16a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
----------------------------------------------------------------------
diff --git a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
index afe0e95..2cff4c8 100644
--- a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
+++ b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
@@ -39,6 +39,8 @@ public class HazelcastClusterImpl implements HazelcastCluster{
     private String message = "";
     private Member leader;
 
+    private IMap<String, String> lock_map;
+
     public HazelcastClusterImpl(HazelcastInstance hazelcastInstance) {
         _hazelcastInstance = hazelcastInstance;
         init();
@@ -57,6 +59,8 @@ public class HazelcastClusterImpl implements HazelcastCluster{
         __log.info("Registering HZ localMember ID " + localMemberID);
         _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_NODE_MAP)
                 .put(localMemberID, isMaster);
+
+        lock_map = _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_LOCK_MAP);
     }
 
     public String getHazelCastNodeID(Member member) {
@@ -65,20 +69,12 @@ public class HazelcastClusterImpl implements HazelcastCluster{
         return hostName + ":" + port;
     }
 
-    class ClusterManager {
-        IMap<String, String> lock_map;
-
-        ClusterManager() {
-            lock_map = _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_LOCK_MAP);
-        }
-
-        void lock(String key) {
-            lock_map.lock(key);
-        }
+    public void lock(String key) {
+        lock_map.lock(key);
+    }
 
-        void unlock(String key) {
-            lock_map.unlock(key);
-        }
+    public void unlock(String key) {
+        lock_map.unlock(key);
     }
 
     class ClusterMemberShipListener implements MembershipListener {


Mime
View raw message