[jboss-cvs] JBossAS SVN: r69505 - in trunk: tomcat and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 31 13:26:00 EST 2008


Author: bstansberry at jboss.com
Date: 2008-01-31 13:26:00 -0500 (Thu, 31 Jan 2008)
New Revision: 69505

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapper.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapperMBean.java
   trunk/tomcat/src/resources/jboss-web-service.xml
Modified:
   trunk/build/build-distr.xml
   trunk/tomcat/build.xml
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java
Log:
[JBAS-5191] Manage JBoss Web runtime lifecycle via a JMX service in deploy

Modified: trunk/build/build-distr.xml
===================================================================
--- trunk/build/build-distr.xml	2008-01-31 18:06:03 UTC (rev 69504)
+++ trunk/build/build-distr.xml	2008-01-31 18:26:00 UTC (rev 69505)
@@ -1268,7 +1268,7 @@
       </fileset>
     </copy>
 
-    <!-- Copy the deployables -->
+    <!-- Copy the deployers -->
     <mkdir dir="${install.server}/all/deployers/jbossweb.deployer"/>
     <copy todir="${install.server}/all/deployers/jbossweb.deployer">
       <fileset dir="${_module.output}/deploy/jboss-web.deployer"/>
@@ -1281,6 +1281,12 @@
       file="${project.root}/${_module.name}/src/resources/war-clustering-deployers-beans.xml" overwrite="true"/>
     -->
   	
+  	 <!-- Copy the webserver runtime sar -->
+  	 <mkdir dir="${install.server}/all/deploy/jbossweb.sar"/>
+    <copy todir="${install.server}/all/deploy/jbossweb.sar">
+      <fileset dir="${_module.output}/deploy/jbossweb.sar"/>
+    </copy>
+  	
     <!-- Copy the ROOT.war -->
     <copy todir="${install.server}/all/deploy" filtering="no">
       <fileset dir="${_module.output}/deploy">

Modified: trunk/tomcat/build.xml
===================================================================
--- trunk/tomcat/build.xml	2008-01-31 18:06:03 UTC (rev 69504)
+++ trunk/tomcat/build.xml	2008-01-31 18:26:00 UTC (rev 69505)
@@ -311,6 +311,11 @@
    <copy tofile="${build.deploy}/cluster/jbossweb-clusteredsso-beans.xml"
          file="${build.resources}/jbossweb-clusteredsso-beans.xml"/>
 
+    <!-- SAR for the webserver runtime -->
+  	 <mkdir dir="${build.deploy}/jbossweb.sar/META-INF"/>
+    <copy tofile="${build.deploy}/jbossweb.sar/META-INF/jboss-service.xml"
+          file="${build.resources}/jboss-web-service.xml"/>
+  	
     <!-- Update the build marker to allow bypassing -->
     <touch file="${build-bypass.marker}"/>
 

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java	2008-01-31 18:06:03 UTC (rev 69504)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java	2008-01-31 18:26:00 UTC (rev 69505)
@@ -26,17 +26,26 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Properties;
 
 import javax.management.Attribute;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanException;
+import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.security.jacc.PolicyContext;
+import javax.security.jacc.PolicyContextException;
 
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.connector.Connector;
@@ -57,6 +66,7 @@
 import org.jboss.web.deployers.AbstractWarDeployment;
 import org.jboss.web.tomcat.security.HttpServletRequestPolicyContextHandler;
 import org.jboss.web.tomcat.service.session.SessionIDGenerator;
+import org.jboss.xb.binding.JBossXBException;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
@@ -161,6 +171,8 @@
    /** */
    private String[] filteredPackages;
 
+   private boolean runtimeLifecycleCoupled = false;
+   
    public TomcatDeployer()
    {
    }
