- private void restartConfigModules(final BundleContext bundleContext, final 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;
- }
-
- try (ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade(
- "BlueprintContainerRestartService")) {
- restartConfigModules(configModules, configFacade);
- } catch (ParserConfigurationException | DocumentedException | ValidationException
- | ConflictingVersionException e) {
- LOG.error("Error restarting config modules", e);
- } finally {
- bundleContext.ungetService(configFacadeFactoryRef);
- }
-
- }
-
- private void restartConfigModules(final List<Entry<String, ModuleIdentifier>> configModules,
- final 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 (final 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();
- }
-