Search in sources :

Example 1 with CreateEVPNInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNInput in project netvirt by opendaylight.

the class NeutronEvpnManager method createEVPN.

@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<CreateEVPNOutput>> createEVPN(CreateEVPNInput input) {
    CreateEVPNOutputBuilder opBuilder = new CreateEVPNOutputBuilder();
    SettableFuture<RpcResult<CreateEVPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    List<String> existingRDs = neutronvpnUtils.getExistingRDs();
    for (Evpn vpn : input.nonnullEvpn()) {
        if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input", vpn.getId().getValue())));
            continue;
        }
        if (vpn.getRouteDistinguisher().size() > 1) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}", vpn.getId().getValue(), vpn.getRouteDistinguisher())));
            continue;
        }
        if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already " + "configured", vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
            continue;
        }
        try {
            List<String> rdList = vpn.getRouteDistinguisher() != null ? new ArrayList<>(vpn.getRouteDistinguisher()) : new ArrayList<>();
            List<String> importRdList = vpn.getImportRT() != null ? new ArrayList<>(vpn.getImportRT()) : new ArrayList<>();
            List<String> exportRdList = vpn.getExportRT() != null ? new ArrayList<>(vpn.getExportRT()) : new ArrayList<>();
            neutronvpnManager.createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), rdList, importRdList, exportRdList, null, /*router-id*/
            null, /*network-id*/
            true, /*isL2Vpn*/
            0);
        } catch (Exception ex) {
            errorList.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, formatAndLog(LOG::error, "Creation of EVPN failed for VPN {}", vpn.getId().getValue(), ex), ex.getMessage()));
            failurecount++;
        }
    }
    if (failurecount != 0) {
        result.set(RpcResultBuilder.<CreateEVPNOutput>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("EVPN creation successful with no errors");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.success(opBuilder.build()).build());
    }
    return result;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) Evpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createevpn.input.Evpn) ExecutionException(java.util.concurrent.ExecutionException) CreateEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutputBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 CreateEVPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutputBuilder)1 Evpn (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createevpn.input.Evpn)1 RpcError (org.opendaylight.yangtools.yang.common.RpcError)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1