@@ -337,16 +349,69 @@
    public void setDeploymentClass(Class deploymentClass)
    {
       this.deploymentClass = deploymentClass;
+   }   
+   
+   /**
+    * Gets whether this object should start/stop the JBoss Web runtime
+    * during execution of its own start/stop lifecycle callbacks.
+    * 
+    * @return <code>true</code> if a call to {@link #start()} should
+    *        trigger a call to {@link #startWebServer()} and a call to
+    *        {@link #stop()} should trigger a call to {@link #stopWebServer()};
+    *        <code>false</code> if the webserver runtime lifecycle will
+    *        be separately managed.  Default is <code>false</code>.
+    */
+   public boolean isRuntimeLifecycleCoupled()
+   {
+      return runtimeLifecycleCoupled;
    }
 
    /**
+    * Sets whether this object should start/stop the JBoss Web runtime
+    * during execution of its own start/stop lifecycle callbacks.
+    * 
+    * @param coupled <code>true</code> if a call to {@link #start()} should
+    *        trigger a call to {@link #startWebServer()} and a call to
+    *        {@link #stop()} should trigger a call to {@link #stopWebServer()};
+    *        <code>false</code> if the webserver runtime lifecycle will
+    *        be separately managed. Default is <code>false</code>.
+    */
+   public void setRuntimeLifecycleCoupled(boolean coupled)
+   {
+      runtimeLifecycleCoupled = coupled;
+   }
+
+   /**
     * Start the deployer. This sets up the tomcat core.
     */
    public void start()
       throws Exception
    {
       super.start();
+      
+      // Parse shared web.xml
+      Unmarshaller unmarshaller = factory.newUnmarshaller();
+      URL webXml = this.getClass().getClassLoader().getResource("web.xml");
+      if (webXml == null)
+      {
+         webXml = this.getClass().getClassLoader().getResource("conf/web.xml");;
+      }
+      if (webXml == null)
+         throw new IllegalStateException("Unable to find shared web.xml or conf/web.xml");
+      SchemaBinding schema = JBossXBBuilder.build(Web25MetaData.class);
+      Web25MetaData confWebMD = (Web25MetaData) unmarshaller.unmarshal(webXml.toString(), schema);
+      sharedMetaData = new JBoss50WebMetaData();
+      sharedMetaData.merge(null, confWebMD);
+      
+      if (isRuntimeLifecycleCoupled())
+         startWebServer();
+   }
 
