Search in sources :

Example 6 with ValidationException

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

the class ConfigTransactionClientsTest method testValidateBean2.

@Test(expected = ValidationException.class)
public void testValidateBean2() throws Exception {
    MBeanServer mbsLocal = mock(MBeanServer.class);
    MBeanException mBeanException = new MBeanException(new ValidationException(Collections.<String, Map<String, ExceptionMessageWithStackTrace>>emptyMap()));
    doThrow(mBeanException).when(mbsLocal).invoke(transactionControllerON, "validate", null, null);
    ConfigTransactionJMXClient jmxTransactionClientFake = new ConfigTransactionJMXClient(null, transactionControllerON, mbsLocal);
    jmxTransactionClientFake.validateBean(transactionControllerON);
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) MBeanException(javax.management.MBeanException) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 7 with ValidationException

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

the class TransactionProvider method commitTransaction.

/**
 * Commit and notification send must be atomic.
 */
public synchronized CommitStatus commitTransaction(final ConfigRegistryClient client) throws ValidationException, ConflictingVersionException {
    if (!getTransaction().isPresent()) {
        // making empty commit without prior opened transaction, just return commit
        // status with empty lists
        LOG.debug("Making commit without open candidate transaction for session {}", sessionIdForReporting);
        return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    }
    final Optional<ObjectName> maybeTaON = getTransaction();
    ObjectName taON = maybeTaON.get();
    try {
        CommitStatus status = client.commitConfig(taON);
        // clean up
        allOpenedTransactions.remove(candidateTx);
        candidateTx = null;
        return status;
    } catch (final ValidationException validationException) {
        // no clean up: user can reconfigure and recover this transaction
        LOG.warn("Transaction {} failed on {}", taON, validationException.toString());
        throw validationException;
    } catch (final ConflictingVersionException e) {
        LOG.debug("Exception while commit of {}, aborting transaction", taON, e);
        // clean up
        abortTransaction();
        throw e;
    }
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) ObjectName(javax.management.ObjectName)

Example 8 with ValidationException

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

the class MultipleDependenciesModuleTest method testDestroyModuleDependency.

@Test
public void testDestroyModuleDependency() throws Exception {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    ObjectName r1 = transaction.createModule(factory.getImplementationName(), "root1");
    ObjectName m1 = transaction.createModule(factory.getImplementationName(), "middle1");
    MultipleDependenciesModuleMXBean r1Proxy = transaction.newMXBeanProxy(r1, MultipleDependenciesModuleMXBean.class);
    r1Proxy.setSingle(m1);
    transaction.commit();
    transaction = configRegistryClient.createTransaction();
    transaction.destroyModule(factory.getImplementationName(), "middle1");
    try {
        transaction.commit();
        fail("Validation exception expected");
    } catch (ValidationException e) {
        assertThat(e.getFailedValidations().keySet(), CoreMatchers.hasItem("multiple-dependencies"));
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ValidationException(org.opendaylight.controller.config.api.ValidationException) ObjectName(javax.management.ObjectName) Test(org.junit.Test) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest)

Example 9 with ValidationException

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

the class DependentWiringTest method testDependencies.

@Test
public void testDependencies() throws Exception {
    ObjectName apspON;
    {
        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
        // create fixed1
        ObjectName threadPoolTransactionON = createFixed1(transaction, TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
        // create apsp-parallel
        ObjectName apspNameTransactionON = createParallelAPSP(transaction, threadPoolTransactionON);
        TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction.newMXBeanProxy(apspNameTransactionON, TestingParallelAPSPConfigMXBean.class);
        // trigger validation
        parallelAPSPConfigProxy.setSomeParam("");
        // failure
        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()) {
                    assertThat(entry.getValue().getMessage(), containsString("Parameter 'SomeParam' is blank"));
                }
            }
        }
        // try committing (validation fails)
        try {
            transaction.commit();
            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()) {
                    String err = entry.getValue().getMessage();
                    assertTrue("Unexpected error message: " + err, err.contains("Parameter 'SomeParam' is blank"));
                }
            }
        }
        // fix validation
        parallelAPSPConfigProxy.setSomeParam("abc");
        // failure
        transaction.commit();
        apspON = ObjectNameUtil.withoutTransactionName(apspNameTransactionON);
    }
    // test reported apsp number of threads
    TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient.newMXBeanProxy(apspON, TestingParallelAPSPConfigMXBean.class);
    assertEquals((Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS, parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
    // next transaction - recreate new thread pool
    int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
    {
        // start new transaction
        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
        ObjectName threadPoolNamesNewTx = transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
        TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction.newMXBeanProxy(threadPoolNamesNewTx, TestingFixedThreadPoolConfigMXBean.class);
        fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
        transaction.commit();
    }
    // new reference should be copied to apsp-parallel
    assertEquals((Integer) newNumberOfThreads, parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ExceptionMessageWithStackTrace(org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace) ValidationException(org.opendaylight.controller.config.api.ValidationException) TestingFixedThreadPoolConfigMXBean(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) ObjectName(javax.management.ObjectName) TestingParallelAPSPConfigMXBean(org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean) Test(org.junit.Test)

Example 10 with ValidationException

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

the class BlankTransactionServiceTrackerTest method testValidationException.

@Test
public void testValidationException() throws Exception {
    IllegalArgumentException argumentException = new IllegalArgumentException();
    ValidationException validationException = ValidationException.createForSingleException(new ModuleIdentifier("m", "i"), argumentException);
    doThrow(validationException).when(blankTx).hit();
    tracker.addingService(getMockServiceReference());
    verify(blankTx, times(10)).hit();
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Test(org.junit.Test)

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