X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2FBlueprintBundleTracker.java;h=657d6451e882b72d730bc01ae4977ef777a58812;hb=82284ce97ea00c26af1cad479211ce1fed68a533;hp=08a8da0bb6d98575be91098e124ce85fe239a35f;hpb=0e0e2378d379e2fbc12d8f93ef41b3267e10f83a;p=controller.git diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java index 08a8da0bb6..657d6451e8 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java @@ -11,22 +11,22 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Dictionary; import java.util.Enumeration; import java.util.HashSet; -import java.util.Hashtable; import java.util.List; -import javax.annotation.Nullable; +import java.util.Map; import org.apache.aries.blueprint.NamespaceHandler; import org.apache.aries.blueprint.services.BlueprintExtenderService; import org.apache.aries.quiesce.participant.QuiesceParticipant; import org.apache.aries.util.AriesFrameworkUtil; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.controller.blueprint.ext.OpendaylightNamespaceHandler; -import org.opendaylight.controller.config.api.ConfigSystemService; +import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.SynchronousBundleListener; @@ -51,7 +51,8 @@ import org.slf4j.LoggerFactory; public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCustomizer, BlueprintListener, SynchronousBundleListener { private static final Logger LOG = LoggerFactory.getLogger(BlueprintBundleTracker.class); - private static final String BLUEPRINT_FILE_PATH = "org/opendaylight/blueprint/"; + private static final String ODL_CUSTOM_BLUEPRINT_FILE_PATH = "org/opendaylight/blueprint/"; + private static final String STANDARD_BLUEPRINT_FILE_PATH = "OSGI-INF/blueprint/"; private static final String BLUEPRINT_FLE_PATTERN = "*.xml"; private static final long SYSTEM_BUNDLE_ID = 0; @@ -74,6 +75,9 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus public void start(final BundleContext context) { LOG.info("Starting {}", getClass().getSimpleName()); + // CONTROLLER-1867: force UntrustedXML initialization, so that it uses our TCCL to initialize + UntrustedXML.newDocumentBuilder(); + restartService = new BlueprintContainerRestartServiceImpl(); bundleContext = context; @@ -84,7 +88,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus bundleTracker = new BundleTracker<>(context, Bundle.ACTIVE, this); - blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class.getName(), + blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class, new ServiceTrackerCustomizer() { @Override public BlueprintExtenderService addingService( @@ -104,7 +108,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus }); blueprintExtenderServiceTracker.open(); - quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class.getName(), + quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class, new ServiceTrackerCustomizer() { @Override public QuiesceParticipant addingService( @@ -146,21 +150,20 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus restartService.setBlueprintExtenderService(blueprintExtenderService); - blueprintContainerRestartReg = bundleContext.registerService( - BlueprintContainerRestartService.class.getName(), restartService, new Hashtable<>()); + blueprintContainerRestartReg = bundleContext.registerService(BlueprintContainerRestartService.class, + restartService, null); return blueprintExtenderService; } private void registerNamespaceHandler(final BundleContext context) { - Dictionary props = new Hashtable<>(); - props.put("osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_1_0_0); - namespaceReg = context.registerService(NamespaceHandler.class.getName(), - new OpendaylightNamespaceHandler(), props); + namespaceReg = context.registerService(NamespaceHandler.class, new OpendaylightNamespaceHandler(), + FrameworkUtil.asDictionary(Map.of( + "osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_2_0_0))); } private void registerBlueprintEventHandler(final BundleContext context) { - eventHandlerReg = context.registerService(BlueprintListener.class.getName(), this, new Hashtable<>()); + eventHandlerReg = context.registerService(BlueprintListener.class, this, null); } /** @@ -208,7 +211,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } if (bundle.getState() == Bundle.ACTIVE) { - List paths = findBlueprintPaths(bundle); + List paths = findBlueprintPaths(bundle, ODL_CUSTOM_BLUEPRINT_FILE_PATH); if (!paths.isEmpty()) { LOG.info("Creating blueprint container for bundle {} with paths {}", bundle, paths); @@ -232,7 +235,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * @param event the event to handle */ @Override - public void blueprintEvent(BlueprintEvent event) { + public void blueprintEvent(final BlueprintEvent event) { if (event.getType() == BlueprintEvent.CREATED) { LOG.info("Blueprint container for bundle {} was successfully created", event.getBundle()); return; @@ -255,13 +258,17 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } } - @SuppressWarnings({ "rawtypes", "unchecked" }) static List findBlueprintPaths(final Bundle bundle) { - Enumeration rntries = bundle.findEntries(BLUEPRINT_FILE_PATH, BLUEPRINT_FLE_PATTERN, false); + List paths = findBlueprintPaths(bundle, STANDARD_BLUEPRINT_FILE_PATH); + return !paths.isEmpty() ? paths : findBlueprintPaths(bundle, ODL_CUSTOM_BLUEPRINT_FILE_PATH); + } + + private static List findBlueprintPaths(final Bundle bundle, final String path) { + Enumeration rntries = bundle.findEntries(path, BLUEPRINT_FLE_PATTERN, false); if (rntries == null) { - return Collections.emptyList(); + return List.of(); } else { - return Collections.list((Enumeration)rntries); + return List.copyOf(Collections.list(rntries)); } } @@ -270,12 +277,6 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus restartService.close(); - // Close all CSS modules first. - ConfigSystemService configSystem = getOSGiService(ConfigSystemService.class); - if (configSystem != null) { - configSystem.closeAllConfigModules(); - } - LOG.info("Shutting down all blueprint containers..."); Collection containerBundles = new HashSet<>(Arrays.asList(bundleContext.getBundles())); @@ -294,7 +295,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus LOG.info("Shutdown of blueprint containers complete"); } - private List getBundlesToDestroy(final Collection containerBundles) { + private static List getBundlesToDestroy(final Collection containerBundles) { List bundlesToDestroy = new ArrayList<>(); // Find all container bundles that either have no registered services or whose services are no @@ -315,7 +316,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } if (!bundlesToDestroy.isEmpty()) { - Collections.sort(bundlesToDestroy, (b1, b2) -> (int) (b2.getLastModified() - b1.getLastModified())); + bundlesToDestroy.sort((b1, b2) -> (int) (b2.getLastModified() - b1.getLastModified())); LOG.debug("Selected bundles {} for destroy (no services in use)", bundlesToDestroy); } else { @@ -339,8 +340,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus return bundlesToDestroy; } - @Nullable - private Bundle findBundleWithHighestUsedServiceId(final Collection containerBundles) { + private static @Nullable Bundle findBundleWithHighestUsedServiceId(final Collection containerBundles) { ServiceReference highestServiceRef = null; for (Bundle bundle : containerBundles) { ServiceReference[] references = bundle.getRegisteredServices(); @@ -371,28 +371,4 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus Bundle[] usingBundles = ref.getUsingBundles(); return usingBundles != null ? usingBundles.length : 0; } - - private T getOSGiService(final Class serviceInterface) { - try { - ServiceReference serviceReference = bundleContext.getServiceReference(serviceInterface); - if (serviceReference == null) { - LOG.warn("{} service reference not found", serviceInterface.getSimpleName()); - return null; - } - - T service = bundleContext.getService(serviceReference); - if (service == null) { - // This could happen on shutdown if the service was already unregistered so we log as debug. - LOG.debug("{} service instance was not found", serviceInterface.getSimpleName()); - } - - return service; - } catch (final IllegalStateException e) { - // This is thrown if the BundleContext is no longer valid which is possible on shutdown so we - // log as debug. - LOG.debug("Error obtaining OSGi service {}", serviceInterface.getSimpleName(), e); - } - - return null; - } }