ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1181170 - in /incubator/ace/trunk/ace-deployment-servlet: ./ src/main/java/org/apache/ace/deployment/processor/ src/main/java/org/apache/ace/deployment/servlet/
Date Mon, 10 Oct 2011 19:42:05 GMT
Author: marrs
Date: Mon Oct 10 19:42:04 2011
New Revision: 1181170

URL: http://svn.apache.org/viewvc?rev=1181170&view=rev
Log:
ACE-186 implemented a mechanism for adding DeploymentProcessor plugins

Added:
    incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/
    incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java
  (with props)
Modified:
    incubator/ace/trunk/ace-deployment-servlet/pom.xml
    incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/Activator.java
    incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java

Modified: incubator/ace/trunk/ace-deployment-servlet/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-servlet/pom.xml?rev=1181170&r1=1181169&r2=1181170&view=diff
==============================================================================
--- incubator/ace/trunk/ace-deployment-servlet/pom.xml (original)
+++ incubator/ace/trunk/ace-deployment-servlet/pom.xml Mon Oct 10 19:42:04 2011
@@ -33,7 +33,7 @@
     <packaging>bundle</packaging>
 
     <name>Apache ACE :: Deployment :: Servlet</name>
-    <description />
+    <description>Servlet that is used by management agents to get an overview of available
versions and request 'deployment packages' of specific versions or deltas between versions.</description>
 
     <scm>
         <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/ace/trunk/ace-deployment-servlet</connection>
@@ -42,7 +42,11 @@
     </scm>
 
     <properties>
+        <export.package>
+            org.apache.ace.deployment.processor;version=${project.version}
+        </export.package>
         <import.package>
+            org.apache.ace.deployment.processor;version=${project.version},
             org.apache.ace.deployment.provider;version=${project.version},
             org.apache.ace.deployment.streamgenerator;version=${project.version},
             *
@@ -58,6 +62,10 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.deployment.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
             <artifactId>org.apache.ace.deployment.provider.api</artifactId>
         </dependency>
         <dependency>
@@ -85,5 +93,4 @@
             <artifactId>servlet-api</artifactId>
         </dependency>
     </dependencies>
-
 </project>
\ No newline at end of file

Added: incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java?rev=1181170&view=auto
==============================================================================
--- incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java
(added)
+++ incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java
Mon Oct 10 19:42:04 2011
@@ -0,0 +1,44 @@
+package org.apache.ace.deployment.processor;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Deployment processors can post process the deployment package before it is sent to the
original requester. This allows you to
+ * transform how the data is actually sent, allowing you to basically "repackage" the content
on the fly. Deployment processors
+ * should be registered as services with a service property called "processor" which should
match a request property of the same
+ * name and value.
+ */
+public interface DeploymentProcessor {
+    /**
+     * Post-process the stream and send it to the response. The input stream is the deployment
package as it was generated. You
+     * should set the correct mime type and start writing to the response.
+     * 
+     * @param inputStream the input stream for the deployment package
+     * @param request the original request, in case you want to access certain parameters
+     * @param response the response to write to
+     */
+    public void process(InputStream inputStream, HttpServletRequest request, HttpServletResponse
response) throws IOException;
+}

Propchange: incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/processor/DeploymentProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/Activator.java?rev=1181170&r1=1181169&r2=1181170&view=diff
==============================================================================
--- incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/Activator.java
(original)
+++ incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/Activator.java
Mon Oct 10 19:42:04 2011
@@ -20,6 +20,7 @@ package org.apache.ace.deployment.servle
 
 import javax.servlet.Servlet;
 
+import org.apache.ace.deployment.processor.DeploymentProcessor;
 import org.apache.ace.deployment.provider.DeploymentProvider;
 import org.apache.ace.deployment.streamgenerator.StreamGenerator;
 import org.apache.felix.dm.DependencyActivatorBase;
@@ -35,10 +36,12 @@ public class Activator extends Dependenc
         manager.add(createComponent()
             .setInterface(Servlet.class.getName(), null)
             .setImplementation(DeploymentServlet.class)
+            .add(createConfigurationDependency().setPropagate(true).setPid(PID))
             .add(createServiceDependency().setService(StreamGenerator.class).setRequired(true))
             .add(createServiceDependency().setService(DeploymentProvider.class).setRequired(true))
+            .add(createServiceDependency().setService(DeploymentProcessor.class).setRequired(false).setCallbacks("addProcessor",
"removeProcessor"))
             .add(createServiceDependency().setService(LogService.class).setRequired(false))
-            .add(createConfigurationDependency().setPropagate(true).setPid(PID)));
+        );
     }
 
     @Override

