X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Futil%2FConfigTransactionJMXClient.java;h=4cf766a8120ef4c559eb45a9883c7583c1983f8b;hp=548c0e9ea4f6eedc7c317cabc7cbc820cda03f62;hb=f32ff81642b317eedcb973f7cdf0ffc9642bcf3e;hpb=9fb64948564e252018f9b1e13e7cea2c92f991aa diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java index 548c0e9ea4..4cf766a812 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java @@ -7,17 +7,16 @@ */ package org.opendaylight.controller.config.util; +import java.util.Map; import java.util.Set; - import javax.management.Attribute; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.JMException; import javax.management.JMX; +import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.ObjectName; -import javax.management.RuntimeMBeanException; - import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; @@ -26,27 +25,39 @@ import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXB import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; public class ConfigTransactionJMXClient implements ConfigTransactionClient { - private final ConfigRegistryMXBean configTransactionManagerProxy; + private final ConfigRegistryMXBean configRegistryMXBeanProxy; private final ObjectName configTransactionControllerON; - private final ConfigTransactionControllerMXBean configControllerProxy; + private final ConfigTransactionControllerMXBean configTransactionControllerMXBeanProxy; private final MBeanServer configMBeanServer; public ConfigTransactionJMXClient( - ConfigRegistryMXBean configTransactionManagerProxy, + ConfigRegistryMXBean configRegistryMXBeanProxy, ObjectName configTransactionControllerON, MBeanServer configMBeanServer) { this.configMBeanServer = configMBeanServer; - this.configTransactionManagerProxy = configTransactionManagerProxy; + this.configRegistryMXBeanProxy = configRegistryMXBeanProxy; this.configTransactionControllerON = configTransactionControllerON; - this.configControllerProxy = JMX.newMXBeanProxy(configMBeanServer, + this.configTransactionControllerMXBeanProxy = JMX.newMXBeanProxy(configMBeanServer, configTransactionControllerON, ConfigTransactionControllerMXBean.class); } public T newMXBeanProxy(ObjectName on, Class clazz) { + // if on is without transaction, add it. Reason is that when using getters on MXBeans the transaction name is stripped + on = ObjectNameUtil.withTransactionName(on, getTransactionName()); + // if this is service reference and user requests for implementation, look it up + on = ConfigRegistryJMXClient.translateServiceRefIfPossible(on, clazz, configMBeanServer); + on = ObjectNameUtil.withTransactionName(on, getTransactionName()); return JMX.newMXBeanProxy(configMBeanServer, on, clazz); } + /** + * Usage of this method indicates error as config JMX uses solely MXBeans. + * Use {@link #newMXBeanProxy(javax.management.ObjectName, Class)} + * or {@link JMX#newMBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)} + * This method will be removed soon. + */ + @Deprecated public T newMBeanProxy(ObjectName on, Class clazz) { return JMX.newMBeanProxy(configMBeanServer, on, clazz); } @@ -54,7 +65,7 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { @Override public CommitStatus commit() throws ConflictingVersionException, ValidationException { - return configTransactionManagerProxy + return configRegistryMXBeanProxy .commitConfig(configTransactionControllerON); } @@ -73,30 +84,41 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { @Override public ObjectName createModule(String moduleName, String instanceName) throws InstanceAlreadyExistsException { - return configControllerProxy.createModule(moduleName, instanceName); + return configTransactionControllerMXBeanProxy.createModule(moduleName, instanceName); } @Override public void destroyModule(ObjectName objectName) throws InstanceNotFoundException { - configControllerProxy.destroyModule(objectName); + configTransactionControllerMXBeanProxy.destroyModule(objectName); } @Override + @Deprecated + /** + * {@inheritDoc} + */ public void destroyConfigBean(String moduleName, String instanceName) throws InstanceNotFoundException { destroyModule(ObjectNameUtil.createTransactionModuleON( getTransactionName(), moduleName, instanceName)); } + @Override + public void destroyModule(String moduleName, String instanceName) + throws InstanceNotFoundException { + destroyModule(ObjectNameUtil.createTransactionModuleON( + getTransactionName(), moduleName, instanceName)); + } + @Override public void abortConfig() { - configControllerProxy.abortConfig(); + configTransactionControllerMXBeanProxy.abortConfig(); } @Override public void validateConfig() throws ValidationException { - configControllerProxy.validateConfig(); + configTransactionControllerMXBeanProxy.validateConfig(); } @Override @@ -121,12 +143,12 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { @Override public String getTransactionName() { - return configControllerProxy.getTransactionName(); + return configTransactionControllerMXBeanProxy.getTransactionName(); } @Override public Set getAvailableModuleNames() { - return configControllerProxy.getAvailableModuleNames(); + return configTransactionControllerMXBeanProxy.getAvailableModuleNames(); } @Override @@ -136,36 +158,101 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { @Override public Set lookupConfigBeans() { - return configControllerProxy.lookupConfigBeans(); + return configTransactionControllerMXBeanProxy.lookupConfigBeans(); } @Override public Set lookupConfigBeans(String moduleName) { - return configControllerProxy.lookupConfigBeans(moduleName); + return configTransactionControllerMXBeanProxy.lookupConfigBeans(moduleName); } @Override public ObjectName lookupConfigBean(String moduleName, String instanceName) throws InstanceNotFoundException { - return configControllerProxy.lookupConfigBean(moduleName, instanceName); + return configTransactionControllerMXBeanProxy.lookupConfigBean(moduleName, instanceName); } @Override public Set lookupConfigBeans(String moduleName, String instanceName) { - return configControllerProxy + return configTransactionControllerMXBeanProxy .lookupConfigBeans(moduleName, instanceName); } + @Override + public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { + configTransactionControllerMXBeanProxy.checkConfigBeanExists(objectName); + } + + @Override + public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.saveServiceReference(serviceInterfaceName,refName, moduleON); + } + + @Override + public void removeServiceReference(String serviceInterfaceName, String refName) throws InstanceNotFoundException{ + configTransactionControllerMXBeanProxy.removeServiceReference(serviceInterfaceName, refName); + } + + @Override + public void removeAllServiceReferences() { + configTransactionControllerMXBeanProxy.removeAllServiceReferences(); + } + + @Override + public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) { + return configTransactionControllerMXBeanProxy.lookupConfigBeanByServiceInterfaceName(serviceInterfaceQName, refName); + } + + @Override + public Map> getServiceMapping() { + return configTransactionControllerMXBeanProxy.getServiceMapping(); + } + + @Override + public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) { + return configTransactionControllerMXBeanProxy.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceQName); + } + + @Override + public Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.lookupServiceInterfaceNames(objectName); + } + + @Override + public String getServiceInterfaceName(String namespace, String localName) { + return configTransactionControllerMXBeanProxy.getServiceInterfaceName(namespace, localName); + } + + @Override + public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.removeServiceReferences(objectName); + } + + @Override + public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.getServiceReference(serviceInterfaceQName, refName); + } + + @Override + public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException { + configTransactionControllerMXBeanProxy.checkServiceReferenceExists(objectName); + } + @Override public void validateBean(ObjectName configBeanON) throws ValidationException { try { configMBeanServer.invoke(configBeanON, "validate", null, null); + } catch (MBeanException e) { + Exception targetException = e.getTargetException(); + if (targetException instanceof ValidationException){ + throw (ValidationException) targetException; + } else { + throw new RuntimeException(e); + } } catch (JMException e) { throw new RuntimeException(e); - } catch (RuntimeMBeanException e) { - throw e.getTargetException(); } } @@ -182,4 +269,9 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { + attrName + " for " + on, e); } } + + @Override + public Set getAvailableModuleFactoryQNames() { + return configTransactionControllerMXBeanProxy.getAvailableModuleFactoryQNames(); + } }