use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class ClientBackedDataStoreTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
final SchemaContext schemaContext = TestModel.createTestContext();
Mockito.when(actorContext.getSchemaContext()).thenReturn(schemaContext);
Mockito.when(actorContext.getDatastoreContext()).thenReturn(DatastoreContext.newBuilder().build());
Mockito.when(clientTransaction.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
Mockito.when(clientSnapshot.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
Mockito.when(clientActor.getIdentifier()).thenReturn(CLIENT_IDENTIFIER);
Mockito.when(clientActor.createTransaction()).thenReturn(clientTransaction);
Mockito.when(clientActor.createLocalHistory()).thenReturn(clientLocalHistory);
Mockito.when(clientActor.createSnapshot()).thenReturn(clientSnapshot);
}
use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class BenchmarkModel method createTestContext.
public static SchemaContext createTestContext() {
final SchemaContext schemaContext;
final List<InputStream> streams = Collections.singletonList(getInputStream());
try {
schemaContext = YangParserTestUtils.parseYangStreams(streams);
} catch (ReactorException e) {
throw new RuntimeException("Unable to build schema context from " + streams, e);
}
return schemaContext;
}
use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class TransactionProxyTest method testReadRoot.
@Test
public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
SchemaContext 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);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
NormalizedNode<?, ?> normalizedNode = readOptional.get();
assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
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.SchemaContext 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);
SchemaContext 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());
DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName);
checkNotNull(dataSchema, "%s: Could not obtain the schema for %s", logName, bindingContext.bindingQName);
checkCondition(bindingContext.schemaType.isAssignableFrom(dataSchema.getClass()), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass());
NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigXMLFile(schemaContext, dataSchema);
if (dataNode == null) {
dataNode = fallback.get(schemaService.getGlobalContext(), dataSchema);
}
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.SchemaContext in project controller by opendaylight.
the class DataStoreAppConfigMetadata method createDefaultInstance.
private DataObject createDefaultInstance() {
try {
ConfigURLProvider inputStreamProvider = appConfigFileName -> {
File appConfigFile = new File(DEFAULT_APP_CONFIG_FILE_PATH, appConfigFileName);
LOG.debug("{}: parsePossibleDefaultAppConfigXMLFile looking for file {}", logName(), appConfigFile.getAbsolutePath());
if (!appConfigFile.exists()) {
return Optional.absent();
}
LOG.debug("{}: Found file {}", logName(), appConfigFile.getAbsolutePath());
return Optional.of(appConfigFile.toURI().toURL());
};
DataStoreAppConfigDefaultXMLReader<?> reader = new DataStoreAppConfigDefaultXMLReader<>(logName(), defaultAppConfigFileName, getOSGiService(DOMSchemaService.class), bindingSerializer, bindingContext, inputStreamProvider);
return reader.createDefaultInstance((schemaContext, dataSchema) -> {
// Fallback if file cannot be read, try XML from Config
NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigElement(schemaContext, dataSchema);
if (dataNode == null) {
// or, as last resort, defaults from the model
return bindingContext.newDefaultNode(dataSchema);
} else {
return dataNode;
}
});
} catch (final ConfigXMLReaderException | IOException | SAXException | XMLStreamException | ParserConfigurationException | URISyntaxException e) {
if (e.getCause() == null) {
setFailureMessage(e.getMessage());
} else {
setFailure(e.getMessage(), e);
}
return null;
}
}
Aggregations