* fix : yang-generator can't find SIE if its base is another SIE 22/3822/7
authorMartin Bobak <mbobak@cisco.com>
Wed, 18 Dec 2013 13:37:02 +0000 (14:37 +0100)
committerMartin Bobak <mbobak@cisco.com>
Mon, 13 Jan 2014 17:56:38 +0000 (18:56 +0100)
JMXGenerator processes modules in dependency sorted order. Known SIE
tracker introduced for use in ServiceInterfaceEntry#create.

Change-Id: I36899dcdc3ea80661c43056dfc63c8f41d7c1f4d
Signed-off-by: Martin Bobak <mbobak@cisco.com>
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntryTest.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntryTest.java
opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/MbeParser.java

index 10f19e8..7075865 100644 (file)
@@ -12,6 +12,16 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
@@ -22,6 +32,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry
 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator;
@@ -29,17 +40,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.impl.StaticLoggerBinder;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 /**
  * This class interfaces with yang-maven-plugin. Gets parsed yang modules in
  * {@link SchemaContext}, and parameters form the plugin configuration, and
@@ -70,7 +70,7 @@ public class JMXGenerator implements CodeGenerator {
 
     @Override
     public Collection<File> generateSources(SchemaContext context,
-            File outputBaseDir, Set<Module> yangModulesInCurrentMavenModule) {
+                                            File outputBaseDir, Set<Module> yangModulesInCurrentMavenModule) {
 
         Preconditions.checkArgument(context != null, "Null context received");
         Preconditions.checkArgument(outputBaseDir != null,
@@ -86,24 +86,25 @@ public class JMXGenerator implements CodeGenerator {
             outputBaseDir.mkdirs();
 
         GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker();
+        // create SIE structure qNamesToSIEs
         Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
 
-        // create SIE structure qNamesToSIEs
+
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
         for (Module module : context.getModules()) {
             String packageName = packageTranslator.getPackageName(module);
             Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
-                    .create(module, packageName);
+                    .create(module, packageName, knownSEITracker);
 
             for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries
                     .entrySet()) {
-
                 // merge value into qNamesToSIEs
                 if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) {
                     qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue());
                 } else {
                     throw new IllegalStateException(
-                            "Cannot add two SIE with same qname "
-                                    + sieEntry.getValue());
+                        "Cannot add two SIE  with same qname "
+                                + sieEntry.getValue());
                 }
             }
             if (yangModulesInCurrentMavenModule.contains(module)) {
index 869488e..5bcc540 100644 (file)
@@ -7,11 +7,9 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
-import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -21,7 +19,6 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AbstractDependencyAttribute;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
@@ -52,10 +49,10 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName;
 
 /**
  * Represents part of yang model that describes a module.
index aa2d6a5..ef40d95 100644 (file)
@@ -7,10 +7,7 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.lang.String.format;
-import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME;
-
+import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -18,15 +15,15 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.String.format;
+import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME;
 
 /**
  * Represents identity derived from {@link ConfigConstants#SERVICE_TYPE_Q_NAME}.
@@ -123,7 +120,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
      *         values
      */
     public static Map<QName, ServiceInterfaceEntry> create(Module currentModule,
-            String packageName) {
+            String packageName,Map<IdentitySchemaNode, ServiceInterfaceEntry> definedSEItracker) {
         logger.debug("Generating ServiceInterfaces from {} to package {}",
                 currentModule.getNamespace(), packageName);
 
@@ -152,7 +149,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                     // this is a base type
                     created = new ServiceInterfaceEntry(identity, packageName, ModuleUtil.getQName(currentModule));
                 } else {
-                    ServiceInterfaceEntry foundBase = identitiesToSIs
+                    ServiceInterfaceEntry foundBase = definedSEItracker
                             .get(identity.getBaseIdentity());
                     // derived type, did we convert the parent?
                     if (foundBase != null) {
@@ -160,12 +157,15 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                                 Optional.of(foundBase), identity, packageName, ModuleUtil.getQName(currentModule));
                     }
                 }
