Search in sources :

Example 1 with AssociateRouterOutput

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

the class NeutronvpnManager method associateRouter.

/**
 * It handles the invocations to the neutronvpn:associateRouter RPC method.
 */
@Override
public ListenableFuture<RpcResult<AssociateRouterOutput>> associateRouter(AssociateRouterInput input) {
    SettableFuture<RpcResult<AssociateRouterOutput>> result = SettableFuture.create();
    LOG.debug("associateRouter {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
    Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "associateRouter: RouterIds list is empty!");
    Preconditions.checkNotNull(vpnId, "associateRouter; VpnId not found!");
    Preconditions.checkNotNull(vpnId, "associateRouter; RouterIds not found!");
    for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIds routerId : keyRouterIdsMap.values()) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        Router rtr = neutronvpnUtils.getNeutronRouter(routerId.getRouterId());
        if (vpnMap != null) {
            if (rtr != null) {
                Uuid extVpnId = neutronvpnUtils.getVpnForRouter(routerId.getRouterId(), true);
                if (vpnMap.getRouterIds() != null && vpnMap.getRouterIds().size() > 1) {
                    returnMsg.append("vpn ").append(vpnId.getValue()).append(" already associated to router ").append(routerId.getRouterId());
                } else if (extVpnId != null) {
                    returnMsg.append("router ").append(routerId.getRouterId()).append(" already associated to " + "another VPN ").append(extVpnId.getValue());
                } else {
                    LOG.debug("associateRouter RPC: VpnId {}, routerId {}", vpnId.getValue(), routerId.getRouterId());
                    associateRouterToVpn(vpnId, routerId.getRouterId());
                }
            } else {
                returnMsg.append("router not found : ").append(routerId.getRouterId());
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            result.set(RpcResultBuilder.<AssociateRouterOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "associate router to vpn {} failed " + "due to {}", routerId.getRouterId(), returnMsg)).build());
        } else {
            result.set(RpcResultBuilder.success(new AssociateRouterOutputBuilder().build()).build());
        }
    }
    LOG.debug("associateRouter returns..");
    return result;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) 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) AssociateRouterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateRouterOutputBuilder) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 AssociateRouterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateRouterOutputBuilder)1 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)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