Search in sources :

Example 11 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class UpdateAppTest method testFullUpdate.

@Test
@Ignore
public void testFullUpdate() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = setupApp();
    updateApp(manager, app);
    assertAppMessage("hello brave new world");
}
Also used : AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 12 with AriesApplication

use of org.apache.aries.application.management.AriesApplication 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 13 with AriesApplication

use of org.apache.aries.application.management.AriesApplication 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 14 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class IsolatedRuntimeTest method testFrameworkResolvedBeforeInnerBundlesStart.

@Test
@Ignore
public void testFrameworkResolvedBeforeInnerBundlesStart() throws Exception {
    /*
       * Lazy bundles have in the past triggered recursive bundle trackers to handle them before
       * the composite bundle framework was even resolved. In such a case the below loadClass
       * operation on a class that depends on a class imported from the outside of the composite 
       * will fail with an NPE.
       */
    final AtomicBoolean loadedClass = new AtomicBoolean(false);
    context().addBundleListener(new SynchronousBundleListener() {

        public void bundleChanged(BundleEvent event) {
            Bundle b = event.getBundle();
            if (event.getType() == BundleEvent.STARTING || event.getType() == BundleEvent.LAZY_ACTIVATION) {
                if (b.getEntry("org/apache/aries/isolated/sample/SharedImpl.class") != null) {
                    try {
                        Class<?> cl = b.loadClass("org.apache.aries.isolated.sample.SharedImpl");
                        cl.newInstance();
                        loadedClass.set(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    }
                }
            } else if (event.getType() == BundleEvent.INSTALLED && b instanceof CompositeBundle) {
                ((CompositeBundle) b).getCompositeFramework().getBundleContext().addBundleListener(this);
            }
        }
    });
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    AriesApplicationContext ctx = manager.install(app);
    try {
        ctx.start();
        app = ctx.getApplication();
        assertEquals(1, app.getDeploymentMetadata().getApplicationDeploymentContents().size());
        assertEquals(1, app.getDeploymentMetadata().getApplicationProvisionBundles().size());
        assertTrue(loadedClass.get());
    } finally {
        manager.uninstall(ctx);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompositeBundle(org.osgi.service.framework.CompositeBundle) Bundle(org.osgi.framework.Bundle) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleEvent(org.osgi.framework.BundleEvent) PerClass(org.ops4j.pax.exam.spi.reactors.PerClass) CompositeBundle(org.osgi.service.framework.CompositeBundle) File(java.io.File) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 15 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class EBAInstaller method install.

public void install(File applicationLocation) throws Exception {
    AriesApplication app = applicationManager.createApplication(FileSystem.getFSRoot(applicationLocation));
    String appSymName = app.getApplicationMetadata().getApplicationSymbolicName();
    Version appVersion = app.getApplicationMetadata().getApplicationVersion();
    LOGGER.debug("created app from {} : {} {} with contents {}", new Object[] { applicationLocation.getName(), appSymName, appVersion, app.getApplicationMetadata().getApplicationContents() });
    AriesApplicationContext context = applicationManager.install(app);
    LOGGER.debug("installed app {} {} state: {}", new Object[] { appSymName, appVersion, context.getApplicationState() });
    context.start();
    LOGGER.debug("started app {} {} state: {}", new Object[] { appSymName, appVersion, context.getApplicationState() });
    // Store the application context away because it is the application context we need
    // to pass to the application manager if we're later asked to uninstall the application
    appContexts.put(applicationLocation, context);
}
Also used : Version(org.osgi.framework.Version) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication)

Aggregations

AriesApplication (org.apache.aries.application.management.AriesApplication)42 Test (org.junit.Test)32 File (java.io.File)25 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)24 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)24 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)23 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)11 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)10 Ignore (org.junit.Ignore)9 Repository (org.apache.felix.bundlerepository.Repository)8 DeploymentContent (org.apache.aries.application.DeploymentContent)7 HelloWorld (org.apache.aries.sample.HelloWorld)7 Version (org.osgi.framework.Version)7 MethodCall (org.apache.aries.unittest.mocks.MethodCall)5 Bundle (org.osgi.framework.Bundle)5 Content (org.apache.aries.application.Content)4 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)3