use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class RpcErrorsExceptionTest method setUp.
@Before
public void setUp() throws Exception {
final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "error", "error message");
final RpcError rpcWarning = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "warning", "warning message");
rpcErrors = new ArrayList<>();
rpcErrors.add(rpcError);
rpcErrors.add(rpcWarning);
exception = new RpcErrorsException(ERROR_MESSAGE, rpcErrors);
}
use of org.opendaylight.yangtools.yang.common.RpcError in project netvirt by opendaylight.
the class VpnManagerImpl method createIdPool.
private void createIdPool() {
CreateIdPoolInput createPool = new CreateIdPoolInputBuilder().setPoolName(VpnConstants.VPN_IDPOOL_NAME).setLow(VpnConstants.VPN_IDPOOL_LOW).setHigh(VpnConstants.VPN_IDPOOL_HIGH).build();
try {
Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
if (result != null && result.get().isSuccessful()) {
LOG.info("Created IdPool for VPN Service");
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to create idPool for VPN Service", e);
}
// Now an IdPool for InterVpnLink endpoint's pseudo ports
CreateIdPoolInput createPseudoLporTagPool = new CreateIdPoolInputBuilder().setPoolName(VpnConstants.PSEUDO_LPORT_TAG_ID_POOL_NAME).setLow(VpnConstants.LOWER_PSEUDO_LPORT_TAG).setHigh(VpnConstants.UPPER_PSEUDO_LPORT_TAG).build();
try {
Future<RpcResult<Void>> result = idManager.createIdPool(createPseudoLporTagPool);
if (result.get().isSuccessful()) {
LOG.debug("Created IdPool for Pseudo Port tags");
} else {
Collection<RpcError> errors = result.get().getErrors();
StringBuilder errMsg = new StringBuilder();
for (RpcError err : errors) {
errMsg.append(err.getMessage()).append("\n");
}
LOG.error("IdPool creation for PseudoPort tags failed. Reasons: {}", errMsg);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to create idPool for Pseudo Port tags", e);
}
}
use of org.opendaylight.yangtools.yang.common.RpcError in project netvirt by opendaylight.
the class VpnRpcServiceImpl method addStaticRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
String destination = input.getDestination();
String vpnInstanceName = input.getVpnInstanceName();
String nexthop = input.getNexthop();
Long label = input.getLabel();
LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
if (!rpcErrors.isEmpty()) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
return result;
}
if (label == null || label == 0) {
label = (long) VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
if (label == 0) {
String message = "Unable to retrieve a new Label for the new Route";
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
}
String vpnRd = VpnUtil.getVpnRd(dataBroker, input.getVpnInstanceName());
VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
if (vpnRd == null) {
String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
if (optIVpnLink.isPresent()) {
try {
InterVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label.intValue(), dataBroker, fibManager, bgpManager);
} catch (Exception e) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
return result;
}
} else {
vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
null, /*Adjacency*/
encapType, null);
}
AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
result.set(RpcResultBuilder.success(labelOutput).build());
return result;
}
use of org.opendaylight.yangtools.yang.common.RpcError in project netvirt by opendaylight.
the class AclLiveStatisticsHelper method handleRpcErrors.
/**
* Handle rpc errors.
*
* @param lstAclPortStats the lst acl port stats
* @param aclStatsBuilder the acl stats builder
* @param rpcResult the rpc result
*/
private static void handleRpcErrors(List<AclPortStats> lstAclPortStats, AclPortStatsBuilder aclStatsBuilder, RpcResult<GetFlowStatisticsOutput> rpcResult) {
LOG.error("Unable to retrieve drop counts due to error: {}", rpcResult);
String errMsg = "Unable to retrieve drop counts due to error: ";
if (rpcResult != null && rpcResult.getErrors() != null) {
for (RpcError error : rpcResult.getErrors()) {
errMsg += error.getMessage();
break;
}
} else {
errMsg += "Internal RPC call failed.";
}
addError(lstAclPortStats, aclStatsBuilder, errMsg);
}
use of org.opendaylight.yangtools.yang.common.RpcError in project netvirt by opendaylight.
the class NeutronvpnManager method createL3VPN.
/**
* It handles the invocations to the createVPN RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<CreateL3VPNOutput>> createL3VPN(CreateL3VPNInput input) {
CreateL3VPNOutputBuilder opBuilder = new CreateL3VPNOutputBuilder();
SettableFuture<RpcResult<CreateL3VPNOutput>> result = SettableFuture.create();
List<RpcError> errorList = new ArrayList<>();
int failurecount = 0;
int warningcount = 0;
List<L3vpn> vpns = input.getL3vpn();
for (L3vpn vpn : vpns) {
if (neutronvpnUtils.doesVpnExist(vpn.getId())) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to VPN with the same ID already present", vpn.getId().getValue())));
warningcount++;
continue;
}
if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to absence of RD/iRT/eRT input", vpn.getId().getValue())));
warningcount++;
continue;
}
VpnInstance.Type vpnInstanceType = VpnInstance.Type.L3;
long l3vni = 0;
if (vpn.getL3vni() != null) {
l3vni = vpn.getL3vni();
}
List<String> existingRDs = neutronvpnUtils.getExistingRDs();
if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} as another VPN with the same RD {} " + "is already configured", vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
warningcount++;
continue;
}
Optional<String> operationalVpn = getExistingOperationalVpn(vpn.getRouteDistinguisher().get(0));
if (operationalVpn.isPresent()) {
errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, "application-error", formatAndLog(LOG::error, "Creation of L3VPN failed for VPN {} as another VPN {} with the same RD {} " + "is still available. Please retry creation of a new vpn with the same RD" + " after a couple of minutes.", vpn.getId().getValue(), operationalVpn.get(), vpn.getRouteDistinguisher().get(0))));
warningcount++;
continue;
}
if (vpn.getRouterId() != null) {
if (neutronvpnUtils.getNeutronRouter(vpn.getRouterId()) == null) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to router not found {}", vpn.getId().getValue(), vpn.getRouterId().getValue())));
warningcount++;
continue;
}
Uuid vpnId = neutronvpnUtils.getVpnForRouter(vpn.getRouterId(), true);
if (vpnId != null) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to router {} already associated to " + "another VPN {}", vpn.getId().getValue(), vpn.getRouterId().getValue(), vpnId.getValue())));
warningcount++;
continue;
}
}
if (vpn.getNetworkIds() != null) {
int initialWarningCount = warningcount;
for (Uuid nw : vpn.getNetworkIds()) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
Uuid vpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (network == null) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to network not found {}", vpn.getId().getValue(), nw.getValue())));
warningcount++;
} else if (vpnId != null) {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to network {} already associated" + " to another VPN {}", vpn.getId().getValue(), nw.getValue(), vpnId.getValue())));
warningcount++;
}
}
if (warningcount != initialWarningCount) {
continue;
}
}
try {
createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(), vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds(), vpnInstanceType, l3vni);
} catch (Exception ex) {
errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Creation of VPN failed for VPN {}", vpn.getId().getValue(), ex), ex.getMessage()));
failurecount++;
}
}
// if none succeeds; result is failure
if (failurecount + warningcount == vpns.size()) {
result.set(RpcResultBuilder.<CreateL3VPNOutput>failed().withRpcErrors(errorList).build());
} else {
List<String> errorResponseList = new ArrayList<>();
if (!errorList.isEmpty()) {
for (RpcError rpcError : errorList) {
errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
}
} else {
errorResponseList.add("Operation successful with no errors");
}
opBuilder.setResponse(errorResponseList);
result.set(RpcResultBuilder.<CreateL3VPNOutput>success().withResult(opBuilder.build()).build());
}
return result;
}
Aggregations