cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r345248 - in /cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal: deployment/ deployment/impl/ pluto/om/
Date Thu, 17 Nov 2005 14:23:20 GMT
Author: cziegeler
Date: Thu Nov 17 06:23:10 2005
New Revision: 345248

URL: http://svn.apache.org/viewcvs?rev=345248&view=rev
Log:
Fix local portlet handling and start implementing undeployment

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
Thu Nov 17 06:23:10 2005
@@ -36,6 +36,12 @@
     throws DeploymentException;
 
     /**
+     * Undeploy an artifact.
+     */
+    DeploymentStatus undeploy(String uri)
+    throws DeploymentException;
+
+    /**
      * Scan for new artifacts to deploy/old artifacts to undeploy.
      * For each artifact found, a {@link  DeploymentEvent} is fired.
      */

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
Thu Nov 17 06:23:10 2005
@@ -33,9 +33,9 @@
     extends DeploymentStatus, Event {
 
     /**
-	 * Get the corresponding deployment object.
+	 * Get the corresponding uri.
 	 */
-	DeploymentObject getDeploymentObject();
+	String getDeploymentUri();
 
 	/**
 	 * Sets the status of this event. @see getEvent()

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
Thu Nov 17 06:23:10 2005
@@ -20,6 +20,8 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
 
 import org.apache.avalon.framework.activity.Startable;
@@ -34,10 +36,9 @@
 import org.apache.cocoon.portal.deployment.DeploymentManager;
 import org.apache.cocoon.portal.deployment.DeploymentObject;
 import org.apache.cocoon.portal.deployment.DeploymentStatus;
+import org.apache.cocoon.portal.deployment.UndeploymentEvent;
 import org.apache.cocoon.portal.impl.AbstractComponent;
-import org.apache.excalibur.source.ModifiableSource;
 import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.TraversableSource;
 
@@ -64,21 +65,30 @@
     /** Are we already started? */
     protected boolean started = false;
 
-    /** The threadpool name to be used for daemon thread */
+    /** The threadpool name to be used for daemon thread. */
     protected String threadPoolName = "daemon";
 
     /** Do we enable hot deployment? */
     protected boolean hotDeployment = true;
 
-    protected long              scanningDelay = 60 * 1000;
-    protected String[]          deploymentUris;
-    protected final HashMap     ignoredFiles;
+    /** The delay between each scan task. Default is one minute. */
+    protected long scanningDelay = 60 * 1000;
+
+    /** All locations to look for deployable artifacts. */
+    protected String[] deploymentUris;
+
+    /** These files have been ignored during the last scan. */
+    protected final Map failedArtifacts;
+
+    /** Already deployed artifacts. */
+    protected final List deployedArtifacts;
 
     /**
      * Default Constructor.
      */
     public DefaultDeploymentManager() {
-        this.ignoredFiles = new HashMap();
+        this.failedArtifacts = new HashMap();
+        this.deployedArtifacts = new ArrayList();
     }
 
     /**
@@ -117,6 +127,9 @@
         this.threadPoolName = parameters.getParameter("thread-pool-name", this.threadPoolName);
     }
 
+    /**
+     * Test the provided locations.
+     */
     protected void testSources()
     throws IOException {
         if ( this.getLogger().isInfoEnabled() ) {
@@ -154,23 +167,22 @@
             this.getLogger().info("Starting auto deployment service: " + this.getClass().getName());
             this.getLogger().info("Hot-Deployment: " + this.hotDeployment);
             this.getLogger().info("Deployment scanning delay: " + this.scanningDelay);
-            if (this.scanningDelay < 0) {
+            if (this.scanningDelay < 1) {
                 this.getLogger().info("Scanning delay set to " + this.scanningDelay
                                     + " has disabled automatic scanning of deployment directories.");
             }
         }
 
-        if (this.scanningDelay > -1) {
+        if (this.scanningDelay > 0) {
             this.testSources();
         }
-
     }
 
     /**
      * @see org.apache.avalon.framework.activity.Startable#start()
      */
     public void start() throws Exception {
-        if ( this.scanningDelay > -1 ) {
+        if ( this.scanningDelay > 0 ) {
             if ( this.hotDeployment ) {
                 this.started = true;
                 RunnableManager runnableManager = null;
@@ -224,16 +236,30 @@
     }
 
     /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentManager#undeploy(String)
+     */
+    public synchronized DeploymentStatus undeploy(String uri)
+    throws DeploymentException {
+        UndeploymentEvent event = null;
+        event = new UndeploymentEventImpl(uri);
+        this.portalService.getComponentManager().getEventManager().send(event);
+
+        return event;
+    }
+
+    /**
      * @see org.apache.cocoon.portal.deployment.DeploymentManager#scan()
      */
-    public void scan() {
+    public synchronized void scan() {
         Collection deploymentArtifacts = this.getAllDeploymentArtifactSources();
-        final Iterator i = deploymentArtifacts.iterator();
+        Iterator i = deploymentArtifacts.iterator();
+        final List newlyProcessedArtifacts = new ArrayList();
         try {
             while ( i.hasNext() ) {
                 // check for new deployment
-                Source current = (Source)i.next();
-                if (!ignoreSource(current) ) {
+                final Source current = (Source)i.next();
+                newlyProcessedArtifacts.add(current.getURI());
+                if (!ignoreSource(current) && !this.deployedArtifacts.contains(current.getURI())
) {
                     DeploymentStatus status = null;
                     Exception de = null;
                     try {
@@ -247,13 +273,7 @@
                         if ( this.getLogger().isInfoEnabled() ) {
                             this.getLogger().info("Deployed source " + current.getURI());
                         }
-                        /*if ( current instanceof ModifiableSource ) {
-                            try {
-                                ((ModifiableSource)current).delete();
-                            } catch (SourceException se) {
-                                this.getLogger().warn("Exception during deletion of deployed
artifact " + current.getURI());
-                            }
-                        }*/
+                        this.deployedArtifacts.add(current.getURI());
                     } else {
                         if ( de != null ) {
                             this.getLogger().error("Failure deploying " + current.getURI(),
de);                            
@@ -263,7 +283,7 @@
                         } else {
                             this.getLogger().error("Failure deploying " + current.getURI());
                         }
-                        this.ignoredFiles.put(current.getURI(), new Long(current.getLastModified()));
+                        this.failedArtifacts.put(current.getURI(), new Long(current.getLastModified()));
                     }
                 }
             }
@@ -271,13 +291,44 @@
             // release everything
             this.releaseSources(deploymentArtifacts);
         }
+        // now check for undeployment
+        i = this.deployedArtifacts.iterator();
+        while ( i.hasNext() ) {
+            final String uri = (String)i.next();
+            if ( !newlyProcessedArtifacts.contains(uri) ) {
+                // remove this artifact from the deployed list, even if undeployment fails
+                i.remove();
+                DeploymentStatus status = null;
+                Exception de = null;
+                try {
+                    status = this.undeploy(uri);
+                } catch (Exception e) {                    
+                    de = e;
+                }
+                if ( status != null
+                        && status.getStatus() == DeploymentStatus.STATUS_OKAY ) {
+                    if ( this.getLogger().isInfoEnabled() ) {
+                        this.getLogger().info("Undeployed source " + uri);
+                    }
+                } else {
+                    if ( de != null ) {
+                        this.getLogger().error("Failure undeploying " + uri, de);       
                    
+                    } else if (status == null
+                               || status.getStatus() == DeploymentStatus.STATUS_EVAL) {
+                        this.getLogger().warn("Unrecognized deployed source: " + uri);
+                    } else {
+                        this.getLogger().error("Failure deploying " + uri);
+                    }
+                }
+            }
+        }
     }
 
     protected boolean ignoreSource(Source source) {
-        Long previousModified = (Long) ignoredFiles.get(source.getURI());
+        Long previousModified = (Long)this.failedArtifacts.get(source.getURI());
         if (previousModified != null) {
             if (previousModified.longValue() != source.getLastModified()) {
-                ignoredFiles.remove(source.getURI());
+                this.failedArtifacts.remove(source.getURI());
             } else {
                 return true;
             }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
Thu Nov 17 06:23:10 2005
@@ -15,18 +15,17 @@
  */
 package org.apache.cocoon.portal.deployment.impl;
 
-import org.apache.cocoon.portal.deployment.DeploymentEvent;
-import org.apache.cocoon.portal.deployment.DeploymentObject;
+import org.apache.cocoon.portal.deployment.UndeploymentEvent;
 
 /**
  * Default implementation of the undeployment event.
  *
  * @version $Id$
  */
-public class UndeploymentEventImpl implements DeploymentEvent {
+public class UndeploymentEventImpl implements UndeploymentEvent {
 
-    /** The corresponding deployment object. */
-    protected DeploymentObject deploymentObject;
+    /** The corresponding uri. */
+    protected String uri;
 
     /** The deployment status. */
     protected int status = STATUS_EVAL;
@@ -34,15 +33,15 @@
     /**
      * 
      */
-    public UndeploymentEventImpl(DeploymentObject depObject) {
-        this.deploymentObject = depObject;
+    public UndeploymentEventImpl(String uri) {
+        this.uri = uri;
     }
     
     /**
-     * @see org.apache.cocoon.portal.deployment.DeploymentEvent#getDeploymentObject()
+     * @see org.apache.cocoon.portal.deployment.UndeploymentEvent#getDeploymentUri()
      */
-    public DeploymentObject getDeploymentObject() {        
-        return this.deploymentObject;
+    public String getDeploymentUri() {
+        return this.uri;
     }
 
     /**

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
Thu Nov 17 06:23:10 2005
@@ -100,6 +100,9 @@
     /** The castor mapping for the web.xml. */
     protected Mapping mappingWebXml = new Mapping();
 
+    /** Should we scan the webapps directory on startup? */
+    protected boolean scanOnStartup = true;
+
     /**
      * Default constructor.
      */
@@ -123,6 +126,7 @@
         this.webAppDir = params.getParameter("webapp-directory", null);
         this.localAppDir = params.getParameter("localapp-directory", this.localAppDir);
         this.stripLoggers = params.getParameterAsBoolean("strip-loggers", this.stripLoggers);
+        this.scanOnStartup = params.getParameterAsBoolean("scan-on-startup", this.scanOnStartup);
     }
 
     /**
@@ -147,6 +151,7 @@
             if ( this.webAppDir != null ) {
                 this.getLogger().info("Web application directory: " + this.webAppDir);
             }
+            this.getLogger().info("Scan on startup: " + this.scanOnStartup);
         }
         super.initialize();
 
@@ -163,7 +168,7 @@
             // END PATCH for IBM WebSphere
             int lastIndex = baseWMDir.lastIndexOf(File.separatorChar);
             this.contextName = baseWMDir.substring(lastIndex + 1);
-            baseWMDir = baseWMDir.substring(0, lastIndex + 1);
+            baseWMDir = baseWMDir.substring(0, lastIndex);
             if (this.getLogger().isDebugEnabled()) {
                 this.getLogger().debug("servletContext.getRealPath('') =" + servletContext.getRealPath(""));
                 this.getLogger().debug("baseWMDir = " + baseWMDir);
@@ -222,15 +227,17 @@
         } 
 
         // now load existing webapps/portlets
-        if ( this.webAppDir == null ) {
-            if (this.getLogger().isWarnEnabled()) {
-                this.getLogger().warn("Only local portlets are supported when deployed as
a war " 
-                                    + "and 'webapp-directory' is not configured.");
+        if ( this.scanOnStartup ) {
+            if ( this.webAppDir == null ) {
+                if (this.getLogger().isWarnEnabled()) {
+                    this.getLogger().warn("Only local portlets are supported when deployed
as a war " 
+                                        + "and 'webapp-directory' is not configured.");
+                }
+                this.contextName = "local";
+                this.loadLocal(servletConfig);
+            } else {
+                this.scanWebapps();
             }
-            this.contextName = "local";
-            this.loadLocal();
-        } else {
-            this.load(this.webAppDir);
         }
 
         ((PortletApplicationEntityListCtrl)this.portletApplicationEntities).add("cocoon");
@@ -250,18 +257,18 @@
         return (PortletDefinition)portletsKeyObjectId.get(id);
     }
 
-    protected void load(String baseWMDir) 
+    protected void scanWebapps() 
     throws Exception {
-        File f = new File(baseWMDir);
+        File f = new File(this.webAppDir);
         String[] entries = f.list();
         List entryList = Arrays.asList(entries);
         for (int i=0; i<entries.length; i++) {
-            File entry = new File(baseWMDir+entries[i]);
+            File entry = new File(f, entries[i]);
             if ( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug("Searching file: " + entry);
             }
             if (entry.isDirectory()) {
-                loadWebApp(baseWMDir, entries[i]);
+                loadWebApp(f.getAbsolutePath(), entries[i]);
             } else if (entry.isFile()) {
                 String name = entry.getName();
                 int index = name.lastIndexOf(".war");
@@ -275,16 +282,9 @@
         }
     }
 
-    private void loadLocal()
+    protected void loadLocal(ServletConfig config)
     throws Exception {
-        ServletConfig config = (ServletConfig)this.context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
-        if (config == null) {
-            if (this.getLogger().isDebugEnabled()) {
-                this.getLogger().debug("Unable to locate servlet config.");
-            }
-            return;
-        }
-        ServletContext servletContext = config.getServletContext();
+        final ServletContext servletContext = config.getServletContext();
         URL url = servletContext.getResource("/" + PORTLET_XML);
         if (url != null) {
             InputSource portletSource = new InputSource(url.openStream());
@@ -305,7 +305,7 @@
         }
     }
 
-    private void loadWar(File warFile, String webModule)
+    protected void loadWar(File warFile, String webModule)
     throws Exception {
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("Searching war " + warFile.getName());
@@ -338,7 +338,7 @@
 
     private void loadWebApp(String baseDir, String webModule)
     throws Exception {
-        String directory = baseDir + webModule + File.separatorChar + "WEB-INF" + File.separatorChar;
+        String directory = baseDir + File.separatorChar + webModule + File.separatorChar
+ "WEB-INF" + File.separatorChar;
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("Searching in directory: " + directory);
         }



Mime
View raw message