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;
}
Aggregations