Search in sources :

Example 1 with JmxAttributeValidationException

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

the class DependencyResolverImpl method resolveInstance.

// TODO: check for cycles
@Override
public <T> T resolveInstance(final Class<T> expectedType, final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
    final Module module = resolveModuleInstance(dependentReadOnlyON, jmxAttribute);
    synchronized (this) {
        this.dependencies.add(module.getIdentifier());
    }
    final AutoCloseable instance = module.getInstance();
    if (instance == null) {
        final String message = String.format("Error while %s resolving instance %s. getInstance() returned null. Expected type %s, attribute %s", this.name, module.getIdentifier(), expectedType, jmxAttribute);
        throw new JmxAttributeValidationException(message, jmxAttribute);
    }
    try {
        return expectedType.cast(instance);
    } catch (final ClassCastException e) {
        final String message = String.format("Instance cannot be cast to expected type. Instance class is %s, expected type %s , attribute %s", instance.getClass(), expectedType, jmxAttribute);
        throw new JmxAttributeValidationException(message, e, jmxAttribute);
    }
}
Also used : JmxAttributeValidationException(org.opendaylight.controller.config.api.JmxAttributeValidationException) Module(org.opendaylight.controller.config.spi.Module)

Example 2 with JmxAttributeValidationException

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

the class DependencyResolverImpl method validateDependency.

/**
 * {@inheritDoc}
 */
// TODO: check for cycles
@Override
public void validateDependency(final Class<? extends AbstractServiceInterface> expectedServiceInterface, final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
    this.transactionStatus.checkNotCommitted();
    if (expectedServiceInterface == null) {
        throw new NullPointerException("Parameter 'expectedServiceInterface' is null");
    }
    if (jmxAttribute == null) {
        throw new NullPointerException("Parameter 'jmxAttribute' is null");
    }
    JmxAttributeValidationException.checkNotNull(dependentReadOnlyON, "is null, expected dependency implementing " + expectedServiceInterface, jmxAttribute);
    // check that objectName belongs to this transaction - this should be
    // stripped
    // in DynamicWritableWrapper
    final boolean hasTransaction = ObjectNameUtil.getTransactionName(dependentReadOnlyON) != null;
    JmxAttributeValidationException.checkCondition(!hasTransaction, String.format("ObjectName should not contain " + "transaction name. %s set to %s. ", jmxAttribute, dependentReadOnlyON), jmxAttribute);
    final ObjectName newDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON);
    final ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(newDependentReadOnlyON, ObjectNameUtil.TYPE_MODULE);
    final ModuleFactory foundFactory = this.modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute);
    final boolean implementsSI = foundFactory.isModuleImplementingServiceInterface(expectedServiceInterface);
    if (!implementsSI) {
        final String message = String.format("Found module factory does not expose expected service interface. " + "Module name is %s : %s, expected service interface %s, dependent module ON %s , " + "attribute %s", foundFactory.getImplementationName(), foundFactory, expectedServiceInterface, newDependentReadOnlyON, jmxAttribute);
        throw new JmxAttributeValidationException(message, jmxAttribute);
    }
    synchronized (this) {
        this.dependencies.add(moduleIdentifier);
    }
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) JmxAttributeValidationException(org.opendaylight.controller.config.api.JmxAttributeValidationException) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ObjectName(javax.management.ObjectName)

Aggregations

JmxAttributeValidationException (org.opendaylight.controller.config.api.JmxAttributeValidationException)2 ObjectName (javax.management.ObjectName)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 Module (org.opendaylight.controller.config.spi.Module)1 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)1