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);
}
}
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);
}
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);
}
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());
}
}
}
}
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();
}
Aggregations