Search in sources :

Example 56 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.

the class ListInsertionDataChangeListenerTest method replaceTopNodeSubtreeListeners.

@Test
public void replaceTopNodeSubtreeListeners() {
    TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
    TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
    TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
    TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
    ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
    writeTx.put(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
    assertCommit(writeTx.submit());
    final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> top = topListener.event();
    final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> all = allListener.event();
    final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> foo = fooListener.event();
    final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> bar = barListener.event();
    // Listener for TOP element
    assertContains(top.getOriginalData(), TOP, TOP_FOO);
    assertContains(top.getCreatedData(), TOP_BAR);
    assertContains(top.getUpdatedData(), TOP);
    assertContains(top.getRemovedPaths(), TOP_FOO);
    /*
         *  Listener for all list items
         *
         *  Updated should be empty, since no list item was
         *  updated, items were only removed and added
         */
    assertContains(all.getOriginalData(), TOP_FOO);
    assertContains(all.getCreatedData(), TOP_BAR);
    assertEmpty(all.getUpdatedData());
    assertContains(all.getRemovedPaths(), TOP_FOO);
    /*
         *  Listener for all Foo item
         *
         *  This one should see only Foo item removed
         */
    assertContains(foo.getOriginalData(), TOP_FOO);
    assertEmpty(foo.getCreatedData());
    assertEmpty(foo.getUpdatedData());
    assertContains(foo.getRemovedPaths(), TOP_FOO);
    /*
         *  Listener for bar list items
         *
         *  Updated should be empty, since no list item was
         *  updated, items were only removed and added
         */
    assertEmpty(bar.getOriginalData());
    assertContains(bar.getCreatedData(), TOP_BAR);
    assertEmpty(bar.getUpdatedData());
    assertEmpty(bar.getRemovedPaths());
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 57 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.

the class AbstractForwardedDataBroker method toBinding.

protected Set<InstanceIdentifier<?>> toBinding(final InstanceIdentifier<?> path, final Set<YangInstanceIdentifier> normalized) {
    final Set<InstanceIdentifier<?>> hashSet = new HashSet<>();
    for (final YangInstanceIdentifier normalizedPath : normalized) {
        try {
            final Optional<InstanceIdentifier<? extends DataObject>> potential = getCodec().toBinding(normalizedPath);
            if (potential.isPresent()) {
                final InstanceIdentifier<? extends DataObject> binding = potential.get();
                hashSet.add(binding);
            } else if (normalizedPath.getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) {
                hashSet.add(path);
            }
        } catch (final DeserializationException e) {
            LOG.warn("Failed to transform {}, omitting it", normalizedPath, e);
        }
    }
    return hashSet;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DeserializationException(org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException) HashSet(java.util.HashSet)

Example 58 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.

the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.

@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
    DataBroker dataBroker = testContext.getDataBroker();
    // We wrote initial state NODE_0_FLOW
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
    transaction.submit().get(5, TimeUnit.SECONDS);
    // We registered DataChangeListener
    final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
    dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
    assertFalse(eventFuture.isDone());
    final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
    secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
    secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
    secondTx.submit().get(5, TimeUnit.SECONDS);
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
    assertNotNull(event);
    // Data change should contains NODE_1 Flow - which was added
    assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
    // Data change must not containe NODE_0 Flow which was replaced with same value.
    assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 59 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project bgpcep by opendaylight.

the class NodeChangedListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();
    final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
    final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
    final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();
    for (final DataTreeModification<?> change : changes) {
        final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
        final DataObjectModification<?> rootNode = change.getRootNode();
        handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
    }
    // Now walk all nodes, check for removals/additions and cascade them to LSPs
    for (final InstanceIdentifier<Node> iid : nodes) {
        enumerateLsps(iid, (Node) original.get(iid), lsps);
        enumerateLsps(iid, (Node) updated.get(iid), lsps);
        enumerateLsps(iid, (Node) created.get(iid), lsps);
    }
    // We now have list of all affected LSPs. Walk them create/remove them
    updateTransaction(trans, lsps, original, updated, created);
    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
            LOG.trace("Topology change committed successfully");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to propagate a topology change, target topology became inconsistent", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : HashMap(java.util.HashMap) SupportingNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) HashSet(java.util.HashSet)

Example 60 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project openflowplugin by opendaylight.

the class PacketOutConvertor method getPortNumber.

private static PortNumber getPortNumber(final PathArgument pathArgument, final Short ofVersion) {
    // FIXME VD P! find InstanceIdentifier helper
    InstanceIdentifier.IdentifiableItem<?, ?> item = Arguments.checkInstanceOf(pathArgument, InstanceIdentifier.IdentifiableItem.class);
    NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
    Long port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.get(ofVersion), key.getId());
    return new PortNumber(port);
}
Also used : InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Aggregations

InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)142 Logger (org.slf4j.Logger)57 LoggerFactory (org.slf4j.LoggerFactory)57 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)52 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)52 ArrayList (java.util.ArrayList)47 List (java.util.List)47 Collections (java.util.Collections)40 Optional (com.google.common.base.Optional)39 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)37 BigInteger (java.math.BigInteger)36 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)35 Inject (javax.inject.Inject)34 Singleton (javax.inject.Singleton)34 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)30 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)29 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)28 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)26 PostConstruct (javax.annotation.PostConstruct)24 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)24