incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r910261 - in /incubator/aries/trunk/application: application-api/src/main/java/org/apache/aries/application/management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/...
Date Mon, 15 Feb 2010 16:50:43 GMT
Author: not
Date: Mon Feb 15 16:50:42 2010
New Revision: 910261

URL: http://svn.apache.org/viewvc?rev=910261&view=rev
Log:
ARIES-162 Do bundle install as a result of installing an app, rather than as a result of starting
an app.

Modified:
    incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ApplicationContextManager.java
    incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationManager.java
    incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationResolver.java
    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java

Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ApplicationContextManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ApplicationContextManager.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ApplicationContextManager.java
(original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ApplicationContextManager.java
Mon Feb 15 16:50:42 2010
@@ -21,6 +21,8 @@
 
 import java.util.Set;
 
+import org.osgi.framework.BundleException;
+
 /**
  * An ApplicationContextManager is responsible for managing Aries applications in the 
  * server's OSGi runtime. We expect that many projects consuming this code will provide
@@ -33,8 +35,10 @@
    * started via an ApplicationContext. 
    * @param app The applicaton for which to obtain an ApplicationContext. 
    * @return ApplicationContext
+   * @throws BundleException 
+   * @throws ManagementException 
    */
-  public ApplicationContext getApplicationContext(AriesApplication app);
+  public ApplicationContext getApplicationContext(AriesApplication app) throws BundleException,
ManagementException;
 
   /**
    * @return The set of all ApplicationContexts.

Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationManager.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationManager.java
(original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationManager.java
Mon Feb 15 16:50:42 2010
@@ -53,8 +53,9 @@
    * @param app Application to install 
    * @return ApplicationContext, a handle to an application in the runtime
    * @throws BundleException
+   * @throws ManagementException 
    */
-  public ApplicationContext install(AriesApplication app) throws BundleException;
+  public ApplicationContext install(AriesApplication app) throws BundleException, ManagementException;
   
   /**
    * Uninstall an AriesApplication - i.e. unload its bundles from the runtime. 

Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationResolver.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationResolver.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationResolver.java
(original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationResolver.java
Mon Feb 15 16:50:42 2010
@@ -21,6 +21,8 @@
 
 import java.util.Set;
 
+import org.osgi.framework.Version;
+
 public interface AriesApplicationResolver {
 
   /** Resolve an AriesApplication 
@@ -31,4 +33,14 @@
    * @throws ResolverException if the application cannot be resolved.  
    */
   Set<BundleInfo> resolve (AriesApplication app) throws ResolverException ;
+
+  /** 
+   * Return the info for the requested bundle. If no matching bundle exists in the
+   * resolver runtime then null is returned.
+   * 
+   * @param bundleSymbolicName the bundle symbolic name.
+   * @param bundleVersion      the version of the bundle
+   * @return the BundleInfo for the requested bundle, or null if none could be found.
+   */
+  BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion);
 }

Modified: incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
(original)
+++ incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
Mon Feb 15 16:50:42 2010
@@ -226,7 +226,7 @@
     return null;
   } 
 
