Search in sources :

Example 1 with DataObjectModification

use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.

the class LocalUcastMacListener method getChildMod.

@Override
protected Map<InstanceIdentifier<LocalUcastMacs>, DataObjectModification<LocalUcastMacs>> getChildMod(final InstanceIdentifier<Node> parentIid, final DataObjectModification<Node> mod) {
    Map<InstanceIdentifier<LocalUcastMacs>, DataObjectModification<LocalUcastMacs>> result = new HashMap<>();
    DataObjectModification<HwvtepGlobalAugmentation> aug = mod.getModifiedAugmentation(HwvtepGlobalAugmentation.class);
    if (aug != null && getModificationType(aug) != null) {
        Collection<? extends DataObjectModification<? extends DataObject>> children = aug.getModifiedChildren();
        if (children == null) {
            return result;
        }
        children.stream().filter(childMod -> getModificationType(childMod) != null).filter(childMod -> childMod.getDataType() == LocalUcastMacs.class).forEach(childMod -> {
            LocalUcastMacs afterMac = (LocalUcastMacs) childMod.getDataAfter();
            LocalUcastMacs mac = afterMac != null ? afterMac : (LocalUcastMacs) childMod.getDataBefore();
            InstanceIdentifier<LocalUcastMacs> iid = parentIid.augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class, mac.key());
            result.put(iid, (DataObjectModification<LocalUcastMacs>) childMod);
        });
    }
    return result;
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ElanL2GwCacheUtils(org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils) LoggerFactory(org.slf4j.LoggerFactory) SrcnodeAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SrcnodeAugmentation) LocalUcastMacsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsKey) ElanForwardingTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanForwardingTables) CacheProvider(org.opendaylight.infrautils.caches.CacheProvider) RecoverableListener(org.opendaylight.serviceutils.srm.RecoverableListener) HAOpClusteredListener(org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener) ElanClusterUtils(org.opendaylight.netvirt.elan.utils.ElanClusterUtils) ElanUtils(org.opendaylight.netvirt.elan.utils.ElanUtils) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) Nullable(org.eclipse.jdt.annotation.Nullable) Locale(java.util.Locale) Map(java.util.Map) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) 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) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) Predicate(java.util.function.Predicate) MacTable(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTable) Collection(java.util.Collection) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) Objects(java.util.Objects) ElanL2GatewayUtils(org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) ElanConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig) PostConstruct(javax.annotation.PostConstruct) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) L2GatewayServiceRecoveryHandler(org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayServiceRecoveryHandler) HwvtepPhysicalLocatorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) 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) MacEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder) Lists(com.google.common.collect.Lists) DataTreeModification(org.opendaylight.mdsal.binding.api.DataTreeModification) ClusteredDataTreeChangeListener(org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener) InstanceIdDataObjectCache(org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) 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) ServiceRecoveryRegistry(org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry) HwvtepHACache(org.opendaylight.genius.utils.hwvtep.HwvtepHACache) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) SrcnodeAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SrcnodeAugmentationBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) LocalUcastMacsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsBuilder) Collections(java.util.Collections) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 2 with DataObjectModification

use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.

the class MergeCommandsAggregator method copyModification.

