Search in sources :

Example 1 with ConfigRegistry

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();
}
Also used : ConfigRegistry(org.opendaylight.controller.config.api.ConfigRegistry) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) Element(org.w3c.dom.Element) InstanceNotFoundException(javax.management.InstanceNotFoundException) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Document(org.w3c.dom.Document) ConfigRegistryJMXClient(org.opendaylight.controller.config.util.ConfigRegistryJMXClient) ObjectName(javax.management.ObjectName)

Example 2 with ConfigRegistry

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");
    }
}
Also used : ConfigRegistry(org.opendaylight.controller.config.api.ConfigRegistry) Stopwatch(com.google.common.base.Stopwatch) ConfigRegistryJMXClient(org.opendaylight.controller.config.util.ConfigRegistryJMXClient) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Aggregations

ObjectName (javax.management.ObjectName)2 ConfigRegistry (org.opendaylight.controller.config.api.ConfigRegistry)2 ConfigRegistryJMXClient (org.opendaylight.controller.config.util.ConfigRegistryJMXClient)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 Before (org.junit.Before)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)1 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)1 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1