Search in sources :

Example 1 with SchemaContext

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);
}
Also used : SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Before(org.junit.Before)

Example 2 with SchemaContext

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;
}
Also used : ReactorException(org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException) InputStream(java.io.InputStream) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext)

Example 3 with 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));
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) Collection(java.util.Collection) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 4 with SchemaContext

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;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 5 with SchemaContext

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;
    }
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ClusteredDataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExtendedBlueprintContainer(org.apache.aries.blueprint.services.ExtendedBlueprintContainer) Optional(com.google.common.base.Optional) XMLStreamException(javax.xml.stream.XMLStreamException) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Logger(org.slf4j.Logger) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Objects(java.util.Objects) ModificationType(org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType) Futures(com.google.common.util.concurrent.Futures) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) SAXException(org.xml.sax.SAXException) DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ConfigURLProvider(org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider) ConfigURLProvider(org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService)

Aggregations

SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)9 Test (org.junit.Test)4 Collection (java.util.Collection)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 TestKit (akka.testkit.javadsl.TestKit)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 Shard (org.opendaylight.controller.cluster.datastore.Shard)2 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)2 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)2 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 Success (akka.actor.Status.Success)1 Optional (com.google.common.base.Optional)1