Search in sources :

Example 56 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project netvirt by opendaylight.

the class NeutronvpnManager method deleteL3VPN.

/**
 * It handles the invocations to the neutronvpn:deleteL3VPN RPC method.
 */
@Override
public Future<RpcResult<DeleteL3VPNOutput>> deleteL3VPN(DeleteL3VPNInput input) {
    DeleteL3VPNOutputBuilder opBuilder = new DeleteL3VPNOutputBuilder();
    SettableFuture<RpcResult<DeleteL3VPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    int warningcount = 0;
    List<Uuid> vpns = input.getId();
    for (Uuid vpn : vpns) {
        RpcError error;
        String msg;
        try {
            InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
            Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
            if (optionalVpn.isPresent()) {
                removeVpn(vpn);
            } else {
                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "VPN with vpnid: {} does not exist", vpn.getValue())));
                warningcount++;
            }
        } catch (ReadFailedException ex) {
            errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Deletion of L3VPN failed when deleting for uuid {}", vpn.getValue()), ex.getMessage()));
            failurecount++;
        }
    }
    // if none succeeds; result is failure
    if (failurecount + warningcount == vpns.size()) {
        result.set(RpcResultBuilder.<DeleteL3VPNOutput>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.<DeleteL3VPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DeleteL3VPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)

Example 57 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateNetworksFromVpn.

/**
 * Parses and disassociates networks list from given VPN.
 *
 * @param vpnId Uuid of given VPN.
 * @param networks List list of network Ids (Uuid), which will be disassociated.
 * @return list of formatted strings with detailed error messages.
 */
@Nonnull
protected List<String> dissociateNetworksFromVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
    List<String> failedNwList = new ArrayList<>();
    HashSet<Uuid> passedNwList = new HashSet<>();
    if (networks.isEmpty()) {
        LOG.error("dissociateNetworksFromVpn: Failed as networks list is empty");
        failedNwList.add(String.format("Failed to disassociate networks from VPN %s as networks list is empty", vpnId.getValue()));
        return failedNwList;
    }
    for (Uuid nw : networks) {
        Network network = neutronvpnUtils.getNeutronNetwork(nw);
        if (network == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS");
            failedNwList.add(String.format("Failed to disassociate network %s as is not found in ConfigDS", nw.getValue()));
            continue;
        }
        Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
        if (networkVpnId == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} is not associated to any VPN", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not associated to any VPN", nw.getValue()));
            continue;
        }
        if (!vpnId.equals(networkVpnId)) {
            LOG.error("dissociateNetworksFromVpn: Network {} is associated to another VPN {} instead of given {}", nw.getValue(), networkVpnId.getValue(), vpnId.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as it is associated to another " + "vpn %s instead of given %s", nw.getValue(), networkVpnId.getValue(), vpnId.getValue()));
            continue;
        }
        if (neutronvpnUtils.getIsExternal(network)) {
            if (disassociateExtNetworkFromVpn(vpnId, network)) {
                passedNwList.add(nw);
                continue;
            } else {
                LOG.error("dissociateNetworksFromVpn: Failed to withdraw Provider Network {} from VPN {}", nw.getValue(), vpnId.getValue());
                failedNwList.add(String.format("Failed to withdraw Provider Network %s from VPN %s", nw.getValue(), vpnId.getValue()));
                continue;
            }
        }
        List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
        if (networkSubnets == null) {
            passedNwList.add(nw);
            continue;
        }
        for (Uuid subnet : networkSubnets) {
            Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sm, vpnId)) {
                IpVersionChoice ipVersionsToRemove = IpVersionChoice.UNDEFINED;
                IpVersionChoice ipVersion = neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
                neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersionsToRemove.addVersion(ipVersion), false);
            }
            LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
            removeSubnetFromVpn(vpnId, subnet, null);
            passedNwList.add(nw);
        }
    }
    LOG.info("dissociateNetworksFromVpn: Withdraw networks list {} from VPN {}", networks.toString(), vpnId.getValue());
    clearFromVpnMaps(vpnId, null, new ArrayList<Uuid>(passedNwList));
    return failedNwList;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) Nonnull(javax.annotation.Nonnull)

Example 58 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project netvirt by opendaylight.

the class NeutronvpnManager method associateNetworks.

/**
 * It handles the invocations to the neutronvpn:associateNetworks RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
    AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
    SettableFuture<RpcResult<AssociateNetworksOutput>> result = SettableFuture.create();
    LOG.debug("associateNetworks {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    try {
        if (neutronvpnUtils.getVpnMap(vpnId) != null) {
            List<Uuid> netIds = input.getNetworkId();
            if (netIds != null && !netIds.isEmpty()) {
                List<String> failed = associateNetworksToVpn(vpnId, netIds);
                if (!failed.isEmpty()) {
                    returnMsg.append(failed);
                }
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
        } else {
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("associateNetworks returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AssociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput) AssociateNetworksOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 59 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project netvirt by opendaylight.

the class NeutronvpnManager method removeFromNeutronRouterInterfacesMap.

protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
    synchronized (routerId.getValue().intern()) {
        InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
        try {
            Optional<RouterInterfaces> optRouterInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
            Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
            if (optRouterInterfaces.isPresent()) {
                RouterInterfaces routerInterfaces = optRouterInterfaces.get();
                List<Interfaces> interfaces = routerInterfaces.getInterfaces();
                if (interfaces != null && interfaces.remove(routerInterface)) {
                    if (interfaces.isEmpty()) {
                        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
                    } else {
                        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
                    }
                }
            }
        } catch (ReadFailedException | TransactionCommitFailedException e) {
            LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
        }
    }
}
Also used : VpnInterfaces(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey) InterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesKey) InterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesBuilder)

Example 60 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project netvirt by opendaylight.

the class NeutronvpnManager method deleteVpnInterface.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected boolean deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    Optional<VpnInterface> optionalVpnInterface = null;
    try {
        optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
    } catch (ReadFailedException ex) {
        LOG.error("Error during deletion of vpninterface {}", infName, ex);
        return false;
    }
    if (!optionalVpnInterface.isPresent()) {
        LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
        return false;
    }
    boolean wrtConfigTxnPresent = true;
    if (wrtConfigTxn == null) {
        wrtConfigTxnPresent = false;
        wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    if (vpnId != null) {
        VpnInterface vpnInterface = optionalVpnInterface.get();
        List<VpnInstanceNames> vpnList = vpnInterface.getVpnInstanceNames();
        if (vpnList != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, vpnList)) {
            VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, vpnList);
            if (!vpnList.isEmpty()) {
                if (!wrtConfigTxnPresent) {
                    wrtConfigTxn.submit();
                }
                LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
                return false;
            }
            VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(vpnList);
            wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
        }
    }
    LOG.debug("Deleting vpn interface {}", infName);
    wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
    if (!wrtConfigTxnPresent) {
        wrtConfigTxn.submit();
    }
    return true;
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)81 ArrayList (java.util.ArrayList)65 ExecutionException (java.util.concurrent.ExecutionException)61 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)41 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)30 BigInteger (java.math.BigInteger)29 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)25 List (java.util.List)24 Optional (com.google.common.base.Optional)23 Test (org.junit.Test)22 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)22 RpcError (org.opendaylight.yangtools.yang.common.RpcError)20 Logger (org.slf4j.Logger)20 LoggerFactory (org.slf4j.LoggerFactory)20 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)19 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)17 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)17 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)16 Nonnull (javax.annotation.Nonnull)15 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)15