use of org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode in project controller by opendaylight.
the class SchemaContextTest method assertAllIdentitiesAreExpected.
private static void assertAllIdentitiesAreExpected(final Module module, final Map<String, /* identity name */
Optional<QName>> expectedIdentitiesToBases) {
Map<String, Optional<QName>> /* identity name */
copyOfExpectedNames = new HashMap<>(expectedIdentitiesToBases);
for (IdentitySchemaNode id : module.getIdentities()) {
String localName = id.getQName().getLocalName();
assertTrue("Unexpected identity " + localName, copyOfExpectedNames.containsKey(localName));
Optional<QName> maybeExpectedBaseQName = copyOfExpectedNames.remove(localName);
if (maybeExpectedBaseQName.isPresent()) {
assertEquals("Unexpected base identity of " + localName, maybeExpectedBaseQName.get(), id.getBaseIdentities().iterator().next().getQName());
}
}
assertEquals("Expected identities not found " + copyOfExpectedNames, Collections.emptyMap(), copyOfExpectedNames);
}
use of org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode in project controller by opendaylight.
the class SchemaContextTest method testReadingIdentities_threadsModule.
@Test
public void testReadingIdentities_threadsModule() {
IdentitySchemaNode serviceType = findIdentityByQName(configModule, SERVICE_TYPE_Q_NAME);
Map<String, Optional<QName>> /* identity name */
expectedIdentitiesToBases = ImmutableMap.of("eventbus", Optional.<QName>absent(), "threadfactory", Optional.<QName>absent(), "threadpool", Optional.<QName>absent(), "scheduled-threadpool", Optional.<QName>absent());
assertThat(threadsModule.getIdentities().size(), is(expectedIdentitiesToBases.size()));
assertAllIdentitiesAreExpected(threadsModule, expectedIdentitiesToBases);
IdentitySchemaNode eventBusSchemaNode = null;
for (IdentitySchemaNode id : threadsModule.getIdentities()) {
String localName = id.getQName().getLocalName();
if (localName.equals("eventbus")) {
eventBusSchemaNode = id;
}
// serviceType
if (localName.equals("scheduled-threadpool") == false) {
assertEquals(serviceType, id.getBaseIdentities().iterator().next());
}
}
assertNotNull(eventBusSchemaNode);
// check unknown schma nodes
List<UnknownSchemaNode> unknownSchemaNodes = eventBusSchemaNode.getUnknownSchemaNodes();
assertEquals(1, unknownSchemaNodes.size());
UnknownSchemaNode usn = unknownSchemaNodes.get(0);
assertEquals("com.google.common.eventbus.EventBus", usn.getQName().getLocalName());
assertEquals(ConfigConstants.JAVA_CLASS_EXTENSION_QNAME, usn.getNodeType());
}
use of org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode in project controller by opendaylight.
the class ConfigSubsystemFacade method transformIdentities.
private static Map<String, Map<Optional<Revision>, IdentityMapping>> transformIdentities(final Set<Module> modules) {
Map<String, Map<Optional<Revision>, IdentityMapping>> mappedIds = new HashMap<>();
for (Module module : modules) {
String namespace = module.getNamespace().toString();
Map<Optional<Revision>, IdentityMapping> revisionsByNamespace = mappedIds.computeIfAbsent(namespace, k -> new HashMap<>());
Optional<Revision> revision = Optional.fromJavaUtil(module.getRevision());
IdentityMapping identityMapping = revisionsByNamespace.computeIfAbsent(revision, k -> new IdentityMapping());
for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
identityMapping.addIdSchemaNode(identitySchemaNode);
}
}
return mappedIds;
}
use of org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode in project controller by opendaylight.
the class JMXGenerator method generateSources.
@Override
public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir, final Set<Module> currentModules, final Function<Module, Optional<String>> moduleResourcePathResolver) {
Preconditions.checkArgument(context != null, "Null context received");
Preconditions.checkArgument(outputBaseDir != null, "Null outputBaseDir received");
Preconditions.checkArgument(this.namespaceToPackageMapping != null && !this.namespaceToPackageMapping.isEmpty(), "No namespace to package mapping provided in additionalConfiguration");
final PackageTranslator packageTranslator = new PackageTranslator(this.namespaceToPackageMapping);
if (!outputBaseDir.exists()) {
outputBaseDir.mkdirs();
}
final GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker();
// create SIE structure qNamesToSIEs
final Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
final Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
for (final Module module : context.getModules()) {
final String packageName = packageTranslator.getPackageName(module);
final Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry.create(module, packageName, knownSEITracker);
for (final Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries.entrySet()) {
// merge value into qNamesToSIEs
if (qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue()) != null) {
throw new IllegalStateException("Cannot add two SIE with same qname " + sieEntry.getValue());
}
}
if (currentModules.contains(module)) {
// write this sie to disk
for (final ServiceInterfaceEntry sie : namesToSIEntries.values()) {
try {
generatedFiles.addFile(this.codeWriter.writeSie(sie, outputBaseDir));
} catch (final Exception e) {
throw new RuntimeException("Error occurred during SIE source generate phase", e);
}
}
}
}
final File mainBaseDir = concatFolders(this.projectBaseDir, "src", "main", "java");
Preconditions.checkNotNull(this.resourceBaseDir, "resource base dir attribute was null");
final StringBuilder fullyQualifiedNamesOfFactories = new StringBuilder();
// create MBEs
for (final Module module : currentModules) {
final String packageName = packageTranslator.getPackageName(module);
final Map<String, ModuleMXBeanEntry> /* MB identity local name */
namesToMBEs = ModuleMXBeanEntry.create(module, qNamesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)), packageName);
for (final Entry<String, ModuleMXBeanEntry> mbeEntry : namesToMBEs.entrySet()) {
final ModuleMXBeanEntry mbe = mbeEntry.getValue();
try {
final List<File> files1 = this.codeWriter.writeMbe(mbe, outputBaseDir, mainBaseDir);
generatedFiles.addFile(files1);
} catch (final Exception e) {
throw new RuntimeException("Error occurred during MBE source generate phase", e);
}
fullyQualifiedNamesOfFactories.append(mbe.getFullyQualifiedName(mbe.getStubFactoryName()));
fullyQualifiedNamesOfFactories.append("\n");
}
}
// create ModuleFactory file if needed
if (fullyQualifiedNamesOfFactories.length() > 0 && this.generateModuleFactoryFile) {
final File serviceLoaderFile = JMXGenerator.concatFolders(this.resourceBaseDir, "META-INF", "services", ModuleFactory.class.getName());
// if this file does not exist, create empty file
serviceLoaderFile.getParentFile().mkdirs();
try {
serviceLoaderFile.createNewFile();
Files.asCharSink(serviceLoaderFile, StandardCharsets.UTF_8).write(fullyQualifiedNamesOfFactories.toString());
} catch (final IOException e) {
final String message = "Cannot write to " + serviceLoaderFile;
LOG.error(message, e);
throw new RuntimeException(message, e);
}
}
return generatedFiles.getFiles();
}
use of org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode in project controller by opendaylight.
the class ModuleMXBeanEntryTest method test_jmxImplModule.
@Test
public void test_jmxImplModule() {
final Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
final Map<QName, ServiceInterfaceEntry> modulesToSIEs = ServiceInterfaceEntry.create(this.threadsModule, PACKAGE_NAME, identitiesToSIs);
modulesToSIEs.putAll(ServiceInterfaceEntry.create(this.jmxModule, PACKAGE_NAME, identitiesToSIs));
final Map<String, ModuleMXBeanEntry> /* identity local name */
namesToMBEs = ModuleMXBeanEntry.create(this.jmxImplModule, modulesToSIEs, this.context, new TypeProviderWrapper(new TypeProviderImpl(this.context)), PACKAGE_NAME);
final Map<String, AttributeIfc> attributes = namesToMBEs.get("impl-netconf").getAttributes();
assertCorrectAttributesSize(namesToMBEs, attributes);
//
final DependencyAttribute threadFactoryAttribute = (DependencyAttribute) attributes.get("thread-factory");
assertNotNull(threadFactoryAttribute);
assertFalse(threadFactoryAttribute.getDependency().isMandatory());
assertThat(threadFactoryAttribute.getDependency().getSie().getTypeName(), is("ThreadFactoryServiceInterface"));
assertThat(threadFactoryAttribute.getAttributeYangName(), is("thread-factory"));
assertThat(threadFactoryAttribute.getLowerCaseCammelCase(), is("threadFactory"));
assertThat(threadFactoryAttribute.getUpperCaseCammelCase(), is("ThreadFactory"));
assertThat(threadFactoryAttribute.getOpenType(), isA(SimpleType.class));
assertNull(threadFactoryAttribute.getNullableDefault());
assertNull(threadFactoryAttribute.getNullableDescription());
assertThat(threadFactoryAttribute.getType().getName(), is("ObjectName"));
}
Aggregations