Merge "Added functionality to store capability info."
authorEd Warnicke <eaw@cisco.com>
Fri, 10 Jan 2014 17:39:29 +0000 (17:39 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 10 Jan 2014 17:39:29 +0000 (17:39 +0000)
.gitignore
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionClient.java
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java
opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java [moved from opendaylight/config/yang-test/src/test/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java with 64% similarity]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/api/AugmentationCodec.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/api/CodecRegistry.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/InstanceIdentifierCodecImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java

index 18817e7..b079cba 100644 (file)
@@ -20,3 +20,4 @@ opendaylight/northbound/integrationtest/logs/*
 .idea
 xtend-gen
 classes
+out/
index 75b1809..4f02db5 100644 (file)
@@ -32,8 +32,13 @@ public interface ConfigTransactionClient extends
 
     void validateBean(ObjectName configBeanON) throws ValidationException;
 
-    void destroyConfigBean(String moduleName, String instanceName)
-            throws InstanceNotFoundException;
+    @Deprecated
+    /**
+     * Use {@link #destroyModule(String, String)}
+     */
+    void destroyConfigBean(String moduleName, String instanceName) throws InstanceNotFoundException;
+
+    void destroyModule(String moduleName, String instanceName) throws InstanceNotFoundException;
 
     void setAttribute(ObjectName on, String jmxName, Attribute attribute);
 }
