Search in sources :

Example 11 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.rsvp.error.spec.ErrorType 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 ListenableFuture<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();
    if (vpns == null) {
        vpns = Collections.emptyList();
    }
    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;
        }
        long l3vni = 0;
        if (vpn.getL3vni() != null) {
            l3vni = vpn.getL3vni().toJava();
        }
        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.getRouterIds() != null && !vpn.getRouterIds().isEmpty()) {
            Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds> keyRouterIdsMap = vpn.getRouterIds();
            for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds routerId : keyRouterIdsMap.values()) {
                if (neutronvpnUtils.getNeutronRouter(routerId.getRouterId()) == null) {
                    errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to absense of routers" + "{}", vpn.getId(), routerId.getRouterId())));
                    warningcount++;
                    continue;
                }
                Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId.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(), routerId.getRouterId(), 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;
            }
        }
        List<Uuid> rtrIdsList = new ArrayList<>();
        if (vpn.getRouterIds() != null && !vpn.getRouterIds().isEmpty()) {
            for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds rtrId : vpn.getRouterIds().values()) {
                rtrIdsList.add(rtrId.getRouterId());
            }
        }
        try {
            LOG.debug("L3VPN add RPC: VpnID {}, name {}, tenantID {}, RDList {}, iRTList {}, eRTList{}, " + "routerIdList {}, networksList {}", vpn.getId().getValue(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(), vpn.getImportRT(), vpn.getExportRT(), rtrIdsList, vpn.getNetworkIds());
            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<>();
            createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), rdList, importRdList, exportRdList, rtrIdsList, vpn.getNetworkIds(), false, /*isL2Vpn*/
            l3vni);
        } catch (Exception ex) {
            LOG.error("VPN Creation 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;
}
Also used : RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) CreateL3VPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutputBuilder) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) L3vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) L3vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn)

Example 12 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.rsvp.error.spec.ErrorType in project bgpcep by opendaylight.

the class Util method createErrorMessage.

public static Pcerr createErrorMessage(final PCEPErrors error, final Open openObject) {
    final PcerrBuilder errMessageBuilder = new PcerrBuilder();
    final ErrorObject err = new ErrorObjectBuilder().setType(error.getErrorType()).setValue(error.getErrorValue()).build();
    if (openObject == null) {
        return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).build()).build();
    }
    final ErrorType type = new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(openObject).build()).build();
    return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).setErrorType(type).build()).build();
}
Also used : SessionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCaseBuilder) PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder) ErrorType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.ErrorType) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.ErrorsBuilder) SessionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.session._case.SessionBuilder) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessageBuilder)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 ExecutionException (java.util.concurrent.ExecutionException)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 ArrayList (java.util.ArrayList)4 RpcError (org.opendaylight.yangtools.yang.common.RpcError)4 OptimisticLockFailedException (org.opendaylight.mdsal.common.api.OptimisticLockFailedException)3 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)3 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)3 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)2 ErrorType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey)1 AssociateNetworksOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput)1 AssociateNetworksOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder)1 CreateEVPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutputBuilder)1 CreateL3VPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutputBuilder)1 DeleteEVPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteEVPNOutputBuilder)1 DeleteL3VPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder)1 DissociateNetworksOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput)1 DissociateNetworksOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutputBuilder)1