Search in sources :

Example 1 with Config

use of org.opendaylight.controller.config.facade.xml.mapping.config.Config in project controller by opendaylight.

the class ConfigPusherImplTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    doReturn("content").when(yangStoreService).getModuleSource(any(SourceIdentifier.class));
    doReturn("mocked snapshot").when(mockedConfigSnapshot).toString();
    doReturn("<mocked-snapshot/>").when(mockedConfigSnapshot).getConfigSnapshot();
    doReturn(Collections.<Module>emptySet()).when(yangStoreService).getModules();
    final Config mock = mock(Config.class);
    doReturn("mocked config").when(mock).toString();
    doReturn(facade).when(facadeFactory).createFacade(anyString());
    doReturn(Sets.newHashSet()).when(facadeFactory).getCurrentCapabilities();
    doReturn(mock).when(facade).getConfigMapping();
    doNothing().when(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class), any(NotificationFilter.class), anyObject());
}
Also used : Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) NotificationFilter(javax.management.NotificationFilter) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener) Before(org.junit.Before)

Example 2 with Config

use of org.opendaylight.controller.config.facade.xml.mapping.config.Config 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 3 with Config

use of org.opendaylight.controller.config.facade.xml.mapping.config.Config in project controller by opendaylight.

the class ConfigSubsystemFacade method getConfiguration.

public Element getConfiguration(final Document document, final Datastore source, final Optional<String> maybeNamespace) {
    final ConfigTransactionClient registryClient;
    // in case of candidate, get current transaction representing candidate
    if (source == Datastore.running) {
        final ObjectName readTx = transactionProvider.getOrCreateReadTransaction();
        registryClient = configRegistryClient.getConfigTransactionClient(readTx);
    } else {
        registryClient = configRegistryClient.getConfigTransactionClient(transactionProvider.getOrCreateTransaction());
    }
    try {
        Element dataElement = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.<String>absent());
        final Set<ObjectName> instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider).queryInstances(configRegistryClient);
        final Config configMapping = new Config(transformMbeToModuleConfigs(yangStoreService.getModuleMXBeanEntryMap()), yangStoreService.getEnumResolver());
        ServiceRegistryWrapper serviceTracker = new ServiceRegistryWrapper(registryClient);
        dataElement = configMapping.toXml(instances, maybeNamespace, document, dataElement, serviceTracker);
        return dataElement;
    } finally {
        if (source == Datastore.running) {
            transactionProvider.closeReadTransaction();
        }
    }
}
Also used : ModuleConfig(org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) InstanceConfig(org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ConfigTransactionClient(org.opendaylight.controller.config.util.ConfigTransactionClient) ServiceRegistryWrapper(org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper) ObjectName(javax.management.ObjectName)

Example 4 with Config

use of org.opendaylight.controller.config.facade.xml.mapping.config.Config in project controller by opendaylight.

the class ConfigSubsystemFacade method getConfigMapping.

public Config getConfigMapping() {
    final YangStoreContext snapshot = yangStoreService.getCurrentSnapshot();
    Map<String, Map<String, ModuleConfig>> factories = transformMbeToModuleConfigs(snapshot.getModuleMXBeanEntryMap());
    Map<String, Map<Optional<Revision>, IdentityMapping>> identitiesMap = transformIdentities(snapshot.getModules());
    return new Config(factories, identitiesMap, snapshot.getEnumResolver());
}
Also used : YangStoreContext(org.opendaylight.controller.config.facade.xml.osgi.YangStoreContext) Revision(org.opendaylight.yangtools.yang.common.Revision) ModuleConfig(org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) InstanceConfig(org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)4 ObjectName (javax.management.ObjectName)3 InstanceConfig (org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig)2 ModuleConfig (org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig)2 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 NotificationFilter (javax.management.NotificationFilter)1 NotificationListener (javax.management.NotificationListener)1 Before (org.junit.Before)1 ConfigRegistry (org.opendaylight.controller.config.api.ConfigRegistry)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)1 ServiceRegistryWrapper (org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper)1 YangStoreContext (org.opendaylight.controller.config.facade.xml.osgi.YangStoreContext)1 ConfigRegistryJMXClient (org.opendaylight.controller.config.util.ConfigRegistryJMXClient)1 ConfigTransactionClient (org.opendaylight.controller.config.util.ConfigTransactionClient)1 Revision (org.opendaylight.yangtools.yang.common.Revision)1