List of usage examples for com.google.common.util.concurrent Futures immediateFailedFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable)
From source file:org.opendaylight.vpnservice.natservice.internal.ExternalRoutersListener.java
private void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, long routerId, String extIp, final String vpnName) { //Inform BGP about the route removal String rd = NatUtil.getVpnRd(dataBroker, vpnName); NatUtil.removePrefixFromBGP(bgpManager, rd, extIp, LOG); LOG.debug("Removing fib entry for externalIp {} in routerId {}", extIp, routerId); //Get IPMaps from the DB for the router ID List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId); if (dbIpMaps == null || dbIpMaps.isEmpty()) { LOG.error("NAT Service : IPMaps not found for router {}", routerId); return;/*ww w.j av a2s. c o m*/ } long tempLabel = NatConstants.INVALID_ID; for (IpMap dbIpMap : dbIpMaps) { String dbExternalIp = dbIpMap.getExternalIp(); LOG.debug("Retrieved dbExternalIp {} for router id {}", dbExternalIp, routerId); //Select the IPMap, whose external IP is the IP for which FIB is installed if (extIp.equals(dbExternalIp)) { tempLabel = dbIpMap.getLabel(); LOG.debug("Retrieved label {} for dbExternalIp {} with router id {}", tempLabel, dbExternalIp, routerId); break; } } if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) { LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId); return; } final long label = tempLabel; final String externalIp = extIp; RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId) .setIpAddress(externalIp).setServiceId(label).build(); Future<RpcResult<Void>> future = fibService.removeFibEntry(input); ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform( JdkFutureAdapters.listenInPoolThread(future), new AsyncFunction<RpcResult<Void>, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(RpcResult<Void> result) throws Exception { //Release label if (result.isSuccessful()) { removeTunnelTableEntry(dpnId, label); removeLFibTableEntry(dpnId, label); RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<Void>> labelFuture = vpnService.removeVpnLabel(labelInput); return JdkFutureAdapters.listenInPoolThread(labelFuture); } else { String errMsg = String.format( "RPC call to remove custom FIB entries on dpn %s for prefix %s Failed - %s", dpnId, externalIp, result.getErrors()); LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } } }); Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { LOG.error("NAT Service : Error in removing the label or custom fib entries", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName); } else { LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors()); } } }); }
From source file:org.opendaylight.netvirt.natservice.internal.ExternalRoutersListener.java
protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName, long tempLabel) { LOG.debug("NAT Service : Removing fib entry for externalIp {} in routerId {}", extIp, routerId); String routerName = NatUtil.getRouterName(dataBroker, routerId); if (routerName == null) { LOG.error("NAT Service : Could not retrieve Router Name from Router ID {} ", routerId); return;// ww w. j a v a2 s .c o m } ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName); if (extNwProvType == null) { return; } /* Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the * external network provided type is VxLAN */ if (extNwProvType == ProviderTypes.VXLAN) { evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName); return; } if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) { LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId); return; } final long label = tempLabel; final String externalIp = extIp; RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId) .setIpAddress(externalIp).setServiceId(label).build(); Future<RpcResult<Void>> future = fibService.removeFibEntry(input); ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform( JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> { //Release label if (result.isSuccessful()) { removeTunnelTableEntry(dpnId, label); removeLFibTableEntry(dpnId, label); NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId); RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput); return JdkFutureAdapters.listenInPoolThread(labelFuture1); } else { String errMsg = String.format( "RPC call to remove custom FIB entries on dpn %s for prefix %s " + "Failed - %s", dpnId, externalIp, result.getErrors()); LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } }); Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { LOG.error("NAT Service : Error in removing the label or custom fib entries", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName); } else { LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors()); } } }); }
From source file:org.opendaylight.netvirt.natservice.internal.ExternalRoutersListener.java
private void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName) { LOG.debug("NAT Service : Removing fib entry for externalIp {} in routerId {}", extIp, routerId); String routerName = NatUtil.getRouterName(dataBroker, routerId); if (routerName == null) { LOG.error("NAT Service : Could not retrieve Router Name from Router ID {} ", routerId); return;// w ww .ja v a 2 s .c o m } ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName); if (extNwProvType == null) { return; } /* Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the * external network provided type is VxLAN */ if (extNwProvType == ProviderTypes.VXLAN) { evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName); return; } //Get IPMaps from the DB for the router ID List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId); if (dbIpMaps == null || dbIpMaps.isEmpty()) { LOG.error("NAT Service : IPMaps not found for router {}", routerId); return; } long tempLabel = NatConstants.INVALID_ID; for (IpMap dbIpMap : dbIpMaps) { String dbExternalIp = dbIpMap.getExternalIp(); LOG.debug("Retrieved dbExternalIp {} for router id {}", dbExternalIp, routerId); //Select the IPMap, whose external IP is the IP for which FIB is installed if (extIp.equals(dbExternalIp)) { tempLabel = dbIpMap.getLabel(); LOG.debug("Retrieved label {} for dbExternalIp {} with router id {}", tempLabel, dbExternalIp, routerId); break; } } if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) { LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId); return; } final long label = tempLabel; final String externalIp = extIp; RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId) .setIpAddress(externalIp).setServiceId(label).build(); Future<RpcResult<Void>> future = fibService.removeFibEntry(input); ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform( JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> { //Release label if (result.isSuccessful()) { removeTunnelTableEntry(dpnId, label); removeLFibTableEntry(dpnId, label); RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput); return JdkFutureAdapters.listenInPoolThread(labelFuture1); } else { String errMsg = String.format( "RPC call to remove custom FIB entries on dpn %s for " + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors()); LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } }); Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { LOG.error("NAT Service : Error in removing the label or custom fib entries", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName); } else { LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors()); } } }); }