Search in sources :

Example 1 with Capability

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

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

use of org.opendaylight.controller.config.util.capability.Capability in project controller by opendaylight.

the class YangStoreService method notifyListeners.

void notifyListeners(final YangStoreSnapshot previous, final YangStoreSnapshot current) {
    final Set<Module> prevModules = previous.getModules();
    final Set<Module> currModules = current.getModules();
    final Set<Module> removed = Sets.difference(prevModules, currModules);
    final Set<Module> added = Sets.difference(currModules, prevModules);
    final Set<Capability> addedCaps = toCapabilities(added, current);
    final Set<Capability> removedCaps = toCapabilities(removed, current);
    synchronized (this.listeners) {
        for (final ModuleListener listener : this.listeners) {
            listener.onCapabilitiesChanged(addedCaps, removedCaps);
        }
    }
}
Also used : ModuleListener(org.opendaylight.controller.config.util.capability.ModuleListener) Capability(org.opendaylight.controller.config.util.capability.Capability) YangModuleCapability(org.opendaylight.controller.config.util.capability.YangModuleCapability) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 4 with Capability

use of org.opendaylight.controller.config.util.capability.Capability in project controller by opendaylight.

the class ConfigPersisterNotificationListener method handleAfterCommitNotification.

private void handleAfterCommitNotification() {
    try {
        final Set<Capability> currentCapabilities = facade.getCurrentCapabilities();
        final Element configSnapshot = facade.createFacade("config-persister").getConfiguration(XmlUtil.newDocument(), Datastore.running, Optional.<String>absent());
        persisterAggregator.persistConfig(new CapabilityStrippingConfigSnapshotHolder(configSnapshot, ConfigPusherImpl.transformCapabilities(currentCapabilities)));
        LOG.trace("Configuration persisted successfully");
    } catch (final IOException e) {
        throw new RuntimeException("Unable to persist configuration snapshot", e);
    }
}
Also used : Capability(org.opendaylight.controller.config.util.capability.Capability) Element(org.w3c.dom.Element) IOException(java.io.IOException)

Example 5 with Capability

use of org.opendaylight.controller.config.util.capability.Capability in project controller by opendaylight.

the class ConfigSubsystemFacadeFactory method getCurrentCapabilities.

public Set<Capability> getCurrentCapabilities() {
    Set<Module> modules = yangStoreService.getModules();
    final Set<Capability> capabilities = Sets.newHashSet();
    for (Module module : modules) {
        capabilities.add(new YangModuleCapability(module, yangStoreService.getModuleSource(RevisionSourceIdentifier.create(module.getName(), module.getRevision()))));
    }
    return capabilities;
}
Also used : Capability(org.opendaylight.controller.config.util.capability.Capability) YangModuleCapability(org.opendaylight.controller.config.util.capability.YangModuleCapability) Module(org.opendaylight.yangtools.yang.model.api.Module) YangModuleCapability(org.opendaylight.controller.config.util.capability.YangModuleCapability)

Aggregations

Capability (org.opendaylight.controller.config.util.capability.Capability)7 Element (org.w3c.dom.Element)4 Test (org.junit.Test)3 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)3 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)3 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)2 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)2 YangModuleCapability (org.opendaylight.controller.config.util.capability.YangModuleCapability)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 ModuleListener (org.opendaylight.controller.config.util.capability.ModuleListener)1