Skip to content

Commit

Permalink
[ARIES-1383] Provide option to disable the provisioning of dependenci…
Browse files Browse the repository at this point in the history
…es at install time.

Composites in the INSTALLING state and having apache-aries-provision-dependencies:=resolve must have their export sharing policies set in order for any offered capabilities
to be considered valid as part of computing the dependencies of another subsystem having the same state and directive value. Currently, a brute force method is used whereby
all composites fitting the above criteria will have their export policies temporarily enabled. Any that did not end up offering a capability used to resolve the other
subsystem will have their policies rolled back.

Plus test.

git-svn-id: https://svn.apache.org/repos/asf/aries/trunk@1720175 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
John Ross committed Dec 15, 2015
1 parent 645a92b commit afe81b7
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 22 deletions.
Expand Up @@ -14,7 +14,6 @@
package org.apache.aries.subsystem.core.internal;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -50,7 +49,6 @@
import org.osgi.service.coordinator.Coordination;
import org.osgi.service.coordinator.CoordinationException;
import org.osgi.service.coordinator.Participant;
import org.osgi.service.resolver.ResolutionException;
import org.osgi.service.subsystem.Subsystem;
import org.osgi.service.subsystem.Subsystem.State;
import org.osgi.service.subsystem.SubsystemConstants;
Expand Down Expand Up @@ -134,6 +132,10 @@ private Object doRun() {
// If necessary, install the dependencies.
if (State.INSTALLING.equals(target.getState()) &&
!Utils.isProvisionDependenciesInstall(target)) {
// The following line is necessary in order to ensure that
// the export sharing policies of composites are in place
// for capability validation.
setExportPolicyOfAllInstallingSubsystemsWithProvisionDependenciesResolve(coordination);
Collection<Subsystem> subsystems = new ArrayList<Subsystem>();
subsystems.addAll(Activator.getInstance().getSubsystems().getChildren(target));
subsystems.addAll(target.getParents());
Expand Down Expand Up @@ -302,7 +304,7 @@ private static void resolve(BasicSubsystem subsystem, Coordination coordination)
}
}

private static void setExportIsolationPolicy(BasicSubsystem subsystem, Coordination coordination) throws InvalidSyntaxException, IOException, BundleException, URISyntaxException, ResolutionException {
private static void setExportIsolationPolicy(final BasicSubsystem subsystem, Coordination coordination) throws InvalidSyntaxException {
if (!subsystem.isComposite())
return;
final Region from = ((BasicSubsystem)subsystem.getParents().iterator().next()).getRegion();
Expand All @@ -317,15 +319,39 @@ private static void setExportIsolationPolicy(BasicSubsystem subsystem, Coordinat
if (logger.isDebugEnabled())
logger.debug("Establishing region connection: from=" + from
+ ", to=" + to + ", filter=" + regionFilter);
from.connectRegion(to, regionFilter);
try {
from.connectRegion(to, regionFilter);
}
catch (BundleException e) {
// TODO Assume this means that the export sharing policy has already
// been set. Bad assumption?
return;
}
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination coordination) throws Exception {
// Nothing.
// It may be necessary to rollback the export sharing policy
// even when the coordination did not fail. For example, this
// might have been a subsystem whose export sharing policy was
// set just in case it offered dependencies for some other
// subsystem.
unsetExportIsolationPolicyIfNecessary();
}

@Override
public void failed(Coordination coordination) throws Exception {
// Nothing to do because a coordination is always ended.
}

private void unsetExportIsolationPolicyIfNecessary() throws BundleException, InvalidSyntaxException {
if (!EnumSet.of(State.INSTALLING, State.INSTALLED).contains(subsystem.getState())) {
// The subsystem is either RESOLVED or ACTIVE and therefore
// does not require a rollback.
return;
}
// The subsystem is either INSTALLING or INSTALLED and therefore
// requires a rollback since the export sharing policy must only
// be set upon entering the RESOLVED state.
RegionUpdater updater = new RegionUpdater(from, to);
updater.addRequirements(null);
}
Expand Down Expand Up @@ -533,4 +559,14 @@ private static void logFailedResolution(BasicSubsystem subsystem, Collection<Bun
}
logger.error(diagnostics.toString());
}

private static void setExportPolicyOfAllInstallingSubsystemsWithProvisionDependenciesResolve(Coordination coordination) throws InvalidSyntaxException {
for (BasicSubsystem subsystem : Activator.getInstance().getSubsystems().getSubsystems()) {
if (!State.INSTALLING.equals(subsystem.getState())
|| Utils.isProvisionDependenciesInstall(subsystem)) {
continue;
}
setExportIsolationPolicy(subsystem, coordination);
}
}
}
Expand Up @@ -194,13 +194,14 @@ private InputStream createCoreFragment() {
@SuppressWarnings("rawtypes")
protected Collection<ServiceRegistration> serviceRegistrations = new ArrayList<ServiceRegistration>();

protected final List<Region> deletableRegions = new ArrayList<Region>();
protected final List<Subsystem> stoppableSubsystems = new ArrayList<Subsystem>();
protected final List<Bundle> uninstallableBundles = new ArrayList<Bundle>();
protected final List<Subsystem> uninstallableSubsystems = new ArrayList<Subsystem>();
protected final List<Region> deletableRegions = Collections.synchronizedList(new ArrayList<Region>());
protected final List<Subsystem> stoppableSubsystems = Collections.synchronizedList(new ArrayList<Subsystem>());
protected final List<Bundle> uninstallableBundles = Collections.synchronizedList(new ArrayList<Bundle>());
protected final List<Subsystem> uninstallableSubsystems = Collections.synchronizedList(new ArrayList<Subsystem>());

@Before
public void setUp() throws Exception {
serviceRegistrations.clear();
deletableRegions.clear();
stoppableSubsystems.clear();
uninstallableBundles.clear();
Expand Down Expand Up @@ -232,7 +233,6 @@ public void tearDown() throws Exception
bundleContext.removeServiceListener(subsystemEvents);
for (ServiceRegistration registration : serviceRegistrations)
Utils.unregisterQuietly(registration);
serviceRegistrations.clear();
}

protected void createApplications() throws Exception {
Expand Down

0 comments on commit afe81b7

Please sign in to comment.