use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig in project netvirt by opendaylight.
the class StatisticsImpl method releaseElementCountersRequestHandler.
@Override
public Future<RpcResult<ReleaseElementCountersRequestHandlerOutput>> releaseElementCountersRequestHandler(ReleaseElementCountersRequestHandlerInput 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();
ReadWriteTransaction tx = db.newReadWriteTransaction();
CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
try {
Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
LOG.warn("Couldn't read element counters config data from DB");
StatisticsPluginImplCounters.failed_reading_counter_data_from_config.inc();
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
}
if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
LOG.warn("Handler does not exists");
StatisticsPluginImplCounters.unknown_request_handler.inc();
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
}
String generatedKey = null;
if (ingressRequestData.get().isPresent()) {
handleReleaseTransaction(input, ingressPath, ingressRequestData, iecrcOpt.get().getCounterRequests());
generatedKey = ingressRequestData.get().get().getGeneratedUniqueId();
}
if (egressRequestData.get().isPresent()) {
handleReleaseTransaction(input, egressPath, egressRequestData, eecrcOpt.get().getCounterRequests());
generatedKey = egressRequestData.get().get().getGeneratedUniqueId();
}
releaseId(generatedKey);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
}
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>success().buildFuture();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig 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();
}
Aggregations