Search in sources :

Example 1 with ConfigRegistryJMXClient

use of org.opendaylight.controller.config.util.ConfigRegistryJMXClient 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 ConfigRegistryJMXClient

use of org.opendaylight.controller.config.util.ConfigRegistryJMXClient 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)

Example 3 with ConfigRegistryJMXClient

use of org.opendaylight.controller.config.util.ConfigRegistryJMXClient in project controller by opendaylight.

the class AbstractConfigTest method initConfigTransactionManagerImpl.

// this method should be called in @Before
protected void initConfigTransactionManagerImpl(final ModuleFactoriesResolver resolver) {
    final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    this.configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(platformMBeanServer);
    initBundleContext();
    this.baseJmxRegistrator = new BaseJMXRegistrator(platformMBeanServer);
    this.configRegistry = new ConfigRegistryImpl(resolver, platformMBeanServer, this.baseJmxRegistrator, new BindingContextProvider() {

        @Override
        public synchronized void update(final ClassLoadingStrategy classLoadingStrategy, final SchemaContextProvider ctxProvider) {
        // NOOP
        }

        @Override
        public synchronized BindingRuntimeContext getBindingContext() {
            return getBindingRuntimeContext();
        }
    });
    this.notifyingConfigRegistry = new JMXNotifierConfigRegistry(this.configRegistry, platformMBeanServer);
    try {
        this.configRegistryJMXRegistrator.registerToJMXNoNotifications(this.configRegistry);
        this.configRegistryJMXRegistrator.registerToJMX(this.notifyingConfigRegistry);
    } catch (final InstanceAlreadyExistsException e) {
        throw new RuntimeException(e);
    }
    this.configRegistryClient = new ConfigRegistryJMXClient(platformMBeanServer);
    this.currentBundleContextServiceRegistrationHandler = new RecordingBundleContextServiceRegistrationHandler();
}
Also used : JMXNotifierConfigRegistry(org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry) BindingContextProvider(org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider) BaseJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy) SchemaContextProvider(org.opendaylight.yangtools.yang.model.api.SchemaContextProvider) ConfigRegistryJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator) ConfigRegistryJMXClient(org.opendaylight.controller.config.util.ConfigRegistryJMXClient) MBeanServer(javax.management.MBeanServer)

Aggregations

ConfigRegistryJMXClient (org.opendaylight.controller.config.util.ConfigRegistryJMXClient)3 ObjectName (javax.management.ObjectName)2 ConfigRegistry (org.opendaylight.controller.config.api.ConfigRegistry)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanServer (javax.management.MBeanServer)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 BaseJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator)1 ConfigRegistryJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator)1 JMXNotifierConfigRegistry (org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry)1 BindingContextProvider (org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider)1 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)1 ClassLoadingStrategy (org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy)1 SchemaContextProvider (org.opendaylight.yangtools.yang.model.api.SchemaContextProvider)1