incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1165633 - in /incubator/ace/trunk: ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java
Date Tue, 06 Sep 2011 12:20:22 GMT
Author: marrs
Date: Tue Sep  6 12:20:22 2011
New Revision: 1165633

URL: http://svn.apache.org/viewvc?rev=1165633&view=rev
Log:
ACE-173 refactorings

Modified:
    incubator/ace/trunk/ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java
    incubator/ace/trunk/ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java

Modified: incubator/ace/trunk/ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java?rev=1165633&r1=1165632&r2=1165633&view=diff
==============================================================================
--- incubator/ace/trunk/ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java
(original)
+++ incubator/ace/trunk/ace-deployment-deploymentadmin/src/main/java/org/apache/ace/deployment/deploymentadmin/DeploymentAdminDeployer.java
Tue Sep  6 12:20:22 2011
@@ -55,6 +55,9 @@ public class DeploymentAdminDeployer imp
 
     public Object[] list() {
         // DeploymentAdmin spec says this call should never return null
+        // TODO this will return all deployment packages and their versions (dependent code

+        //      just takes all versions and finds the highest, which does not make sense
if
+        //      there is more than one DP)
         return m_admin.listDeploymentPackages();
     }
 }
\ No newline at end of file

Modified: incubator/ace/trunk/ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java?rev=1165633&r1=1165632&r2=1165633&view=diff
==============================================================================
--- incubator/ace/trunk/ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java
(original)
+++ incubator/ace/trunk/ace-deployment-task/src/main/java/org/apache/ace/deployment/task/Activator.java
Tue Sep  6 12:20:22 2011
@@ -18,7 +18,11 @@
  */
 package org.apache.ace.deployment.task;
 
+import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.ace.deployment.Deployment;
@@ -26,52 +30,141 @@ import org.apache.ace.deployment.service
 import org.apache.ace.discovery.Discovery;
 import org.apache.ace.identification.Identification;
 import org.apache.ace.scheduler.constants.SchedulerConstants;
+import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.service.log.LogService;
 
-public class Activator extends DependencyActivatorBase {
+public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
+    private static final String MA_NAME = "ma";
+    private DependencyManager m_manager;
+    private final Map<String, List<Component>> m_instances = new HashMap<String,
List<Component>>();
+    private BundleContext m_context;
+
+    
     public void init(BundleContext context, DependencyManager manager) throws Exception {
+        m_context = context;
+        m_manager = manager;
+        List<Component> components = createServices(null);
+        for (Component component : components) {
+            m_manager.add(component);
+        }
+    }
+
+    private List<Component> createServices(String ma) {
+        List<Component> result = new ArrayList<Component>();
         Dictionary updateProperties = new Properties();
-        updateProperties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, "Task that synchronizes
the artifacts (bundles, resources) installed on this gateway with the server.");
-        updateProperties.put(SchedulerConstants.SCHEDULER_NAME_KEY, DeploymentUpdateTask.class.getName());
+        Dictionary checkProperties = new Properties();
+        Dictionary deploymentProperties = new Properties();
+        String updateSchedulerName;
+        String updateDescription;
+        String checkSchedulerName;
+        String checkDescription;
+        String identificationFilter;
+        String discoveryFilter;
+        String deploymentFilter;
+
+        if (ma == null) {
+            updateSchedulerName = DeploymentUpdateTask.class.getName();
+            updateDescription = "Task that synchronizes the artifacts (bundles, resources)
installed on this target with the server.";
+            checkSchedulerName = DeploymentCheckTask.class.getName();
+            checkDescription = "Task that checks for updates of artifacts installed on this
target with the server.";
+            identificationFilter = "(&("+Constants.OBJECTCLASS+"="+Identification.class.getName()+")(!(ma=*)))";
+            discoveryFilter = "(&("+Constants.OBJECTCLASS+"="+Discovery.class.getName()+")(!(ma=*)))";
+            deploymentFilter = "(&("+Constants.OBJECTCLASS+"="+DeploymentService.class.getName()+")(!(ma=*)))";
+        }
+        else {
+            updateSchedulerName = "ma=" + ma + ";name=" + DeploymentUpdateTask.class.getName();
+            updateDescription = "Task that synchronizes the artifacts (bundles, resources)
installed on this target with the server with ma=" + ma + ".";
+            checkSchedulerName = "ma=" + ma + ";name=" + DeploymentCheckTask.class.getName();
+            checkDescription = "Task that checks for updates of artifacts installed on this
target with the server with ma=" + ma + ".";
+            identificationFilter = "(&("+Constants.OBJECTCLASS+"="+Identification.class.getName()+")(ma="
+ ma + "))";
+            discoveryFilter = "(&("+Constants.OBJECTCLASS+"="+Discovery.class.getName()+")(ma="
+ ma + "))";
+            deploymentFilter = "(&("+Constants.OBJECTCLASS+"="+DeploymentService.class.getName()+")(ma="
+ ma + "))";
+            updateProperties.put(MA_NAME, ma);
+            checkProperties.put(MA_NAME, ma);
+            deploymentProperties.put(MA_NAME, ma);
+        }
+        updateProperties.put(SchedulerConstants.SCHEDULER_NAME_KEY, updateSchedulerName);
+        updateProperties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, updateDescription);
         updateProperties.put(SchedulerConstants.SCHEDULER_RECIPE, "5000");
 
-        Dictionary checkProperties = new Properties();
-        checkProperties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, "Task that checks
for updates for gateway on the server.");
-        checkProperties.put(SchedulerConstants.SCHEDULER_NAME_KEY, DeploymentCheckTask.class.getName());
+        checkProperties.put(SchedulerConstants.SCHEDULER_NAME_KEY, checkSchedulerName);
+        checkProperties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, checkDescription);
         checkProperties.put(SchedulerConstants.SCHEDULER_RECIPE, "5000");
         
         DeploymentTaskBase task = new DeploymentTaskBase();
         DeploymentUpdateTask updateTask = new DeploymentUpdateTask(task);
         DeploymentCheckTask checkTask = new DeploymentCheckTask(task);
 
