Search in sources :

Example 1 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkManagerImpl method updateBundles.

public void updateBundles(final DeploymentMetadata newMetadata, final DeploymentMetadata oldMetadata, final AriesApplication app, final BundleLocator locator, final Set<Bundle> bundles, final boolean startBundles) throws UpdateException {
    UpdateStrategy strategy = null;
    for (UpdateStrategy us : _updateStrategies) {
        if (us.allowsUpdate(newMetadata, oldMetadata)) {
            strategy = us;
            break;
        }
    }
    if (strategy == null)
        throw new IllegalArgumentException("No UpdateStrategy supports the supplied DeploymentMetadata changes.");
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
        final BundleFramework appFwk = _frameworksByAppScope.get(app.getApplicationMetadata().getApplicationScope());
        strategy.update(new UpdateStrategy.UpdateInfo() {

            public void register(Bundle bundle) {
                bundles.add(bundle);
            }

            public void unregister(Bundle bundle) {
                bundles.remove(bundle);
            }

            public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws BundleException {
                return locator.suggestBundle(bundles);
            }

            public boolean startBundles() {
                return startBundles;
            }

            public BundleFramework getSharedFramework() {
                return _sharedBundleFramework;
            }

            public DeploymentMetadata getOldMetadata() {
                return oldMetadata;
            }

            public DeploymentMetadata getNewMetadata() {
                return newMetadata;
            }

            public AriesApplication getApplication() {
                return app;
            }

            public BundleFramework getAppFramework() {
                return appFwk;
            }
        });
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Bundle(org.osgi.framework.Bundle) UpdateStrategy(org.apache.aries.application.management.spi.update.UpdateStrategy) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleException(org.osgi.framework.BundleException) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentContent(org.apache.aries.application.DeploymentContent)

Example 2 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkManagerImpl method installIsolatedBundles.

public Bundle installIsolatedBundles(Collection<BundleSuggestion> bundlesToInstall, AriesApplication app) throws BundleException {
    Bundle frameworkBundle = null;
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
        // We need to create a new isolated framework for this content and install
        // the bundles to it
        BundleFramework isolatedFramework = isolatedInstall(bundlesToInstall, _sharedBundleFramework.getIsolatedBundleContext(), app);
        _frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
        _frameworksByAppScope.put(app.getApplicationMetadata().getApplicationScope(), isolatedFramework);
        frameworkBundle = isolatedFramework.getFrameworkBundle();
    }
    return frameworkBundle;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework)

Example 3 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkManagerTest method testFailedInstall.

@Test
public void testFailedInstall() throws Exception {
    /*
     * Mock up a failing framework install
     */
    BundleFramework fwk = Skeleton.newMock(new Object() {

        public Bundle install(BundleSuggestion suggestion, AriesApplication app) throws BundleException {
            throw new BundleException("Expected failure");
        }
    }, BundleFramework.class);
    frameworkFactory.setReturnValue(new MethodCall(BundleFrameworkFactory.class, "createBundleFramework", BundleContext.class, BundleFrameworkConfiguration.class), fwk);
    try {
        sut.installIsolatedBundles(Arrays.asList(Skeleton.newMock(BundleSuggestion.class)), Skeleton.newMock(AriesApplication.class));
        fail("Expected a BundleException");
    } catch (BundleException be) {
        // when a failure occurred we need to have cleaned up the new framework, otherwise it is
        // left as floating debris
        Skeleton.getSkeleton(fwk).assertCalled(new MethodCall(BundleFramework.class, "close"));
    }
}
Also used : BundleFrameworkFactory(org.apache.aries.application.management.spi.framework.BundleFrameworkFactory) Bundle(org.osgi.framework.Bundle) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) BundleContext(org.osgi.framework.BundleContext) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration) Test(org.junit.Test)

Example 4 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class IsolationTestUtils method prepareSampleBundleV2.

/**
   * Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle, 
   * which returns the message "hello brave new world" rather than "hello world"
   * 
   * This means setting up a global bundle repository as well as a global OBR repository
   */
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
    BundleRepository repo = new BundleRepository() {

        public int getCost() {
            return 1;
        }

        public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
            if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
                return new BundleSuggestion() {

                    public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
                        File f = new File("sample_2.0.0.jar");
                        try {
                            return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
                        } catch (MalformedURLException mue) {
                            throw new RuntimeException(mue);
                        }
                    }

                    public Version getVersion() {
                        return new Version("2.0.0");
                    }

                    public Set<Content> getImportPackage() {
                        return Collections.emptySet();
                    }

                    public Set<Content> getExportPackage() {
                        return Collections.emptySet();
                    }

                    public int getCost() {
                        return 1;
                    }
                };
            } else {
                return null;
            }
        }
    };
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
    runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
    Attributes attrs = new Attributes();
    attrs.putValue("Bundle-ManifestVersion", "2");
    attrs.putValue("Bundle-Version", "2.0.0");
    attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
    attrs.putValue("Manifest-Version", "1");
    ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
    repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
Also used : MalformedURLException(java.net.MalformedURLException) Hashtable(java.util.Hashtable) AriesApplication(org.apache.aries.application.management.AriesApplication) Attributes(java.util.jar.Attributes) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) DeploymentContent(org.apache.aries.application.DeploymentContent) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Version(org.osgi.framework.Version) DeploymentContent(org.apache.aries.application.DeploymentContent) Content(org.apache.aries.application.Content) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 5 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkManagerImpl method isolatedInstall.

private BundleFramework isolatedInstall(Collection<BundleSuggestion> bundlesToBeInstalled, BundleContext parentCtx, AriesApplication app) throws BundleException {
    LOGGER.debug(LOG_ENTRY, "isolatedInstall", new Object[] { bundlesToBeInstalled, app });
    /**
     * Build the configuration information for this application framework
     */
    BundleFrameworkConfiguration config = _bundleFrameworkConfigurationFactory.createBundleFrameworkConfig(app.getApplicationMetadata().getApplicationScope(), parentCtx, app);
    /**
     * Install and start the new isolated bundle framework
     */
    BundleFramework bundleFramework = _bundleFrameworkFactory.createBundleFramework(parentCtx, config);
    // We should now have a bundleFramework
    if (bundleFramework != null) {
        try {
            bundleFramework.init();
            /**
         * Install the bundles into the new framework
         */
            BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
            if (frameworkBundleContext != null) {
                for (BundleSuggestion suggestion : bundlesToBeInstalled) bundleFramework.install(suggestion, app);
            }
        } catch (BundleException be) {
            bundleFramework.close();
            throw be;
        } catch (RuntimeException re) {
            bundleFramework.close();
            throw re;
        }
    }
    LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
    return bundleFramework;
}
Also used : BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)7 Bundle (org.osgi.framework.Bundle)4 BundleException (org.osgi.framework.BundleException)4 AriesApplication (org.apache.aries.application.management.AriesApplication)3 BundleContext (org.osgi.framework.BundleContext)3 DeploymentContent (org.apache.aries.application.DeploymentContent)2 BundleFrameworkConfiguration (org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)2 BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)2 ServiceReference (org.osgi.framework.ServiceReference)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Semaphore (java.util.concurrent.Semaphore)1 Attributes (java.util.jar.Attributes)1 Content (org.apache.aries.application.Content)1 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)1