Search in sources :

Example 1 with HwvtepGlobalAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation in project netvirt by opendaylight.

the class L2GwValidateCli method compareNodes.

private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, LogicalDatastoreType datastoreType) {
    if (node1 == null || node2 == null) {
        return false;
    }
    InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
    InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
    NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
    NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
    PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
    PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
    HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
    HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
    boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
    MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
    for (MergeCommand cmd : commands) {
        List<DataObject> data1 = null;
        List<DataObject> data2 = null;
        if (globalNodes) {
            data1 = cmd.getData(aug1);
            data2 = cmd.getData(aug2);
        } else {
            data1 = cmd.getData(node1);
            data2 = cmd.getData(node2);
        }
        data1 = data1 == null ? Collections.EMPTY_LIST : data1;
        data2 = data2 == null ? Collections.EMPTY_LIST : data2;
        if (parentChildComparison) {
            data2 = cmd.transform(nodeIid1, data2);
        }
        Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
        data1 = Lists.transform(data1, withoutUuidTransformer);
        data2 = Lists.transform(data2, withoutUuidTransformer);
        Map<Identifier<?>, DataObject> map1 = new HashMap<>();
        Map<Identifier<?>, DataObject> map2 = new HashMap<>();
        for (DataObject dataObject : data1) {
            map1.put(cmd.getKey(dataObject), dataObject);
        }
        for (DataObject dataObject : data2) {
            map2.put(cmd.getKey(dataObject), dataObject);
        }
        Set<DataObject> diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map2.get(entry.getKey());
            if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                diff.add(obj1);
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
            } else {
                pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
        diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map1.get(entry.getKey());
            if (globalNodes || parentChildComparison) {
                if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                    diff.add(obj1);
                }
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
            } else {
                pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with HwvtepGlobalAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation 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<DataObjectModification<? extends DataObject>> children = aug.getModifiedChildren();
        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.getKey());
            result.put(iid, (DataObjectModification<LocalUcastMacs>) childMod);
        });
    }
    return result;
}
Also used : ClusteredDataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener) ElanL2GwCacheUtils(org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) HashSet(java.util.HashSet) Inject(javax.inject.Inject) HAOpClusteredListener(org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) Locale(java.util.Locale) Map(java.util.Map) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) 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) Nullable(javax.annotation.Nullable) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) 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) Predicate(java.util.function.Predicate) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) Collection(java.util.Collection) ElanInstanceCache(org.opendaylight.netvirt.elan.cache.ElanInstanceCache) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) HwvtepHACache(org.opendaylight.genius.utils.hwvtep.HwvtepHACache) Sets(com.google.common.collect.Sets) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) ElanL2GatewayUtils(org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) Collections(java.util.Collections) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) HashMap(java.util.HashMap) DataObjectModification(org.opendaylight.controller.md.sal.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 3 with HwvtepGlobalAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation in project netvirt by opendaylight.

the class HwvtepHAUtil method getChildNodeIdsFromManagerOtherConfig.

/**
 * Returns ha child node path from ha node of config data tree.
 *
 * @param haGlobalConfigNodeOptional HA global node
 * @return ha Child ids
 */
public static List<NodeId> getChildNodeIdsFromManagerOtherConfig(Optional<Node> haGlobalConfigNodeOptional) {
    List<NodeId> childNodeIds = new ArrayList<>();
    if (!haGlobalConfigNodeOptional.isPresent()) {
        return childNodeIds;
    }
    HwvtepGlobalAugmentation augmentation = haGlobalConfigNodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class);
    if (augmentation != null && augmentation.getManagers() != null && augmentation.getManagers().size() > 0) {
        Managers managers = augmentation.getManagers().get(0);
        if (null == managers.getManagerOtherConfigs()) {
            return childNodeIds;
        }
        for (ManagerOtherConfigs otherConfigs : managers.getManagerOtherConfigs()) {
            if (otherConfigs.getOtherConfigKey().equals(HA_CHILDREN)) {
                String nodeIdsVal = otherConfigs.getOtherConfigValue();
                if (nodeIdsVal != null) {
                    String[] parts = nodeIdsVal.split(",");
                    for (String part : parts) {
                        childNodeIds.add(new NodeId(part));
                    }
                }
            }
        }
    }
    return childNodeIds;
}
Also used : Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ArrayList(java.util.ArrayList) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ManagerOtherConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigs)

Example 4 with HwvtepGlobalAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation in project netvirt by opendaylight.

the class HwvtepHAUtil method buildSwitchesForHANode.

/**
 * Transform child switch (Source) to HA swicthes using HA node path.
 *
 * @param childNode  HA child node
 * @param haNodePath  HA node path
 * @param haNode Ha node object
 * @return Transformed switches
 */
public static List<Switches> buildSwitchesForHANode(Node childNode, InstanceIdentifier<Node> haNodePath, Optional<Node> haNode) {
    List<Switches> psList = new ArrayList<>();
    boolean switchesAlreadyPresent = false;
    if (haNode.isPresent()) {
        Node node = haNode.get();
        HwvtepGlobalAugmentation augmentation = node.getAugmentation(HwvtepGlobalAugmentation.class);
        if (augmentation != null) {
            if (augmentation.getSwitches() != null) {
                if (augmentation.getSwitches().size() > 0) {
                    switchesAlreadyPresent = true;
                }
            }
        }
    }
    if (!switchesAlreadyPresent) {
        HwvtepGlobalAugmentation augmentation = childNode.getAugmentation(HwvtepGlobalAugmentation.class);
        if (augmentation != null && augmentation.getSwitches() != null) {
            List<Switches> src = augmentation.getSwitches();
            if (src != null && src.size() > 0) {
                psList.add(new SwitchesCmd().transform(haNodePath, src.get(0)));
            }
        }
    }
    return psList;
}
Also used : SwitchesCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.SwitchesCmd) Switches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches) 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) ArrayList(java.util.ArrayList) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)

Example 5 with HwvtepGlobalAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation in project netvirt by opendaylight.

the class NodeConnectedHandler method copyHANodeConfigToChild.

/**
 * Copy HA global node data to Child HA node of config data tree .
 *
 * @param srcNode Node which to be transformed
 * @param childPath Path to which source node will be transformed
 * @param tx Transaction
 */
private void copyHANodeConfigToChild(Node srcNode, InstanceIdentifier<Node> childPath, ReadWriteTransaction tx) {
    if (srcNode == null) {
        return;
    }
    HwvtepGlobalAugmentation src = srcNode.getAugmentation(HwvtepGlobalAugmentation.class);
    if (src == null) {
        return;
    }
    NodeBuilder nodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(childPath);
    HwvtepGlobalAugmentationBuilder dstBuilder = new HwvtepGlobalAugmentationBuilder();
    globalAugmentationMerger.mergeConfigData(dstBuilder, src, childPath);
    globalNodeMerger.mergeConfigData(nodeBuilder, srcNode, childPath);
    nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, dstBuilder.build());
    Node dstNode = nodeBuilder.build();
    tx.put(CONFIGURATION, childPath, dstNode, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : HwvtepGlobalAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)

Aggregations

HwvtepGlobalAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)19 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)11 ArrayList (java.util.ArrayList)8 LogicalSwitches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches)8 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)7 Optional (com.google.common.base.Optional)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Inject (javax.inject.Inject)4 Singleton (javax.inject.Singleton)4 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 HwvtepHAUtil (org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil)4 HwvtepGlobalAugmentationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder)4 LocalUcastMacs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs)4 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collection (java.util.Collection)3