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;
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;
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
@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,
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)) {
*/
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;
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;
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.
*/
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;
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}.
* 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);
// 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) {
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();
}
}
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;
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;
@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);
*/
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;
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() {
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
*/
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";
private static final URI THREADS_NAMESPACE;
private static final Date THREADS_REVISION_DATE;
+
static {
try {
THREADS_NAMESPACE = new URI(ConfigConstants.CONFIG_NAMESPACE
@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()));
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;
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()) {