X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FDynamicWritableWrapper.java;h=c3885150d572f80d1000320678424e597d2558ce;hb=f298b5a67b70daf3face69bf65483de544a6da61;hp=a1cd6b01339dd7fc82864c3219bc5f32fc7de0ba;hpb=33ea0032f0837333a9181dd7556faa3266155080;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java index a1cd6b0133..c3885150d5 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java @@ -7,7 +7,13 @@ */ package org.opendaylight.controller.config.manager.impl.dynamicmbean; -import java.lang.reflect.Method; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; +import org.opendaylight.controller.config.manager.impl.TransactionIdentifier; +import org.opendaylight.controller.config.spi.Module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.concurrent.ThreadSafe; import javax.management.Attribute; @@ -20,14 +26,7 @@ import javax.management.MBeanOperationInfo; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.ReflectionException; - -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.config.api.ValidationException; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.manager.impl.TransactionIdentifier; -import org.opendaylight.controller.config.spi.Module; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.reflect.Method; /** * Wraps {@link org.opendaylight.controller.config.spi.Module} instance in a @@ -48,18 +47,18 @@ import org.slf4j.LoggerFactory; */ @ThreadSafe public class DynamicWritableWrapper extends AbstractDynamicWrapper { - private static final Logger logger = LoggerFactory + private static final Logger LOGGER = LoggerFactory .getLogger(DynamicWritableWrapper.class); private final ReadOnlyAtomicBoolean configBeanModificationDisabled; public DynamicWritableWrapper(Module module, - ModuleIdentifier moduleIdentifier, - TransactionIdentifier transactionIdentifier, - ReadOnlyAtomicBoolean configBeanModificationDisabled, - MBeanServer internalServer, MBeanServer configMBeanServer) { + ModuleIdentifier moduleIdentifier, + TransactionIdentifier transactionIdentifier, + ReadOnlyAtomicBoolean configBeanModificationDisabled, + MBeanServer internalServer, MBeanServer configMBeanServer) { super(module, true, moduleIdentifier, ObjectNameUtil - .createTransactionModuleON(transactionIdentifier.getName(), moduleIdentifier), getOperations(moduleIdentifier), + .createTransactionModuleON(transactionIdentifier.getName(), moduleIdentifier), getOperations(moduleIdentifier), internalServer, configMBeanServer); this.configBeanModificationDisabled = configBeanModificationDisabled; } @@ -68,47 +67,70 @@ public class DynamicWritableWrapper extends AbstractDynamicWrapper { ModuleIdentifier moduleIdentifier) { Method validationMethod; try { - validationMethod = DynamicWritableWrapper.class.getMethod( - "validate", new Class[0]); + validationMethod = DynamicWritableWrapper.class.getMethod("validate"); } catch (NoSuchMethodException e) { - throw new IllegalStateException("No such method exception on " - + moduleIdentifier, e); + throw new IllegalStateException("No such method exception on " + moduleIdentifier, e); } - return new MBeanOperationInfo[] { new MBeanOperationInfo("Validation", - validationMethod) }; + return new MBeanOperationInfo[]{new MBeanOperationInfo("Validation", validationMethod)}; } @Override public synchronized void setAttribute(Attribute attribute) - throws AttributeNotFoundException, InvalidAttributeValueException, - MBeanException, ReflectionException { - if (configBeanModificationDisabled.get() == true) + throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { + Attribute newAttribute = attribute; + if (configBeanModificationDisabled.get() == true) { throw new IllegalStateException("Operation is not allowed now"); + } - if (attribute.getName().equals("Attribute")) { - setAttribute((Attribute) attribute.getValue()); + if ("Attribute".equals(newAttribute.getName())) { + setAttribute((Attribute) newAttribute.getValue()); return; } try { - if (attribute.getValue() instanceof ObjectName) { - AttributeHolder attributeHolder = attributeHolderMap - .get(attribute.getName()); - if (attributeHolder.getRequireInterfaceOrNull() != null) { - attribute = new Attribute(attribute.getName(), - fixObjectName((ObjectName) attribute.getValue())); - } else { - attribute = new Attribute(attribute.getName(), - attribute.getValue()); - } + if (newAttribute.getValue() instanceof ObjectName) { + newAttribute = fixDependencyAttribute(newAttribute); + } else if (newAttribute.getValue() instanceof ObjectName[]) { + newAttribute = fixDependencyListAttribute(newAttribute); } - internalServer.setAttribute(objectNameInternal, attribute); + + internalServer.setAttribute(objectNameInternal, newAttribute); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } } + private Attribute fixDependencyListAttribute(Attribute attribute) { + Attribute newAttribute = attribute; + AttributeHolder attributeHolder = attributeHolderMap.get(newAttribute.getName()); + if (attributeHolder.getRequireInterfaceOrNull() != null) { + newAttribute = new Attribute(newAttribute.getName(), fixObjectNames((ObjectName[]) newAttribute.getValue())); + } + return newAttribute; + } + + private Attribute fixDependencyAttribute(Attribute attribute) { + Attribute newAttribute = attribute; + AttributeHolder attributeHolder = attributeHolderMap.get(newAttribute.getName()); + if (attributeHolder.getRequireInterfaceOrNull() != null) { + newAttribute = new Attribute(newAttribute.getName(), fixObjectName((ObjectName) newAttribute.getValue())); + } else { + newAttribute = new Attribute(newAttribute.getName(), newAttribute.getValue()); + } + return newAttribute; + } + + private ObjectName[] fixObjectNames(ObjectName[] dependencies) { + int i = 0; + + for (ObjectName dependencyOn : dependencies) { + dependencies[i++] = fixObjectName(dependencyOn); + } + + return dependencies; + } + @Override public AttributeList setAttributes(AttributeList attributes) { AttributeList result = new AttributeList(); @@ -118,8 +140,7 @@ public class DynamicWritableWrapper extends AbstractDynamicWrapper { setAttribute(attribute); result.add(attribute); } catch (Exception e) { - logger.warn("Setting attribute {} failed on {}", - attribute.getName(), moduleIdentifier, e); + LOGGER.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e); throw new IllegalArgumentException( "Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e); @@ -137,8 +158,9 @@ public class DynamicWritableWrapper extends AbstractDynamicWrapper { try { validate(); } catch (Exception e) { - throw ValidationException.createForSingleException( - moduleIdentifier, e); + + throw new MBeanException(ValidationException.createForSingleException( + moduleIdentifier, e)); } return Void.TYPE; }