use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class StatisticsImpl method acquireElementCountersRequestHandler.
@Override
public Future<RpcResult<AcquireElementCountersRequestHandlerOutput>> acquireElementCountersRequestHandler(AcquireElementCountersRequestHandlerInput input) {
AcquireElementCountersRequestHandlerOutputBuilder aecrhob = new AcquireElementCountersRequestHandlerOutputBuilder();
ReadWriteTransaction transaction = db.newReadWriteTransaction();
UUID randomNumber = UUID.randomUUID();
Integer intRequestKey = allocateId(randomNumber.toString());
if (intRequestKey == null) {
LOG.warn("failed generating unique request identifier");
StatisticsPluginImplCounters.failed_generating_unique_request_id.inc();
return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed generating unique request identifier").buildFuture();
}
String requestKey = String.valueOf(intRequestKey);
try {
if (input.getIncomingTraffic() != null) {
CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
if (!eecrcOpt.isPresent()) {
LOG.warn("failed creating incoming traffic counter request data container in DB");
StatisticsPluginImplCounters.failed_creating_egress_counter_data_config.inc();
return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating egress counter request data container in DB").buildFuture();
}
if (!isIdenticalCounterRequestExist(input.getPortId(), ElementCountersDirection.EGRESS.toString(), input.getIncomingTraffic().getFilters(), eecrcOpt.get().getCounterRequests())) {
installCounterSpecificRules(input.getPortId(), getLportTag(input.getPortId()), getDpn(input.getPortId()), ElementCountersDirection.EGRESS, input.getIncomingTraffic().getFilters());
}
putEgressElementCounterRequestInConfig(input, ElementCountersDirection.EGRESS, transaction, requestKey, CountersServiceUtils.EECRC_IDENTIFIER, eecrcOpt, randomNumber.toString());
transaction.submit();
aecrhob.setIncomingTrafficHandler(requestKey);
bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.EGRESS);
}
if (input.getOutgoingTraffic() != null) {
transaction = db.newReadWriteTransaction();
CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
if (!iecrcOpt.isPresent()) {
LOG.warn("failed creating outgoing traffc counter request data container in DB");
StatisticsPluginImplCounters.failed_creating_ingress_counter_data_config.inc();
return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating ingress counter request data container in DB").buildFuture();
}
if (!isIdenticalCounterRequestExist(input.getPortId(), ElementCountersDirection.INGRESS.toString(), input.getOutgoingTraffic().getFilters(), iecrcOpt.get().getCounterRequests())) {
installCounterSpecificRules(input.getPortId(), getLportTag(input.getPortId()), getDpn(input.getPortId()), ElementCountersDirection.INGRESS, input.getOutgoingTraffic().getFilters());
}
putIngressElementCounterRequestInConfig(input, ElementCountersDirection.INGRESS, transaction, requestKey, CountersServiceUtils.IECRC_IDENTIFIER, iecrcOpt, randomNumber.toString());
transaction.submit();
aecrhob.setIncomingTrafficHandler(requestKey);
bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.INGRESS);
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
}
return RpcResultBuilder.success(aecrhob.build()).buildFuture();
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class TestUtil method verifyHAOpNode.
public static void verifyHAOpNode(Node d1GlobalOpNode, Node d2GlobalOpNode, Node haGlobalOpNode, Node d1PsOpNode, Node d2PsOpNode, Node haPsOpNode, InstanceIdentifier<Node> haId, InstanceIdentifier<Node> d1PsId, InstanceIdentifier<Node> d2PsId, InstanceIdentifier<Node> haPsId, NodeId haNodeId, DataBroker dataBroker) throws ReadFailedException {
ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
TestComparators.compareLogicalSwitches(d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode, haId);
TestComparators.compareRemoteUcastMacs(d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode, haId);
TestComparators.compareRemoteMcastMacs(d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode, haId);
TestComparators.compareLocalUcastMacs(d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode, haId);
TestComparators.compareLocalMcastMacs(d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode, haId);
TestComparators.verifySwitches(haGlobalOpNode, haPsOpNode);
TestComparators.verifySwitches(d1GlobalOpNode, d1PsOpNode);
TestComparators.verifySwitches(d2GlobalOpNode, d2PsOpNode);
TestComparators.comparePhysicalSwitches(d1PsOpNode, d2PsOpNode, haPsOpNode, d1PsId, d2PsId, haPsId, transaction, "s3", d1GlobalOpNode, d2GlobalOpNode, haGlobalOpNode);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class NeutronEvpnUtils method updateElanWithVpnInfo.
public void updateElanWithVpnInfo(String elanInstanceName, VpnInstance vpnInstance, Operation operation) {
String vpnName = vpnInstance.getVpnInstanceName();
InstanceIdentifier<ElanInstance> elanIid = ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
Optional<ElanInstance> elanInstanceOptional = Optional.absent();
try {
elanInstanceOptional = transaction.read(LogicalDatastoreType.CONFIGURATION, elanIid).checkedGet();
} catch (ReadFailedException e) {
LOG.error("updateElanWithVpnInfo throws ReadFailedException e {}", e);
}
if (!elanInstanceOptional.isPresent()) {
return;
}
EvpnAugmentationBuilder evpnAugmentationBuilder = new EvpnAugmentationBuilder();
ElanInstanceBuilder elanInstanceBuilder = new ElanInstanceBuilder(elanInstanceOptional.get());
if (elanInstanceBuilder.getAugmentation(EvpnAugmentation.class) != null) {
evpnAugmentationBuilder = new EvpnAugmentationBuilder(elanInstanceBuilder.getAugmentation(EvpnAugmentation.class));
}
if (operation == Operation.ADD) {
evpnAugmentationBuilder.setEvpnName(vpnName);
LOG.debug("Writing Elan-EvpnAugmentation with key {}", elanInstanceName);
} else {
evpnAugmentationBuilder.setEvpnName(null);
LOG.debug("Deleting Elan-EvpnAugmentation with key {}", elanInstanceName);
}
elanInstanceBuilder.addAugmentation(EvpnAugmentation.class, evpnAugmentationBuilder.build());
transaction.put(LogicalDatastoreType.CONFIGURATION, elanIid, elanInstanceBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
transaction.submit();
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class NeutronEvpnUtils method updateVpnWithElanInfo.
public void updateVpnWithElanInfo(VpnInstance vpnInstance, String elanInstanceName, Operation operation) {
String rd = vpnManager.getPrimaryRdFromVpnInstance(vpnInstance);
InstanceIdentifier<EvpnRdToNetwork> rdToNetworkIdentifier = getRdToNetworkIdentifier(rd);
jobCoordinator.enqueueJob("EVPN_ASSOCIATE-" + rd, () -> {
ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (operation == Operation.DELETE) {
LOG.debug("Deleting Evpn-Network with key {}", rd);
transaction.delete(LogicalDatastoreType.CONFIGURATION, rdToNetworkIdentifier);
} else {
EvpnRdToNetworkBuilder evpnRdToNetworkBuilder = new EvpnRdToNetworkBuilder().setKey(new EvpnRdToNetworkKey(rd));
evpnRdToNetworkBuilder.setRd(rd);
evpnRdToNetworkBuilder.setNetworkId(elanInstanceName);
LOG.info("updating Evpn {} with elaninstance {} and rd {}", vpnInstance.getVpnInstanceName(), elanInstanceName, rd);
transaction.put(LogicalDatastoreType.CONFIGURATION, rdToNetworkIdentifier, evpnRdToNetworkBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
}
futures.add(transaction.submit());
return futures;
});
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method writeFlow.
private void writeFlow(final CommandInterpreter ci, final FlowBuilder flow, final NodeBuilder nodeBuilder) {
final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
final CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void notUsed) {
ci.println("Status of Group Data Loaded Transaction: success.");
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error(throwable.getMessage(), throwable);
ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
}
}, MoreExecutors.directExecutor());
}
Aggregations