use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutputBuilder 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