cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r344990 - in /cocoon/blocks: portal-sample/trunk/samples/conf/ portal/trunk/ portal/trunk/java/org/apache/cocoon/portal/ portal/trunk/java/org/apache/cocoon/portal/deployment/ portal/trunk/java/org/apache/cocoon/portal/deployment/impl/
Date Wed, 16 Nov 2005 12:29:22 GMT
Author: cziegeler
Date: Wed Nov 16 04:29:06 2005
New Revision: 344990

URL: http://svn.apache.org/viewcvs?rev=344990&view=rev
Log:
Add deployment infrastructure

Added:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
  (with props)
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
  (with props)
Modified:
    cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/portal.roles
    cocoon/blocks/portal/trunk/status.xml

Modified: cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf?rev=344990&r1=344989&r2=344990&view=diff
==============================================================================
--- cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf (original)
+++ cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf Wed Nov 16 04:29:06
2005
@@ -161,6 +161,18 @@
     <parameter name="defaultSecurePort" value="443"/>
   </portal-link-service>
 
+  <!--+
+      | Deployment Manager.
+      +-->
+  <portal-deployment-manager>
+    <!-- Scan the provided directories every minute: -->
+    <scanning-delay>60000</scanning-delay>
+    <!-- Scan the following locations (comma-separated): -->
+    <deployment-sources>conf/deply</deployment-sources>
+    <!-- Turn on/off hot deployment: -->
+    <hot-deployment>true</hot-deployment>
+  </portal-deployment-manager>
+
   <!-- Renderer configuration -->
   <component class="org.apache.cocoon.core.container.DefaultServiceSelector"
              role="org.apache.cocoon.portal.layout.renderer.RendererSelector">

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+import org.apache.cocoon.portal.event.Event;
+import org.apache.cocoon.portal.event.Receiver;
+
+/**
+ * A deployment event is fired when a new artifact is found for deployment.
+ * A {@link Receiver} for this event should first check the status before performing
+ * an action. If the receiver could deploy the artifact, it should set the status
+ * accordingly. If the receiver is not responsible for deploying this type of artifact
+ * or if the artifact has already been deployed, the receiver should just ignore the
+ * event. If an error occurs during deployment the status should be updated by the
+ * receiver as well.
+ *
+ * @version $Id$
+ */
+public interface DeploymentEvent
+    extends DeploymentStatus, Event {
+
+    /**
+	 * Get the corresponding deployment object.
+	 */
+	DeploymentObject getDeploymentObject();
+
+	/**
+	 * Sets the status of this event. @see getEvent()
+	 */
+	void setStatus(int status);
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentEvent.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+import org.apache.cocoon.portal.PortalException;
+
+/**
+ * Base class for all deployment exceptions.
+ *
+ * @version $Id$
+ */
+public class DeploymentException extends PortalException {
+
+    public DeploymentException() {
+        super();
+    }
+
+    public DeploymentException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DeploymentException(String message) {
+        super(message);
+    }
+
+    public DeploymentException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+import org.apache.excalibur.source.Source;
+
+
+/**
+ * This component scans for artifacts to be deployed and fires {@link DeploymentEvent}s
+ * to deploy/undeploy an artifact.
+ *
+ * @version $Id$
+ */
+public interface DeploymentManager {
+
+    /** The role of this component. */
+    String ROLE = DeploymentManager.class.getName();
+
+    /**
+     * Deploy a new artifact.
+     */
+    DeploymentStatus deploy(Source source)
+    throws DeploymentException;
+
+    /**
+     * Scan for new artifacts to deploy/old artifacts to undeploy.
+     * For each artifact found, a {@link  DeploymentEvent} is fired.
+     */
+    void scan();
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.excalibur.source.Source;
+
+/**
+ * This object describes an artifact to be deployed.
+ *
+ * @version $Id$
+ */
+public interface DeploymentObject {
+
+	/**
+	 * Closes any resources that may have been opend during the use
+	 * of this object.
+     * Usually this method is called by the {@link DeploymentManager}.
+	 * @throws IOException
+	 */
+	void close() throws IOException;
+	
+	/**
+	 * Retreives the configuration for this deployment artifact
+	 * based on the artifact-relative configuration path.
+	 * @param configPath artifact-relative path to the confiuration file
+	 * @return Configuration of this artificat or <code>null</code> if the 
+	 * configuration is not present in the artifact.
+	 * @throws IOException error opening the configuration
+	 */
+	InputStream getConfiguration(String configPath) throws IOException;
+
+	/**
+     * Returns the name of the artifact.
+	 */
+	String getName();
+	
+	/**
+	 * The corresponding source object. 
+	 */
+	Source getSource();
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentObject.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+/**
+ * Status of a deployment or undeployment action.
+ *
+ * @version $Id$
+ */
+public interface DeploymentStatus {
+
+    /** The operation could be performed successfully. */
+    int STATUS_OKAY   = 1;
+    /** The operation hasn't been performed yet. */
+    int STATUS_EVAL   = 0;
+    /** An error occured during the operation. */
+    int STATUS_FAILED = -1;
+
+    /**
+     * Return the status of the operation (deployment or undeployment)
+     */
+    int getStatus();
+}
\ No newline at end of file

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/DeploymentStatus.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment;
+
+import org.apache.cocoon.portal.event.Event;
+import org.apache.cocoon.portal.event.Receiver;
+
+/**
+ * An undeployment event is fired when a deployed artifact should be undeployed.
+ * A {@link Receiver} for this event should first check the status before performing
+ * an action. If the receiver could undeploy the artifact, it should set the status
+ * accordingly. If the receiver is not responsible for undeploying this type of artifact
+ * or if the artifact has already been undeployed, the receiver should just ignore the
+ * event. If an error occurs during undeployment the status should be updated by the
+ * receiver as well.
+ *
+ * @version $Id$
+ */
+public interface UndeploymentEvent
+    extends DeploymentStatus, Event {
+
+    /**
+	 * Get the corresponding deployment object.
+	 */
+	DeploymentObject getDeploymentObject();
+
+	/**
+	 * Sets the status of this event. @see getEvent()
+	 */
+	void setStatus(int status);
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/UndeploymentEvent.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,342 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.components.thread.RunnableManager;
+import org.apache.cocoon.portal.deployment.DeploymentEvent;
+import org.apache.cocoon.portal.deployment.DeploymentException;
+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.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;
+
+/**
+ * This is the default deployment manager scanning a directory for artifacts to deploy.
+ *
+ * TODO - Undeployment is not covered yet
+ * TODO - Handling of ignored files is not really covered yet
+ * TODO - Handling of sources other than files is not implemented yet.
+ *
+ * @see DeploymentManager 
+ * @version $Id$
+ */
+public class DefaultDeploymentManager
+    extends AbstractComponent
+    implements DeploymentManager, Parameterizable, Startable, Runnable {
+
+    /** Wait ten seconds before scanning. */
+    protected static final int STARTUP_DELAY = 10 * 1000;
+
+    /** Source resolver. */
+    protected SourceResolver resolver;
+
+    /** Are we already started? */
+    protected boolean started = false;
+
+    /** 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;
+
+    /**
+     * Default Constructor.
+     */
+    public DefaultDeploymentManager() {
+        this.ignoredFiles = new HashMap();
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.impl.AbstractComponent#dispose()
+     */
+    public void dispose() {
+        if ( this.manager != null ) {
+            this.manager.release(this.resolver);
+            this.resolver = null;
+        }
+        super.dispose();
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.impl.AbstractComponent#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        this.resolver = (SourceResolver)this.manager.lookup(SourceResolver.ROLE);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void parameterize(Parameters parameters) throws ParameterException {
+        this.scanningDelay = parameters.getParameterAsLong("scanning-delay", this.scanningDelay);
+        this.hotDeployment = parameters.getParameterAsBoolean("hot-deployment", this.hotDeployment);
+        final String deploymentDirs = parameters.getParameter("deployment-sources", "conf/deploy");
+        final StringTokenizer st = new StringTokenizer(deploymentDirs, ",");
+        this.deploymentUris = new String[st.countTokens()];
+        int i = 0;
+        while (st.hasMoreTokens()) {
+            this.deploymentUris[i] = st.nextToken();
+            i++;
+        }
+        this.threadPoolName = parameters.getParameter("thread-pool-name", this.threadPoolName);
+    }
+
+    protected void testSources()
+    throws IOException {
+        if ( this.getLogger().isInfoEnabled() ) {
+            this.getLogger().info("Testing configured deployment sources.");
+        }
+        for (int i = 0; i < this.deploymentUris.length; i++) {
+            Source source = null;
+            try {
+                source = this.resolver.resolveURI(this.deploymentUris[i]);
+                if (!source.exists()) {
+                    this.getLogger().warn("Deployment source '" + source.getURI() + 
+                                          "' does not exist. It will be ignored for deployment.");
+                    this.deploymentUris[i] = null;
+                } else if ( !(source instanceof TraversableSource) ) {
+                    this.getLogger().warn("Deployment source '" + source.getURI() +
+                                          "' is not a directory. It will be ignored for deployment.");
+                    this.deploymentUris[i] = null;
+                }
+            } finally {
+                this.resolver.release(source);
+            }
+        }        
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.impl.AbstractComponent#initialize()
+     */
+    public void initialize()
+    throws Exception {
+        super.initialize();
+        if ( this.getLogger().isInfoEnabled() ) {
+            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) {
+                this.getLogger().info("Scanning delay set to " + this.scanningDelay
+                                    + " has disabled automatic scanning of deployment directories.");
+            }
+        }
+
+        if (this.scanningDelay > -1) {
+            this.testSources();
+        }
+
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Startable#start()
+     */
+    public void start() throws Exception {
+        if ( this.scanningDelay > -1 ) {
+            if ( this.hotDeployment ) {
+                this.started = true;
+                RunnableManager runnableManager = null;
+                try {
+                    runnableManager = (RunnableManager)this.manager.lookup(RunnableManager.ROLE);
+                    runnableManager.execute(this.threadPoolName, this, STARTUP_DELAY);
+                } finally {
+                    this.manager.release(runnableManager);
+                }
+                if ( this.getLogger().isInfoEnabled() ) {
+                    this.getLogger().info("Deployment scanner successfuly started!");
+                }
+            } else {
+                Thread.sleep(STARTUP_DELAY);
+                this.scan();                
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Startable#stop()
+     */
+    public void stop() throws Exception {
+        if ( this.started ) {
+            if ( this.getLogger().isInfoEnabled() ) {
+                this.getLogger().info("Deployment scanner stopped.");
+            }
+            this.started = false;
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentManager#deploy(org.apache.excalibur.source.Source)
+     */
+    public synchronized DeploymentStatus deploy(Source source)
+    throws DeploymentException {
+        DeploymentObject deploymentObject = new DefaultDeploymentObject(source);
+        DeploymentEvent event = null;
+        try {
+            event = new DeploymentEventImpl(deploymentObject);
+            this.portalService.getComponentManager().getEventManager().send(event);
+        } finally {
+            if ( deploymentObject != null ) {
+                try {
+                    deploymentObject.close();
+                } catch (IOException e) {                    
+                }
+            }
+        }
+        return event;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentManager#scan()
+     */
+    public void scan() {
+        Collection deploymentArtifacts = this.getAllDeploymentArtifactSources();
+        final Iterator i = deploymentArtifacts.iterator();
+        try {
+            while ( i.hasNext() ) {
+                // check for new deployment
+                Source current = (Source)i.next();
+                if (!ignoreSource(current) ) {
+                    DeploymentStatus status = null;
+                    Exception de = null;
+                    try {
+                        status = this.deploy(current);
+                    } catch (Exception e) {                    
+                        de = e;
+                    }
+                    
+                    if ( status != null
+                         && status.getStatus() == DeploymentStatus.STATUS_OKAY )
{
+                        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());
+                            }
+                        }
+                    } else {
+                        if ( de != null ) {
+                            this.getLogger().error("Failure deploying " + current.getURI(),
de);                            
+                        } else if (status == null
+                                   || status.getStatus() == DeploymentStatus.STATUS_EVAL)
{
+                            this.getLogger().warn("Unrecognized source: " + current.getURI());
+                        } else {
+                            this.getLogger().error("Failure deploying " + current.getURI());
+                        }
+                        this.ignoredFiles.put(current.getURI(), new Long(current.getLastModified()));
+                    }
+                }
+            }
+        } finally {
+            // release everything
+            this.releaseSources(deploymentArtifacts);
+        }
+    }
+
+    protected boolean ignoreSource(Source source) {
+        Long previousModified = (Long) ignoredFiles.get(source.getURI());
+        if (previousModified != null) {
+            if (previousModified.longValue() != source.getLastModified()) {
+                ignoredFiles.remove(source.getURI());
+            } else {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * This method scans all deployment sources and returns a list of all
+     * found artifacts. 
+     */
+    protected Collection getAllDeploymentArtifactSources() {
+        final ArrayList sourceList = new ArrayList();
+        boolean release = true;
+        try {
+            for (int i = 0; i < this.deploymentUris.length; i++) {
+                Source source = null;
+                try {
+                    if ( this.deploymentUris[i] != null ) {
+                        source = this.resolver.resolveURI(this.deploymentUris[i]);
+                        if ( source.exists() && source instanceof TraversableSource
) {
+                            final TraversableSource ts = (TraversableSource)source;
+                            sourceList.addAll(ts.getChildren());
+                        }
+                    }
+                } catch (IOException ioe) {
+                    this.getLogger().warn("Exception during scanning of " + this.deploymentUris[i],
ioe);
+                } finally {
+                    this.resolver.release(source);
+                }
+            }
+            release = false;
+        } finally {
+            // release all sources in case of an error
+            if ( release ) {
+                this.releaseSources(sourceList);
+            }
+        }
+
+        return sourceList;
+    }
+
+    protected void releaseSources(Collection c) {
+        final Iterator i = c.iterator();
+        while ( i.hasNext() ) {
+            final Source current = (Source)i.next();
+            this.resolver.release(current);
+        }
+        c.clear();
+    }
+
+    /**
+     * @see java.lang.Runnable#run()
+     */
+    public void run() {
+       while (this.started) {
+            this.scan();
+            try {
+                Thread.sleep(this.scanningDelay);
+            } catch (InterruptedException e) {
+                // ignore
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.cocoon.portal.deployment.DeploymentObject;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceUtil;
+
+/**
+ * Default implementation of a {@link org.apache.cocoon.portal.deployment.DeploymentObject}.
+ *
+ * @version $Id$
+ */
+public class DefaultDeploymentObject implements DeploymentObject {
+
+    /** The deployment artifact. */
+    protected Source deploymentObject;
+
+    protected ZipFile zipFile;
+
+    /**
+     * @throws SourceNotDeployableException
+     */
+    public DefaultDeploymentObject(Source deploymentObject)
+    throws SourceNotDeployableException {
+        if ( !verifyExtension(deploymentObject)) {
+            throw new SourceNotDeployableException("Artifact '" + deploymentObject.getURI()
+                    + " is not supported by the default deployment object.");
+        }
+        this.deploymentObject = deploymentObject;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentObject#close()
+     */
+    public void close() throws IOException {
+        if (zipFile != null) {
+            zipFile.close();
+            zipFile = null;
+        }
+        this.deploymentObject = null;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentObject#getConfiguration(java.lang.String)
+     */
+    public InputStream getConfiguration(String configPath)
+    throws IOException {
+        ZipFile zipFile = this.getZipFile();
+        ZipEntry entry = zipFile.getEntry(configPath);
+        if (entry != null) {
+            return zipFile.getInputStream(entry);
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentObject#getName()
+     */
+    public String getName() {
+        final String uri = this.deploymentObject.getURI();
+        int pos = uri.lastIndexOf('/');
+        return uri.substring(pos+1);
+    }
+
+    /**
+     * Get a zip file for the artifact.
+     * @throws IOException
+     */
+    protected ZipFile getZipFile() throws IOException {
+        if (this.zipFile == null) {
+            File file = SourceUtil.getFile(this.deploymentObject);
+            if ( file == null ) {
+                throw new IOException("Handling of sources of type '" + this.deploymentObject.getClass()
+ "' is currently not supported.");
+            }
+            this.zipFile = new ZipFile(file);
+        }
+        return this.zipFile;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentObject#getSource()
+     */
+    public Source getSource() {
+        return this.deploymentObject;
+    }
+
+    /**
+     * Test if the extension of the source is either "war", "jar" or "zip".
+     */
+    protected boolean verifyExtension(Source source) {
+        final String uri = source.getURI();
+        int dot = uri.lastIndexOf('.');
+        if (dot != -1) {
+            final String ext = uri.substring(dot);
+            return ext.equals(".war") || ext.equals(".jar") || ext.equals(".zip");
+        } else {
+            return false;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DefaultDeploymentObject.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment.impl;
+
+import org.apache.cocoon.portal.deployment.DeploymentEvent;
+import org.apache.cocoon.portal.deployment.DeploymentObject;
+
+/**
+ * Default implementation of the deployment event.
+ *
+ * @version $Id$
+ */
+public class DeploymentEventImpl implements DeploymentEvent {
+
+    /** The corresponding deployment object. */
+    protected DeploymentObject deploymentObject;
+
+    /** The deployment status. */
+    protected int status = STATUS_EVAL;
+
+    /**
+     * 
+     */
+    public DeploymentEventImpl(DeploymentObject depObject) {
+        this.deploymentObject = depObject;
+    }
+    
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentEvent#getDeploymentObject()
+     */
+    public DeploymentObject getDeploymentObject() {        
+        return this.deploymentObject;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentStatus#getStatus()
+     */
+    public int getStatus() {
+        return this.status;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentEvent#setStatus(int)
+     */
+    public void setStatus(int i) {
+        this.status = i;
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/DeploymentEventImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java?rev=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment.impl;
+
+import org.apache.cocoon.portal.deployment.DeploymentException;
+
+/**
+ * This exception is thrown if the artifact is of an unknown type or format.
+ *
+ * @version $Id$
+ */
+public class SourceNotDeployableException extends DeploymentException {
+
+    public SourceNotDeployableException() {
+        super();
+    }
+
+    public SourceNotDeployableException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public SourceNotDeployableException(String message) {
+        super(message);
+    }
+
+    public SourceNotDeployableException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/SourceNotDeployableException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=344990&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
(added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
Wed Nov 16 04:29:06 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.deployment.impl;
+
+import org.apache.cocoon.portal.deployment.DeploymentEvent;
+import org.apache.cocoon.portal.deployment.DeploymentObject;
+
+/**
+ * Default implementation of the undeployment event.
+ *
+ * @version $Id$
+ */
+public class UndeploymentEventImpl implements DeploymentEvent {
+
+    /** The corresponding deployment object. */
+    protected DeploymentObject deploymentObject;
+
+    /** The deployment status. */
+    protected int status = STATUS_EVAL;
+
+    /**
+     * 
+     */
+    public UndeploymentEventImpl(DeploymentObject depObject) {
+        this.deploymentObject = depObject;
+    }
+    
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentEvent#getDeploymentObject()
+     */
+    public DeploymentObject getDeploymentObject() {        
+        return this.deploymentObject;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentStatus#getStatus()
+     */
+    public int getStatus() {
+        return this.status;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.deployment.DeploymentEvent#setStatus(int)
+     */
+    public void setStatus(int i) {
+        this.status = i;
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/deployment/impl/UndeploymentEventImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/portal.roles
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/portal.roles?rev=344990&r1=344989&r2=344990&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/portal.roles (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/portal.roles Wed Nov 16 04:29:06
2005
@@ -242,4 +242,11 @@
     <role name="org.apache.cocoon.portal.profile.ProfileManager"
           shorthand="portal-profile-manager"/>
 
+  <!--+
+      | Deployment Manager
+      |
+      +-->
+    <role name="org.apache.cocoon.portal.deployment.DeploymentManager"
+          shorthand="portal-deployment-manager"
+          default-class="org.apache.cocoon.portal.deployment.impl.DefaultDeploymentManager"/>
 </role-list>

Modified: cocoon/blocks/portal/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/status.xml?rev=344990&r1=344989&r2=344990&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/status.xml (original)
+++ cocoon/blocks/portal/trunk/status.xml Wed Nov 16 04:29:06 2005
@@ -65,6 +65,9 @@
  <!-- The following list contains the changes since the latest 2.1.x version. -->
  <changes>
   <release version="@version@" date="@date@">
+    <action dev="CZ" type="add">
+      Add deployment infrastructure.
+    </action>
     <action dev="CZ" type="add" fixes-bug="COCOON-1674">
       Improved user support for portlets: user name, principal and role are "forwarded"
       from the authentication mechanism to the portlet.



Mime
View raw message