Search in sources :

Example 6 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project bgpcep by opendaylight.

the class ApplicationPeer method processRoutesTable.

private synchronized void processRoutesTable(final DataTreeCandidateNode node, final YangInstanceIdentifier identifier, final DOMDataWriteTransaction tx, final YangInstanceIdentifier routeTableIdentifier) {
    for (final DataTreeCandidateNode child : node.getChildNodes()) {
        final YangInstanceIdentifier childIdentifier = identifier.node(child.getIdentifier());
        switch(child.getModificationType()) {
            case DELETE:
                LOG.trace("App peer -> AdjRibsIn path delete: {}", childIdentifier);
                tx.delete(LogicalDatastoreType.OPERATIONAL, childIdentifier);
                break;
            case UNMODIFIED:
                // No-op
                break;
            case SUBTREE_MODIFIED:
                // we need to go deeper three levels
                if (!routeTableIdentifier.equals(childIdentifier.getParent().getParent().getParent())) {
                    processRoutesTable(child, childIdentifier, tx, routeTableIdentifier);
                    break;
                }
            case WRITE:
                if (child.getDataAfter().isPresent()) {
                    final NormalizedNode<?, ?> dataAfter = child.getDataAfter().get();
                    LOG.trace("App peer -> AdjRibsIn path : {}", childIdentifier);
                    LOG.trace("App peer -> AdjRibsIn data : {}", dataAfter);
                    tx.put(LogicalDatastoreType.OPERATIONAL, childIdentifier, dataAfter);
                }
                break;
            default:
                break;
        }
    }
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 7 with DataTreeCandidateNode

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

the class CandidateListChangeListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
    for (DataTreeCandidate change : changes) {
        DataTreeCandidateNode changeRoot = change.getRootNode();
        ModificationType type = changeRoot.getModificationType();
        LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath());
        NodeIdentifierWithPredicates candidateKey = (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
        String candidate = candidateKey.getKeyValues().get(CANDIDATE_NAME_QNAME).toString();
        YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
        if (type == ModificationType.WRITE || type == ModificationType.APPEARED) {
            LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId);
            Collection<String> newCandidates = addToCurrentCandidates(entityId, candidate);
            shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(newCandidates)), shard);
        } else if (type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) {
            LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId);
            Collection<String> newCandidates = removeFromCurrentCandidates(entityId, candidate);
            shard.tell(new CandidateRemoved(entityId, candidate, new ArrayList<>(newCandidates)), shard);
        }
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) ModificationType(org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType) CandidateAdded(org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CandidateRemoved(org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateRemoved) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 8 with DataTreeCandidateNode

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

the class DataTreeCandidateInputOutput method writeDataTreeCandidate.

public static void writeDataTreeCandidate(final DataOutput out, DataTreeCandidate candidate) throws IOException {
    try (NormalizedNodeDataOutput writer = NormalizedNodeInputOutput.newDataOutput(out)) {
        writer.writeYangInstanceIdentifier(candidate.getRootPath());
        final DataTreeCandidateNode node = candidate.getRootNode();
        switch(node.getModificationType()) {
            case APPEARED:
                writer.writeByte(APPEARED);
                writeChildren(writer, node.getChildNodes());
                break;
            case DELETE:
                writer.writeByte(DELETE);
                break;
            case DISAPPEARED:
                writer.writeByte(DISAPPEARED);
                writeChildren(writer, node.getChildNodes());
                break;
            case SUBTREE_MODIFIED:
                writer.writeByte(SUBTREE_MODIFIED);
                writeChildren(writer, node.getChildNodes());
                break;
            case UNMODIFIED:
                writer.writeByte(UNMODIFIED);
                break;
            case WRITE:
                writer.writeByte(WRITE);
                writer.writeNormalizedNode(node.getDataAfter().get());
                break;
            default:
                throwUnhandledNodeType(node);
        }
    }
}
Also used : NormalizedNodeDataOutput(org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)

Example 9 with DataTreeCandidateNode

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

the class AbstractShardTest method mockUnmodifiedCandidate.

static DataTreeCandidateTip mockUnmodifiedCandidate(final String name) {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
    final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
    doReturn(ModificationType.UNMODIFIED).when(mockCandidateNode).getModificationType();
    doReturn(YangInstanceIdentifier.EMPTY).when(mockCandidate).getRootPath();
    doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
    return mockCandidate;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Example 10 with DataTreeCandidateNode

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

the class AbstractShardTest method mockCandidate.

public static DataTreeCandidateTip mockCandidate(final String name) {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
    final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
    doReturn(ModificationType.WRITE).when(mockCandidateNode).getModificationType();
    doReturn(Optional.of(ImmutableNodes.containerNode(CarsModel.CARS_QNAME))).when(mockCandidateNode).getDataAfter();
    doReturn(CarsModel.BASE_PATH).when(mockCandidate).getRootPath();
    doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
    return mockCandidate;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)38 Test (org.junit.Test)18 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)13 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)12 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)2 Collection (java.util.Collection)1 Before (org.junit.Before)1 CandidateAdded (org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded)1