index e683d91..3583daf 100644 (file)
@@ -84,12 +84,23 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient {
     }
 
     @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() {
         configTransactionControllerMXBeanProxy.abortConfig();
@@ -4,8 +4,6 @@ import com.google.common.collect.Lists;
 import junit.framework.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.config.api.ConflictingVersionException;
-import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
@@ -15,8 +13,14 @@ import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.ObjectName;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 public class NetconfTestImplModuleTest  extends AbstractConfigTest {
 
     public static final String TESTING_DEP_PREFIX = "testing-dep";
@@ -32,17 +36,16 @@ public class NetconfTestImplModuleTest  extends AbstractConfigTest {
     }
 
     @Test
-    public void testDependencyList() throws InstanceAlreadyExistsException, ValidationException,
-            ConflictingVersionException {
+    public void testDependencyList() throws Exception {
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
 
         ObjectName on = createInstance(transaction, instanceName, 4);
         transaction.validateConfig();
-        CommitStatus status = transaction.commit();
+        CommitStatus status1 = transaction.commit();
 
         assertBeanCount(1, factory.getImplementationName());
         assertBeanCount(4 + 1, DepTestImplModuleFactory.NAME);
-        assertStatus(status, 1 + 4 + 1, 0, 0);
+        assertStatus(status1, 1 + 4 + 1, 0, 0);
 
         transaction = configRegistryClient.createTransaction();
 
@@ -56,6 +59,38 @@ public class NetconfTestImplModuleTest  extends AbstractConfigTest {
         assertTestingDeps(testingDeps, 4);
 
         transaction.abortConfig();
+
+        // check that reuse logic works - equals on list of dependencies.
+        transaction = configRegistryClient.createTransaction();
+        CommitStatus status2 = transaction.commit();
+        assertStatus(status2, 0, 0, 6);
+
+        // replace single dependency
+        transaction = configRegistryClient.createTransaction();
+        String instanceName1 = TESTING_DEP_PREFIX + 1;
+        transaction.destroyModule(DepTestImplModuleFactory.NAME, instanceName1);
+        transaction.createModule(DepTestImplModuleFactory.NAME, instanceName1);
+        CommitStatus status3 = transaction.commit();
+        assertStatus(status3, 1, 1, 4);
+
+    }
+
+    @Test
+    public void testNullCheckInListOfDependencies() throws Exception {
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+
+        ObjectName on = createInstance(transaction, instanceName, 4);
+        NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
+        try{
+            proxy.setTestingDeps(null);
+            fail();
+        }catch(RuntimeException e) {
+            Throwable cause = e.getCause();
+            assertNotNull(cause);
+            assertTrue("Invalid type " + cause, cause instanceof IllegalArgumentException);
+            assertEquals("Null not supported", cause.getMessage());
+        }
+        proxy.setTestingDeps(Collections.<ObjectName>emptyList());
     }
 
     private void assertTestingDeps(List<ObjectName> testingDeps, int i) {
index cdddec7..970e077 100644 (file)
@@ -1,6 +1,7 @@
 package org.opendaylight.controller.sal.binding.dom.serializer.api;
 
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 
@@ -12,4 +13,6 @@ public interface AugmentationCodec<A extends Augmentation<?>> extends DomCodec<A
     
     @Override
     public ValueWithQName<A> deserialize(Node<?> input);
+
+    public QName getAugmentationQName();
 }
index b9a4fe8..4565b54 100644 (file)
@@ -10,6 +10,7 @@ import java.util.List;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.controller.sal.binding.dom.serializer.api.IdentifierCodec;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 
 
 public interface CodecRegistry {
@@ -36,4 +37,6 @@ public interface CodecRegistry {
     void bindingClassEncountered(Class<?> cls);
 
     void putPathToClass(List<QName> names, Class<?> cls);
+
+    public abstract QName getQNameForAugmentation(Class<?> cls);
 }
index 150d0f1..f84503b 100644 (file)
@@ -26,13 +26,13 @@ import org.opendaylight.yangtools.yang.binding.Augmentable
 import com.google.common.collect.ImmutableList
 import org.opendaylight.yangtools.yang.binding.Augmentation
 import java.util.concurrent.ConcurrentHashMap
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections
 
 class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec {
     
     private static val LOG = LoggerFactory.getLogger(InstanceIdentifierCodecImpl);
     val CodecRegistry codecRegistry;
     
-    val Map<Class<?>,QName> classToQName = new WeakHashMap;
     val Map<Class<?>, Map<List<QName>, Class<?>>> classToPreviousAugment = new WeakHashMap;
     
     public new(CodecRegistry registry) {
@@ -106,7 +106,7 @@ class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec {
                 
                 previousAugmentation = null;
             } else {
-                previousQName = resolveQname(baArg.type);
+                previousQName = codecRegistry.getQNameForAugmentation(baArg.type as Class);
                 previousAugmentation = baArg.type;
             }
         }
@@ -122,7 +122,7 @@ class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec {
     
     private def dispatch PathArgument serializePathArgument(Item argument, QName previousQname) {
         val type = argument.type;
-        val qname = resolveQname(type);
+        val qname = BindingReflections.findQName(type);
         if(previousQname == null) {
             return new NodeIdentifier(qname);
         }
@@ -134,7 +134,7 @@ class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec {
         val Map<QName,Object> predicates = new HashMap();
         val type = argument.type;
         val keyCodec = codecRegistry.getIdentifierCodecForIdentifiable(type);
-        val qname = resolveQname(type);
+        val qname = BindingReflections.findQName(type);
         val combinedInput =  new ValueWithQName(previousQname,argument.key)
         val compositeOutput = keyCodec.serialize(combinedInput as ValueWithQName);
         for(outputValue :compositeOutput.value) {
@@ -145,15 +145,4 @@ class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec {
         }
         return new NodeIdentifierWithPredicates(QName.create(previousQname,qname.localName),predicates);
     }
-    
-    def resolveQname(Class<?> class1) {
-        val qname = classToQName.get(class1);
-        if(qname !== null) {
-            return qname;
-        }
-        val qnameField = class1.getField("QNAME");
-        val qnameValue = qnameField.get(null) as QName;
-        classToQName.put(class1,qnameValue);
-        return qnameValue;
-    }
 }
\ No newline at end of file
index cabb1bc..89d9b49 100644 (file)
@@ -44,6 +44,7 @@ import org.opendaylight.yangtools.yang.binding.BindingCodec;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
@@ -153,6 +154,12 @@ public class LazyGeneratedCodecRegistry implements //
         }
         return codec;
     }
+    
+    @Override
+    public QName getQNameForAugmentation(Class<?> cls) {
+        checkArgument(Augmentation.class.isAssignableFrom(cls));
+        return getCodecForAugmentation((Class<? extends Augmentation>)cls).getAugmentationQName();
+    }
 
     private static Class<? extends Augmentable<?>> getAugmentableArgumentFrom(
             final Class<? extends Augmentation<?>> augmentation) {
@@ -909,9 +916,11 @@ public class LazyGeneratedCodecRegistry implements //
             Delegator<BindingCodec> {
 
         private BindingCodec delegate;
+        private QName augmentationQName;
 
         public AugmentationCodecWrapper(BindingCodec<Map<QName, Object>, Object> rawCodec) {
             this.delegate = rawCodec;
+            this.augmentationQName = BindingReflections.findQName(rawCodec.getClass());
         }
 
         @Override
@@ -936,6 +945,11 @@ public class LazyGeneratedCodecRegistry implements //
             Object rawCodecValue = getDelegate().deserialize((Map<QName, Object>) input);
             return new ValueWithQName<T>(input.getNodeType(), (T) rawCodecValue);
         }
+        
+        @Override
+        public QName getAugmentationQName() {
+            return augmentationQName;
+        }
     }
 
     private class IdentityCompositeCodec implements IdentitityCodec {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.