Search in sources :

Example 6 with DeploymentContent

use of org.apache.aries.application.DeploymentContent in project aries by apache.

the class AriesApplicationManagerImplTest method testCreate.

@Test
public void testCreate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "Test application");
    assertEquals(appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
    assertEquals(appMeta.getApplicationVersion(), new Version("1.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(appContent.size(), 2);
    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
    assertTrue(appContent.contains(fbw));
    assertTrue(appContent.contains(mbl));
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
    assertEquals(2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl("foo.bar.widgets;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("my.business.logic;deployed-version=1.1.0");
    DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue(dcList.contains(dc1));
    assertTrue(dcList.contains(dc2));
    dcList = dm.getApplicationProvisionBundles();
    assertEquals(1, dcList.size());
    assertTrue(dcList.contains(dc3));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 7 with DeploymentContent

use of org.apache.aries.application.DeploymentContent 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 8 with DeploymentContent

use of org.apache.aries.application.DeploymentContent 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)

Example 9 with DeploymentContent

use of org.apache.aries.application.DeploymentContent in project aries by apache.

the class TwitterTest method testTwitter.

/**
 * Test for ARIES-461
 * Application that bring in dependency bundles from a bundle repository doesn't deploy
 *
 * @throws Exception
 */
@Test
public void testTwitter() throws Exception {
    // provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
    deleteRepos();
    MavenArtifactUrlReference twitterEbaUrl = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.eba").versionAsInProject().type("eba");
    MavenArtifactUrlReference twitterCommonLangJar = maven("commons-lang", "commons-lang").versionAsInProject();
    MavenArtifactUrlReference twitterJar = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.twitter4j").versionAsInProject();
    // add the repository xml to the repository admin
    String repositoryXML = getRepoContent("/obr/twitter/TwitterRepository.xml");
    // replace the jar file url with the real url related to the environment
    String repo = repositoryXML.replaceAll("commons.lang.location", twitterCommonLangJar.getURL()).replaceAll("twitter4j.location", twitterJar.getURL());
    URL url = getRepoUrl(repo);
    repositoryAdmin.addRepository(url);
    AriesApplication app = manager.createApplication(new URL(twitterEbaUrl.getURL()));
    app = manager.resolve(app);
    DeploymentMetadata depMeta = app.getDeploymentMetadata();
    List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
    Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
    Collection<DeploymentContent> appContent = depMeta.getApplicationDeploymentContents();
    // We cannot be sure whether there are two or three provision bundles pulled in by Felix OBR as there is an outstanding defect
    // https://issues.apache.org/jira/browse/FELIX-2672
    // The workaround is to check we get the two bundles we are looking for, instead of insisting on just having two bundles.
    List<String> provisionBundleSymbolicNames = new ArrayList<String>();
    for (DeploymentContent dep : provision) {
        provisionBundleSymbolicNames.add(dep.getContentName());
    }
    String provision_bundle1 = "org.apache.commons.lang";
    String provision_bundle2 = "twitter4j";
    assertTrue("Bundle " + provision_bundle1 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle1));
    assertTrue("Bundle " + provision_bundle2 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle2));
    assertEquals(useBundles.toString(), 0, useBundles.size());
    assertEquals(appContent.toString(), 1, appContent.size());
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) ArrayList(java.util.ArrayList) URL(java.net.URL) MavenArtifactUrlReference(org.ops4j.pax.exam.options.MavenArtifactUrlReference) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 10 with DeploymentContent

use of org.apache.aries.application.DeploymentContent 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)

Aggregations

DeploymentContent (org.apache.aries.application.DeploymentContent)11 AriesApplication (org.apache.aries.application.management.AriesApplication)7 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Content (org.apache.aries.application.Content)4 Bundle (org.osgi.framework.Bundle)4 Version (org.osgi.framework.Version)4 File (java.io.File)3 HashMap (java.util.HashMap)3 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)3 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)3 BundleException (org.osgi.framework.BundleException)3 Map (java.util.Map)2 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)2 ContentImpl (org.apache.aries.application.impl.ContentImpl)2 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)2 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)2 BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)2 BundleRepository (org.apache.aries.application.management.spi.repository.BundleRepository)2