Search in sources :

Example 1 with ValidationException

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);
    }
}
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 ValidationException

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());
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ArrayList(java.util.ArrayList) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)

Example 3 with ValidationException

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);
}
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 4 with ValidationException

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;
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Element(org.w3c.dom.Element) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) ConfigSubsystemFacade(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) SAXException(org.xml.sax.SAXException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException)

Example 5 with ValidationException

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

Aggregations

ValidationException (org.opendaylight.controller.config.api.ValidationException)10 ObjectName (javax.management.ObjectName)4 Test (org.junit.Test)4 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)4 Map (java.util.Map)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanException (javax.management.MBeanException)2 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)2 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)2 ExceptionMessageWithStackTrace (org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace)2 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)2 ConfigSubsystemFacade (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade)2 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)2 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanServer (javax.management.MBeanServer)1