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();
}
}
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);
}
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();
}
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;
}
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;
}
Aggregations