+   /**
+    * Initializes and starts the webserver runtime. 
+    */
+   public void startWebServer() throws Exception
+   {
       // Load Catalina properties
       CatalinaProperties.getProperty("");
       
@@ -412,19 +477,19 @@
       PolicyContext.registerHandler(HttpServletRequestPolicyContextHandler.WEB_REQUEST_KEY,
          handler, true);
 
-      // Parse shared web.xml
-      Unmarshaller unmarshaller = factory.newUnmarshaller();
-      URL webXml = this.getClass().getClassLoader().getResource("web.xml");
-      if (webXml == null)
-      {
-         webXml = this.getClass().getClassLoader().getResource("conf/web.xml");;
-      }
-      if (webXml == null)
-         throw new IllegalStateException("Unable to find shared web.xml or conf/web.xml");
-      SchemaBinding schema = JBossXBBuilder.build(Web25MetaData.class);
-      Web25MetaData confWebMD = (Web25MetaData) unmarshaller.unmarshal(webXml.toString(), schema);
-      sharedMetaData = new JBoss50WebMetaData();
-      sharedMetaData.merge(null, confWebMD);
+//      // Parse shared web.xml
+//      Unmarshaller unmarshaller = factory.newUnmarshaller();
+//      URL webXml = this.getClass().getClassLoader().getResource("web.xml");
+//      if (webXml == null)
+//      {
+//         webXml = this.getClass().getClassLoader().getResource("conf/web.xml");;
+//      }
+//      if (webXml == null)
+//         throw new IllegalStateException("Unable to find shared web.xml or conf/web.xml");
+//      SchemaBinding schema = JBossXBBuilder.build(Web25MetaData.class);
+//      Web25MetaData confWebMD = (Web25MetaData) unmarshaller.unmarshal(webXml.toString(), schema);
+//      sharedMetaData = new JBoss50WebMetaData();
+//      sharedMetaData.merge(null, confWebMD);
 
       // If we are hot-deployed *after* the overall server is started
       // we'll never receive Server.START_NOTIFICATION_TYPE, so check
@@ -452,6 +517,17 @@
    public void stop()
       throws Exception
    {
+      if (isRuntimeLifecycleCoupled())
+         stopWebServer();
+      
+      super.stop();
+   }
+
+   /**
+    * Stops the webserver runtime.
+    */
+   public void stopWebServer() throws Exception
+   {
       MBeanServer server = super.getServer();
       String objectNameS = catalinaDomain + ":type=server";
       ObjectName objectName = new ObjectName(objectNameS);
@@ -492,7 +568,6 @@
          ObjectName name = oi.getObjectName();
          server2.unregisterMBean(name);
       }
-      super.stop();
    }
 
    /**
@@ -657,6 +732,13 @@
       if(vf != null)
         config.setXacmlPolicyURL(vf.toURL());
       
+      // Add a dependency on the webserver itself
+      List<String> depends = metaData.getDepends();
+      if (depends == null)
+         depends = new ArrayList<String>();
+      depends.add(TomcatDeployerMBean.OBJECT_NAME.getCanonicalName());
+      metaData.setDepends(depends);     
+      
       deployment.setServer(super.getServer());
       deployment.init(config);
 
@@ -665,15 +747,15 @@
    
    public void create() throws Exception
    {
-      MBeanServer server = MBeanServerLocator.locateJBoss();
-      if (server != null)
-         server.registerMBean(this, OBJECT_NAME);
+//      MBeanServer server = MBeanServerLocator.locateJBoss();
+//      if (server != null)
+//         server.registerMBean(this, OBJECT_NAME);
    }
 
    public void destroy() throws Exception
    {
-      MBeanServer server = MBeanServerLocator.locateJBoss();
-      if (server != null)
-         server.unregisterMBean(OBJECT_NAME);
+//      MBeanServer server = MBeanServerLocator.locateJBoss();
+//      if (server != null)
+//         server.unregisterMBean(OBJECT_NAME);
    } 
 }

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapper.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapper.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapper.java	2008-01-31 18:26:00 UTC (rev 69505)
@@ -0,0 +1,246 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.web.tomcat.service.deployers;
+
+import org.jboss.security.plugins.JaasSecurityManagerServiceMBean;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * Temporary workaround to support controlling the lifecycle of the webserver 
+ * runtime portion of TomcatDeployer via a JMX service in the deploy directory.  
+ * We want it in deploy so dependencies on services in deploy can be properly 
+ * expressed. We want it as a JMX service so the ServiceBindingManager can 
+ * alter the connector ports.
+ * <p>
+ * A more long term solution involves:
+ * <ol>
+ * <li>separating out the JBossWeb runtime aspects from TomcatDeployer and 
+ * putting them in a separate class</li>
+ * <li>developing a ProfileService-based alternative to ServiceBindingManager</li>
+ * </ol>
+ * </p> 
+ *  
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class TomcatDeployerWrapper 
+    extends ServiceMBeanSupport
+    implements TomcatDeployerWrapperMBean
+{
+   private TomcatDeployer tomcatDeployer;
+   
+   
+   // Dependency inject the TomcatDeployer pojo
+   
+   public TomcatDeployer getTomcatDeployer()
+   {
+      return tomcatDeployer;
+   }
+
+   public void setTomcatDeployer(TomcatDeployer tomcatDeployer)
+   {
+      this.tomcatDeployer = tomcatDeployer;
+   }
+   
+   // In our lifecycle, we invoke the webserver lifecycle-related operations
+   // in the TomcatDeployer
+
+   @Override
+   protected void startService() throws Exception
+   {
+      if (tomcatDeployer == null)
+         throw new IllegalStateException("Must set TomcatDeployer before starting");
+      tomcatDeployer.startWebServer();
+   }
+
+   @Override
+   protected void stopService() throws Exception
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.stopWebServer();
+   }
+   
+   // Expose the TomcatDeployer MBean interface
+
+   public String getConfigFile()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getConfigFile();
+   }
+
+   public String getContextMBeanCode()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getContextMBeanCode();
+   }
+
+   public String getDomain()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getDomain();
+   }
+
+   public String[] getFilteredPackages()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getFilteredPackages();
+   }
+
+   public String getManagerClass()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getManagerClass();
+   }
+
+   public String getSessionIdAlphabet()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getSessionIdAlphabet();
+   }
+
+   public String getSubjectAttributeName()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getSubjectAttributeName();
+   }
+
+   public boolean getUseJBossWebLoader()
+   {
+      return tomcatDeployer == null ? false : tomcatDeployer.getUseJBossWebLoader();
+   }
+
+   public boolean isAllowSelfPrivilegedWebApps()
+   {
+      return tomcatDeployer == null ? false : tomcatDeployer.isAllowSelfPrivilegedWebApps();
+   }
+
+   public void setAllowSelfPrivilegedWebApps(boolean flag)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setAllowSelfPrivilegedWebApps(flag);
+   }
+
+   public void setConfigFile(String configFile)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setConfigFile(configFile);
+   }
+
+   public void setContextMBeanCode(String className)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setContextMBeanCode(className);
+   }
+
+   public void setDomain(String domainName)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setDomain(domainName);
+   }
+
+   public void setFilteredPackages(String[] pkgs)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setFilteredPackages(pkgs);
+   }
+
+   public void setManagerClass(String managerClass)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setManagerClass(managerClass);
+   }
+
+   public void setSecurityManagerService(JaasSecurityManagerServiceMBean mgr)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setSecurityManagerService(mgr);
+   }
+
+   public void setSessionIdAlphabet(String sessionIdAlphabet)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setSessionIdAlphabet(sessionIdAlphabet);
+   }
+
+   public void setSubjectAttributeName(String name)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setSubjectAttributeName(name);
+   }
+
+   public void setUseJBossWebLoader(boolean flag)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setUseJBossWebLoader(flag);
+   }
+
+   public void startConnectors() throws Exception
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.startConnectors();
+   }
+
+   public void stopConnectors() throws Exception
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.stopConnectors();
+   }
+
+   public String getDefaultSecurityDomain()
+   {
+      return tomcatDeployer == null ? null : tomcatDeployer.getDefaultSecurityDomain();
+   }
+
+   public boolean getJava2ClassLoadingCompliance()
+   {
+      return tomcatDeployer == null ? false : tomcatDeployer.getJava2ClassLoadingCompliance();
+   }
+
+   public boolean getLenientEjbLink()
+   {
+      return tomcatDeployer == null ? false : tomcatDeployer.getLenientEjbLink();
+   }
+
+   public boolean getUnpackWars()
+   {
+      return tomcatDeployer == null ? false : tomcatDeployer.getUnpackWars();
+   }
+
+   public void setDefaultSecurityDomain(String defaultSecurityDomain)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setDefaultSecurityDomain(defaultSecurityDomain);
+   }
+
+   public void setJava2ClassLoadingCompliance(boolean flag)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setJava2ClassLoadingCompliance(flag);
+   }
+
+   public void setLenientEjbLink(boolean flag)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setLenientEjbLink(flag);
+   }
+
+   public void setUnpackWars(boolean flag)
+   {
+      if (tomcatDeployer != null)
+         tomcatDeployer.setUnpackWars(flag);
+   }
+
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapperMBean.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapperMBean.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployerWrapperMBean.java	2008-01-31 18:26:00 UTC (rev 69505)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.web.tomcat.service.deployers;
+
+import org.jboss.system.ServiceMBean;
+
+/**
+ * StandardMBean interface for the TomcatDeployerWrapper.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TomcatDeployerWrapperMBean extends TomcatDeployerMBean, ServiceMBean
+{
+   public void setTomcatDeployer(TomcatDeployer tomcatDeployer);
+}

Added: trunk/tomcat/src/resources/jboss-web-service.xml
===================================================================
--- trunk/tomcat/src/resources/jboss-web-service.xml	                        (rev 0)
+++ trunk/tomcat/src/resources/jboss-web-service.xml	2008-01-31 18:26:00 UTC (rev 69505)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id: jboss-service-all.xml 60489 2007-02-12 08:22:28Z scott.stark at jboss.org $ -->
+
+<server> 
+   <!-- 
+       JBoss Web Service
+       
+       This is a wrapper around the WarDeployer bean deployed in
+       deployers/jboss-web.deployer/war-deployers-beans.xml.  This wrapper
+       controls the lifecycle of the JBoss Web runtime exposed by the
+       WarDeployer bean.
+   -->   
+   <mbean code="org.jboss.web.tomcat.service.deployers.TomcatDeployerWrapper"
+      name="jboss.web:service=WebServer">
+      
+    <!-- Inject the TomcatDeployer -->
+    <attribute name="TomcatDeployer">
+       <inject bean="WarDeployer"/>
+    </attribute> 
+    
+    <!-- 
+       Do not configure other JMX attributes via this file.
+       Use the WarDeployer bean in deployers/jboss-web.deployer/war-deployers-beans.xml
+    -->
+      
+   </mbean>
+</server>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list