Search in sources :

Example 1 with BundleSuggestion

use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion in project aries by apache.

the class ApplicationRepositoryTest method testBundleNotInApp.

@Test
public void testBundleNotInApp() {
    AriesApplication app = Skeleton.newMock(AriesApplication.class);
    BundleInfo bi = Skeleton.newMock(BundleInfo.class);
    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getSymbolicName"), "test.bundle");
    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getVersion"), new Version("1.0.0"));
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getBundleInfo"), new HashSet<BundleInfo>());
    ApplicationRepository rep = new ApplicationRepository(app);
    BundleSuggestion sug = rep.suggestBundleToUse(new DeploymentContentImpl("test.bundle", new Version("2.0.0")));
    assertNull("We have apparently found a bundle that is not in the application in the ApplicationRepository", sug);
}
Also used : DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) BundleInfo(org.apache.aries.application.management.BundleInfo) Version(org.osgi.framework.Version) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 2 with BundleSuggestion

use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion 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 3 with BundleSuggestion

use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion in project aries by apache.

the class BundleRepositoryManagerImpl method getBundleSuggestions.

public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
    Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
    Iterator<DeploymentContent> it = content.iterator();
    while (it.hasNext()) {
        DeploymentContent bundleToFind = it.next();
        Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
        for (BundleRepository obj : providers) {
            BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
            if (suggestion != null) {
                List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
                if (suggestions == null) {
                    suggestions = new ArrayList<BundleSuggestion>();
                    bundlesuggestions.put(suggestion.getVersion(), suggestions);
                }
                suggestions.add(suggestion);
            }
        }
        BundleSuggestion suggestion = null;
        if (!!!bundlesuggestions.isEmpty()) {
            List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
            if (thoughts != null) {
                Collections.sort(thoughts, new Comparator<BundleSuggestion>() {

                    public int compare(BundleSuggestion o1, BundleSuggestion o2) {
                        return o1.getCost() - o2.getCost();
                    }
                });
                suggestion = thoughts.get(0);
            }
        }
        // add the suggestion to the list
        if (suggestion != null) {
            urlToBeInstalled.put(bundleToFind, suggestion);
        } else {
            throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
        }
    }
    LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
    return urlToBeInstalled;
}
Also used : HashMap(java.util.HashMap) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ContextException(org.apache.aries.application.management.spi.repository.ContextException) DeploymentContent(org.apache.aries.application.DeploymentContent) Version(org.osgi.framework.Version) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) ArrayList(java.util.ArrayList) List(java.util.List) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList)

Example 4 with BundleSuggestion

use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion 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)

Example 5 with BundleSuggestion

use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion in project aries by apache.

the class ApplicationContextImpl method installBundles.

/**
 * This method finds bundles matching the list of content passed in
 * @param bundlesToFind       bundles to find and start if the bundle is shared.  If isolated, install it.
 * @param shared                      whether the bundles will be shared or isolated
 * @return the result of execution
 */
private void installBundles(List<DeploymentContent> bundlesToFind, boolean shared) throws BundleException {
    LOGGER.debug(LOG_ENTRY, "install", new Object[] { bundlesToFind, Boolean.valueOf(shared) });
    if (!bundlesToFind.isEmpty() || !shared) {
        Iterator<DeploymentContent> it = bundlesToFind.iterator();
        /**
         * Dont install any bundles from the list which are already
         * installed
         */
        Bundle[] sharedBundles = _bundleFrameworkManager.getSharedBundleFramework().getIsolatedBundleContext().getBundles();
        if (shared) {
            if (sharedBundles.length > 0) {
                while (it.hasNext()) {
                    DeploymentContent bundleToFind = it.next();
                    for (Bundle b : sharedBundles) {
                        if (bundleToFind.getContentName().equals(b.getSymbolicName()) && bundleToFind.getExactVersion().equals(b.getVersion())) {
                            it.remove();
                            _bundles.add(b);
                            break;
                        }
                    }
                }
            }
        }
        /**
         * Ask the repository manager to find us a list of suggested bundles
         * to install based on our content list
         */
        Map<DeploymentContent, BundleSuggestion> bundlesToBeInstalled = findBundleSuggestions(bundlesToFind);
        /**
         * Perform the install of the bundles
         */
        try {
            if (shared)
                _bundles.addAll(_bundleFrameworkManager.installSharedBundles(new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
            else
                _bundles.add(_bundleFrameworkManager.installIsolatedBundles(new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
        } catch (BundleException e) {
            LOGGER.debug(LOG_EXCEPTION, e);
            throw e;
        }
    }
    LOGGER.debug(LOG_EXIT, "install");
}
Also used : Bundle(org.osgi.framework.Bundle) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) DeploymentContent(org.apache.aries.application.DeploymentContent)

Aggregations

BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)5 BundleException (org.osgi.framework.BundleException)3 DeploymentContent (org.apache.aries.application.DeploymentContent)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)2 BundleFrameworkConfiguration (org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2 Test (org.junit.Test)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2 Version (org.osgi.framework.Version)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1 BundleFrameworkFactory (org.apache.aries.application.management.spi.framework.BundleFrameworkFactory)1 BundleRepository (org.apache.aries.application.management.spi.repository.BundleRepository)1 ContextException (org.apache.aries.application.management.spi.repository.ContextException)1 ArrayServiceList (org.apache.aries.application.utils.service.ArrayServiceList)1