+
+
                 if (created != null) {
                     created.setYangModuleName(currentModule.getName());
                     // TODO how to get local name
                     created.setYangModuleLocalname(identity.getQName()
                             .getLocalName());
                     identitiesToSIs.put(identity, created);
+                    definedSEItracker.put(identity, created);
                     iterator.remove();
                 }
             }
index e86c876..9ea34ca 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.config.yangjmxgenerator;
 
 import com.google.common.collect.Sets;
+import java.util.HashMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
@@ -22,6 +23,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 
 import javax.management.openmbean.ArrayType;
@@ -94,16 +96,18 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest {
 
     @Before
     public void setUp() {
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
         modulesToSIEs = ServiceInterfaceEntry.create(threadsModule,
-                "packages.sis");
+                "packages.sis",identitiesToSIs);
     }
 
     @Test
     public void test_jmxImplModule() {
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
         Map<QName, ServiceInterfaceEntry> modulesToSIEs = ServiceInterfaceEntry
-                .create(threadsModule, PACKAGE_NAME);
+                .create(threadsModule, PACKAGE_NAME,identitiesToSIs);
         modulesToSIEs.putAll(ServiceInterfaceEntry.create(jmxModule,
-                PACKAGE_NAME));
+                PACKAGE_NAME,identitiesToSIs));
         Map<String /* identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
                 .create(jmxImplModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context))
                         , PACKAGE_NAME);
index 97258fb..b570302 100644 (file)
@@ -7,12 +7,14 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
+import java.util.HashMap;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 
@@ -41,6 +43,7 @@ public class RuntimeBeanEntryTest extends AbstractYangTest {
     public static final String SLEEP_RPC_OUTPUT = "ThreadState";
     public static final String SLEEP_RPC_INPUT_NAME = "millis";
     public static final String SLEEP_RPC_INPUT_TYPE = "Long";
+    private static final Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
 
     @Test
     public void createRuntimeBean() {
@@ -61,7 +64,7 @@ public class RuntimeBeanEntryTest extends AbstractYangTest {
     public void runtimeBeanRPCTest() {
         // create service interfaces
         Map<QName, ServiceInterfaceEntry> modulesToSIEs = ServiceInterfaceEntry
-                .create(threadsModule, "packages.sis");
+                .create(threadsModule, "packages.sis",identitiesToSIs);
         assertNotNull(modulesToSIEs);
 
         // create MXBeans map
index 0da61b4..eed8695 100644 (file)
@@ -7,27 +7,26 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
+import com.google.common.collect.Sets;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
-
-import com.google.common.collect.Sets;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 
 public class ServiceInterfaceEntryTest extends AbstractYangTest {
     public static final String PACKAGE_NAME = "packages.sis";
@@ -38,6 +37,7 @@ public class ServiceInterfaceEntryTest extends AbstractYangTest {
 
     private static final URI THREADS_NAMESPACE;
     private static final Date THREADS_REVISION_DATE;
+
     static {
         try {
             THREADS_NAMESPACE = new URI(ConfigConstants.CONFIG_NAMESPACE
@@ -77,8 +77,9 @@ public class ServiceInterfaceEntryTest extends AbstractYangTest {
     @Test
     public void testCreateFromIdentities() {
         // each identity has to have a base that leads to service-type
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> definedIdentities = new HashMap<>();
         Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
-                .create(threadsModule, PACKAGE_NAME);
+                .create(threadsModule, PACKAGE_NAME,definedIdentities);
         // expected eventbus, threadfactory, threadpool,
         // scheduled-threadpool,thread-rpc-context
         assertThat(namesToSIEntries.size(), is(expectedSIEFileNames.size()));
index 2be6c81..d54996d 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry
 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
@@ -47,11 +48,12 @@ public class MbeParser {
 
         Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
 
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
         // create SIE structure qNamesToSIEs
         for (Module module : resolveSchemaContext.getModules()) {
             String packageName = packageTranslator.getPackageName(module);
             Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
-                    .create(module, packageName);
+                    .create(module, packageName,knownSEITracker);
 
             for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries
                     .entrySet()) {

©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.