use of org.opendaylight.controller.config.api.ValidationException 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.ValidationException in project controller by opendaylight.
the class ConfigTransactionControllerImpl method validateNoLocks.
@SuppressWarnings("IllegalCatch")
private void validateNoLocks() throws ValidationException {
transactionStatus.checkNotAborted();
LOG.trace("Validating transaction {}", getTransactionIdentifier());
// call validate()
List<ValidationException> collectedExceptions = new ArrayList<>();
for (Entry<ModuleIdentifier, Module> entry : dependencyResolverManager.getAllModules().entrySet()) {
ModuleIdentifier name = entry.getKey();
Module module = entry.getValue();
try {
module.validate();
} catch (final Exception e) {
LOG.warn("Validation exception in {}", getTransactionName(), e);
collectedExceptions.add(ValidationException.createForSingleException(name, e));
}
}
if (!collectedExceptions.isEmpty()) {
throw ValidationException.createFromCollectedValidationExceptions(collectedExceptions);
}
LOG.trace("Validated transaction {}", getTransactionIdentifier());
}
use of org.opendaylight.controller.config.api.ValidationException 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.ValidationException 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;
}
use of org.opendaylight.controller.config.api.ValidationException 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());
}
}
}
}
Aggregations