Ask Your Question
0

Is it possible to acccess datastore in an rpc handle function?

asked 2016-11-11 00:55:27 -0700

icehong gravatar image

I want read ietf topology tree in a rpc handle function, But I got an exception on read transaction.

Here is the the error message :

org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture cannot be cast to org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology

And the sample code (in and rpc process context) :

        ReadOnlyTransaction readTx = dataProvider.newReadOnlyTransaction();

    TopologyId topoId = new TopologyId("flow:1");
    TopologyKey key = new TopologyKey(topoId);
    InstanceIdentifier<Topology> topoIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
            .child(Topology.class, key).build();
    Topology topology;
    try {
        topology = (Topology) readTx.read(LogicalDatastoreType.OPERATIONAL, topoIdentifier).get();
        // error happens here.   
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-13 17:56:02 -0700

icehong gravatar image

finally resoved by such code .

        TopologyId topoId = new TopologyId("flow:1");
    TopologyKey key = new TopologyKey(topoId);
    InstanceIdentifier<Topology> topoIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
            .child(Topology.class, key).build();
    Optional <Topology> optional;
    try {
        optional = readTx.read(LogicalDatastoreType.OPERATIONAL, topoIdentifier).get();
        if(optional.isPresent())
        {
            Topology rxTopology = optional.get();
edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2016-11-11 00:55:27 -0700

Seen: 28 times

Last updated: Nov 13 '16