use of org.opendaylight.yangtools.yang.common.RpcResultBuilder in project genius by opendaylight.
the class ItmManagerRpcService method addL2GwMlagDevice.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> addL2GwMlagDevice(AddL2GwMlagDeviceInput input) {
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
try {
final IpAddress hwIp = input.getIpAddress();
final List<String> nodeId = input.getNodeId();
InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
LOG.error("No teps configured");
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
return result;
}
String transportZone = transportZones.getTransportZone().get(0).getZoneName();
if (transportZones.getTransportZone().get(0).getSubnets() == null || transportZones.getTransportZone().get(0).getSubnets().isEmpty()) {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
return result;
}
SubnetsKey subnetsKey = transportZones.getTransportZone().get(0).getSubnets().get(0).getKey();
DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId.get(0));
InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(nodeId.get(0)).setTopologyId(input.getTopologyId()).build();
WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
// TO DO: add retry if it fails
LOG.trace("writing hWvtep{}", deviceVtep);
writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
if (nodeId.size() == 2) {
LOG.trace("second node-id {}", nodeId.get(1));
DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().setKey(deviceVtepKey2).setIpAddress(hwIp).setNodeId(nodeId.get(1)).setTopologyId(input.getTopologyId()).build();
// TO DO: add retry if it fails
LOG.trace("writing {}", deviceVtep2);
writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
}
ListenableFuture<Void> futureCheck = writeTransaction.submit();
Futures.addCallback(futureCheck, new FutureCallback<Void>() {
@Override
public void onSuccess(Void voidInstance) {
result.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to write HwVtep %s to datastore", nodeId);
LOG.error("Unable to write HwVtep {}, {} to datastore", nodeId, hwIp);
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
}, MoreExecutors.directExecutor());
}
return result;
} catch (RuntimeException e) {
RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
return Futures.immediateFuture(resultBuilder.build());
}
}
use of org.opendaylight.yangtools.yang.common.RpcResultBuilder in project genius by opendaylight.
the class ItmManagerRpcService method addL2GwDevice.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> addL2GwDevice(AddL2GwDeviceInput input) {
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
boolean foundVxlanTzone = false;
try {
final IpAddress hwIp = input.getIpAddress();
final String nodeId = input.getNodeId();
// iterate through all transport zones and put TORs under vxlan
// if no vxlan tzone is cnfigured, return an error.
InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
LOG.error("No transportZone configured");
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No transportZone Configured").build());
return result;
}
for (TransportZone tzone : transportZones.getTransportZone()) {
if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
continue;
}
String transportZone = tzone.getZoneName();
if (tzone.getSubnets() == null || tzone.getSubnets().isEmpty()) {
continue;
}
foundVxlanTzone = true;
SubnetsKey subnetsKey = tzone.getSubnets().get(0).getKey();
DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId);
InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(nodeId).setTopologyId(input.getTopologyId()).build();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
// TO DO: add retry if it fails
transaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
ListenableFuture<Void> futureCheck = transaction.submit();
Futures.addCallback(futureCheck, new FutureCallback<Void>() {
@Override
public void onSuccess(Void voidInstance) {
result.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to write HwVtep %s to datastore", nodeId);
LOG.error("Unable to write HwVtep {}, {} to datastore", nodeId, hwIp);
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
});
}
} else {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No TransportZones configured").build());
return result;
}
if (!foundVxlanTzone) {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No VxLan TransportZones configured").build());
}
return result;
} catch (Exception e) {
RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
return Futures.immediateFuture(resultBuilder.build());
}
}
use of org.opendaylight.yangtools.yang.common.RpcResultBuilder in project genius by opendaylight.
the class ItmManagerRpcService method isDcgwPresent.
@Override
public Future<RpcResult<IsDcgwPresentOutput>> isDcgwPresent(IsDcgwPresentInput input) {
RpcResultBuilder<IsDcgwPresentOutput> resultBld = RpcResultBuilder.success();
List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
String dcgwIpStr = input.getDcgwIp();
IpAddress dcgwIpAddr = IpAddressBuilder.getDefaultInstance(dcgwIpStr);
long retVal;
if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty() && dcGatewayIpList.stream().anyMatch(gwIp -> Objects.equal(gwIp.getIpAddress(), dcgwIpAddr))) {
// Match found
retVal = 1;
IsDcgwPresentOutputBuilder output = new IsDcgwPresentOutputBuilder().setRetVal(retVal);
resultBld.withResult(output.build());
} else {
// Match not found
retVal = 2;
IsDcgwPresentOutputBuilder output = new IsDcgwPresentOutputBuilder().setRetVal(retVal);
resultBld.withResult(output.build());
}
return Futures.immediateFuture(resultBld.build());
}
use of org.opendaylight.yangtools.yang.common.RpcResultBuilder in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImpl method addMissingGroups.
ListenableFuture<RpcResult<Void>> addMissingGroups(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final List<ItemSyncBox<Group>> groupsAddPlan, final SyncCrudCounters counters) {
if (groupsAddPlan.isEmpty()) {
LOG.trace("no groups configured for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
}
ListenableFuture<RpcResult<Void>> chainedResult;
try {
if (!groupsAddPlan.isEmpty()) {
final CrudCounts groupCrudCounts = counters.getGroupCrudCounts();
groupCrudCounts.setAdded(ReconcileUtil.countTotalPushed(groupsAddPlan));
groupCrudCounts.setUpdated(ReconcileUtil.countTotalUpdated(groupsAddPlan));
if (LOG.isDebugEnabled()) {
LOG.debug("adding groups: planSteps={}, toAddTotal={}, toUpdateTotal={}", groupsAddPlan.size(), groupCrudCounts.getAdded(), groupCrudCounts.getUpdated());
}
chainedResult = flushAddGroupPortionAndBarrier(nodeIdent, groupsAddPlan.get(0));
for (final ItemSyncBox<Group> groupsPortion : Iterables.skip(groupsAddPlan, 1)) {
chainedResult = Futures.transformAsync(chainedResult, input -> {
final ListenableFuture<RpcResult<Void>> result;
if (input.isSuccessful()) {
result = flushAddGroupPortionAndBarrier(nodeIdent, groupsPortion);
} else {
// pass through original unsuccessful rpcResult
result = Futures.immediateFuture(input);
}
return result;
}, MoreExecutors.directExecutor());
}
} else {
chainedResult = RpcResultBuilder.<Void>success().buildFuture();
}
} catch (IllegalStateException e) {
chainedResult = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "failed to add missing groups", e).buildFuture();
}
return chainedResult;
}
use of org.opendaylight.yangtools.yang.common.RpcResultBuilder in project openflowplugin by opendaylight.
the class MultiLayerFlowService method processFlowModInputBuilders.
public ListenableFuture<RpcResult<O>> processFlowModInputBuilders(final List<FlowModInputBuilder> ofFlowModInputs) {
final List<ListenableFuture<RpcResult<O>>> partialFutures = new ArrayList<>(ofFlowModInputs.size());
for (final FlowModInputBuilder flowModInputBuilder : ofFlowModInputs) {
partialFutures.add(handleServiceCall(flowModInputBuilder));
}
final ListenableFuture<List<RpcResult<O>>> allFutures = Futures.successfulAsList(partialFutures);
final SettableFuture<RpcResult<O>> finalFuture = SettableFuture.create();
Futures.addCallback(allFutures, new FutureCallback<List<RpcResult<O>>>() {
@Override
public void onSuccess(@Nonnull final List<RpcResult<O>> results) {
final ArrayList<RpcError> errors = new ArrayList();
for (RpcResult<O> flowModResult : results) {
if (flowModResult == null) {
errors.add(RpcResultBuilder.newError(RpcError.ErrorType.PROTOCOL, OFConstants.APPLICATION_TAG, "unexpected flowMod result (null) occurred"));
} else if (!flowModResult.isSuccessful()) {
errors.addAll(flowModResult.getErrors());
}
}
final RpcResultBuilder<O> rpcResultBuilder;
if (errors.isEmpty()) {
rpcResultBuilder = RpcResultBuilder.success();
} else {
rpcResultBuilder = RpcResultBuilder.<O>failed().withRpcErrors(errors);
}
finalFuture.set(rpcResultBuilder.build());
}
@Override
public void onFailure(final Throwable throwable) {
RpcResultBuilder<O> rpcResultBuilder = RpcResultBuilder.failed();
finalFuture.set(rpcResultBuilder.build());
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
Aggregations