Search in sources :

Example 36 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.

the class TxchainBaRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
        for (long l = 0; l < outerListElem; l++) {
            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
            try {
                Optional<OuterList> 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 37 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.

the class EventSourceTopicTest method setUp.

@Before
public void setUp() throws Exception {
    final NotificationPattern notificationPattern = new NotificationPattern("value1");
    eventSourceServiceMock = mock(EventSourceService.class);
    doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build()).buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class));
    eventSourceTopologyMock = mock(EventSourceTopology.class);
    dataBrokerMock = mock(DataBroker.class);
    doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
    doReturn(dataBrokerMock).when(eventSourceTopologyMock).getDataBroker();
    WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
    doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
    doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
    CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class);
    doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit();
    ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
    doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
    CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class);
    doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
    eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
}
Also used : NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) EventSourceService(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService) JoinTopicInput(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) JoinTopicOutputBuilder(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Before(org.junit.Before)

Example 38 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.

the class EventSourceTopologyTest method topicTestHelper.

private void topicTestHelper() throws Exception {
    constructorTestHelper();
    createTopicInputMock = mock(CreateTopicInput.class);
    eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock);
    NotificationPattern notificationPattern = new NotificationPattern("value1");
    doReturn(notificationPattern).when(createTopicInputMock).getNotificationPattern();
    Pattern pattern = new Pattern("valuePattern1");
    doReturn(pattern).when(createTopicInputMock).getNodeIdPattern();
    listenerRegistrationMock = mock(ListenerRegistration.class);
    doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener(any(DataTreeIdentifier.class), any(EventSourceTopic.class));
    ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
    doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
    CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
    doReturn(checkedFutureMock).when(readOnlyTransactionMock).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    Optional optionalMock = mock(Optional.class);
    doReturn(optionalMock).when(checkedFutureMock).checkedGet();
    doReturn(true).when(optionalMock).isPresent();
    Topology topologyMock = mock(Topology.class);
    doReturn(topologyMock).when(optionalMock).get();
    Node nodeMock = mock(Node.class);
    List<Node> nodeList = new ArrayList<>();
    nodeList.add(nodeMock);
    doReturn(nodeList).when(topologyMock).getNode();
    NodeId nodeId = new NodeId("nodeIdValue1");
    doReturn(nodeId).when(nodeMock).getNodeId();
}
Also used : Pattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern) NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) Optional(com.google.common.base.Optional) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ArrayList(java.util.ArrayList) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) CreateTopicInput(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) CheckedFuture(com.google.common.util.concurrent.CheckedFuture)

Example 39 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class MatchBgpNeighborSetHandler method loadRoleSets.

private List<PeerId> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
    final Optional<NeighborSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key))).get();
    if (!result.isPresent()) {
        return Collections.emptyList();
    }
    return result.get().getNeighbor().stream().map(nei -> RouterIds.createPeerId(nei.getAddress())).collect(Collectors.toList());
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId) RouterIds(org.opendaylight.protocol.bgp.rib.spi.RouterIds) NeighborSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSet) StringUtils(org.apache.commons.lang3.StringUtils) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) MatchSetOptionsRestrictedType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsRestrictedType) BGPRouteEntryImportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters) Optional(com.google.common.base.Optional) Objects.requireNonNull(java.util.Objects.requireNonNull) RouteEntryBaseAttributes(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes) Nonnull(javax.annotation.Nonnull) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) Nullable(javax.annotation.Nullable) DefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) BgpConditionsAugmentationPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsAugmentationPolicy) MatchBgpNeighborSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.bgp.neighbor.grouping.MatchBgpNeighborSet) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) RoutingPolicy(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy) Collectors(java.util.stream.Collectors) NeighborSetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSetKey) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) NeighborSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.defined.sets.NeighborSets) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) BgpNeighbor(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.BgpNeighbor) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) MatchBgpNeighborCondition(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchBgpNeighborCondition) CacheBuilder(com.google.common.cache.CacheBuilder) Collections(java.util.Collections) NeighborSetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSetKey) NeighborSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSet) MatchBgpNeighborSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.bgp.neighbor.grouping.MatchBgpNeighborSet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)

Example 40 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class MatchClusterIdSetHandler method loadSets.

private ClusterIdSet loadSets(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
    final Optional<ClusterIdSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, CLUSTERS_ID_SETS_IID.child(ClusterIdSet.class, new ClusterIdSetKey(key))).get();
    return result.orNull();
}
Also used : ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ClusterIdSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSet) ClusterIdSetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSetKey)

Aggregations

ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)65 Optional (com.google.common.base.Optional)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 ExecutionException (java.util.concurrent.ExecutionException)17 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)13 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)12 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)8 ArrayList (java.util.ArrayList)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)7 List (java.util.List)6 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)6 Test (org.junit.Test)5 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)5 Nonnull (javax.annotation.Nonnull)4 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)4 CacheBuilder (com.google.common.cache.CacheBuilder)3