Search in sources :

Example 1 with FluentFuture

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);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) HwvtepPhysicalLocatorAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation) RemoteMcastMacsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey) CacheProvider(org.opendaylight.infrautils.caches.CacheProvider) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) Future(java.util.concurrent.Future) ElanClusterUtils(org.opendaylight.netvirt.elan.utils.ElanClusterUtils) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) Pair(org.apache.commons.lang3.tuple.Pair) BigInteger(java.math.BigInteger) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) DeleteLogicalSwitchJob(org.opendaylight.netvirt.elan.l2gw.jobs.DeleteLogicalSwitchJob) VlanBindings(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings) MacTable(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTable) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Set(java.util.Set) TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) FluentFutures(org.opendaylight.yangtools.util.concurrent.FluentFutures) Interfaces(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces) DeleteL2GwDeviceMacsFromElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.DeleteL2GwDeviceMacsFromElanJob) RemoteMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs) HwvtepPhysicalPortAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) ElanConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig) HwvtepPhysicalPortAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation) NonNull(org.eclipse.jdt.annotation.NonNull) HwvtepSouthboundConstants(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) ExternalTeps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ExternalTeps) DpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) GetDpidFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) GetDpidFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput) HwvtepNodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName) ElanInstanceDpnsCache(org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache) FutureCallback(com.google.common.util.concurrent.FutureCallback) RemoteUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ExecutionException(java.util.concurrent.ExecutionException) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TopologyKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey) AddL2GwDeviceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceOutput) IetfYangUtil(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) TerminationPointBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ScheduledFuture(java.util.concurrent.ScheduledFuture) ElanItmUtils(org.opendaylight.netvirt.elan.utils.ElanItmUtils) ElanL2GwCacheUtils(org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils) ElanConstants(org.opendaylight.netvirt.elan.utils.ElanConstants) LoggerFactory(org.slf4j.LoggerFactory) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) HwvtepMacTableGenericAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepMacTableGenericAttributes) PreDestroy(javax.annotation.PreDestroy) ElanUtils(org.opendaylight.netvirt.elan.utils.ElanUtils) Nullable(org.eclipse.jdt.annotation.Nullable) Locale(java.util.Locale) AddL2GwDeviceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceInputBuilder) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Collection(java.util.Collection) DeviceVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVteps) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ElanDmacUtils(org.opendaylight.netvirt.elan.utils.ElanDmacUtils) Collectors(java.util.stream.Collectors) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) Optional(java.util.Optional) LocatorSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HwvtepPhysicalLocatorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef) Singleton(javax.inject.Singleton) Function(java.util.function.Function) MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ElanInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances) InstanceIdDataObjectCache(org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache) TerminationPointKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey) HwvtepLogicalSwitchRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Logger(org.slf4j.Logger) ElanInstanceCache(org.opendaylight.netvirt.elan.cache.ElanInstanceCache) Scheduler(org.opendaylight.netvirt.elan.utils.Scheduler) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) SystemPropertyReader(org.opendaylight.genius.utils.SystemPropertyReader) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TimeUnit(java.util.concurrent.TimeUnit) InterfaceKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) Collections(java.util.Collections) FluentFuture(com.google.common.util.concurrent.FluentFuture) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Objects(java.util.Objects) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)

Example 2 with FluentFuture

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();
    }
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) ExecutionException(java.util.concurrent.ExecutionException) FluentFuture(com.google.common.util.concurrent.FluentFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 3 with FluentFuture

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);
    });
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ElanL2GwCacheUtils(org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) PreDestroy(javax.annotation.PreDestroy) ElanClusterUtils(org.opendaylight.netvirt.elan.utils.ElanClusterUtils) Nullable(org.eclipse.jdt.annotation.Nullable) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) LocalUcastMacListener(org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Set(java.util.Set) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) DisAssociateHwvtepFromElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.DisAssociateHwvtepFromElanJob) ElanUtils.isVxlanNetworkOrVxlanSegment(org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment) NonNull(org.eclipse.jdt.annotation.NonNull) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) AssociateHwvtepToElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.AssociateHwvtepToElanJob) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Lists(com.google.common.collect.Lists) Collections.emptyMap(java.util.Collections.emptyMap) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ElanInstanceCache(org.opendaylight.netvirt.elan.cache.ElanInstanceCache) Scheduler(org.opendaylight.netvirt.elan.utils.Scheduler) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) FutureCallback(com.google.common.util.concurrent.FutureCallback) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) L2gatewayKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayKey) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) FluentFuture(com.google.common.util.concurrent.FluentFuture) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Optional(java.util.Optional) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 4 with 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());
    });
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces) LoggerFactory(org.slf4j.LoggerFactory) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) RecoverableListener(org.opendaylight.serviceutils.srm.RecoverableListener) PreDestroy(javax.annotation.PreDestroy) HAOpClusteredListener(org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener) ElanClusterUtils(org.opendaylight.netvirt.elan.utils.ElanClusterUtils) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) TypedReadTransaction(org.opendaylight.mdsal.binding.util.TypedReadTransaction) Map(java.util.Map) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Collection(java.util.Collection) L2GatewayInstanceRecoveryHandler(org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayInstanceRecoveryHandler) L2GatewayUtils(org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayUtils) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) Optional(java.util.Optional) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) IL2gwService(org.opendaylight.netvirt.elanmanager.api.IL2gwService) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HAOpNodeListener(org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) L2gwZeroDayConfigUtil(org.opendaylight.netvirt.elan.l2gw.utils.L2gwZeroDayConfigUtil) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Logger(org.slf4j.Logger) AbstractClusteredAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) ServiceRecoveryRegistry(org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry) HwvtepHACache(org.opendaylight.genius.utils.hwvtep.HwvtepHACache) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Collections(java.util.Collections) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) FluentFuture(com.google.common.util.concurrent.FluentFuture) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 5 with FluentFuture

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();
        }
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) ExecutionException(java.util.concurrent.ExecutionException) FluentFuture(com.google.common.util.concurrent.FluentFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

FluentFuture (com.google.common.util.concurrent.FluentFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 FutureCallback (com.google.common.util.concurrent.FutureCallback)3 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 PreDestroy (javax.annotation.PreDestroy)3 Inject (javax.inject.Inject)3 Singleton (javax.inject.Singleton)3 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AddressFromURIString (akka.actor.AddressFromURIString)2 Lists (com.google.common.collect.Lists)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 HashMap (java.util.HashMap)2