-        manager.add(createComponent()
-            .setInterface(DeploymentService.class.getName(), null)
+        Component deploymentServiceComponent = createComponent()
+            .setInterface(DeploymentService.class.getName(), deploymentProperties)
             .setImplementation(task)
             .add(createServiceDependency().setService(Deployment.class).setRequired(true))
-            .add(createServiceDependency().setService(Identification.class).setRequired(true))
-            .add(createServiceDependency().setService(Discovery.class).setRequired(true))
+            .add(createServiceDependency().setService(Identification.class, identificationFilter).setRequired(true))
+            .add(createServiceDependency().setService(Discovery.class, discoveryFilter).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(false))
-            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+            .add(createServiceDependency().setService(LogService.class).setRequired(false));
 
-        manager.add(createComponent()
+        Component updateTaskComponent = createComponent()
             .setInterface(Runnable.class.getName(), updateProperties)
             .setImplementation(updateTask)
-            .add(createServiceDependency().setService(DeploymentService.class).setRequired(true).setAutoConfig(false))
-            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+            .add(createServiceDependency().setService(DeploymentService.class, deploymentFilter).setRequired(true).setAutoConfig(false))
+            .add(createServiceDependency().setService(LogService.class).setRequired(false));
 
-        manager.add(createComponent()
+        Component checkTaskComponent = createComponent()
             .setInterface(Runnable.class.getName(), checkProperties)
             .setImplementation(checkTask)
-            .add(createServiceDependency().setService(DeploymentService.class).setRequired(true).setAutoConfig(false))
+            .add(createServiceDependency().setService(DeploymentService.class, deploymentFilter).setRequired(true).setAutoConfig(false))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(false))
-            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+            .add(createServiceDependency().setService(LogService.class).setRequired(false));
+
+        result.add(deploymentServiceComponent);
+        result.add(updateTaskComponent);
+        result.add(checkTaskComponent);
+
+        return result;
     }
 
     public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
         // do nothing
     }
+
+    public String getName() {
+        return "Deployment Service";
+    }
+
+    public void updated(String pid, Dictionary dict) throws ConfigurationException {
+        String ma = (String) dict.get(MA_NAME);
+        List<Component> components = m_instances.get(pid);
+        if (components == null) {
+            components = createServices(ma);
+            synchronized (m_instances) {
+                m_instances.put(pid, components);
+            }
+            for (Component component : components) {
+                m_manager.add(component);
+            }
+        }
+        else {
+            // TODO do we want to deal with changes here?
+        }
+    }
+
+    public void deleted(String pid) {
+        List<Component> components;
+        synchronized (m_instances) {
+            components = m_instances.remove(pid);
+        }
+        if (components != null) {
+            for (Component component : components) {
+                m_manager.remove(component);
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message