Search in sources :

Example 6 with Capability

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

Example 7 with Capability

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

the class ConfigPusherImpl method waitForCapabilities.

private void waitForCapabilities(final Set<String> expectedCapabilities, final String idForReporting) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    ConfigPusherException lastException;
    do {
        try {
            final Set<Capability> currentCaps = facade.getCurrentCapabilities();
            final Set<String> notFoundCapabilities = computeNotFoundCapabilities(expectedCapabilities, currentCaps);
            if (notFoundCapabilities.isEmpty()) {
                return;
            } else {
                LOG.debug("Netconf server did not provide required capabilities for {} ", idForReporting, "Expected but not found: {}, all expected {}, current {}", notFoundCapabilities, expectedCapabilities, currentCaps);
                throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundCapabilities, notFoundCapabilities);
            }
        } catch (final ConfigPusherException e) {
            LOG.debug("Not enough capabilities: {}", e.toString());
            lastException = e;
            sleep();
        }
    } while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < maxWaitForCapabilitiesMillis);
    LOG.error("Unable to push configuration due to missing yang models." + " Yang models that are missing, but required by the configuration: {}." + " For each mentioned model check: " + " 1. that the mentioned yang model namespace/name/revision is identical to those in the yang model itself" + " 2. the yang file is present in the system" + " 3. the bundle with that yang file is present in the system and active" + " 4. the yang parser did not fail while attempting to parse that model", ((NotEnoughCapabilitiesException) lastException).getMissingCaps());
    throw new IllegalStateException("Unable to push configuration due to missing yang models." + " Required yang models that are missing: " + ((NotEnoughCapabilitiesException) lastException).getMissingCaps(), lastException);
}
Also used : Capability(org.opendaylight.controller.config.util.capability.Capability) Stopwatch(com.google.common.base.Stopwatch)

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