Search in sources :

Example 1 with DissociateRouterInput

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

the class NeutronvpnManager method dissociateRouter.

/**
 * It handles the invocations to the neutronvpn:dissociateRouter RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<DissociateRouterOutput>> dissociateRouter(DissociateRouterInput input) {
    SettableFuture<RpcResult<DissociateRouterOutput>> result = SettableFuture.create();
    LOG.debug("dissociateRouter {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
    String routerIdsString = "";
    Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "dissociateRouter: RouterIds list is empty!");
    Preconditions.checkNotNull(vpnId, "dissociateRouter: vpnId not found!");
    Preconditions.checkNotNull(keyRouterIdsMap, "dissociateRouter: keyRouterIdsMap not found!");
    if (neutronvpnUtils.getVpnMap(vpnId) != null) {
        for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIds routerId : keyRouterIdsMap.values()) {
            try {
                if (routerId != null) {
                    routerIdsString += routerId.getRouterId() + ", ";
                    Router rtr = neutronvpnUtils.getNeutronRouter(routerId.getRouterId());
                    if (rtr != null) {
                        Uuid routerVpnId = neutronvpnUtils.getVpnForRouter(routerId.getRouterId(), true);
                        if (routerVpnId == null) {
                            returnMsg.append("input router ").append(routerId.getRouterId()).append(" not associated to any vpn yet");
                        } else if (vpnId.equals(routerVpnId)) {
                            dissociateRouterFromVpn(vpnId, routerId.getRouterId());
                        } else {
                            returnMsg.append("input router ").append(routerId.getRouterId()).append(" associated to vpn ").append(routerVpnId.getValue()).append("instead of the vpn given as input");
                        }
                    } else {
                        returnMsg.append("router not found : ").append(routerId.getRouterId());
                    }
                }
                if (returnMsg.length() != 0) {
                    result.set(RpcResultBuilder.<DissociateRouterOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "dissociate router {} to " + "vpn {} failed due to {}", routerId.getRouterId(), vpnId.getValue(), returnMsg)).build());
                } else {
                    result.set(RpcResultBuilder.success(new DissociateRouterOutputBuilder().build()).build());
                }
            } catch (Exception ex) {
                result.set(RpcResultBuilder.<DissociateRouterOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "disssociate router {} to vpn {} failed due to {}", routerId.getRouterId(), vpnId.getValue(), ex.getMessage(), ex)).build());
            }
        }
    } else {
        returnMsg.append("VPN not found : ").append(vpnId.getValue());
    }
    LOG.debug("dissociateRouter returns..");
    return result;
}
Also used : DissociateRouterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateRouterOutputBuilder) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) 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) DissociateRouterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateRouterOutput)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 OptimisticLockFailedException (org.opendaylight.mdsal.common.api.OptimisticLockFailedException)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 DissociateRouterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateRouterOutput)1 DissociateRouterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateRouterOutputBuilder)1 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds)1 RouterIdsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey)1 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1