Modified: incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java?rev=1181170&r1=1181169&r2=1181170&view=diff
==============================================================================
--- incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java
(original)
+++ incubator/ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java
Mon Oct 10 19:42:04 2011
@@ -23,12 +23,17 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Dictionary;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ace.deployment.processor.DeploymentProcessor;
 import org.apache.ace.deployment.provider.DeploymentProvider;
 import org.apache.ace.deployment.streamgenerator.StreamGenerator;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.log.LogService;
@@ -38,17 +43,16 @@ import org.osgi.service.log.LogService;
  * of data containing the DeploymentPackage (or fix package) for a specific gateway and version.
  */
 public class DeploymentServlet extends HttpServlet implements ManagedService {
-
     private static final long serialVersionUID = 1L;
-
     public static final String CURRENT = "current";
+    public static final String PROCESSOR = "processor";
     public static final String VERSIONS = "versions";
     public static final String DP_MIMETYPE = "application/vnd.osgi.dp";
     public static final String TEXT_MIMETYPE = "text/plain";
-
     private volatile LogService m_log;                  /* injected by dependency manager
*/
     private volatile StreamGenerator m_streamGenerator; /* injected by dependency manager
*/
     private volatile DeploymentProvider m_provider;     /* injected by dependency manager
*/
+    private final ConcurrentHashMap<String, DeploymentProcessor> m_processors = new
ConcurrentHashMap<String, DeploymentProcessor>();
 
     /**
      * Responds to GET requests sent to this endpoint, the response depends on the requested
path:
@@ -76,7 +80,6 @@ public class DeploymentServlet extends H
                 String version = pathElements[3];
                 handlePackageDelivery(gatewayID, version, versions, request, response);
             }
-
         }
         catch (AceRestException e) {
             m_log.log(LogService.LOG_WARNING, e.getMessage(), e);
@@ -113,13 +116,12 @@ public class DeploymentServlet extends H
     private void handlePackageDelivery(final String gatewayID, final String version, final
List<String> versions, final HttpServletRequest request, final HttpServletResponse response)
throws AceRestException {
         ServletOutputStream output = null;
 
-        response.setContentType(TEXT_MIMETYPE);
         try {
-            output = response.getOutputStream();
             if (!versions.contains(version)) {
                 throw new AceRestException(HttpServletResponse.SC_NOT_FOUND, "Unknown version
(" + version + ")");
             }
             String current = request.getParameter(CURRENT);
+            String processor = request.getParameter(PROCESSOR);
 
             InputStream inputStream;
             if (current != null) {
@@ -129,7 +131,18 @@ public class DeploymentServlet extends H
                 inputStream = m_streamGenerator.getDeploymentPackage(gatewayID, version);
             }
 
+            if (processor != null) {
+                DeploymentProcessor deploymentProcessor = m_processors.get(processor);
+                if (deploymentProcessor != null) {
+                    deploymentProcessor.process(inputStream, request, response);
+                    return;
+                }
+                else {
+                    throw new AceRestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Could not find a deployment processor called: " + processor);
+                }
+            }
             response.setContentType(DP_MIMETYPE);
+            output = response.getOutputStream();
             byte[] buffer = new byte[1024 * 32];
             for (int bytesRead = inputStream.read(buffer); bytesRead != -1; bytesRead = inputStream.read(buffer))
{
                 output.write(buffer, 0, bytesRead);
@@ -200,4 +213,22 @@ public class DeploymentServlet extends H
     public void updated(Dictionary settings) throws ConfigurationException {
         // Nothing needs to be done - handled by DependencyManager
     }
+
+    public void addProcessor(ServiceReference ref, DeploymentProcessor processor) {
+        String key = (String) ref.getProperty(PROCESSOR);
+        if (key == null) {
+            m_log.log(LogService.LOG_WARNING, "Deployment processor ignored, required service
property '" + PROCESSOR + "' is missing.");
+            return;
+        }
+        m_processors.putIfAbsent(key, processor);
+    }
+
+    public void removeProcessor(ServiceReference ref, DeploymentProcessor processor) {
+        String key = (String) ref.getProperty(PROCESSOR);
+        if (key == null) {
+            // we do not log this here again, we already did so in 'addProcessor'
+            return;
+        }
+        m_processors.remove(key);
+    }
 }
\ No newline at end of file



Mime
View raw message