Search in sources :

Example 16 with DataObject

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

the class BindingDOMRpcImplementationAdapter method invokeRpc.

@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
    final SchemaPath schemaPath = rpc.getType();
    final DataObject bindingInput = input != null ? deserialize(rpc.getType(), input) : null;
    final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
    return transformResult(bindingResult);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Nonnull(javax.annotation.Nonnull)

Example 17 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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 18 with DataObject

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

the class AbstractRIBTestSetup method mockedMethods.

@SuppressWarnings("unchecked")
private void mockedMethods() throws Exception {
    MockitoAnnotations.initMocks(this);
    final ReadOnlyTransaction readTx = mock(ReadOnlyTransaction.class);
    doReturn(new listenerRegistration()).when(this.service).registerDataTreeChangeListener(any(DOMDataTreeIdentifier.class), any(ClusteredDOMDataTreeChangeListener.class));
    final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> map = new HashMap<>();
    map.put(DOMDataTreeChangeService.class, this.service);
    doNothing().when(readTx).close();
    final CheckedFuture<Optional<DataObject>, ReadFailedException> readFuture = mock(CheckedFuture.class);
    doNothing().when(this.domTransWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    doNothing().when(this.domTransWrite).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
    doNothing().when(this.domTransWrite).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    doReturn(Optional.absent()).when(readFuture).checkedGet();
    doReturn(readFuture).when(readTx).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    doNothing().when(this.domChain).close();
    doReturn(this.domTransWrite).when(this.domChain).newWriteOnlyTransaction();
    doNothing().when(getTransaction()).put(eq(LogicalDatastoreType.OPERATIONAL), eq(YangInstanceIdentifier.of(BgpRib.QNAME)), any(NormalizedNode.class));
    doReturn(map).when(this.dom).getSupportedExtensions();
    doReturn(this.domChain).when(this.dom).createTransactionChain(any(BGPPeer.class));
    doReturn(this.transWrite).when(this.chain).newWriteOnlyTransaction();
    doReturn(false).when(this.o).isPresent();
    doReturn(this.o).when(this.future).checkedGet();
    doReturn(this.future).when(this.domTransWrite).submit();
    doNothing().when(this.future).addListener(any(Runnable.class), any(Executor.class));
    doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
    doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
    doReturn(this.future).when(this.transWrite).submit();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Executor(java.util.concurrent.Executor) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 19 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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 20 with DataObject

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

the class ListDeserializerTest method test.

/**
 * Tests {@link ListDeserializer#deserializeList(short, int, ByteBuf, CodeKeyMaker, DeserializerRegistry)}.
 */
@Test
public void test() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    List<DataObject> list = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, 42, buffer, keyMaker, registry);
    Assert.assertNull("List is not null", list);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

DataObject (org.opendaylight.yangtools.yang.binding.DataObject)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)24 Test (org.junit.Test)14 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)10 Optional (com.google.common.base.Optional)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 Collection (java.util.Collection)5 Nonnull (javax.annotation.Nonnull)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)4