Search in sources :

Example 1 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException in project controller by opendaylight.

the class BlueprintContainerRestartServiceImpl method restartConfigModules.

private void restartConfigModules(final BundleContext bundleContext, final List<Entry<String, ModuleIdentifier>> configModules) {
    if (configModules.isEmpty()) {
        return;
    }
    ServiceReference<ConfigSubsystemFacadeFactory> configFacadeFactoryRef = bundleContext.getServiceReference(ConfigSubsystemFacadeFactory.class);
    if (configFacadeFactoryRef == null) {
        LOG.debug("ConfigSubsystemFacadeFactory service reference not found");
        return;
    }
    ConfigSubsystemFacadeFactory configFacadeFactory = bundleContext.getService(configFacadeFactoryRef);
    if (configFacadeFactory == null) {
        LOG.debug("ConfigSubsystemFacadeFactory service not found");
        return;
    }
    try (ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade("BlueprintContainerRestartService")) {
        restartConfigModules(configModules, configFacade);
    } catch (ParserConfigurationException | DocumentedException | ValidationException | ConflictingVersionException e) {
        LOG.error("Error restarting config modules", e);
    } finally {
        bundleContext.ungetService(configFacadeFactoryRef);
    }
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) ConfigSubsystemFacade(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigSubsystemFacadeFactory(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)

Example 2 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException in project controller by opendaylight.

the class BlankTransactionServiceTracker method blankTransactionSync.

void blankTransactionSync() {
    // race condition check: config-persister might push new configuration while
    // server is starting up.
    ConflictingVersionException lastException = null;
    for (int i = 0; i < maxAttempts; i++) {
        try {
            // create transaction
            CommitStatus commitStatus = blankTransaction.hit();
            LOG.debug("Committed blank transaction with status {}", commitStatus);
            return;
        } catch (final ConflictingVersionException e) {
            lastException = e;
            try {
                Thread.sleep(1000);
            } catch (final InterruptedException interruptedException) {
                Thread.currentThread().interrupt();
                LOG.debug("blankTransactionSync was interrupted");
                return;
            }
        } catch (final ValidationException e) {
            LOG.error("Validation exception while running blank transaction indicates programming error", e);
        }
    }
    LOG.error("Maximal number of attempts reached and still cannot get optimistic lock from config manager", lastException);
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus)

Example 3 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException in project controller by opendaylight.

the class ConfigPusherImpl method pushConfigWithConflictingVersionRetries.

private synchronized boolean pushConfigWithConflictingVersionRetries(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException {
    ConflictingVersionException lastException;
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    do {
        // TODO wait untill all expected modules are in yangStoreService, do we even need to with yangStoreService instead on netconfOperationService?
        String idForReporting = configSnapshotHolder.toString();
        SortedSet<String> expectedCapabilities = checkNotNull(configSnapshotHolder.getCapabilities(), "Expected capabilities must not be null - %s, check %s", idForReporting, configSnapshotHolder.getClass().getName());
        // wait max time for required capabilities to appear
        waitForCapabilities(expectedCapabilities, idForReporting);
        try {
            if (!stopwatch.isRunning()) {
                stopwatch.start();
            }
            return pushConfig(configSnapshotHolder);
        } catch (final ConflictingVersionException e) {
            lastException = e;
            LOG.info("Conflicting version detected, will retry after timeout");
            sleep();
        }
    } while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < conflictingVersionTimeoutMillis);
    throw new IllegalStateException("Max wait for conflicting version stabilization timeout after " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms", lastException);
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) Stopwatch(com.google.common.base.Stopwatch)

Example 4 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException in project controller by opendaylight.

the class SimpleConfigurationTest method testValidation.

private static void testValidation(final ConfigTransactionClient transaction) throws InstanceAlreadyExistsException, ReflectionException, InstanceNotFoundException, MBeanException, ConflictingVersionException {
    ObjectName fixed1names = transaction.createModule(TestingFixedThreadPoolModuleFactory.NAME, FIXED1);
    // call validate on config bean
    try {
        platformMBeanServer.invoke(fixed1names, "validate", new Object[0], new String[0]);
        fail();
    } catch (final MBeanException e) {
        Exception targetException = e.getTargetException();
        assertNotNull(targetException);
        assertEquals(ValidationException.class, targetException.getClass());
    }
    // validate config bean
    try {
        transaction.validateBean(fixed1names);
        fail();
    } catch (final ValidationException e) {
        for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
            for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
                assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
            }
        }
    }
    // validate transaction
    try {
        transaction.validateConfig();
        fail();
    } catch (final ValidationException e) {
        for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
            for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
                assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
            }
        }
    }
    try {
        transaction.commit();
    } catch (final ValidationException e) {
        for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
            for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
                assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
            }
        }
    }
}
Also used : ExceptionMessageWithStackTrace(org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace) ValidationException(org.opendaylight.controller.config.api.ValidationException) MBeanException(javax.management.MBeanException) IntrospectionException(javax.management.IntrospectionException) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 5 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException 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

ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)9 Test (org.junit.Test)4 ValidationException (org.opendaylight.controller.config.api.ValidationException)4 ObjectName (javax.management.ObjectName)2 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)2 AbstractConfigTest (org.opendaylight.controller.config.manager.impl.AbstractConfigTest)2 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)2 Stopwatch (com.google.common.base.Stopwatch)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanException (javax.management.MBeanException)1 ReflectionException (javax.management.ReflectionException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ExceptionMessageWithStackTrace (org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace)1 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)1 ConfigSubsystemFacade (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade)1 ConfigSubsystemFacadeFactory (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)1 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)1 Capability (org.opendaylight.controller.config.util.capability.Capability)1