-  public ApplicationContext install(AriesApplication app) {
+  public ApplicationContext install(AriesApplication app) throws BundleException, ManagementException
{
     ApplicationContext result = _applicationContextManager.getApplicationContext(app);
     return result;
   }

Modified: incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
(original)
+++ incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
Mon Feb 15 16:50:42 2010
@@ -74,6 +74,10 @@
     void setNextResult (Set<BundleInfo> r) { 
       nextResult = r;
     }
+    public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
+    {
+      return null;
+    }
   }
   
   static class DummyLocalPlatform implements LocalPlatform {

Modified: incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java
(original)
+++ incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java
Mon Feb 15 16:50:42 2010
@@ -23,6 +23,7 @@
 import org.apache.aries.application.management.AriesApplication;
 import org.apache.aries.application.management.AriesApplicationResolver;
 import org.apache.aries.application.management.BundleInfo;
+import org.osgi.framework.Version;
 
 /** AriesApplicationManager requires that there be at least one 
  * AriesApplicationResolver service present. This class provides a null 
@@ -36,4 +37,8 @@
     return app.getBundleInfo();
   }
 
-}
+  public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
+  {
+    return null;
+  }
+}
\ No newline at end of file

Modified: incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
(original)
+++ incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
Mon Feb 15 16:50:42 2010
@@ -19,17 +19,26 @@
 
 package org.apache.aries.application.runtime.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
 import org.apache.aries.application.management.ApplicationContext;
 import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationResolver;
 import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ManagementException;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
 
 public class ApplicationContextImpl implements ApplicationContext {
   
@@ -38,10 +47,63 @@
   private ApplicationState _state;
   private BundleContext _bundleContext;
   
-  public ApplicationContextImpl (BundleContext b, AriesApplication app) { 
+  public ApplicationContextImpl (BundleContext b, AriesApplication app) throws BundleException,
ManagementException { 
     _bundleContext = b;
     _application = app;
     _bundles = new HashMap<BundleInfo, Bundle>();
+    
+    DeploymentMetadata meta = _application.getDeploymentMetadata();
+    
+    AriesApplicationResolver resolver = null;
+    
+    ServiceReference ref = b.getServiceReference(AriesApplicationResolver.class.getName());
+
+    if (ref != null) resolver = (AriesApplicationResolver) b.getService(ref);
+    
+    if (resolver == null) {
+      throw new ManagementException(new ServiceException(AriesApplicationResolver.class.getName(),
ServiceException.UNREGISTERED));
+    }
+    
+    try {
+      for (DeploymentContent content : meta.getApplicationDeploymentContents()) {
+        String bundleSymbolicName = content.getContentName();
+        Version bundleVersion = content.getExactVersion();
+        
+        BundleInfo bundleInfo = null;
+        
+        for (BundleInfo info : _application.getBundleInfo()) {
+          if (info.getSymbolicName().equals(bundleSymbolicName) &&
+              info.getVersion().equals(bundleVersion)) {
+            bundleInfo = info;
+            break;
+          }
+        }
+        
+        if (bundleInfo == null) {
+          // call out to the bundle repository.
+          bundleInfo = resolver.getBundleInfo(bundleSymbolicName, bundleVersion);
+        }
+        
+        if (bundleInfo == null) {
+          throw new ManagementException("Cound not find bundles: " + bundleSymbolicName +
"_" + bundleVersion);
+        }
+        
+        Bundle bundle = _bundleContext.installBundle(bundleInfo.getLocation());
+        
+        _bundles.put(bundleInfo, bundle);
+      }
+    } catch (BundleException be) {
+      for (Bundle bundle : _bundles.values()) {
+        bundle.uninstall();
+      }
+      
+      _bundles.clear();
+      
+      throw be;
+    } finally {
+      if (resolver != null) b.ungetService(ref);
+    }
+    
     _state = ApplicationState.INSTALLED;
   }
 
@@ -61,20 +123,32 @@
     return _state;
   }
 
-  public void start() throws BundleException {
-    Set<BundleInfo> bundleInfo = _application.getBundleInfo();
-    for (BundleInfo bi : bundleInfo) { 
-      // TODO: proper synchronisation!
-      if (_bundles.containsKey(bi)) { 
-        Bundle b = _bundles.get(bi);
+  public void start() throws BundleException 
+  {
+    _state = ApplicationState.STARTING;
+    
+    List<Bundle> bundlesWeStarted = new ArrayList<Bundle>();
+    
+    try {
+      for (Bundle b : _bundles.values()) { 
         if (b.getState() != Bundle.ACTIVE) { 
-          b.start();
+          b.start(Bundle.START_ACTIVATION_POLICY);
+          bundlesWeStarted.add(b);
+        }
+      }
+    } catch (BundleException be) {
+      for (Bundle b : bundlesWeStarted) {
+        try {
+          b.stop();
+        } catch (BundleException be2) {
+          // we are doing tidyup here, so we don't want to replace the bundle exception
+          // that occurred during start with one from stop. We also want to try to stop
+          // all the bundles we started even if some bundles wouldn't stop.
         }
-      } else { 
-        Bundle b = _bundleContext.installBundle(bi.getLocation()); 
-        b.start();
-        _bundles.put(bi, b);
       }
+      
+      _state = ApplicationState.INSTALLED;
+      throw be;
     }
     _state = ApplicationState.ACTIVE;
   }

Modified: incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java?rev=910261&r1=910260&r2=910261&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
(original)
+++ incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
Mon Feb 15 16:50:42 2010
@@ -28,7 +28,9 @@
 import org.apache.aries.application.management.ApplicationContext;
 import org.apache.aries.application.management.ApplicationContextManager;
 import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.ManagementException;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 
 public class ApplicationContextManagerImpl implements ApplicationContextManager {
 
@@ -43,7 +45,7 @@
     _bundleContext = b;
   }
   
-  public ApplicationContext getApplicationContext(AriesApplication app) {
+  public ApplicationContext getApplicationContext(AriesApplication app) throws BundleException,
ManagementException {
     ApplicationContext result;
     if (_appToContextMap.containsKey(app)) { 
       result = _appToContextMap.get(app);



Mime
View raw message