X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2FBlueprintContainerRestartServiceImpl.java;h=4448c44287890c8fd2d785465bbb7b7749828044;hb=93b203c3e2223018000af3472e8eca5363152910;hp=e58c956b5aa4229611e98ce8f44fd0d1e90499d5;hpb=4db37f2ab0c8174d1990e2262cb466fe22352573;p=controller.git 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 e58c956b5a..4448c44287 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 @@ -68,6 +68,7 @@ import org.w3c.dom.Element; */ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintContainerRestartService { private static final Logger LOG = LoggerFactory.getLogger(BlueprintContainerRestartServiceImpl.class); + private static final int CONTAINER_CREATE_TIMEOUT_IN_MINUTES = 5; private static final String CONFIG_MODULE_NAMESPACE_PROP = "config-module-namespace"; private static final String CONFIG_MODULE_NAME_PROP = "config-module-name"; private static final String CONFIG_INSTANCE_NAME_PROP = "config-instance-name"; @@ -110,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); @@ -130,8 +131,9 @@ 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 = (Bundle) event.getProperty(EventConstants.BUNDLE); + LOG.debug("handleEvent {} for bundle {}", event.getTopic(), bundle); + if (containerBundles.contains(bundle)) { containerCreationComplete.countDown(); } }); @@ -143,8 +145,13 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo try { - containerCreationComplete.await(5, TimeUnit.MINUTES); - } catch (InterruptedException e) { + if (!containerCreationComplete.await(CONTAINER_CREATE_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES)) { + LOG.warn("Failed to restart all blueprint containers within {} minutes. Attempted to restart {} {} " + + "but only {} completed restart", CONTAINER_CREATE_TIMEOUT_IN_MINUTES, containerBundles.size(), + containerBundles, containerBundles.size() - containerCreationComplete.getCount()); + return; + } + } catch (final InterruptedException e) { LOG.debug("CountDownLatch await was interrupted - returning"); return; } @@ -201,7 +208,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); @@ -211,7 +218,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo }); } - private void restartConfigModules(BundleContext bundleContext, List> configModules) { if (configModules.isEmpty()) { return; @@ -230,21 +237,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(); @@ -268,7 +274,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); } @@ -294,8 +300,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; @@ -318,8 +324,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; @@ -341,8 +347,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( @@ -354,7 +360,7 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo return value.toString(); } - private ServiceRegistration registerEventHandler(BundleContext bundleContext, EventHandler handler) { + private ServiceRegistration registerEventHandler(final BundleContext bundleContext, final EventHandler handler) { Dictionary props = new Hashtable<>(); props.put(org.osgi.service.event.EventConstants.EVENT_TOPIC, new String[]{EventConstants.TOPIC_CREATED, EventConstants.TOPIC_FAILURE});