Author: kfujino
Date: Wed Apr 24 05:54:52 2013
New Revision: 1471259
URL: http://svn.apache.org/r1471259
Log:
Add several improvements for FarmWarDeployer.
Merged following revisions from /trunk.
includes r1467891, r1467893, r1468290, r1468311, r1469138, r1469144, r1469703,
r1469708, r1470852, r1470859.
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/LocalStrings.properties
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-deployer.xml
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
Wed Apr 24 05:54:52 2013
@@ -73,16 +73,28 @@ public class FarmWarDeployer extends Clu
private static final String info = "FarmWarDeployer/1.2";
/*--Instance Variables--------------------------------------*/
- protected boolean started = false; //default 5 seconds
+ protected boolean started = false;
protected HashMap<String, FileMessageFactory> fileFactories =
new HashMap<String, FileMessageFactory>();
+ /**
+ * Deployment directory.
+ */
protected String deployDir;
+ private File deployDirFile = null;
+ /**
+ * Temporary directory.
+ */
protected String tempDir;
+ private File tempDirFile = null;
+ /**
+ * Watch directory.
+ */
protected String watchDir;
+ private File watchDirFile = null;
protected boolean watchEnabled = false;
@@ -171,17 +183,23 @@ public class FarmWarDeployer extends Clu
return;
}
if (watchEnabled) {
- watcher = new WarWatcher(this, new File(getWatchDir()));
+ watcher = new WarWatcher(this, getWatchDirFile());
if (log.isInfoEnabled()) {
log.info(sm.getString(
"farmWarDeployer.watchDir", getWatchDir()));
}
}
-
- configBase = new File(
- System.getProperty(Globals.CATALINA_BASE_PROP), "conf");
- configBase = new File(configBase, engine.getName());
- configBase = new File(configBase, hostname);
+
+ if (host.getXmlBase()!=null) {
+ configBase = getAbsolutePath(host.getXmlBase());
+ } else {
+ StringBuilder xmlDir = new StringBuilder("conf");
+ xmlDir.append('/');
+ xmlDir.append(engine.getName());
+ xmlDir.append('/');
+ xmlDir.append(host.getName());
+ configBase = getAbsolutePath(xmlDir.toString());
+ }
// Retrieve the MBean server
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
@@ -241,7 +259,7 @@ public class FarmWarDeployer extends Clu
String name = factory.getFile().getName();
if (!name.endsWith(".war"))
name = name + ".war";
- File deployable = new File(getDeployDir(), name);
+ File deployable = new File(getDeployDirFile(), name);
try {
String contextName = fmsg.getContextName();
if (!isServiced(contextName)) {
@@ -312,7 +330,7 @@ public class FarmWarDeployer extends Clu
*/
public synchronized FileMessageFactory getFactory(FileMessage msg)
throws java.io.FileNotFoundException, java.io.IOException {
- File writeToFile = new File(getTempDir(), msg.getFileName());
+ File writeToFile = new File(getTempDirFile(), msg.getFileName());
FileMessageFactory factory = fileFactories.get(msg.getFileName());
if (factory == null) {
factory = FileMessageFactory.getInstance(writeToFile, true);
@@ -373,6 +391,8 @@ public class FarmWarDeployer extends Clu
@Override
public void install(String contextName, File webapp) throws IOException {
Member[] members = getCluster().getMembers();
+ if (members.length == 0) return;
+
Member localMember = getCluster().getLocalMember();
FileMessageFactory factory =
FileMessageFactory.getInstance(webapp, false);
@@ -420,15 +440,17 @@ public class FarmWarDeployer extends Clu
@Override
public void remove(String contextName, boolean undeploy)
throws IOException {
- if (log.isInfoEnabled())
- log.info(sm.getString("farmWarDeployer.removeStart", contextName));
- Member localMember = getCluster().getLocalMember();
- UndeployMessage msg = new UndeployMessage(localMember, System
- .currentTimeMillis(), "Undeploy:" + contextName + ":"
- + System.currentTimeMillis(), contextName, undeploy);
- if (log.isDebugEnabled())
- log.debug(sm.getString("farmWarDeployer.removeTxMsg",
contextName));
- cluster.send(msg);
+ if (getCluster().getMembers().length > 0) {
+ if (log.isInfoEnabled())
+ log.info(sm.getString("farmWarDeployer.removeStart",
contextName));
+ Member localMember = getCluster().getLocalMember();
+ UndeployMessage msg = new UndeployMessage(localMember, System
+ .currentTimeMillis(), "Undeploy:" + contextName + ":"
+ + System.currentTimeMillis(), contextName, undeploy);
+ if (log.isDebugEnabled())
+ log.debug(sm.getString("farmWarDeployer.removeTxMsg",
contextName));
+ cluster.send(msg);
+ }
// remove locally
if (undeploy) {
try {
@@ -459,16 +481,28 @@ public class FarmWarDeployer extends Clu
@Override
public void fileModified(File newWar) {
try {
- File deployWar = new File(getDeployDir(), newWar.getName());
- copy(newWar, deployWar);
+ File deployWar = new File(getDeployDirFile(), newWar.getName());
ContextName cn = new ContextName(deployWar.getName());
+ if (deployWar.exists() && deployWar.lastModified() >
newWar.lastModified()) {
+ if (log.isInfoEnabled())
+ log.info(sm.getString("farmWarDeployer.alreadyDeployed",
cn.getName()));
+ return;
+ }
if (log.isInfoEnabled())
log.info(sm.getString("farmWarDeployer.modInstall",
cn.getName(), deployWar.getAbsolutePath()));
- try {
- remove(cn.getName(), false);
- } catch (Exception x) {
- log.error(sm.getString("farmWarDeployer.modRemoveFail"), x);
+ // install local
+ if (!isServiced(cn.getName())) {
+ addServiced(cn.getName());
+ try {
+ copy(newWar, deployWar);
+ check(cn.getName());
+ } finally {
+ removeServiced(cn.getName());
+ }
+ } else {
+ log.error(sm.getString("farmWarDeployer.servicingDeploy",
+ cn.getName(), deployWar.getName()));
}
install(cn.getName(), deployWar);
} catch (Exception x) {
@@ -585,9 +619,9 @@ public class FarmWarDeployer extends Clu
*/
@Override
public void backgroundProcess() {
- if (started) {
+ if (started && watchEnabled) {
count = (count + 1) % processDeployFrequency;
- if (count == 0 && watchEnabled) {
+ if (count == 0) {
watcher.check();
}
}
@@ -649,6 +683,14 @@ public class FarmWarDeployer extends Clu
return deployDir;
}
+ public File getDeployDirFile() {
+ if (deployDirFile != null) return deployDirFile;
+
+ File dir = getAbsolutePath(getDeployDir());
+ this.deployDirFile = dir;
+ return dir;
+ }
+
public void setDeployDir(String deployDir) {
this.deployDir = deployDir;
}
@@ -657,6 +699,14 @@ public class FarmWarDeployer extends Clu
return tempDir;
}
+ public File getTempDirFile() {
+ if (tempDirFile != null) return tempDirFile;
+
+ File dir = getAbsolutePath(getTempDir());
+ this.tempDirFile = dir;
+ return dir;
+ }
+
public void setTempDir(String tempDir) {
this.tempDir = tempDir;
}
@@ -665,6 +715,14 @@ public class FarmWarDeployer extends Clu
return watchDir;
}
+ public File getWatchDirFile() {
+ if (watchDirFile != null) return watchDirFile;
+
+ File dir = getAbsolutePath(getWatchDir());
+ this.watchDirFile = dir;
+ return dir;
+ }
+
public void setWatchDir(String watchDir) {
this.watchDir = watchDir;
}
@@ -738,4 +796,16 @@ public class FarmWarDeployer extends Clu
return true;
}
+ private File getAbsolutePath(String path) {
+ File dir = new File(path);
+ File base = new File(System.getProperty(Globals.CATALINA_BASE_PROP));
+ if (!dir.isAbsolute()) {
+ dir = new File(base, dir.getPath());
+ }
+ try {
+ dir = dir.getCanonicalFile();
+ } catch (IOException e) {// ignore
+ }
+ return dir;
+ }
}
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/LocalStrings.properties?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/LocalStrings.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/LocalStrings.properties
Wed Apr 24 05:54:52 2013
@@ -21,6 +21,7 @@ farmWarDeployer.fileCopyFail=Unable to c
farmWarDeployer.hostOnly=FarmWarDeployer can only work as host cluster
subelement!
farmWarDeployer.hostParentEngine=FarmWarDeployer can only work if parent of
[{0}] is an engine!
farmWarDeployer.mbeanNameFail=Can't construct MBean object name for engine
[{0}] and host [{1}]
+farmWarDeployer.alreadyDeployed=webapp [{0}] are already deployed.
farmWarDeployer.modInstall=Installing webapp [{0}] from [{1}]
farmWarDeployer.modRemoveFail=No removal
farmWarDeployer.modInstallFail=Unable to install WAR file
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml
Wed Apr 24 05:54:52 2013
@@ -39,5 +39,9 @@
name="watchEnabled"
description="Is watching enabled?"
type="boolean"/>
+ <attribute
+ name="processDeployFrequency"
+ description="Frequency of the Farm watchDir check."
+ type="int"/>
</mbean>
</mbeans-descriptors>
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java Wed
Apr 24 05:54:52 2013
@@ -1458,9 +1458,8 @@ public class HostConfig
DeployedApplication app = deployed.get(name);
if (app != null) {
checkResources(app);
- } else {
- deployApps(name);
}
+ deployApps(name);
}
/**
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Apr 24 05:54:52 2013
@@ -77,6 +77,13 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Cluster">
+ <changelog>
+ <fix>
+ Add several improvements for FarmWarDeployer. (kfujino)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Web applications">
<changelog>
<fix>
Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-deployer.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-deployer.xml?rev=1471259&r1=1471258&r2=1471259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-deployer.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-deployer.xml Wed Apr 24
05:54:52 2013
@@ -34,29 +34,59 @@
</section>
<section name="Introduction">
- <p>TODO - Complete documentation</p>
-
-
+ <p>The Farm War Deployer can deploy and undeploy web applications on the
other
+ nodes in the cluster.</p>
+ <p><strong>Note: </strong>FarmWarDeployer can be configured at host level
+ cluster only.
+ </p>
</section>
-<section name="Attributes">
-
- <subsection name="Common Attributes">
-
- <attributes>
+<section name="org.apache.catalina.ha.deploy.FarmWarDeployer">
- <attribute name="className" required="true">
-
- </attribute>
-
-
- </attributes>
+ <subsection name="Attributes">
+ <attributes>
+ <attribute name="className" required="true">
+ The cluster deployer class, currently only one is available,
+ <code>org.apache.catalina.ha.deploy.FarmWarDeployer.</code>
+ </attribute>
+ <attribute name="deployDir" required="true">
+ Deployment directory. This is the pathname of a directory where deploy
+ the web applications. You may specify an absolute pathname, or a
+ pathname that is relative to the $CATALINA_BASE directory. In the
+ current implementation, this attribute must be the same value as the
+ <strong>Host's appBase</strong>.
+ </attribute>
+ <attribute name="tempDir" required="true">
+ The temporaryDirectory to store binary data when downloading a war from
+ the cluster. You may specify an absolute pathname, or a pathname that
is
+ relative to the $CATALINA_BASE directory.
+ </attribute>
+ <attribute name="watchDir" required="false">
+ This is the pathname of a directory where watch for
changes(add/modify/remove)
+ of web applications. You may specify an absolute pathname, or a
pathname
+ that is relative to the $CATALINA_BASE directory.
+ <strong>Note: </strong> if <strong>watchEnabled</strong> is false, this
+ attribute will have no effect.
+ </attribute>
+ <attribute name="watchEnabled" required="false">
+ Set to true if you want to watch for changes of web applications.
+ Only when this attribute set to true, you can trigger a deploy/undeploy
+ of web applications. The flag's value defaults to false.
+ </attribute>
+ <attribute name="processDeployFrequency" required="false">
+ Frequency of the Farm watchDir check. Cluster wide deployment will be
+ done once for the specified amount of backgrondProcess calls (ie, the
+ lower the amount, the most often the checks will occur). The minimum
+ value is 1, and the default value is 2.
+ <strong>Note: </strong> if <strong>watchEnabled</strong> is false, this
+ attribute will have no effect.
+ </attribute>
+ </attributes>
</subsection>
-
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]