X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2FBlueprintContainerRestartServiceImpl.java;h=05a796843aeaa9f3a6f15c31011992a1c38ad930;hp=5adb4e51a60c8c3e9674bf03e244ab6da969142c;hb=0e0e2378d379e2fbc12d8f93ef41b3267e10f83a;hpb=ab1fee874f408a740df16f55190610e1013446ac diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintContainerRestartServiceImpl.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintContainerRestartServiceImpl.java index 5adb4e51a6..05a796843a 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintContainerRestartServiceImpl.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintContainerRestartServiceImpl.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Deque; -import java.util.Dictionary; import java.util.Hashtable; import java.util.LinkedHashSet; import java.util.List; @@ -54,8 +53,8 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.blueprint.container.EventConstants; -import org.osgi.service.event.EventHandler; +import org.osgi.service.blueprint.container.BlueprintEvent; +import org.osgi.service.blueprint.container.BlueprintListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -88,12 +87,13 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo } public void restartContainer(final Bundle bundle, final List paths) { + LOG.debug("restartContainer for bundle {}", bundle); + if (restartExecutor.isShutdown()) { + LOG.debug("Already closed - returning"); return; } - LOG.debug("restartContainer for bundle {}", bundle); - restartExecutor.execute(() -> { blueprintExtenderService.destroyContainer(bundle, blueprintExtenderService.getContainer(bundle)); blueprintExtenderService.createContainer(bundle, paths); @@ -111,7 +111,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo restartExecutor.execute(() -> restartContainerAndDependentsInternal(bundle)); } - private void restartContainerAndDependentsInternal(Bundle forBundle) { + private void restartContainerAndDependentsInternal(final Bundle forBundle) { Preconditions.checkNotNull(blueprintExtenderService); Preconditions.checkNotNull(quiesceParticipant); @@ -131,9 +131,17 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo // restart config modules. final CountDownLatch containerCreationComplete = new CountDownLatch(containerBundles.size()); ServiceRegistration eventHandlerReg = registerEventHandler(forBundle.getBundleContext(), event -> { - LOG.debug("handleEvent {} for bundle {}", event.getTopic(), event.getProperty(EventConstants.BUNDLE)); - if (containerBundles.contains(event.getProperty(EventConstants.BUNDLE))) { + final Bundle bundle = event.getBundle(); + if (event.isReplay()) { + LOG.trace("Got replay BlueprintEvent {} for bundle {}", event.getType(), bundle); + return; + } + + LOG.debug("Got BlueprintEvent {} for bundle {}", event.getType(), bundle); + if (containerBundles.contains(bundle) + && (event.getType() == BlueprintEvent.CREATED || event.getType() == BlueprintEvent.FAILURE)) { containerCreationComplete.countDown(); + LOG.debug("containerCreationComplete is now {}", containerCreationComplete.getCount()); } }); @@ -150,7 +158,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo containerBundles, containerBundles.size() - containerCreationComplete.getCount()); return; } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { LOG.debug("CountDownLatch await was interrupted - returning"); return; } @@ -159,6 +167,8 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo // Now restart any associated config system Modules. restartConfigModules(forBundle.getBundleContext(), configModules); + + LOG.info("Finished restarting blueprint containers for bundle {} and its dependent bundles", forBundle); } /** @@ -207,7 +217,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo }, Collections.singletonList(nextBundle)); } - private void createContainers(List containerBundles) { + private void createContainers(final List containerBundles) { containerBundles.forEach(bundle -> { List paths = BlueprintBundleTracker.findBlueprintPaths(bundle); @@ -217,7 +227,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo }); } - private void restartConfigModules(BundleContext bundleContext, List> configModules) { if (configModules.isEmpty()) { return; @@ -236,21 +246,20 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo return; } - ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade("BlueprintContainerRestartService"); - try { + try (ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade( + "BlueprintContainerRestartService")) { restartConfigModules(configModules, configFacade); } catch (ParserConfigurationException | DocumentedException | ValidationException | ConflictingVersionException e) { LOG.error("Error restarting config modules", e); } finally { - configFacade.close(); bundleContext.ungetService(configFacadeFactoryRef); } } - private void restartConfigModules(List> configModules, - ConfigSubsystemFacade configFacade) throws ParserConfigurationException, DocumentedException, + private void restartConfigModules(final List> configModules, + final ConfigSubsystemFacade configFacade) throws ParserConfigurationException, DocumentedException, ValidationException, ConflictingVersionException { Document document = XmlUtil.newDocument(); @@ -274,7 +283,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo Element moduleElement = configMapping.moduleToXml(moduleNamespace, moduleId.getFactoryName(), moduleId.getInstanceName(), instanceON, document); modulesElement.appendChild(moduleElement); - } catch (InstanceNotFoundException e) { + } catch (final InstanceNotFoundException e) { LOG.warn("Error looking up config module: namespace {}, module name {}, instance {}", moduleNamespace, moduleId.getFactoryName(), moduleId.getInstanceName(), e); } @@ -300,8 +309,8 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo * @param containerBundles the current set of bundles containing blueprint containers * @param configModules the current set of bundles containing config modules */ - private void findDependentContainersRecursively(Bundle bundle, Set containerBundles, - List> configModules) { + private void findDependentContainersRecursively(final Bundle bundle, final Set containerBundles, + final List> configModules) { if (!containerBundles.add(bundle)) { // Already seen this bundle... return; @@ -324,8 +333,8 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo } } - private void possiblyAddConfigModuleIdentifier(ServiceReference reference, - List> configModules) { + private void possiblyAddConfigModuleIdentifier(final ServiceReference reference, + final List> configModules) { Object moduleNamespace = reference.getProperty(CONFIG_MODULE_NAMESPACE_PROP); if (moduleNamespace == null) { return; @@ -347,8 +356,8 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo } @Nullable - private String getRequiredConfigModuleProperty(String propName, Object moduleNamespace, - ServiceReference reference) { + private String getRequiredConfigModuleProperty(final String propName, final Object moduleNamespace, + final ServiceReference reference) { Object value = reference.getProperty(propName); if (value == null) { LOG.warn( @@ -360,15 +369,15 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo return value.toString(); } - private ServiceRegistration registerEventHandler(BundleContext bundleContext, EventHandler handler) { - Dictionary props = new Hashtable<>(); - props.put(org.osgi.service.event.EventConstants.EVENT_TOPIC, - new String[]{EventConstants.TOPIC_CREATED, EventConstants.TOPIC_FAILURE}); - return bundleContext.registerService(EventHandler.class.getName(), handler, props); + private ServiceRegistration registerEventHandler(final BundleContext bundleContext, + final BlueprintListener listener) { + return bundleContext.registerService(BlueprintListener.class.getName(), listener, new Hashtable<>()); } @Override public void close() { + LOG.debug("Closing"); + restartExecutor.shutdownNow(); } }