Search in sources :

Example 46 with ReadOnlyTransaction

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

the class PCEPStatefulPeerProposal method setPeerProposal.

void setPeerProposal(final NodeId nodeId, final TlvsBuilder openTlvsBuilder, final byte[] speakerId) {
    if (isSynOptimizationEnabled(openTlvsBuilder)) {
        Optional<LspDbVersion> result = Optional.absent();
        try (ReadOnlyTransaction rTx = this.dataBroker.newReadOnlyTransaction()) {
            final ListenableFuture<Optional<LspDbVersion>> future = rTx.read(LogicalDatastoreType.OPERATIONAL, this.topologyId.child(Node.class, new NodeKey(nodeId)).augmentation(Node1.class).child(PathComputationClient.class).augmentation(PathComputationClient1.class).child(LspDbVersion.class));
            try {
                result = future.get();
            } catch (final InterruptedException | ExecutionException e) {
                LOG.warn("Failed to read toplogy {}.", InstanceIdentifier.keyOf(PCEPStatefulPeerProposal.this.topologyId), e);
            }
        }
        if (speakerId == null && !result.isPresent()) {
            return;
        }
        final Tlvs3Builder syncBuilder = new Tlvs3Builder();
        if (result.isPresent()) {
            syncBuilder.setLspDbVersion(result.get());
        }
        if (speakerId != null) {
            syncBuilder.setSpeakerEntityId(new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(speakerId).build());
        }
        openTlvsBuilder.addAugmentation(Tlvs3.class, syncBuilder.build()).build();
    }
}
Also used : Optional(com.google.common.base.Optional) PathComputationClient(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClient) SpeakerEntityIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.speaker.entity.id.tlv.SpeakerEntityIdBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Tlvs3Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.Tlvs3Builder) Tlvs3(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.Tlvs3) LspDbVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.lsp.db.version.tlv.LspDbVersion) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)

Example 47 with ReadOnlyTransaction

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

the class L2GatewayConnectionListener method loadL2GwDeviceCache.

private void loadL2GwDeviceCache(final int trialNo) {
    scheduler.getScheduledExecutorService().schedule(() -> {
        if (trialNo == MAX_READ_TRIALS) {
            LOG.error("Failed to read config topology");
            return;
        }
        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
        InstanceIdentifier<Topology> topoIid = HwvtepSouthboundUtils.createHwvtepTopologyInstanceIdentifier();
        Futures.addCallback(tx.read(CONFIGURATION, topoIid), new FutureCallback<Optional<Topology>>() {

            @Override
            public void onSuccess(Optional<Topology> topologyOptional) {
                if (topologyOptional != null && topologyOptional.isPresent()) {
                    loadL2GwDeviceCache(topologyOptional.get().getNode());
                }
                registerListener(CONFIGURATION, broker);
            }

            @Override
            public void onFailure(Throwable throwable) {
                loadL2GwDeviceCache(trialNo + 1);
            }
        }, MoreExecutors.directExecutor());
        tx.close();
    }, 1, TimeUnit.SECONDS);
}
Also used : Optional(com.google.common.base.Optional) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)

Example 48 with ReadOnlyTransaction

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

the class StatisticsImpl method getElementCountersByHandler.

@Override
public Future<RpcResult<GetElementCountersByHandlerOutput>> getElementCountersByHandler(GetElementCountersByHandlerInput input) {
    InstanceIdentifier<CounterRequests> ingressPath = InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    InstanceIdentifier<CounterRequests> egressPath = InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    ReadOnlyTransaction tx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
    List<CounterResult> counters = new ArrayList<>();
    try {
        if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
            LOG.warn("Handler does not exists");
            return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
        }
        if (ingressRequestData.get().isPresent()) {
            CounterRequests ingressCounterRequest = ingressRequestData.get().get();
            CounterResultDataStructure ingressCounterResultDS = createElementCountersResult(ingressCounterRequest);
            if (ingressCounterResultDS == null) {
                LOG.warn("Unable to get counter results");
                StatisticsPluginImplCounters.failed_getting_counter_results.inc();
                return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
            }
            createCounterResults(counters, ingressCounterResultDS, CountersServiceUtils.INGRESS_COUNTER_RESULT_ID);
        }
        if (egressRequestData.get().isPresent()) {
            CounterRequests egressCounterRequest = egressRequestData.get().get();
            CounterResultDataStructure egressCounterResultDS = createElementCountersResult(egressCounterRequest);
            if (egressCounterResultDS == null) {
                LOG.warn("Unable to get counter results");
                StatisticsPluginImplCounters.failed_getting_counter_results.inc();
                return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
            }
            createCounterResults(counters, egressCounterResultDS, CountersServiceUtils.EGRESS_COUNTER_RESULT_ID);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    }
    GetElementCountersByHandlerOutputBuilder gecbhob = new GetElementCountersByHandlerOutputBuilder();
    gecbhob.setCounterResult(counters);
    return RpcResultBuilder.success(gecbhob.build()).buildFuture();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) GetElementCountersByHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutput) GetElementCountersByHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutputBuilder) Optional(com.google.common.base.Optional) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) ArrayList(java.util.ArrayList) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 49 with ReadOnlyTransaction

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

the class StatisticsImpl method checkPoolExists.

private boolean checkPoolExists() {
    ReadOnlyTransaction roTransaction = db.newReadOnlyTransaction();
    InstanceIdentifier<IdPool> path = InstanceIdentifier.create(IdPools.class).child(IdPool.class, new IdPoolKey(CountersServiceUtils.COUNTERS_PULL_NAME));
    CheckedFuture<Optional<IdPool>, ReadFailedException> pool = roTransaction.read(LogicalDatastoreType.CONFIGURATION, path);
    try {
        Optional<IdPool> poolOpt = pool.get();
        if (poolOpt.isPresent()) {
            return true;
        }
    } catch (InterruptedException | ExecutionException e) {
        return false;
    }
    return false;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) ExecutionException(java.util.concurrent.ExecutionException) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)

Example 50 with ReadOnlyTransaction

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

the class ShellUtil method getNodeInfo.

public static OFNode getNodeInfo(final Long nodeId, final DataBroker broker) {
    OFNode ofNode = null;
    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
    InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_PREFIX + nodeId))).build();
    Optional<Node> result;
    try {
        CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
        result = checkedFuture.get();
        if (result.isPresent()) {
            Node node = result.get();
            String name = null;
            List<NodeConnector> nodeConnectors = null;
            List<String> portList = new ArrayList<>();
            FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
            if (flowCapableNode != null) {
                name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
            } else {
                LOG.error("Error while converting OFNode:{} to FlowCapableNode: {}", node.getId());
                return null;
            }
            nodeConnectors = node.getNodeConnector();
            for (NodeConnector nodeConnector : nodeConnectors) {
                FlowCapableNodeConnector flowCapableNodeConnector = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
                if (flowCapableNodeConnector == null) {
                    LOG.error("Error for OFNode:{} while reading nodeConnectors {}", node.getId());
                    return null;
                } else {
                    String portName = flowCapableNodeConnector.getName();
                    portList.add(portName);
                }
            }
            ofNode = new OFNode(nodeId, name, portList);
        } else {
            LOG.error("OFNode with nodeId {} not present Inventory DS: {}", nodeId);
            return null;
        }
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Error reading node {} from Inventory DS: {}", nodeId, e);
    }
    return ofNode;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ArrayList(java.util.ArrayList) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

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