private <D extends Datastore> void copyModification(InstanceIdentifier<Node> dstPath, Class<D> datastoreType, BatchedTransaction tx, String srcNodeId, String dstNodeId, DataObjectModification modification, ManagedNewTransactionRunner txRunner) {
    DataObjectModification.ModificationType type = getModificationType(modification);
    if (type == null) {
        return;
    }
    String src = datastoreType == OPERATIONAL ? "child" : "parent";
    MergeCommand mergeCommand = commands.get(modification.getDataType());
    boolean create = false;
    switch(type) {
        case WRITE:
        case SUBTREE_MODIFIED:
            DataObject dataAfter = modification.getDataAfter();
            if (dataAfter == null) {
                return;
            }
            DataObject before = modification.getDataBefore();
            if (Objects.equals(dataAfter, before)) {
                LOG.warn("Ha updated skip not modified {}", src);
                return;
            }
            create = true;
            break;
        case DELETE:
            DataObject dataBefore = modification.getDataBefore();
            if (dataBefore == null) {
                LOG.warn("Ha updated skip delete {}", src);
                return;
            }
            break;
        default:
            return;
    }
    DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
    InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
    if (tx.updateMetric()) {
        LOG.info("Ha updated processing {}", src);
    }
    if (create) {
        DataObject transformedItem = mergeCommand.transform(dstPath, modification.getDataAfter());
        tx.put(transformedId, transformedItem);
        // if tunnel ip command do this for
        if (mergeCommand.getClass() == TunnelIpCmd.class) {
            if (Operational.class.equals(datastoreType)) {
                txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, configTx -> {
                    configTx.put(transformedId, transformedItem);
                });
            }
        }
    } else {
        if (deleteInProgressIids.getIfPresent(transformedId) == null) {
            // TODO uncomment this code
            /*if (isLocalMacMoved(mergeCommand, transformedId, tx, srcNodeId, txRunner)) {
                    return;
                }*/
            tx.delete(transformedId);
            if (mergeCommand.getClass() == TunnelIpCmd.class) {
                if (Operational.class.equals(datastoreType)) {
                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, configTx -> {
                        tx.delete(transformedId);
                    });
                }
            }
            deleteInProgressIids.put(transformedId, Boolean.TRUE);
        } else {
            return;
        }
    }
    String created = create ? "created" : "deleted";
    Futures.addCallback(tx.getFt(transformedId), new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void voidResult) {
            LOG.info("Ha updated skip not modified {}", mergeCommand.getDescription());
            deleteInProgressIids.invalidate(transformedId);
        }

        @Override
        public void onFailure(Throwable throwable) {
            LOG.error("Ha failed {}", mergeCommand.getDescription());
            deleteInProgressIids.invalidate(transformedId);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)

Example 3 with DataObjectModification

use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.

the class MergeCommandsAggregator method mergeUpdate.

@SuppressWarnings("illegalcatch")
public <D extends Datastore> void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, Class<D> datastoreType, TypedReadWriteTransaction<D> transaction, ManagedNewTransactionRunner txRunner) {
    BatchedTransaction tx = null;
    if (mod == null || mod.getModifiedChildren() == null) {
        return;
    }
    if (!(transaction instanceof BatchedTransaction)) {
        return;
    } else {
        tx = (BatchedTransaction) transaction;
    }
    final BatchedTransaction transaction1 = tx;
    String srcNodeId = transaction1.getSrcNodeId().getValue();
    String dstNodeId = dstPath.firstKeyOf(Node.class).getNodeId().getValue();
    Collection<DataObjectModification> modifications = mod.getModifiedChildren();
    modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
        try {
            copyModification(dstPath, datastoreType, transaction1, srcNodeId, dstNodeId, modification, txRunner);
        } catch (Exception e) {
            LOG.error("Failed to copy mod from {} to {} {} {} id  {}", srcNodeId, dstNodeId, modification.getDataType().getSimpleName(), modification, modification.getIdentifier(), e);
        }
    });
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) LoggerFactory(org.slf4j.LoggerFactory) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) RemoteUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd) RemoteMcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteMcastCmd) Tunnels(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels) BiPredicate(java.util.function.BiPredicate) Map(java.util.Map) Datastore(org.opendaylight.mdsal.binding.util.Datastore) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) Builder(org.opendaylight.yangtools.concepts.Builder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) TunnelIpCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TunnelIpCmd) Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Collection(java.util.Collection) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) SuperTypeUtil(org.opendaylight.genius.utils.SuperTypeUtil) LocalUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalUcastCmd) 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) LocalMcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalMcastCmd) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) RemoteMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs) TerminationPointCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TerminationPointCmd) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PhysicalLocatorCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.PhysicalLocatorCmd) LocalMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs) Optional(java.util.Optional) TunnelCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TunnelCmd) CacheBuilder(com.google.common.cache.CacheBuilder) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) Cache(com.google.common.cache.Cache) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification)

Aggregations

DataObjectModification (org.opendaylight.mdsal.binding.api.DataObjectModification)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 TimeUnit (java.util.concurrent.TimeUnit)2 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)2 OPERATIONAL (org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL)2 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)2 MergeCommand (org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1