use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project controller by opendaylight.
the class DataStoreAppConfigDefaultXMLReader method createDefaultInstance.
@SuppressWarnings("unchecked")
public T createDefaultInstance(final FallbackConfigProvider fallback) throws ConfigXMLReaderException, URISyntaxException, ParserConfigurationException, XMLStreamException, SAXException, IOException {
YangInstanceIdentifier yangPath = bindingSerializer.toYangInstanceIdentifier(bindingContext.appConfigPath);
LOG.debug("{}: Creating app config instance from path {}, Qname: {}", logName, yangPath, bindingContext.bindingQName);
checkNotNull(schemaService, "%s: Could not obtain the SchemaService OSGi service", logName);
EffectiveModelContext schemaContext = schemaService.getGlobalContext();
Module module = schemaContext.findModule(bindingContext.bindingQName.getModule()).orElse(null);
checkNotNull(module, "%s: Could not obtain the module schema for namespace %s, revision %s", logName, bindingContext.bindingQName.getNamespace(), bindingContext.bindingQName.getRevision());
final SchemaInferenceStack schemaStack = SchemaInferenceStack.of(schemaContext);
final SchemaTreeEffectiveStatement<?> dataSchema;
try {
dataSchema = schemaStack.enterSchemaTree(bindingContext.bindingQName);
} catch (IllegalArgumentException e) {
throw new ConfigXMLReaderException(logName + ": Could not obtain the schema for " + bindingContext.bindingQName, e);
}
checkCondition(bindingContext.schemaType.isInstance(dataSchema), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass());
NormalizedNode dataNode = parsePossibleDefaultAppConfigXMLFile(schemaStack);
if (dataNode == null) {
dataNode = fallback.get(schemaStack.toSchemaTreeInference());
}
DataObject appConfig = bindingSerializer.fromNormalizedNode(yangPath, dataNode).getValue();
// This shouldn't happen but need to handle it in case...
checkNotNull(appConfig, "%s: Could not create instance for app config binding %s", logName, bindingContext.appConfigBindingClass);
return (T) appConfig;
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project controller by opendaylight.
the class TransactionProxyTest method testReadRoot.
@Test
public void testReadRoot() throws InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
EffectiveModelContext schemaContext = SchemaContextHelper.full();
Configuration configuration = mock(Configuration.class);
doReturn(configuration).when(mockActorContext).getConfiguration();
doReturn(schemaContext).when(mockActorContext).getSchemaContext();
doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
Optional<NormalizedNode> readOptional = transactionProxy.read(YangInstanceIdentifier.empty()).get(5, TimeUnit.SECONDS);
assertTrue("NormalizedNode isPresent", readOptional.isPresent());
NormalizedNode normalizedNode = readOptional.get();
assertTrue("Expect value to be a Collection", normalizedNode.body() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode> collection = (Collection<NormalizedNode>) normalizedNode.body();
for (NormalizedNode node : collection) {
assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
}
assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project controller by opendaylight.
the class NormalizedNodeAggregatorTest method testAggregate.
@Test
public void testAggregate() throws InterruptedException, ExecutionException, DataValidationFailedException {
EffectiveModelContext schemaContext = SchemaContextHelper.full();
NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
Optional<NormalizedNode> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.empty(), ImmutableList.of(Optional.<NormalizedNode>of(getRootNode(expectedNode1, schemaContext)), Optional.<NormalizedNode>of(getRootNode(expectedNode2, schemaContext))), schemaContext, LogicalDatastoreType.CONFIGURATION);
NormalizedNode normalizedNode = optional.get();
assertTrue("Expect value to be a Collection", normalizedNode.body() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode> collection = (Collection<NormalizedNode>) normalizedNode.body();
for (NormalizedNode node : collection) {
assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
}
assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", findChildWithQName(collection, TestModel.TEST_QNAME) != null);
assertEquals(expectedNode1, findChildWithQName(collection, TestModel.TEST_QNAME));
assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
assertEquals(expectedNode2, findChildWithQName(collection, CarsModel.BASE_QNAME));
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project mdsal by opendaylight.
the class OSGiDOMSchemaService method bindSnapshot.
@Reference(policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
void bindSnapshot(final OSGiModuleInfoSnapshot newContext) {
LOG.info("Updating context to generation {}", newContext.getGeneration());
final ModuleInfoSnapshot snapshot = newContext.getService();
final EffectiveModelContext ctx = snapshot.getEffectiveModelContext();
final ModuleInfoSnapshot previous = currentSnapshot.getAndSet(snapshot);
LOG.debug("Snapshot updated from {} to {}", previous, snapshot);
listeners.forEach(listener -> notifyListener(ctx, listener));
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project mdsal by opendaylight.
the class ModuleInfoSnapshotResolver method updateSnapshot.
@Holding("this")
@NonNull
private ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
// Alright, now let's find out which sources got captured
final Set<SourceIdentifier> sources = new HashSet<>();
for (Entry<QNameModule, ModuleEffectiveStatement> entry : effectiveModel.getModuleStatements().entrySet()) {
final Optional<Revision> revision = entry.getKey().getRevision();
final ModuleEffectiveStatement module = entry.getValue();
sources.add(RevisionSourceIdentifier.create(module.argument().getLocalName(), revision));
module.streamEffectiveSubstatements(SubmoduleEffectiveStatement.class).map(submodule -> RevisionSourceIdentifier.create(submodule.argument().getLocalName(), revision)).forEach(sources::add);
}
final Map<SourceIdentifier, YangModuleInfo> moduleInfos = new HashMap<>();
final Map<String, ClassLoader> classLoaders = new HashMap<>();
for (SourceIdentifier source : sources) {
final List<RegisteredModuleInfo> regs = sourceToInfoReg.get(source);
checkState(!regs.isEmpty(), "No registration for %s", source);
final RegisteredModuleInfo reg = regs.get(0);
final YangModuleInfo info = reg.info;
moduleInfos.put(source, info);
final Class<?> infoClass = info.getClass();
classLoaders.put(BindingReflections.getModelRootPackageName(infoClass.getPackage()), infoClass.getClassLoader());
}
final ModuleInfoSnapshot next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
currentSnapshot = next;
return next;
}
Aggregations