Search in sources :

Example 1 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType in project netvirt by opendaylight.

the class MergeCommandsAggregator method mergeUpdate.

public void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, LogicalDatastoreType datastoreType, ReadWriteTransaction tx) {
    if (mod == null) {
        return;
    }
    Collection<DataObjectModification> modifications = mod.getModifiedChildren();
    modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
        MergeCommand mergeCommand = commands.get(modification.getDataType());
        boolean create = modification.getDataAfter() != null;
        DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
        InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
        DataObject transformedItem = mergeCommand.transform(dstPath, data);
        Optional<DataObject> existingDataOptional = null;
        try {
            existingDataOptional = tx.read(datastoreType, transformedId).checkedGet();
        } catch (ReadFailedException ex) {
            LOG.error("Failed to read data {} from {}", transformedId, datastoreType);
            return;
        }
        String destination = datastoreType == CONFIGURATION ? "child" : "parent";
        if (create) {
            if (isDataUpdated(existingDataOptional, transformedItem)) {
                LOG.debug("Copy to {} {} {}", destination, datastoreType, transformedId);
                tx.put(datastoreType, transformedId, transformedItem, true);
            } else {
                LOG.debug("Data not updated skip copy to {}", transformedId);
            }
        } else {
            if (existingDataOptional.isPresent()) {
                LOG.debug("Delete from {} {} {}", destination, datastoreType, transformedId);
                tx.delete(datastoreType, transformedId);
            } else {
                LOG.debug("Delete skipped for {}", transformedId);
            }
        }
    });
}
Also used : Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) CONFIGURATION(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION) HashMap(java.util.HashMap) SuperTypeUtil(org.opendaylight.genius.utils.SuperTypeUtil) LocalUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalUcastCmd) RemoteUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Map(java.util.Map) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) Builder(org.opendaylight.yangtools.concepts.Builder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)

Example 2 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType in project controller by opendaylight.

the class DOMBrokerTest method setupStore.

@Before
public void setupStore() {
    InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
    InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService());
    schemaContext = TestModel.createTestContext();
    operStore.onGlobalContextUpdated(schemaContext);
    configStore.onGlobalContextUpdated(schemaContext);
    final ImmutableMap<LogicalDatastoreType, DOMStore> stores = // 
    ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(CONFIGURATION, // 
    configStore).put(OPERATIONAL, // 
    operStore).build();
    commitExecutor = new CommitExecutorService(Executors.newSingleThreadExecutor());
    futureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 5, "FCB", DOMBrokerTest.class);
    executor = new DeadlockDetectingListeningExecutorService(commitExecutor, TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, futureExecutor);
    domBroker = new SerializedDOMDataBroker(stores, executor);
}
Also used : DOMStore(org.opendaylight.controller.sal.core.spi.data.DOMStore) InMemoryDOMDataStore(org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) Before(org.junit.Before)

Example 3 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType in project controller by opendaylight.

the class SimpletxBaRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
        for (long l = 0; l < outerListElem; l++) {
            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
            Optional<OuterList> optionalDataObject;
            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
            try {
                optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    OuterList outerList = optionalDataObject.get();
                    String[] objectsArray = new String[outerList.getInnerList().size()];
                    for (InnerList innerList : outerList.getInnerList()) {
                        if (objectsArray[innerList.getName()] != null) {
                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
                        }
                        objectsArray[innerList.getName()] = innerList.getValue();
                    }
                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
                        String itemStr = objectsArray[i];
                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
                            break;
                        }
                    }
                    txOk++;
                } else {
                    txError++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InnerList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList) Optional(com.google.common.base.Optional) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) OuterListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)

Example 4 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType in project controller by opendaylight.

the class SimpletxBaWrite method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    long writeCnt = 0;
    for (OuterList element : this.list) {
        InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.getKey());
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, iid, element);
        } else {
            tx.merge(dsType, iid, element);
        }
        writeCnt++;
        if (writeCnt == writesPerTx) {
            try {
                tx.submit().checkedGet();
                txOk++;
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Transaction failed: {}", e);
                txError++;
            }
            tx = dataBroker.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    if (writeCnt != 0) {
        try {
            tx.submit().checkedGet();
        } catch (final TransactionCommitFailedException e) {
            LOG.error("Transaction failed: {}", e);
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)

Example 5 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType 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

LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)27 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)12 Optional (com.google.common.base.Optional)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 DOMStore (org.opendaylight.controller.sal.core.spi.data.DOMStore)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 TestExec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec)6 OuterList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList)6 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)6 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 InMemoryDOMDataStore (org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore)5 Nonnull (javax.annotation.Nonnull)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 QName (org.opendaylight.yangtools.yang.common.QName)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3