Search in sources :

Example 1 with ConfigExecution

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

the class ConfigPusherImplTest method testSuccessConflictingVersionException.

@Test
public void testSuccessConflictingVersionException() throws Exception {
    doReturn(new TreeSet<>(Lists.newArrayList("namespace?module=module&revision=2012-12-12"))).when(mockedConfigSnapshot).getCapabilities();
    final Capability cap = mock(Capability.class);
    doReturn("namespace?module=module&revision=2012-12-12").when(cap).getCapabilityUri();
    doReturn(Sets.newHashSet(cap)).when(facadeFactory).getCurrentCapabilities();
    final ConfigExecution cfgExec = mock(ConfigExecution.class);
    doReturn("cfg exec").when(cfgExec).toString();
    doReturn(cfgExec).when(facade).getConfigExecution(any(Config.class), any(Element.class));
    doNothing().when(facade).executeConfigExecution(any(ConfigExecution.class));
    doThrow(ConflictingVersionException.class).doThrow(ConflictingVersionException.class).doReturn(mock(CommitStatus.class)).when(facade).commitSilentTransaction();
    doReturn(Sets.newHashSet(module)).when(yangStoreService).getModules();
    final ConfigPusherImpl configPusher = new ConfigPusherImpl(facadeFactory, 5000, 5000);
    configPusher.pushConfigs(Collections.singletonList(mockedConfigSnapshot));
    configPusher.processSingle(Lists.<AutoCloseable>newArrayList(), mBeanServer, mockedAggregator, true);
    verify(facade, times(3)).executeConfigExecution(cfgExec);
    verify(facade, times(3)).commitSilentTransaction();
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) Capability(org.opendaylight.controller.config.util.capability.Capability) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) Element(org.w3c.dom.Element) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) Test(org.junit.Test)

Example 2 with ConfigExecution

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

the class ConfigPusherImplTest method testPersisterSuccessfulPush.

@Test
public void testPersisterSuccessfulPush() throws Exception {
    doReturn(new TreeSet<>(Lists.newArrayList("namespace?module=module&revision=2012-12-12"))).when(mockedConfigSnapshot).getCapabilities();
    final Capability cap = mock(Capability.class);
    doReturn("namespace?module=module&revision=2012-12-12").when(cap).getCapabilityUri();
    doReturn(Sets.newHashSet(cap)).when(facadeFactory).getCurrentCapabilities();
    final ConfigExecution cfgExec = mock(ConfigExecution.class);
    doReturn("cfg exec").when(cfgExec).toString();
    doReturn(cfgExec).when(facade).getConfigExecution(any(Config.class), any(Element.class));
    doNothing().when(facade).executeConfigExecution(any(ConfigExecution.class));
    doReturn(mock(CommitStatus.class)).when(facade).commitSilentTransaction();
    doReturn(Sets.newHashSet(module)).when(yangStoreService).getModules();
    final ConfigPusherImpl configPusher = new ConfigPusherImpl(facadeFactory, 0, 0);
    configPusher.pushConfigs(Collections.singletonList(mockedConfigSnapshot));
    configPusher.processSingle(Lists.<AutoCloseable>newArrayList(), mBeanServer, mockedAggregator, true);
    verify(facade).executeConfigExecution(cfgExec);
    verify(facade).commitSilentTransaction();
}
Also used : Capability(org.opendaylight.controller.config.util.capability.Capability) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) Element(org.w3c.dom.Element) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) Test(org.junit.Test)

Example 3 with ConfigExecution

use of org.opendaylight.controller.config.facade.xml.ConfigExecution 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 4 with ConfigExecution

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

the class ConfigPusherImpl method pushConfig.

private synchronized boolean pushConfig(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException {
    Element xmlToBePersisted;
    try {
        xmlToBePersisted = XmlUtil.readXmlToElement(configSnapshotHolder.getConfigSnapshot());
    } catch (SAXException | IOException e) {
        throw new IllegalStateException("Cannot parse " + configSnapshotHolder, e);
    }
    LOG.trace("Pushing last configuration to config mapping: {}", configSnapshotHolder);
    Stopwatch stopwatch = Stopwatch.createStarted();
    final ConfigSubsystemFacade currentFacade = this.facade.createFacade("config-push");
    try {
        ConfigExecution configExecution = createConfigExecution(xmlToBePersisted, currentFacade);
        executeWithMissingModuleFactoryRetries(currentFacade, configExecution);
    } catch (ValidationException | DocumentedException | ModuleFactoryNotFoundException e) {
        LOG.trace("Validation for config: {} failed", configSnapshotHolder, e);
        throw new ConfigSnapshotFailureException(configSnapshotHolder.toString(), "edit", e);
    }
    try {
        currentFacade.commitSilentTransaction();
    } catch (ValidationException | DocumentedException e) {
        throw new ConfigSnapshotFailureException(configSnapshotHolder.toString(), "commit", e);
    }
    LOG.trace("Last configuration loaded successfully");
    LOG.trace("Total time spent {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
    return true;
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Element(org.w3c.dom.Element) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) ConfigSubsystemFacade(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) SAXException(org.xml.sax.SAXException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException)

Example 5 with ConfigExecution

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

the class ConfigPusherImplTest method testPersisterConflictingVersionException.

@Test
public void testPersisterConflictingVersionException() throws Exception {
    doReturn(new TreeSet<>(Lists.newArrayList("namespace?module=module&revision=2012-12-12"))).when(mockedConfigSnapshot).getCapabilities();
    final Capability cap = mock(Capability.class);
    doReturn("namespace?module=module&revision=2012-12-12").when(cap).getCapabilityUri();
    doReturn(Sets.newHashSet(cap)).when(facadeFactory).getCurrentCapabilities();
    final ConfigExecution cfgExec = mock(ConfigExecution.class);
    doReturn("cfg exec").when(cfgExec).toString();
    doReturn(cfgExec).when(facade).getConfigExecution(any(Config.class), any(Element.class));
    doNothing().when(facade).executeConfigExecution(any(ConfigExecution.class));
    doThrow(ConflictingVersionException.class).when(facade).commitSilentTransaction();
    doReturn(Sets.newHashSet(module)).when(yangStoreService).getModules();
    final ConfigPusherImpl configPusher = new ConfigPusherImpl(facadeFactory, 0, 0);
    configPusher.pushConfigs(Collections.singletonList(mockedConfigSnapshot));
    try {
        configPusher.processSingle(Lists.<AutoCloseable>newArrayList(), mBeanServer, mockedAggregator, true);
    } catch (final IllegalStateException e) {
        Throwable cause = Throwables.getRootCause(e);
        assertTrue(cause instanceof ConflictingVersionException);
        return;
    }
    fail();
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) Capability(org.opendaylight.controller.config.util.capability.Capability) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) Element(org.w3c.dom.Element) Test(org.junit.Test)

Aggregations

ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)5 Element (org.w3c.dom.Element)5 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)4 Test (org.junit.Test)3 Capability (org.opendaylight.controller.config.util.capability.Capability)3 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)2 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 ObjectName (javax.management.ObjectName)1 ConfigRegistry (org.opendaylight.controller.config.api.ConfigRegistry)1 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 ValidationException (org.opendaylight.controller.config.api.ValidationException)1 ConfigSubsystemFacade (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade)1 ConfigRegistryJMXClient (org.opendaylight.controller.config.util.ConfigRegistryJMXClient)1 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)1 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)1 Document (org.w3c.dom.Document)1