You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2010/02/14 03:27:15 UTC
svn commit: r909963 - in /synapse/trunk/java:
modules/core/src/main/java/org/apache/synapse/deployers/ repository/conf/
Author: ruwan
Date: Sun Feb 14 02:27:15 2010
New Revision: 909963
URL: http://svn.apache.org/viewvc?rev=909963&view=rev
Log:
Implementing Hot-Update of the synapse artifacts, restoring of the existing artifact upon a failure of updating is yet to be done :-)
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EndpointDeployer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/ProxyServiceDeployer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SequenceDeployer.java
synapse/trunk/java/repository/conf/axis2.xml
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java Sun Feb 14 02:27:15 2010
@@ -37,6 +37,7 @@
import org.apache.synapse.core.SynapseEnvironment;
import javax.xml.stream.XMLStreamException;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -57,6 +58,7 @@
private static final Log log = LogFactory.getLog(AbstractSynapseArtifactDeployer.class);
protected ConfigurationContext cfgCtx;
+ private Map<String, String> updatingArtifacts = new HashMap<String, String>();
/**
* Initializes the Synapse artifact deployment
@@ -98,7 +100,14 @@
// since all synapse artifacts are XML based
OMElement element = new StAXOMBuilder(
StAXUtils.createXMLStreamReader(in)).getDocumentElement();
- String artifatcName = deploySynapseArtifact(element, filename);
+ String artifatcName;
+ if (updatingArtifacts.containsKey(filename)) {
+ String existingArtifactName = updatingArtifacts.get(filename);
+ updatingArtifacts.remove(filename);
+ artifatcName = updateSynapseArtifact(element, filename, existingArtifactName);
+ } else {
+ artifatcName = deploySynapseArtifact(element, filename);
+ }
if (artifatcName != null) {
FileNameToArtifactNameHolder.getInstance().addArtifact(filename, artifatcName);
}
@@ -130,7 +139,17 @@
public void unDeploy(String fileName) throws DeploymentException {
FileNameToArtifactNameHolder holder = FileNameToArtifactNameHolder.getInstance();
if (holder.containsFileName(fileName)) {
- undeploySynapseArtifact(holder.getArtifactNameForFile(fileName));
+ File undeployingFile = new File(fileName);
+ // axis2 treats Hot-Update as (Undeployment + deployment), where synapse needs to differentiate
+ // the Hot-Update from the above two, since it needs some validations for a real undeployment.
+ // also this makes sure a zero downtime of the synapse artifacts which are being Hot-deployed
+ if (undeployingFile.exists()) {
+ // if the file exists, which means it has been updated and is a Hot-Update case
+ updatingArtifacts.put(fileName, holder.getArtifactNameForFile(fileName));
+ } else {
+ // if the file doesn't exists then it is an actual undeployment
+ undeploySynapseArtifact(holder.getArtifactNameForFile(fileName));
+ }
holder.removeArtifactWithFileName(fileName);
} else {
throw new DeploymentException("Artifact representing the filename " + fileName
@@ -156,6 +175,18 @@
public abstract String deploySynapseArtifact(OMElement artifactConfig, String fileName);
/**
+ * All synapse artifact deployers MUST implement this method and it handles artifact specific update
+ * tasks of those artifacts.
+ *
+ * @param artifactConfig built element representing the artifact to be deployed loaded from the file
+ * @param fileName file name from which this artifact is being loaded
+ * @param existingArtifactName name of the artifact that was being deployed using the updated file
+ * @return String artifact name created by the update task
+ */
+ public abstract String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName);
+
+ /**
* All synapse artifact deployers MUST implement this method and it handles artifact specific undeployment
* tasks of those artifacts.
*
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EndpointDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EndpointDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EndpointDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EndpointDeployer.java Sun Feb 14 02:27:15 2010
@@ -72,6 +72,53 @@
}
@Override
+ public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Endpoint Update from file : " + fileName + " : Started");
+ }
+
+ try {
+ Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false);
+ if (ep != null) {
+ ep.setFileName(fileName);
+ if (log.isDebugEnabled()) {
+ log.debug("Endpoint named '" + ep.getName()
+ + "' has been built from the file " + fileName);
+ }
+ ep.init(getSynapseEnvironment());
+ if (log.isDebugEnabled()) {
+ log.debug("Initialized the endpoint : " + ep.getName());
+ }
+ Endpoint existingEp
+ = getSynapseConfiguration().getDefinedEndpoints().get(existingArtifactName);
+ getSynapseConfiguration().removeEndpoint(existingArtifactName);
+ if (!existingArtifactName.equals(ep.getName())) {
+ log.info("Endpoint named " + existingArtifactName + " has been Undeployed");
+ }
+ getSynapseConfiguration().addEndpoint(ep.getName(), ep);
+ existingEp.destroy();
+ if (log.isDebugEnabled()) {
+ log.debug("Endpoint " + (existingArtifactName.equals(ep.getName()) ?
+ "update" : "deployment") + " from file : " + fileName + " : Completed");
+ }
+ log.info("Endpoint named '" + ep.getName()
+ + "' has been " + (existingArtifactName.equals(ep.getName()) ?
+ "update" : "deployed") + " from file : " + fileName);
+ return ep.getName();
+ } else {
+ log.error("Endpoint Update Failed. The artifact described in the file "
+ + fileName + " is not an Endpoint");
+ }
+ } catch (Exception e) {
+ log.error("Endpoint Update from the file : " + fileName + " : Failed.", e);
+ }
+
+ return null;
+ }
+
+ @Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
@@ -91,6 +138,7 @@
log.debug("Endpoint Undeployment of the endpoint named : "
+ artifactName + " : Completed");
}
+ log.info("Endpoint named '" + ep.getName() + "' has been undeployed");
} else {
log.error("Couldn't find the endpoint named : " + artifactName);
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java Sun Feb 14 02:27:15 2010
@@ -72,10 +72,55 @@
}
@Override
+ public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("EventSource Update from file : " + fileName + " : Started");
+ }
+
+ try {
+ SynapseEventSource es = EventSourceFactory.createEventSource(artifactConfig);
+ if (es != null) {
+ es.setFileName(fileName);
+ if (log.isDebugEnabled()) {
+ log.debug("EventSource named '" + es.getName()
+ + "' has been built from the file " + fileName);
+ }
+ getSynapseConfiguration().removeEventSource(existingArtifactName);
+ getSynapseConfiguration().getAxisConfiguration().removeService(existingArtifactName);
+ if (!existingArtifactName.equals(es.getName())) {
+ log.info("EventSource named " + existingArtifactName + " has been Undeployed");
+ }
+ es.buildService(getSynapseConfiguration().getAxisConfiguration());
+ if (log.isDebugEnabled()) {
+ log.debug("Initialized the EventSource : " + es.getName());
+ }
+ getSynapseConfiguration().addEventSource(es.getName(), es);
+ if (log.isDebugEnabled()) {
+ log.debug("EventSource " + (existingArtifactName.equals(es.getName()) ?
+ "update" : "deployment") + " from file : " + fileName + " : Completed");
+ }
+ log.info("EventSource named '" + es.getName()
+ + "' has been " + (existingArtifactName.equals(es.getName()) ?
+ "update" : "deployed") + " from file : " + fileName);
+ return es.getName();
+ } else {
+ log.error("EventSource Update Failed. The artifact described in the file "
+ + fileName + " is not a EventSource");
+ }
+ } catch (Exception e) {
+ log.error("EventSource Update from the file : " + fileName + " : Failed.", e);
+ }
+
+ return null;
+ }
+
+ @Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
- log.debug("EventSource Undeployment of the sequence named : "
+ log.debug("EventSource Undeployment of the event source named : "
+ artifactName + " : Started");
}
@@ -84,9 +129,10 @@
if (es != null) {
getSynapseConfiguration().removeEventSource(artifactName);
if (log.isDebugEnabled()) {
- log.debug("EventSource Undeployment of the EventSource named : "
+ log.debug("EventSource Undyou neeeployment of the EventSource named : "
+ artifactName + " : Completed");
}
+ log.info("EventSource named '" + es.getName() + "' has been undeployed");
} else {
log.error("Couldn't find the EventSource named : " + artifactName);
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java Sun Feb 14 02:27:15 2010
@@ -68,6 +68,46 @@
}
@Override
+ public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("LocalEntry Update from file : " + fileName + " : Started");
+ }
+
+ try {
+ Entry e = EntryFactory.createEntry(artifactConfig);
+ if (e != null) {
+ e.setFileName(fileName);
+ if (log.isDebugEnabled()) {
+ log.debug("LocalEntry with key '" + e.getKey()
+ + "' has been built from the file " + fileName);
+ }
+ getSynapseConfiguration().removeEntry(existingArtifactName);
+ if (!existingArtifactName.equals(e.getKey())) {
+ log.info("LocalEntry named " + existingArtifactName + " has been Undeployed");
+ }
+ getSynapseConfiguration().addEntry(e.getKey(), e);
+ if (log.isDebugEnabled()) {
+ log.debug("LocalEntry " + (existingArtifactName.equals(e.getKey()) ?
+ "update" : "deployment") + " from file : " + fileName + " : Completed");
+ }
+ log.info("LocalEntry named '" + e.getKey()
+ + "' has been " + (existingArtifactName.equals(e.getKey()) ?
+ "updated" : "deployed") + " from file : " + fileName);
+ return e.getKey();
+ } else {
+ log.error("LocalEntry Update Failed. The artifact described in the file "
+ + fileName + " is not a LocalEntry");
+ }
+ } catch (Exception e) {
+ log.error("LocalEntry Update from the file : " + fileName + " : Failed.", e);
+ }
+
+ return null;
+ }
+
+ @Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
@@ -83,6 +123,7 @@
log.debug("LocalEntry Undeployment of the entry named : "
+ artifactName + " : Completed");
}
+ log.info("LocalEntry named '" + e.getKey() + "' has been undeployed");
} else {
log.error("Couldn't find the LocalEntry named : " + artifactName);
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/ProxyServiceDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/ProxyServiceDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/ProxyServiceDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/ProxyServiceDeployer.java Sun Feb 14 02:27:15 2010
@@ -20,6 +20,7 @@
package org.apache.synapse.deployers;
import org.apache.axiom.om.OMElement;
+import org.apache.axis2.deployment.DeploymentException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.ManagedLifecycle;
@@ -50,20 +51,7 @@
log.debug("ProxyService named '" + proxy.getName()
+ "' has been built from the file " + fileName);
}
-
- if (proxy.getTargetInLineEndpoint() instanceof ManagedLifecycle) {
- proxy.getTargetInLineEndpoint().init(getSynapseEnvironment());
- }
- if (proxy.getTargetInLineInSequence() != null) {
- proxy.getTargetInLineInSequence().init(getSynapseEnvironment());
- }
- if (proxy.getTargetInLineOutSequence() != null) {
- proxy.getTargetInLineOutSequence().init(getSynapseEnvironment());
- }
- if (proxy.getTargetInLineFaultSequence() != null) {
- proxy.getTargetInLineFaultSequence().init(getSynapseEnvironment());
- }
-
+ initializeProxy(proxy);
if (log.isDebugEnabled()) {
log.debug("Initialized the ProxyService : " + proxy.getName());
}
@@ -92,6 +80,56 @@
}
@Override
+ public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("ProxyService Update from file : " + fileName + " : Started");
+ }
+
+ try {
+ ProxyService proxy = ProxyServiceFactory.createProxy(artifactConfig);
+ if (proxy != null) {
+ proxy.setFileName(fileName);
+ if (log.isDebugEnabled()) {
+ log.debug("ProxyService named '" + proxy.getName()
+ + "' has been built from the file " + fileName);
+ }
+ initializeProxy(proxy);
+ if (log.isDebugEnabled()) {
+ log.debug("Initialized the ProxyService : " + proxy.getName());
+ }
+ proxy.stop(getSynapseConfiguration());
+ getSynapseConfiguration().removeProxyService(existingArtifactName);
+ if (!existingArtifactName.equals(proxy.getName())) {
+ log.info("ProxyService named " + existingArtifactName + " has been Undeployed");
+ }
+ proxy.buildAxisService(getSynapseConfiguration(),
+ getSynapseConfiguration().getAxisConfiguration());
+ if (log.isDebugEnabled()) {
+ log.debug("Started the ProxyService : " + proxy.getName());
+ }
+ getSynapseConfiguration().addProxyService(proxy.getName(), proxy);
+ if (log.isDebugEnabled()) {
+ log.debug("ProxyService " + (existingArtifactName.equals(proxy.getName()) ?
+ "update" : "deployment") + " from file : " + fileName + " : Completed");
+ }
+ log.info("ProxyService named '" + proxy.getName()
+ + "' has been " + (existingArtifactName.equals(proxy.getName()) ?
+ "update" : "deployed") + " from file : " + fileName);
+ return proxy.getName();
+ } else {
+ log.error("ProxyService Update Failed. The artifact described in the file "
+ + fileName + " is not a ProxyService");
+ }
+ } catch (Exception e) {
+ log.error("ProxyService Update from the file : " + fileName + " : Failed.", e);
+ }
+
+ return null;
+ }
+
+ @Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
@@ -111,6 +149,7 @@
log.debug("ProxyService Undeployment of the proxy named : "
+ artifactName + " : Completed");
}
+ log.info("ProxyService named '" + proxy.getName() + "' has been undeployed");
} else {
log.error("Couldn't find the ProxyService named : " + artifactName);
}
@@ -118,4 +157,19 @@
log.error("ProxyService Undeployement of proxy named : " + artifactName + " : Failed");
}
}
+
+ private void initializeProxy(ProxyService proxy) throws DeploymentException {
+ if (proxy.getTargetInLineEndpoint() != null) {
+ proxy.getTargetInLineEndpoint().init(getSynapseEnvironment());
+ }
+ if (proxy.getTargetInLineInSequence() != null) {
+ proxy.getTargetInLineInSequence().init(getSynapseEnvironment());
+ }
+ if (proxy.getTargetInLineOutSequence() != null) {
+ proxy.getTargetInLineOutSequence().init(getSynapseEnvironment());
+ }
+ if (proxy.getTargetInLineFaultSequence() != null) {
+ proxy.getTargetInLineFaultSequence().init(getSynapseEnvironment());
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SequenceDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SequenceDeployer.java?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SequenceDeployer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SequenceDeployer.java Sun Feb 14 02:27:15 2010
@@ -75,6 +75,60 @@
}
@Override
+ public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+ String existingArtifactName) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Sequence Update from file : " + fileName + " : Started");
+ }
+
+ try {
+ Mediator m = MediatorFactoryFinder.getInstance().getMediator(artifactConfig);
+ if (m instanceof SequenceMediator) {
+ SequenceMediator seq = (SequenceMediator) m;
+ if ((SynapseConstants.MAIN_SEQUENCE_KEY.equals(existingArtifactName)
+ || SynapseConstants.FAULT_SEQUENCE_KEY.equals(existingArtifactName))
+ && !existingArtifactName.equals(seq.getName())) {
+ log.error(existingArtifactName + " sequence cannot be renamed");
+ return existingArtifactName;
+ }
+ seq.setFileName(fileName);
+ if (log.isDebugEnabled()) {
+ log.debug("Sequence named '" + seq.getName()
+ + "' has been built from the file " + fileName);
+ }
+ seq.init(getSynapseEnvironment());
+ if (log.isDebugEnabled()) {
+ log.debug("Initialized the sequence : " + seq.getName());
+ }
+ SequenceMediator existingSeq =
+ getSynapseConfiguration().getDefinedSequences().get(existingArtifactName);
+ getSynapseConfiguration().removeSequence(existingArtifactName);
+ if (!existingArtifactName.equals(seq.getName())) {
+ log.info("Sequence named '" + existingArtifactName + "' has been Undeployed");
+ }
+ getSynapseConfiguration().addSequence(seq.getName(), seq);
+ existingSeq.destroy();
+ if (log.isDebugEnabled()) {
+ log.debug("Sequence " + (existingArtifactName.equals(seq.getName()) ?
+ "update" : "deployment") + " from file : " + fileName + " : Completed");
+ }
+ log.info("Sequence named '" + seq.getName()
+ + "' has been " + (existingArtifactName.equals(seq.getName()) ?
+ "update" : "deployed") + " from file : " + fileName);
+ return seq.getName();
+ } else {
+ log.error("Sequence Update Failed. The artifact described in the file "
+ + fileName + " is not a Sequence");
+ }
+ } catch (Exception e) {
+ log.error("Sequence Update from the file : " + fileName + " : Failed.", e);
+ }
+
+ return null;
+ }
+
+ @Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
@@ -100,6 +154,7 @@
log.debug("Sequence Undeployment of the sequence named : "
+ artifactName + " : Completed");
}
+ log.info("Sequence named '" + seq.getName() + "' has been undeployed");
} else {
log.error("Couldn't find the sequence named : " + artifactName);
}
Modified: synapse/trunk/java/repository/conf/axis2.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/axis2.xml?rev=909963&r1=909962&r2=909963&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/axis2.xml (original)
+++ synapse/trunk/java/repository/conf/axis2.xml Sun Feb 14 02:27:15 2010
@@ -25,7 +25,7 @@
<!-- WARNING: Hot deployment is turned on by default, but it is highly recommended to set this to false
on production environments, unless you really want to use hot deployment in production -->
<parameter name="hotdeployment">true</parameter>
- <parameter name="hotupdate">false</parameter>
+ <parameter name="hotupdate">true</parameter>
<parameter name="enableMTOM">false</parameter>
<parameter name="enableSwA">false</parameter>