Fix (and suppress) some static code analysis warnings in blueprint
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / BlueprintContainerRestartServiceImpl.java
index e58c956b5aa4229611e98ce8f44fd0d1e90499d5..7985c5bce00e2090016986394bc17287033b866e 100644 (file)
@@ -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";
@@ -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,7 +145,12 @@ class BlueprintContainerRestartServiceImpl implements AutoCloseable, BlueprintCo
 
 
         try {
-            containerCreationComplete.await(5, TimeUnit.MINUTES);
+            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 (InterruptedException e) {
             LOG.debug("CountDownLatch await was interrupted - returning");
             return;
@@ -230,14 +237,13 @@ 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);
         }