use of org.opendaylight.controller.config.api.ConfigRegistry in project controller by opendaylight.
the class BlueprintContainerRestartServiceImpl method restartConfigModules.
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();
}
use of org.opendaylight.controller.config.api.ConfigRegistry in project controller by opendaylight.
the class AbstractConfigTestBase method setup.
@Before
@SuppressWarnings("IllegalCatch")
public void setup() throws Exception {
String moduleName = getModuleName();
String instanceName = getInstanceName();
if (moduleName == null || instanceName == null) {
return;
}
LOG.info("Module: {} Instance: {} attempting to configure.", moduleName, instanceName);
Stopwatch stopWatch = Stopwatch.createStarted();
ObjectName objectName = null;
for (int i = 0; i < MODULE_TIMEOUT_MILLIS; i++) {
try {
ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory.getPlatformMBeanServer());
objectName = configRegistryClient.lookupConfigBean(moduleName, instanceName);
LOG.info("Module: {} Instance: {} ObjectName: {}.", moduleName, instanceName, objectName);
break;
} catch (final Exception e) {
if (i < MODULE_TIMEOUT_MILLIS) {
Thread.sleep(1);
continue;
} else {
throw e;
}
}
}
if (objectName != null) {
LOG.info("Module: {} Instance: {} configured after {} ms", moduleName, instanceName, stopWatch.elapsed(TimeUnit.MILLISECONDS));
} else {
throw new RuntimeException("NOT FOUND Module: " + moduleName + " Instance: " + instanceName + " configured after " + stopWatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
}
}
Aggregations