List of usage examples for com.google.common.util.concurrent Futures immediateFailedFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable)
From source file:com.microsoftopentechnologies.intellij.helpers.o365.Office365RestAPIManager.java
@Override public ListenableFuture<List<ServicePrincipal>> addServicePrincipals( @NotNull final List<ServicePrincipal> servicePrincipals) throws ParseException { return requestWithToken(new RequestCallback<List<ServicePrincipal>>() { @Override//from ww w. j ava2 s . c o m public ListenableFuture<List<ServicePrincipal>> execute() throws ParseException { List<ListenableFuture<ServicePrincipal>> futures = Lists.transform(servicePrincipals, new Function<ServicePrincipal, ListenableFuture<ServicePrincipal>>() { @Override public ListenableFuture<ServicePrincipal> apply(ServicePrincipal servicePrincipal) { try { return getDirectoryClient().getservicePrincipals().add(servicePrincipal); } catch (ParseException e) { return Futures.immediateFailedFuture(e); } } }); return Futures.allAsList(futures); } }); }
From source file:org.opendaylight.faas.fabric.general.FabricServiceAPIProvider.java
@Override public Future<RpcResult<Void>> rmStaticRoute(RmStaticRouteInput input) { final List<Ipv4Prefix> destIps = input.getDestinationPrefix(); FabricId fabricId = input.getFabricId(); NodeId ldev = input.getNodeId();/*from ww w . j a v a 2 s . com*/ final FabricInstance fabricObj = FabricInstanceCache.INSTANCE.retrieveFabric(fabricId); if (fabricObj == null) { return Futures.immediateFailedFuture( new IllegalArgumentException(String.format("fabric %s does not exist", fabricId))); } final List<Route> routes = Lists.newArrayList(); for (Ipv4Prefix destIp : destIps) { routes.add(new RouteBuilder().setKey(new RouteKey(destIp)).build()); } final InstanceIdentifier<Routes> routesIId = MdSalUtils.createNodeIId(fabricId, ldev) .augmentation(LogicalRouterAugment.class).child(LrAttribute.class).child(Routes.class); WriteTransaction trans = dataBroker.newWriteOnlyTransaction(); for (Route route : routes) { trans.delete(LogicalDatastoreType.OPERATIONAL, routesIId.child(Route.class, route.getKey())); } return Futures.transform(trans.submit(), new AsyncFunction<Void, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(Void submitResult) throws Exception { fabricObj.notifyRouteUpdated(routesIId.firstIdentifierOf(Node.class), routes, true); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); } }, executor); }
From source file:org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils.java
/** * Update vlan bindings in l2 gateway device. * * @param nodeId/*from w w w. j av a 2 s .com*/ * the node id * @param logicalSwitchName * the logical switch name * @param hwVtepDevice * the hardware device * @param defaultVlanId * the default vlan id * @return the listenable future */ public ListenableFuture<Void> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String logicalSwitchName, Devices hwVtepDevice, Integer defaultVlanId) { if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) { String errMsg = "HwVtepDevice is null or interfaces are empty."; LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } WriteTransaction transaction = broker.newWriteOnlyTransaction(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice .getInterfaces()) { NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName()); TerminationPoint portTerminationPoint = HwvtepUtils.getPhysicalPortTerminationPoint(broker, LogicalDatastoreType.OPERATIONAL, physicalSwitchNodeId, deviceInterface.getInterfaceName()); if (portTerminationPoint == null) { // port is not present in Hwvtep; don't configure VLAN bindings // on this port continue; } List<VlanBindings> vlanBindings = new ArrayList<>(); if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) { for (Integer vlanId : deviceInterface.getSegmentationIds()) { vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, vlanId, logicalSwitchName)); } } else { // Use defaultVlanId (specified in L2GatewayConnection) if Vlan // ID not specified at interface level. vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, defaultVlanId, logicalSwitchName)); } HwvtepUtils.mergeVlanBindings(transaction, nodeId, hwVtepDevice.getDeviceName(), deviceInterface.getInterfaceName(), vlanBindings); } ListenableFuture<Void> future = transaction.submit(); LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}, LogicalSwitch: {}", nodeId.getValue(), logicalSwitchName); return future; }
From source file:org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils.java
/** * Delete vlan bindings from l2 gateway device. * * @param nodeId/*from w ww .ja v a 2 s. c om*/ * the node id * @param hwVtepDevice * the hw vtep device * @param defaultVlanId * the default vlan id * @return the listenable future */ public static ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice, Integer defaultVlanId) { if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) { String errMsg = "HwVtepDevice is null or interfaces are empty."; LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName()); WriteTransaction transaction = broker.newWriteOnlyTransaction(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice .getInterfaces()) { String phyPortName = deviceInterface.getInterfaceName(); if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) { for (Integer vlanId : deviceInterface.getSegmentationIds()) { HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, phyPortName, vlanId); } } else { // Use defaultVlanId (specified in L2GatewayConnection) if Vlan // ID not specified at interface level. HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, phyPortName, defaultVlanId); } } ListenableFuture<Void> future = transaction.submit(); LOG.info("Deleted Hwvtep VlanBindings from config DS. NodeID: {}, hwVtepDevice: {}, defaultVlanId: {} ", nodeId.getValue(), hwVtepDevice, defaultVlanId); return future; }
From source file:org.opendaylight.vpnservice.alivenessmonitor.internal.AlivenessMonitor.java
private void sendMonitorPacket(final MonitoringInfo monitoringInfo) { //TODO: Handle interrupts final Long monitorId = monitoringInfo.getId(); final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId); if (monitorKey == null) { LOG.warn("No monitor Key associated with id {} to send the monitor packet", monitorId); return;//w ww . j ava 2s. c om } else { LOG.debug("Sending monitoring packet for key: {}", monitorKey); } final MonitorProfile profile; Optional<MonitorProfile> optProfile = getMonitorProfile(monitoringInfo.getProfileId()); if (optProfile.isPresent()) { profile = optProfile.get(); } else { LOG.warn( "No monitor profile associated with id {}. " + "Could not send Monitor packet for monitor-id {}", monitoringInfo.getProfileId(), monitorId); return; } final Semaphore lock = lockMap.get(monitorKey); LOG.debug("Acquiring lock for monitor key : {} to send monitor packet", monitorKey); acquireLock(lock); final ReadWriteTransaction tx = broker.newReadWriteTransaction(); ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey)); ListenableFuture<Void> writeResult = Futures.transform(readResult, new AsyncFunction<Optional<MonitoringState>, Void>() { @Override public ListenableFuture<Void> apply(Optional<MonitoringState> optState) throws Exception { if (optState.isPresent()) { MonitoringState state = optState.get(); //Increase the request count Long requestCount = state.getRequestCount() + 1; //Check with the monitor window LivenessState currentLivenessState = state.getState(); //Increase the pending response count long responsePendingCount = state.getResponsePendingCount(); if (responsePendingCount < profile.getMonitorWindow()) { responsePendingCount = responsePendingCount + 1; } //Check with the failure thresold if (responsePendingCount >= profile.getFailureThreshold()) { //Change the state to down and notify if (currentLivenessState != LivenessState.Down) { LOG.debug("Response pending Count: {}, Failure threshold: {} for monitorId {}", responsePendingCount, profile.getFailureThreshold(), state.getMonitorId()); LOG.info("Sending notification for monitor Id : {} with State: {}", state.getMonitorId(), LivenessState.Down); publishNotification(monitorId, LivenessState.Down); currentLivenessState = LivenessState.Down; //Reset requestCount when state changes from UP to DOWN requestCount = INITIAL_COUNT; } } //Update the ODS with state MonitoringState updatedState = new MonitoringStateBuilder(/*state*/) .setMonitorKey(state.getMonitorKey()).setRequestCount(requestCount) .setResponsePendingCount(responsePendingCount).setState(currentLivenessState) .build(); tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(state.getMonitorKey()), updatedState); return tx.submit(); } else { //Close the transaction tx.submit(); String errorMsg = String.format( "Monitoring State associated with id %d is not present to send packet out.", monitorId); return Futures.immediateFailedFuture(new RuntimeException(errorMsg)); } } }); Futures.addCallback(writeResult, new FutureCallback<Void>() { @Override public void onSuccess(Void noarg) { //invoke packetout on protocol handler AlivenessProtocolHandler handler = ethTypeToProtocolHandler.get(profile.getProtocolType()); if (handler != null) { LOG.debug("Sending monitoring packet {}", monitoringInfo); handler.sendPacketOut(monitoringInfo); } releaseLock(lock); } @Override public void onFailure(Throwable error) { LOG.warn("Updating monitoring state for key: {} failed. Monitoring packet is not sent", monitorKey, error); releaseLock(lock); } }); }
From source file:org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitor.java
private void sendMonitorPacket(final MonitoringInfo monitoringInfo) { // TODO: Handle interrupts final Long monitorId = monitoringInfo.getId(); final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId); if (monitorKey == null) { LOG.warn("No monitor Key associated with id {} to send the monitor packet", monitorId); return;// w w w . j a va2 s . c o m } else { LOG.debug("Sending monitoring packet for key: {}", monitorKey); } final MonitorProfile profile; Optional<MonitorProfile> optProfile = getMonitorProfile(monitoringInfo.getProfileId()); if (optProfile.isPresent()) { profile = optProfile.get(); } else { LOG.warn( "No monitor profile associated with id {}. " + "Could not send Monitor packet for monitor-id {}", monitoringInfo.getProfileId(), monitorId); return; } final Semaphore lock = lockMap.get(monitorKey); LOG.debug("Acquiring lock for monitor key : {} to send monitor packet", monitorKey); acquireLock(lock); final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey)); ListenableFuture<Void> writeResult = Futures.transform(readResult, (AsyncFunction<Optional<MonitoringState>, Void>) optState -> { if (optState.isPresent()) { MonitoringState state = optState.get(); // Increase the request count Long requestCount = state.getRequestCount() + 1; // Check with the monitor window LivenessState currentLivenessState = state.getState(); // Increase the pending response count long responsePendingCount = state.getResponsePendingCount(); if (responsePendingCount < profile.getMonitorWindow()) { responsePendingCount = responsePendingCount + 1; } // Check with the failure threshold if (responsePendingCount >= profile.getFailureThreshold()) { // Change the state to down and notify if (currentLivenessState != LivenessState.Down) { LOG.debug("Response pending Count: {}, Failure threshold: {} for monitorId {}", responsePendingCount, profile.getFailureThreshold(), state.getMonitorId()); LOG.info("Sending notification for monitor Id : {} with State: {}", state.getMonitorId(), LivenessState.Down); publishNotification(monitorId, LivenessState.Down); currentLivenessState = LivenessState.Down; // Reset requestCount when state changes // from UP to DOWN requestCount = INITIAL_COUNT; } } // Update the ODS with state MonitoringState updatedState = new MonitoringStateBuilder(/* state */) .setMonitorKey(state.getMonitorKey()).setRequestCount(requestCount) .setResponsePendingCount(responsePendingCount).setState(currentLivenessState) .build(); tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(state.getMonitorKey()), updatedState); return tx.submit(); } else { // Close the transaction tx.submit(); String errorMsg = String.format( "Monitoring State associated with id %d is not present to send packet out.", monitorId); return Futures.immediateFailedFuture(new RuntimeException(errorMsg)); } }); Futures.addCallback(writeResult, new FutureCallback<Void>() { @Override public void onSuccess(Void noarg) { // invoke packetout on protocol handler AlivenessProtocolHandler handler = alivenessProtocolHandlerRegistry .getOpt(profile.getProtocolType()); if (handler != null) { LOG.debug("Sending monitoring packet {}", monitoringInfo); handler.startMonitoringTask(monitoringInfo); } releaseLock(lock); } @Override public void onFailure(Throwable error) { LOG.warn("Updating monitoring state for key: {} failed. Monitoring packet is not sent", monitorKey, error); releaseLock(lock); } }); }
From source file:org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils.java
/** * Delete vlan bindings from l2 gateway device. * * @param nodeId/* w ww . j a v a 2s.c om*/ * the node id * @param hwVtepDevice * the hw vtep device * @param defaultVlanId * the default vlan id * @return the listenable future */ public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice, Integer defaultVlanId) { if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) { String errMsg = "HwVtepDevice is null or interfaces are empty."; LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName()); WriteTransaction transaction = broker.newWriteOnlyTransaction(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice .getInterfaces()) { String phyPortName = deviceInterface.getInterfaceName(); if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) { for (Integer vlanId : deviceInterface.getSegmentationIds()) { HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, phyPortName, vlanId); } } else { // Use defaultVlanId (specified in L2GatewayConnection) if Vlan // ID not specified at interface level. HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, phyPortName, defaultVlanId); } } ListenableFuture<Void> future = transaction.submit(); LOG.info("Deleted Hwvtep VlanBindings from config DS. NodeID: {}, hwVtepDevice: {}, defaultVlanId: {} ", nodeId.getValue(), hwVtepDevice, defaultVlanId); return future; }
From source file:org.opendaylight.vpnservice.natservice.internal.ExternalRoutersListener.java
public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName, final long routerId, final String externalIp, VpnRpcService vpnService, final FibRpcService fibService, final IBgpManager bgpManager, final DataBroker dataBroker, final Logger log) { LOG.debug(/*w w w . ja v a 2 s. c o m*/ "NAT Service : advToBgpAndInstallFibAndTsFlows() entry for DPN ID {}, tableId {}, vpnname {} and externalIp {}", dpnId, tableId, vpnName, externalIp); //Generate VPN label for the external IP GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput); //On successful generation of the VPN label, advertise the route to the BGP and install the FIB routes. ListenableFuture<RpcResult<Void>> future = Futures.transform( JdkFutureAdapters.listenInPoolThread(labelFuture), new AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(RpcResult<GenerateVpnLabelOutput> result) throws Exception { if (result.isSuccessful()) { LOG.debug("NAT Service : inside apply with result success"); GenerateVpnLabelOutput output = result.getResult(); long label = output.getLabel(); //Inform BGP String rd = NatUtil.getVpnRd(dataBroker, vpnName); String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId); NatUtil.addPrefixToBGP(bgpManager, rd, externalIp, nextHopIp, label, log); //Get IPMaps from the DB for the router ID List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId); if (dbIpMaps != null) { for (IpMap dbIpMap : dbIpMaps) { String dbExternalIp = dbIpMap.getExternalIp(); //Select the IPMap, whose external IP is the IP for which FIB is installed if (externalIp.equals(dbExternalIp)) { String dbInternalIp = dbIpMap.getInternalIp(); IpMapKey dbIpMapKey = dbIpMap.getKey(); LOG.debug("Setting label {} for internalIp {} and externalIp {}", label, dbInternalIp, externalIp); IpMap newIpm = new IpMapBuilder().setKey(dbIpMapKey) .setInternalIp(dbInternalIp).setExternalIp(dbExternalIp) .setLabel(label).build(); MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm); break; } } } else { LOG.error( "NAT Service : Failed to write label {} for externalIp {} for routerId {} in DS", label, externalIp, routerId); } //Install custom FIB routes List<Instruction> customInstructions = new ArrayList<>(); customInstructions .add(new InstructionInfo(InstructionType.goto_table, new long[] { tableId }) .buildInstruction(0)); makeTunnelTableEntry(dpnId, label, customInstructions); makeLFibTableEntry(dpnId, label, tableId); CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName) .setSourceDpid(dpnId).setIpAddress(externalIp).setServiceId(label) .setInstruction(customInstructions).build(); Future<RpcResult<Void>> future = fibService.createFibEntry(input); return JdkFutureAdapters.listenInPoolThread(future); } else { LOG.error("NAT Service : inside apply with result failed"); String errMsg = String.format( "Could not retrieve the label for prefix %s in VPN %s, %s", externalIp, vpnName, result.getErrors()); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } } }); Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { log.error("NAT Service : Error in generate label or fib install process", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { log.info("NAT Service : Successfully installed custom FIB routes for prefix {}", externalIp); } else { log.error( "NAT Service : Error in rpc call to create custom Fib entries for prefix {} in DPN {}, {}", externalIp, dpnId, result.getErrors()); } } }); }
From source file:org.opendaylight.netvirt.natservice.internal.ExternalRoutersListener.java
public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName, final long routerId, final String routerName, final String externalIp, final Routers router, VpnRpcService vpnService, final FibRpcService fibService, final IBgpManager bgpManager, final DataBroker dataBroker, final Logger log) { LOG.debug("NAT Service : advToBgpAndInstallFibAndTsFlows() entry for DPN ID {}, tableId {}, vpnname {} " + "and externalIp {}", dpnId, tableId, vpnName, externalIp); String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId); String rd = NatUtil.getVpnRd(dataBroker, vpnName); if (rd == null || rd.isEmpty()) { LOG.error("NAT Service : Unable to get RD for VPN Name {}", vpnName); return;/*from ww w.j av a2s . c o m*/ } ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName); if (extNwProvType == null) { return; } if (extNwProvType == ProviderTypes.VXLAN) { WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp, vpnName, rd, nextHopIp, writeTx, routerId); writeTx.submit(); return; } //Generate VPN label for the external IP GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput); //On successful generation of the VPN label, advertise the route to the BGP and install the FIB routes. ListenableFuture<RpcResult<Void>> future = Futures.transform( JdkFutureAdapters.listenInPoolThread(labelFuture), (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> { if (result.isSuccessful()) { LOG.debug("NAT Service : inside apply with result success"); GenerateVpnLabelOutput output = result.getResult(); final long label = output.getLabel(); int externalIpInDsFlag = 0; //Get IPMaps from the DB for the router ID List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId); if (dbIpMaps != null) { for (IpMap dbIpMap : dbIpMaps) { String dbExternalIp = dbIpMap.getExternalIp(); //Select the IPMap, whose external IP is the IP for which FIB is installed if (dbExternalIp.contains(externalIp)) { String dbInternalIp = dbIpMap.getInternalIp(); IpMapKey dbIpMapKey = dbIpMap.getKey(); LOG.debug("Setting label {} for internalIp {} and externalIp {}", label, dbInternalIp, externalIp); IpMap newIpm = new IpMapBuilder().setKey(dbIpMapKey).setInternalIp(dbInternalIp) .setExternalIp(dbExternalIp).setLabel(label).build(); MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm); externalIpInDsFlag++; } } if (externalIpInDsFlag <= 0) { LOG.debug("NAT Service : External Ip {} not found in DS, Failed to update label {} " + "for routerId {} in DS", externalIp, label, routerId); String errMsg = String.format("Failed to update label %s due to external Ip %s not" + " found in DS for router %s", label, externalIp, routerId); return Futures.immediateFailedFuture(new Exception(errMsg)); } } else { LOG.error("NAT Service : Failed to write label {} for externalIp {} for " + "routerId {} in DS", label, externalIp, routerId); } //Inform BGP long l3vni = 0; if (nvpnManager.getEnforceOpenstackSemanticsConfig()) { l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue(); } Routers extRouter = router != null ? router : NatUtil.getRoutersFromConfigDS(dataBroker, routerName); Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(dataBroker, externalIp, extRouter); NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, externalSubnetId, externalIp, nextHopIp, extRouter.getNetworkId().getValue(), null, label, l3vni, log, RouteOrigin.STATIC, dpnId); //Install custom FIB routes List<Instruction> tunnelTableCustomInstructions = new ArrayList<>(); tunnelTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0)); makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions); makeLFibTableEntry(dpnId, label, tableId); //Install custom FIB routes - FIB table. List<Instruction> fibTableCustomInstructions = createFibTableCustomInstructions(dataBroker, tableId, routerName, externalIp); if (nvpnManager.getEnforceOpenstackSemanticsConfig()) { //Install the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE) NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE); } String fibExternalIp = externalIp.contains("/32") ? externalIp : (externalIp + "/32"); CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName) .setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label) .setInstruction(fibTableCustomInstructions).build(); Future<RpcResult<Void>> future1 = fibService.createFibEntry(input); return JdkFutureAdapters.listenInPoolThread(future1); } else { LOG.error("NAT Service : inside apply with result failed"); String errMsg = String.format("Could not retrieve the label for prefix %s in VPN %s, %s", externalIp, vpnName, result.getErrors()); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } }); Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { log.error("NAT Service : Error in generate label or fib install process", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { log.info("NAT Service : Successfully installed custom FIB routes for prefix {}", externalIp); } else { log.error("NAT Service : Error in rpc call to create custom Fib entries for prefix {} in " + "DPN {}, {}", externalIp, dpnId, result.getErrors()); } } }); }
From source file:org.apache.qpid.server.virtualhost.AbstractVirtualHost.java
public ListenableFuture<Void> registerConnectionAsync(final AMQPConnection<?> connection) { return doOnConfigThread(new Task<ListenableFuture<Void>, RuntimeException>() { @Override/*from w ww .j av a 2 s . com*/ public ListenableFuture<Void> execute() { if (_acceptsConnections.get()) { _connections.add(connection); if (_blocked.get()) { connection.block(); } connection.pushScheduler(_networkConnectionScheduler); return Futures.immediateFuture(null); } else { final VirtualHostUnavailableException exception = new VirtualHostUnavailableException( String.format("VirtualHost '%s' not accepting connections", getName())); return Futures.immediateFailedFuture(exception); } } @Override public String getObject() { return AbstractVirtualHost.this.toString(); } @Override public String getAction() { return "register connection"; } @Override public String getArguments() { return String.valueOf(connection); } }); }