@Test public void testSendIpSgtBindingToPeer_noSxpCapableNode() throws Exception { SendIpSgtBindingToPeerInput input = new SendIpSgtBindingToPeerInputBuilder() .setBinding( Collections .singletonList(new BindingBuilder().setIpPrefix(BINDING_ADDR) .setSgt(BINDING_SGT) .setPeerNode(Collections .singletonList(new PeerNodeBuilder().setNodeIid(PEER_IID).build())) .build())) .build(); when(nodeListener.getDomainIdForPeer(PEER_IID)).thenReturn(null); Future<RpcResult<Void>> response = impl.sendIpSgtBindingToPeer(input); assertFalse(response.get().isSuccessful()); }
@Override public Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input) { Map<String, Multimap<Sgt, IpPrefix>> bindingsMap = new HashMap<>(); boolean success = true; for (Binding binding : input.getBinding()) { success = transformChanges(binding, bindingsMap); if (! success) { break; } } if (! success) { return Futures.immediateCheckedFuture(RpcResultBuilder.<Void>failed().build()); } WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); bindingsMap.entrySet().forEach(bindingEntries -> { String domainId = bindingEntries.getKey(); bindingEntries.getValue().entries().forEach(binding -> writeBinding(binding, domainId, wtx)); }); ListenableFuture<Void> submit = wtx.submit(); SettableFuture<RpcResult<Void>> future = SettableFuture.create(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { future.set(RpcResultBuilder.<Void>success().build()); } @Override public void onFailure(Throwable t) { future.set(RpcResultBuilder.<Void>failed().build()); } }, MoreExecutors.directExecutor()); return future; }
IpSgtDistributionServiceImpl implements AutoCloseable, IpSgtDistributionService { @Override public Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input) { Map<String, Multimap<Sgt, IpPrefix>> bindingsMap = new HashMap<>(); boolean success = true; for (Binding binding : input.getBinding()) { success = transformChanges(binding, bindingsMap); if (! success) { break; } } if (! success) { return Futures.immediateCheckedFuture(RpcResultBuilder.<Void>failed().build()); } WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); bindingsMap.entrySet().forEach(bindingEntries -> { String domainId = bindingEntries.getKey(); bindingEntries.getValue().entries().forEach(binding -> writeBinding(binding, domainId, wtx)); }); ListenableFuture<Void> submit = wtx.submit(); SettableFuture<RpcResult<Void>> future = SettableFuture.create(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { future.set(RpcResultBuilder.<Void>success().build()); } @Override public void onFailure(Throwable t) { future.set(RpcResultBuilder.<Void>failed().build()); } }, MoreExecutors.directExecutor()); return future; } }
IpSgtDistributionServiceImpl implements AutoCloseable, IpSgtDistributionService { @Override public Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input) { Map<String, Multimap<Sgt, IpPrefix>> bindingsMap = new HashMap<>(); boolean success = true; for (Binding binding : input.getBinding()) { success = transformChanges(binding, bindingsMap); if (! success) { break; } } if (! success) { return Futures.immediateCheckedFuture(RpcResultBuilder.<Void>failed().build()); } WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); bindingsMap.entrySet().forEach(bindingEntries -> { String domainId = bindingEntries.getKey(); bindingEntries.getValue().entries().forEach(binding -> writeBinding(binding, domainId, wtx)); }); ListenableFuture<Void> submit = wtx.submit(); SettableFuture<RpcResult<Void>> future = SettableFuture.create(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { future.set(RpcResultBuilder.<Void>success().build()); } @Override public void onFailure(Throwable t) { future.set(RpcResultBuilder.<Void>failed().build()); } }, MoreExecutors.directExecutor()); return future; } IpSgtDistributionServiceImpl(DataBroker dataBroker, SxpControllerService sxpService, IpAddress sourceIp); }
IpSgtDistributionServiceImpl implements AutoCloseable, IpSgtDistributionService { @Override public Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input) { Map<String, Multimap<Sgt, IpPrefix>> bindingsMap = new HashMap<>(); boolean success = true; for (Binding binding : input.getBinding()) { success = transformChanges(binding, bindingsMap); if (! success) { break; } } if (! success) { return Futures.immediateCheckedFuture(RpcResultBuilder.<Void>failed().build()); } WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); bindingsMap.entrySet().forEach(bindingEntries -> { String domainId = bindingEntries.getKey(); bindingEntries.getValue().entries().forEach(binding -> writeBinding(binding, domainId, wtx)); }); ListenableFuture<Void> submit = wtx.submit(); SettableFuture<RpcResult<Void>> future = SettableFuture.create(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { future.set(RpcResultBuilder.<Void>success().build()); } @Override public void onFailure(Throwable t) { future.set(RpcResultBuilder.<Void>failed().build()); } }, MoreExecutors.directExecutor()); return future; } IpSgtDistributionServiceImpl(DataBroker dataBroker, SxpControllerService sxpService, IpAddress sourceIp); @Override Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input); @Override Future<RpcResult<Void>> removeIpSgtBindingFromPeer(RemoveIpSgtBindingFromPeerInput input); @Override void close(); }
IpSgtDistributionServiceImpl implements AutoCloseable, IpSgtDistributionService { @Override public Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input) { Map<String, Multimap<Sgt, IpPrefix>> bindingsMap = new HashMap<>(); boolean success = true; for (Binding binding : input.getBinding()) { success = transformChanges(binding, bindingsMap); if (! success) { break; } } if (! success) { return Futures.immediateCheckedFuture(RpcResultBuilder.<Void>failed().build()); } WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); bindingsMap.entrySet().forEach(bindingEntries -> { String domainId = bindingEntries.getKey(); bindingEntries.getValue().entries().forEach(binding -> writeBinding(binding, domainId, wtx)); }); ListenableFuture<Void> submit = wtx.submit(); SettableFuture<RpcResult<Void>> future = SettableFuture.create(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { future.set(RpcResultBuilder.<Void>success().build()); } @Override public void onFailure(Throwable t) { future.set(RpcResultBuilder.<Void>failed().build()); } }, MoreExecutors.directExecutor()); return future; } IpSgtDistributionServiceImpl(DataBroker dataBroker, SxpControllerService sxpService, IpAddress sourceIp); @Override Future<RpcResult<Void>> sendIpSgtBindingToPeer(SendIpSgtBindingToPeerInput input); @Override Future<RpcResult<Void>> removeIpSgtBindingFromPeer(RemoveIpSgtBindingFromPeerInput input); @Override void close(); static final String SXP_NODE_DESCRIPTION; static final String SXP_TOPOLOGY_ID; }