+
+ try {
+ containerCreationComplete.await(5, TimeUnit.MINUTES);
+ } catch(InterruptedException e) {
+ LOG.debug("CountDownLatch await was interrupted - returning");
+ return;
+ }
+
+ AriesFrameworkUtil.safeUnregisterService(eventHandlerReg);
+
+ // Now restart any associated config system Modules.
+ restartConfigModules(forBundle.getBundleContext(), configModules);
+ }
+
+ private void restartConfigModules(BundleContext bundleContext, List<Entry<String, ModuleIdentifier>> configModules) {
+ if(configModules.isEmpty()) {
+ return;
+ }
+
+ ServiceReference<ConfigSubsystemFacadeFactory> configFacadeFactoryRef =
+ bundleContext.getServiceReference(ConfigSubsystemFacadeFactory.class);
+ if(configFacadeFactoryRef == null) {
+ LOG.debug("ConfigSubsystemFacadeFactory service reference not found");
+ return;
+ }
+
+ ConfigSubsystemFacadeFactory configFacadeFactory = bundleContext.getService(configFacadeFactoryRef);
+ if(configFacadeFactory == null) {
+ LOG.debug("ConfigSubsystemFacadeFactory service not found");
+ return;
+ }
+
+ ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade("BlueprintContainerRestartService");
+ try {
+ restartConfigModules(configModules, configFacade);
+ } catch(Exception e) {
+ LOG.error("Error restarting config modules", e);
+ } finally {
+ configFacade.close();
+ bundleContext.ungetService(configFacadeFactoryRef);
+ }
+
+ }
+
+ private void restartConfigModules(List<Entry<String, ModuleIdentifier>> configModules,
+ ConfigSubsystemFacade configFacade) throws ParserConfigurationException, DocumentedException,
+ ValidationException, ConflictingVersionException {
+
+ Document document = XmlUtil.newDocument();
+ Element dataElement = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.<String>absent());
+ Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY,
+ Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
+ dataElement.appendChild(modulesElement);
+
+ Config configMapping = configFacade.getConfigMapping();
+
+ ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory.getPlatformMBeanServer());
+ for(Entry<String, ModuleIdentifier> entry: configModules) {
+ String moduleNamespace = entry.getKey();
+ ModuleIdentifier moduleId = entry.getValue();
+ try {
+ ObjectName instanceON = configRegistryClient.lookupConfigBean(moduleId.getFactoryName(),
+ moduleId.getInstanceName());
+
+ LOG.debug("Found config module instance ObjectName: {}", instanceON);
+
+ Element moduleElement = configMapping.moduleToXml(moduleNamespace, moduleId.getFactoryName(),
+ moduleId.getInstanceName(), instanceON, document);
+ modulesElement.appendChild(moduleElement);
+ } catch(InstanceNotFoundException e) {
+ LOG.warn("Error looking up config module: namespace {}, module name {}, instance {}",
+ moduleNamespace, moduleId.getFactoryName(), moduleId.getInstanceName(), e);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Pushing config xml: {}", XmlUtil.toString(dataElement));
+ }
+
+ ConfigExecution execution = new ConfigExecution(configMapping, XmlElement.fromDomElement(dataElement),
+ TestOption.testThenSet, EditStrategyType.recreate);
+ configFacade.executeConfigExecution(execution);
+ configFacade.commitSilentTransaction();