Search in sources :

Example 11 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class BundleEventHook method handleExplicitlyInstalledBundleRegionDigraph.

private void handleExplicitlyInstalledBundleRegionDigraph(Bundle origin, BundleRevision bundleRevision) {
    // The bundle needs to be associated with the scoped subsystem of 
    // the region used to install the bundle.
    RegionDigraph digraph = activator.getRegionDigraph();
    Region region = digraph.getRegion(origin);
    for (BasicSubsystem s : getSubsystems().getSubsystems()) {
        if ((s.isApplication() || s.isComposite()) && region.equals(s.getRegion())) {
            Utils.installResource(bundleRevision, s);
            return;
        }
    }
    throw new IllegalStateException("No subsystem found for bundle " + bundleRevision + " in region " + region);
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Region(org.eclipse.equinox.region.Region)

Example 12 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class SubsystemTest method uninstallSubsystem.

protected void uninstallSubsystem(Subsystem subsystem, boolean quietly) throws Exception {
    BasicSubsystem basicSubsystem = (BasicSubsystem) subsystem;
    AriesProvisionDependenciesDirective directive = basicSubsystem.getAriesProvisionDependenciesDirective();
    Bundle b = null;
    Region region = null;
    RegionDigraph digraph = context().getService(RegionDigraph.class);
    if (!quietly) {
        if (directive.isResolve()) {
            assertState(EnumSet.of(State.INSTALLING, State.INSTALLED, State.RESOLVED), subsystem);
        } else {
            assertState(EnumSet.of(State.INSTALLED, State.RESOLVED), subsystem);
        }
        subsystemEvents.clear();
        if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION) || subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
            b = getRegionContextBundle(subsystem);
            region = digraph.getRegion(b);
        }
    }
    State state = subsystem.getState();
    subsystem.uninstall();
    if (quietly) {
        return;
    }
    Collection<Subsystem> parents = subsystem.getParents();
    if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state)) {
        assertEvent(subsystem, State.INSTALLED, 5000);
    }
    assertEvent(subsystem, State.UNINSTALLING, 5000);
    assertEvent(subsystem, State.UNINSTALLED, 5000);
    assertState(State.UNINSTALLED, subsystem);
    for (Subsystem parent : parents) {
        assertNotChild(parent, subsystem);
    }
    if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION) || subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
        assertEquals("Region context bundle not uninstalled", Bundle.UNINSTALLED, b.getState());
        assertNull("Region not removed", digraph.getRegion(region.getName()));
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Bundle(org.osgi.framework.Bundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) CoreOptions.streamBundle(org.ops4j.pax.exam.CoreOptions.streamBundle) State(org.osgi.service.subsystem.Subsystem.State) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) Region(org.eclipse.equinox.region.Region) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesProvisionDependenciesDirective(org.apache.aries.subsystem.core.archive.AriesProvisionDependenciesDirective)

Example 13 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class SubsystemTest method getRegion.

protected Region getRegion(Subsystem subsystem) {
    RegionDigraph digraph = context().getService(RegionDigraph.class);
    String name = getRegionName(subsystem);
    Region region = digraph.getRegion(name);
    assertNotNull("Region not found: " + name, region);
    return region;
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Region(org.eclipse.equinox.region.Region)

Example 14 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class SubsystemTest method tearDown.

@SuppressWarnings("rawtypes")
@After
public void tearDown() throws Exception {
    for (Subsystem subsystem : stoppableSubsystems) {
        stopSubsystemSilently(subsystem);
    }
    for (Subsystem subsystem : uninstallableSubsystems) {
        uninstallSubsystemSilently(subsystem);
    }
    RegionDigraph digraph = context().getService(RegionDigraph.class);
    for (Region region : deletableRegions) {
        digraph.removeRegion(region);
    }
    for (Bundle bundle : uninstallableBundles) {
        uninstallSilently(bundle);
    }
    bundleContext.removeServiceListener(subsystemEvents);
    for (ServiceRegistration registration : serviceRegistrations) Utils.unregisterQuietly(registration);
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Bundle(org.osgi.framework.Bundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) CoreOptions.streamBundle(org.ops4j.pax.exam.CoreOptions.streamBundle) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) Region(org.eclipse.equinox.region.Region) ServiceRegistration(org.osgi.framework.ServiceRegistration) After(org.junit.After)

Example 15 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class RootSubsystemTest method testRegion.

/*
	 * The root subsystem should be associated with the region in which the
	 * subsystems implementation bundle is installed.
	 */
@Test
public void testRegion() throws Exception {
    RegionDigraph digraph = context().getService(RegionDigraph.class);
    Bundle core = getSubsystemCoreBundle();
    Region kernel = digraph.getRegion(core);
    Subsystem root = getRootSubsystem();
    Bundle rootRegionContext = root.getBundleContext().getBundle();
    // Get the region containing the subsystem's region context bundle, 
    // which is the same thing as getting the region with which the 
    // subsystem is associated.
    Region region = digraph.getRegion(root.getBundleContext().getBundle());
    assertEquals("Wrong region", kernel, region);
    // Uninstall the core bundle to remove the persisted root subsystem.
    core.uninstall();
    // Clean up the lingering region context bundle.
    rootRegionContext.uninstall();
    // Create a new region and install the core bundle into it.
    Region user = digraph.createRegion("user");
    // Allow everything from the kernel region into the user region so the 
    // core bundle will resolve.
    user.connectRegion(kernel, digraph.createRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build());
    // Allow everything from the user region into the kernel region so the
    // root subsystem service can be found.
    kernel.connectRegion(user, digraph.createRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build());
    core = user.installBundle(normalizeBundleLocation(core.getLocation()));
    user = digraph.getRegion(core);
    core.start();
    root = getRootSubsystem();
    region = digraph.getRegion(root.getBundleContext().getBundle());
    // The root subsystem should now be in the new region.
    assertEquals("Wrong region", user, region);
    // should still be found and used.
    try {
        Subsystem applicationA = installSubsystemFromFile(root, APPLICATION_A);
        uninstallSubsystemSilently(applicationA);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) Region(org.eclipse.equinox.region.Region) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Aggregations

RegionDigraph (org.eclipse.equinox.region.RegionDigraph)16 Region (org.eclipse.equinox.region.Region)14 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 Bundle (org.osgi.framework.Bundle)4 Subsystem (org.osgi.service.subsystem.Subsystem)4 MapUtils.addToMapSet (org.apache.karaf.features.internal.util.MapUtils.addToMapSet)3 StandardRegionDigraph (org.eclipse.equinox.internal.region.StandardRegionDigraph)3 RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)3 BundleException (org.osgi.framework.BundleException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)2 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)2 Feature (org.apache.karaf.features.Feature)2 Test (org.junit.Test)2