*/
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";
// 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();
}
});
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;
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);
}