From 89ccbc768924cd26241b0dfd2bcb6d1cd3105687 Mon Sep 17 00:00:00 2001 From: Michael Gorovoy Date: Mon, 7 Mar 2011 15:18:48 +0000 Subject: [PATCH] 338819 Externally control Deployment Manager application lifecycle git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2865 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 2 + jetty-deploy/pom.xml | 1 + .../jetty/deploy/DeploymentManager.java | 23 ++++++-- .../deploy/jmx/DeploymentManagerMBean.java | 22 ++++++++ .../jmx/DeploymentManager-mbean.properties | 12 +++-- .../jmx/WebAppDeployer-mbean.properties | 2 +- .../DeploymentManagerLifeCyclePathTest.java | 54 +++++++++++++++++++ 7 files changed, 107 insertions(+), 9 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 76c1f9db50e..842a3fc0db9 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,3 +1,5 @@ +jetty-7.3.2-SNAPSHOT + + 338819 Externally control Deployment Manager application lifecycle jetty-7.3.1.v20110307 7 March 2011 + 316382 Support a more strict SSL option with certificates diff --git a/jetty-deploy/pom.xml b/jetty-deploy/pom.xml index 79ef070474c..e0822b97244 100644 --- a/jetty-deploy/pom.xml +++ b/jetty-deploy/pom.xml @@ -95,6 +95,7 @@ org.eclipse.jetty.toolchain jetty-test-helper + 1.3-SNAPSHOT test diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java index 1e2c0acfb42..5e83a083642 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java @@ -35,7 +35,6 @@ import org.eclipse.jetty.deploy.graph.Path; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.log.Log; @@ -435,10 +434,10 @@ public class DeploymentManager extends AggregateLifeCycle public void requestAppGoal(App app, String nodeName) { AppEntry appentry = findAppByOriginId(app.getOriginId()); - if (appentry == null) - { - throw new IllegalStateException("App not being tracked by Deployment Manager: " + app); - } + if (appentry == null) + { + throw new IllegalStateException("App not being tracked by Deployment Manager: " + app); + } requestAppGoal(appentry,nodeName); } @@ -455,6 +454,10 @@ public class DeploymentManager extends AggregateLifeCycle private void requestAppGoal(AppEntry appentry, String nodeName) { Node destinationNode = _lifecycle.getNodeByName(nodeName); + if (destinationNode == null) + { + throw new IllegalStateException("Node not present in Deployment Manager: " + nodeName); + } // Compute lifecycle steps Path path = _lifecycle.getPath(appentry.lifecyleNode,destinationNode); if (path.isEmpty()) @@ -563,4 +566,14 @@ public class DeploymentManager extends AggregateLifeCycle { this._useStandardBindings = useStandardBindings; } + + public Collection getNodes() + { + return _lifecycle.getNodes(); + } + + public Collection getApps(String nodeName) + { + return getApps(_lifecycle.getNodeByName(nodeName)); + } } diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java index 3a219215f61..3bd53624942 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java @@ -7,6 +7,7 @@ import java.util.List; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.DeploymentManager; +import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.jmx.ObjectMBean; import org.eclipse.jetty.server.handler.ContextHandler; @@ -20,6 +21,14 @@ public class DeploymentManagerMBean extends ObjectMBean _manager=(DeploymentManager)managedObject; } + public Collection getNodes() + { + List nodes = new ArrayList(); + for (Node node: _manager.getNodes()) + nodes.add(node.getName()); + return nodes; + } + public Collection getApps() { List apps=new ArrayList(); @@ -28,6 +37,14 @@ public class DeploymentManagerMBean extends ObjectMBean return apps; } + public Collection getApps(String nodeName) + { + List apps=new ArrayList(); + for (App app: _manager.getApps(nodeName)) + apps.add(app.getOriginId()); + return apps; + } + public Collection getContexts() throws Exception { List apps=new ArrayList(); @@ -40,4 +57,9 @@ public class DeploymentManagerMBean extends ObjectMBean { return _manager.getAppProviders(); } + + public void requestAppGoal(String appId, String nodeName) + { + _manager.requestAppGoal(appId, nodeName); + } } diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties index 726c236b1af..4149820d535 100644 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties +++ b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties @@ -1,4 +1,10 @@ DeploymentManager: Deployment Manager -apps:MBean:Deployed Apps -contexts:MMBean:Deployed Contexts -appProviders:MMBean:Application Providers \ No newline at end of file +nodes:MBean: App LifeCycle Nodes +apps:MBean: Deployed Apps +contexts:MMBean: Deployed Contexts +appProviders:MMBean: Application Providers +getApps(java.lang.String):MBean:ACTION: List apps that are located at specified App LifeCycle node +getApps(java.lang.String)[0]:nodeName: Name of the App LifeCycle node +requestAppGoal(java.lang.String,java.lang.String) ACTION: Request the app to be moved to the specified App LifeCycle node +requestAppGoal(java.lang.String,java.lang.String)[0]:appId:App identifier +requestAppGoal(java.lang.String,java.lang.String)[1]:nodeName:Name of the App LifeCycle node \ No newline at end of file diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties index a1304e1e7a0..2815ae6ee40 100644 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties +++ b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties @@ -1,6 +1,6 @@ WebAppDeployer: Deployer for startup deployment of webapps contexts: MObject: The ContextHandlerCollection to which the deployer deploys -allowDuplicates: Object:R0: Whether or not duplicate deployments are allowed +allowDuplicates: Object:RO: Whether or not duplicate deployments are allowed setAllowDuplicates(boolean):ACTION: Whether or not duplicate deployments are allowed setAllowDuplicates(boolean)[0]:allowDuplicates: True allows duplicate webapps to be deployed while false does not defaultsDescriptor: Object: The webdefault.xml descriptor to use for all webapps deployed by the deployer diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerLifeCyclePathTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerLifeCyclePathTest.java index b15bdc5f4ba..a2395025133 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerLifeCyclePathTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerLifeCyclePathTest.java @@ -15,10 +15,16 @@ // ======================================================================== package org.eclipse.jetty.deploy; +import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.toolchain.jmx.JmxServiceConnection; import org.junit.Test; public class DeploymentManagerLifeCyclePathTest @@ -79,4 +85,52 @@ public class DeploymentManagerLifeCyclePathTest pathtracker.assertExpected("Test StateTransition / New only",expected); } + + @Test + public void testStateTransition_DeployedToUndeployed() throws Exception + { + DeploymentManager depman = new DeploymentManager(); + depman.setDefaultLifeCycleGoal(null); // no default + AppLifeCyclePathCollector pathtracker = new AppLifeCyclePathCollector(); + MockAppProvider mockProvider = new MockAppProvider(); + + // Setup JMX + MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); + mbContainer.start(); + mbContainer.addBean(depman); + + depman.addLifeCycleBinding(pathtracker); + depman.addAppProvider(mockProvider); + depman.setContexts(new ContextHandlerCollection()); + + // Start DepMan + depman.start(); + + // Trigger new App + mockProvider.findWebapp("foo-webapp-1.war"); + + App app = depman.getAppByOriginId("mock-foo-webapp-1.war"); + + // Request Deploy of App + depman.requestAppGoal(app,"deployed"); + + JmxServiceConnection jmxConnection = new JmxServiceConnection(); + jmxConnection.connect(); + + MBeanServerConnection mbsConnection = jmxConnection.getConnection(); + ObjectName dmObjName = new ObjectName("org.eclipse.jetty.deploy:type=deploymentmanager,id=0"); + String[] params = new String[] {"mock-foo-webapp-1.war", "undeployed"}; + String[] signature = new String[] {"java.lang.String", "java.lang.String"}; + mbsConnection.invoke(dmObjName, "requestAppGoal", params, signature); + + // Setup Expectations. + List expected = new ArrayList(); + // SHOULD NOT SEE THIS NODE VISITED - expected.add("undeployed"); + expected.add("deploying"); + expected.add("deployed"); + expected.add("undeploying"); + expected.add("undeployed"); + + pathtracker.assertExpected("Test JMX StateTransition / Deployed -> Undeployed",expected); + } }