use of com.google.common.util.concurrent.FluentFuture in project netvirt by opendaylight.
the class ElanL2GatewayUtils method removeRemoteUcastMacsFromExternalDevice.
/**
* Removes the given MAC Addresses from the specified External Device.
*
* @param deviceNodeId
* the device node id
* @param macAddresses
* the mac addresses
* @return the listenable future
*/
private FluentFuture<? extends @NonNull CommitInfo> removeRemoteUcastMacsFromExternalDevice(String deviceNodeId, String logicalSwitchName, List<PhysAddress> macAddresses) {
NodeId nodeId = new NodeId(deviceNodeId);
// TODO (eperefr)
List<MacAddress> lstMac = macAddresses.stream().filter(Objects::nonNull).map(physAddress -> new MacAddress(physAddress.getValue().toLowerCase(Locale.getDefault()))).collect(Collectors.toList());
return HwvtepUtils.deleteRemoteUcastMacs(broker, nodeId, logicalSwitchName, lstMac);
}
use of com.google.common.util.concurrent.FluentFuture in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionReadsWithShardNotInitiallyReady.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadsWithShardNotInitiallyReady() throws Exception {
final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
final String testName = "testTransactionReadsWithShardNotInitiallyReady";
final String shardName = "test-1";
// Setup the InMemoryJournal to block shard recovery to ensure
// the shard isn't
// initialized until we create the Tx.
final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, testName, false, shardName)) {
// Create the read-write Tx
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// Do some reads on the Tx on a separate thread.
final AtomicReference<FluentFuture<Boolean>> txExistsFuture = new AtomicReference<>();
final AtomicReference<FluentFuture<Optional<NormalizedNode>>> txReadFuture = new AtomicReference<>();
final AtomicReference<Exception> caughtEx = new AtomicReference<>();
final CountDownLatch txReadsDone = new CountDownLatch(1);
final Thread txThread = new Thread(() -> {
try {
readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH));
txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
} catch (Exception e) {
caughtEx.set(e);
} finally {
txReadsDone.countDown();
}
});
txThread.start();
// Wait for the Tx operations to complete.
boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
assertTrue("Tx reads done", done);
// At this point the Tx operations should be waiting for the
// shard to initialize so
// trigger the latch to let the shard recovery to continue.
blockRecoveryLatch.countDown();
// Wait for the reads to complete and verify.
assertEquals("exists", Boolean.TRUE, txExistsFuture.get().get(5, TimeUnit.SECONDS));
assertTrue("read", txReadFuture.get().get(5, TimeUnit.SECONDS).isPresent());
readWriteTx.close();
}
}
use of com.google.common.util.concurrent.FluentFuture in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method readAndCopyLocalUcastMacsToCache.
private void readAndCopyLocalUcastMacsToCache(final String elanName, final L2GatewayDevice l2GatewayDevice) {
final InstanceIdentifier<Node> nodeIid = HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2GatewayDevice.getHwvtepNodeId()));
jobCoordinator.enqueueJob(elanName + ":" + l2GatewayDevice.getDeviceName(), () -> {
final SettableFuture settableFuture = SettableFuture.create();
FluentFuture<Optional<Node>> fluentFuture = broker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, nodeIid);
Futures.addCallback(fluentFuture, new FutureCallback<Optional<Node>>() {
@Override
public void onSuccess(@NonNull Optional<Node> resultNode) {
Optional<Node> nodeOptional = resultNode;
if (nodeOptional.isPresent()) {
Node node = nodeOptional.get();
if (node.augmentation(HwvtepGlobalAugmentation.class) != null) {
List<LocalUcastMacs> localUcastMacs = new ArrayList<>(node.augmentation(HwvtepGlobalAugmentation.class).nonnullLocalUcastMacs().values());
if (localUcastMacs == null) {
return;
}
localUcastMacs.stream().filter(mac -> macBelongsToLogicalSwitch(mac, elanName)).forEach(mac -> {
InstanceIdentifier<LocalUcastMacs> macIid = getMacIid(nodeIid, mac);
localUcastMacListener.added(macIid, mac);
});
}
}
}
@Override
public void onFailure(Throwable throwable) {
}
}, MoreExecutors.directExecutor());
return Lists.newArrayList(fluentFuture);
});
}
use of com.google.common.util.concurrent.FluentFuture in project netvirt by opendaylight.
the class L2GatewayListener method update.
@Override
public void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
LOG.info("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(Sets.newHashSet(update.getUuid()));
if (connections == null) {
LOG.warn("There are no connections associated with l2 gateway uuid {} name {}", update.getUuid(), update.getName());
return;
}
if (original.getDevices() == null) {
connections.forEach((connection) -> l2gwService.addL2GatewayConnection(connection));
return;
}
elanClusterUtils.runOnlyInOwnerNode("l2gw.update", () -> {
DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
FluentFuture<?> fts = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
original.getDevices().values().stream().filter((originalDevice) -> originalDevice.getInterfaces() != null).forEach((originalDevice) -> {
String deviceName = originalDevice.getDeviceName();
L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
originalDevice.getInterfaces().values().stream().filter((intf) -> !updatedDeviceInterfaces.containsInterface(deviceName, intf.getInterfaceName())).forEach((intf) -> {
connections.forEach((connection) -> {
Integer vlanId = connection.getSegmentId();
if (intf.getSegmentationIds() != null && !intf.getSegmentationIds().isEmpty()) {
for (Integer vlan : intf.getSegmentationIds()) {
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, intf.getInterfaceName(), vlan);
}
} else {
LOG.info("Deleting vlan binding {} {} {}", physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
}
});
});
});
});
fts.addCallback(new FutureCallback<Object>() {
@Override
public void onSuccess(Object success) {
LOG.info("Successfully deleted vlan bindings for l2gw update {}", update);
connections.forEach((l2GwConnection) -> l2gwService.addL2GatewayConnection(l2GwConnection, null, update));
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to delete vlan bindings as part of l2gw udpate {}", update);
}
}, MoreExecutors.directExecutor());
});
}
use of com.google.common.util.concurrent.FluentFuture in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionReadFailureWithShardNotInitialized.
@Test(expected = NotInitializedException.class)
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
final String testName = "testTransactionReadFailureWithShardNotInitialized";
final String shardName = "test-1";
// Set the shard initialization timeout low for the test.
datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
// Setup the InMemoryJournal to block shard recovery
// indefinitely.
final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, testName, false, shardName)) {
// Create the read-write Tx
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// Do a read on the Tx on a separate thread.
final AtomicReference<FluentFuture<Optional<NormalizedNode>>> txReadFuture = new AtomicReference<>();
final AtomicReference<Exception> caughtEx = new AtomicReference<>();
final CountDownLatch txReadDone = new CountDownLatch(1);
final Thread txThread = new Thread(() -> {
try {
readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
readWriteTx.close();
} catch (Exception e) {
caughtEx.set(e);
} finally {
txReadDone.countDown();
}
});
txThread.start();
// Wait for the Tx operations to complete.
boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
assertTrue("Tx read done", done);
// have timed out and throw an appropriate exception cause.
try {
txReadFuture.get().get(5, TimeUnit.SECONDS);
} catch (ExecutionException e) {
assertTrue("Expected ReadFailedException cause: " + e.getCause(), e.getCause() instanceof ReadFailedException);
final Throwable root = Throwables.getRootCause(e);
Throwables.throwIfUnchecked(root);
throw new RuntimeException(root);
} finally {
blockRecoveryLatch.countDown();
}
}
}
Aggregations