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