Search in sources :

Example 1 with AssociateNetworksInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInput 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 ListenableFuture<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
    AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
    SettableFuture<RpcResult<AssociateNetworksOutput>> result = SettableFuture.create();
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    try {
        if (neutronvpnUtils.getVpnMap(vpnId) != null) {
            LOG.debug("associateNetworks RPC: VpnId {}, networkList {}", vpnId.getValue(), input.getNetworkId());
            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) {
        LOG.error("associate Networks to vpn failed {}", input.getVpnId().getValue(), 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) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException)

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 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 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1