Search in sources :

Example 26 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class ResolveDataChangeEventsTask method resolveSubtreeChangeEvent.

private boolean resolveSubtreeChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode modification) {
    final Optional<NormalizedNode<?, ?>> maybeBefore = modification.getDataBefore();
    final Optional<NormalizedNode<?, ?>> maybeAfter = modification.getDataAfter();
    Preconditions.checkArgument(maybeBefore.isPresent(), "Subtree change with before-data not present at path %s", state.getPath());
    Preconditions.checkArgument(maybeAfter.isPresent(), "Subtree change with after-data not present at path %s", state.getPath());
    if (!state.needsProcessing()) {
        LOG.trace("Not processing modified subtree {}", state.getPath());
        return true;
    }
    DataChangeScope scope = null;
    for (DataTreeCandidateNode childMod : modification.getChildNodes()) {
        final ResolveDataChangeState childState = state.child(childMod.getIdentifier());
        switch(childMod.getModificationType()) {
            case APPEARED:
            case DELETE:
            case DISAPPEARED:
            case WRITE:
                if (resolveAnyChangeEvent(childState, childMod)) {
                    scope = DataChangeScope.ONE;
                }
                break;
            case SUBTREE_MODIFIED:
                if (resolveSubtreeChangeEvent(childState, childMod) && scope == null) {
                    scope = DataChangeScope.SUBTREE;
                }
                break;
            case UNMODIFIED:
                // no-op
                break;
            default:
                break;
        }
    }
    final NormalizedNode<?, ?> before = maybeBefore.get();
    final NormalizedNode<?, ?> after = maybeAfter.get();
    if (scope != null) {
        DOMImmutableDataChangeEvent one = DOMImmutableDataChangeEvent.builder(scope).addUpdated(state.getPath(), before, after).build();
        state.addEvent(one);
    }
    state.collectEvents(before, after, collectedEvents);
    return scope != null;
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 27 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class DOMBrokerPerformanceTest method measureSeparateWritesOneLevel.

private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception {
    final List<DOMDataReadWriteTransaction> transactions = measure("Txs:" + txNum + " Allocate", () -> {
        List<DOMDataReadWriteTransaction> builder = new ArrayList<>(txNum);
        for (int i = 0; i < txNum; i++) {
            DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
            builder.add(writeTx);
        }
        return builder;
    });
    assertEquals(txNum, transactions.size());
    measure("Txs:" + txNum + " Writes:1", (Callable<Void>) () -> {
        int index = 0;
        for (DOMDataReadWriteTransaction writeTx : transactions) {
            // Writes /test/outer-list/i in writeTx
            writeTx.put(OPERATIONAL, outerListPath(index), outerList(index));
            index++;
        }
        return null;
    });
    measure("Txs:" + txNum + " Writes:" + innerNum, (Callable<Void>) () -> {
        int index = 0;
        for (DOMDataReadWriteTransaction writeTx : transactions) {
            // Writes /test/outer-list/i in writeTx
            YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(index)).node(TestModel.INNER_LIST_QNAME).build();
            writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build());
            for (int j = 0; j < innerNum; j++) {
                YangInstanceIdentifier innerPath = YangInstanceIdentifier.builder(path).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
                writeTx.put(OPERATIONAL, innerPath, ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)));
            }
            index++;
        }
        return null;
    });
    measure("Txs:" + txNum + " Submit, Finish", (Callable<Void>) () -> {
        List<ListenableFuture<?>> allFutures = measure(txNum + " Submits", () -> {
            List<ListenableFuture<?>> builder = new ArrayList<>(txNum);
            for (DOMDataReadWriteTransaction tx : transactions) {
                builder.add(tx.submit());
            }
            return builder;
        });
        Futures.allAsList(allFutures).get();
        return null;
    });
    final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", (Callable<DOMDataReadTransaction>) () -> domBroker.newReadOnlyTransaction());
    measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable<Void>) () -> {
        for (int i = 0; i < txNum; i++) {
            ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, outerListPath(i));
            assertTrue("outerList/" + i, potential.get().isPresent());
        }
        return null;
    });
    measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", (Callable<Void>) () -> {
        for (int i = 0; i < txNum; i++) {
            for (int j = 0; j < innerNum; j++) {
                YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)).node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
                ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, path);
                assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent());
            }
        }
        return null;
    });
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 28 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class DOMBrokerTest method testTransactionCommit.

@Test(timeout = 10000)
public void testTransactionCommit() throws InterruptedException, ExecutionException {
    DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
    assertNotNull(writeTx);
    /**
     * Writes /test in writeTx
     */
    writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    /**
     * Reads /test from writeTx Read should return container.
     */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
    assertTrue(writeTxContainer.get().isPresent());
    writeTx.submit().get();
    Optional<NormalizedNode<?, ?>> afterCommitRead = domBroker.newReadOnlyTransaction().read(OPERATIONAL, TestModel.TEST_PATH).get();
    assertTrue(afterCommitRead.isPresent());
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Optional(com.google.common.base.Optional) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 29 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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)

Example 30 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class SimpletxDomRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
        for (int l = 0; l < outerListElem; l++) {
            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
            CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
            try {
                Optional<NormalizedNode<?, ?>> optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    NormalizedNode<?, ?> ret = optionalDataObject.get();
                    LOG.trace("optionalDataObject is {}", ret);
                    txOk++;
                } else {
                    txError++;
                    LOG.warn("optionalDataObject is either null or .isPresent is false");
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)94 Test (org.junit.Test)55 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)39 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Optional (com.google.common.base.Optional)15 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 ActorRef (akka.actor.ActorRef)8 InOrder (org.mockito.InOrder)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 ExecutionException (java.util.concurrent.ExecutionException)7 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 Map (java.util.Map)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6