Search in sources :

Example 1 with HwvtepGlobalAugmentationBuilder

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

the class HwvtepHAUtil method buildGlobalConfigForHANode.

/**
 * Build HA Global node from child nodes in config data tress.
 *
 * @param tx Transaction
 * @param childNode Child Node object
 * @param haNodePath Ha node path
 * @param haGlobalCfg HA global node object
 */
public static void buildGlobalConfigForHANode(ReadWriteTransaction tx, Node childNode, InstanceIdentifier<Node> haNodePath, Optional<Node> haGlobalCfg) {
    NodeBuilder nodeBuilder = new NodeBuilder();
    HwvtepGlobalAugmentationBuilder hwvtepGlobalBuilder = new HwvtepGlobalAugmentationBuilder();
    hwvtepGlobalBuilder.setSwitches(buildSwitchesForHANode(childNode, haNodePath, haGlobalCfg));
    hwvtepGlobalBuilder.setManagers(buildManagersForHANode(childNode, haGlobalCfg));
    nodeBuilder.setNodeId(haNodePath.firstKeyOf(Node.class).getNodeId());
    nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, hwvtepGlobalBuilder.build());
    Node configHANode = nodeBuilder.build();
    tx.merge(CONFIGURATION, haNodePath, configHANode, Boolean.TRUE);
}
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) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)

Example 2 with HwvtepGlobalAugmentationBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder 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)

Example 3 with HwvtepGlobalAugmentationBuilder

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

the class NodeConnectedHandler method copyChildOpToHA.

/**
 * Copy HA child node to HA node of Operational data tree.
 *
 * @param childNode HA Child Node
 * @param haNodePath HA node path
 * @param tx Transaction
 * @throws ReadFailedException  Exception thrown if read fails
 */
private void copyChildOpToHA(Node childNode, InstanceIdentifier<Node> haNodePath, ReadWriteTransaction tx) throws ReadFailedException {
    if (childNode == null) {
        return;
    }
    HwvtepGlobalAugmentation childData = childNode.getAugmentation(HwvtepGlobalAugmentation.class);
    if (childData == null) {
        return;
    }
    NodeBuilder haNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(haNodePath);
    HwvtepGlobalAugmentationBuilder haBuilder = new HwvtepGlobalAugmentationBuilder();
    Optional<Node> existingHANodeOptional = tx.read(OPERATIONAL, haNodePath).checkedGet();
    Node existingHANode = existingHANodeOptional.isPresent() ? existingHANodeOptional.get() : null;
    HwvtepGlobalAugmentation existingHAData = HwvtepHAUtil.getGlobalAugmentationOfNode(existingHANode);
    globalAugmentationMerger.mergeOperationalData(haBuilder, existingHAData, childData, haNodePath);
    globalNodeMerger.mergeOperationalData(haNodeBuilder, existingHANode, childNode, haNodePath);
    haBuilder.setManagers(HwvtepHAUtil.buildManagersForHANode(childNode, existingHANodeOptional));
    haBuilder.setSwitches(HwvtepHAUtil.buildSwitchesForHANode(childNode, haNodePath, existingHANodeOptional));
    haBuilder.setDbVersion(childData.getDbVersion());
    haNodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, haBuilder.build());
    Node haNode = haNodeBuilder.build();
    tx.merge(OPERATIONAL, haNodePath, haNode, true);
}
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)

Example 4 with HwvtepGlobalAugmentationBuilder

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

the class NodeCopier method copyGlobalNode.

@Override
public void copyGlobalNode(Optional<Node> srcGlobalNodeOptional, InstanceIdentifier<Node> srcPath, InstanceIdentifier<Node> dstPath, LogicalDatastoreType logicalDatastoreType, ReadWriteTransaction tx) throws ReadFailedException {
    if (!srcGlobalNodeOptional.isPresent() && logicalDatastoreType == CONFIGURATION) {
        Futures.addCallback(tx.read(logicalDatastoreType, srcPath), new FutureCallback<Optional<Node>>() {

            @Override
            public void onSuccess(Optional<Node> nodeOptional) {
                HAJobScheduler.getInstance().submitJob(() -> {
                    try {
                        ReadWriteTransaction tx1 = new BatchedTransaction();
                        if (nodeOptional.isPresent()) {
                            copyGlobalNode(nodeOptional, srcPath, dstPath, logicalDatastoreType, tx1);
                        } else {
                            /**
                             * In case the Parent HA Global Node is not present and Child HA node is present
                             * It means that both the child are disconnected/removed hence the parent is deleted.
                             * @see org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener
                             * OnGLobalNode() delete function
                             * So we should delete the existing config child node as cleanup
                             */
                            HwvtepHAUtil.deleteNodeIfPresent(tx1, logicalDatastoreType, dstPath);
                        }
                    } catch (ReadFailedException e) {
                        LOG.error("Failed to read source node {}", srcPath);
                    }
                });
            }

            @Override
            public void onFailure(Throwable throwable) {
            }
        });
        return;
    }
    HwvtepGlobalAugmentation srcGlobalAugmentation = srcGlobalNodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class);
    if (srcGlobalAugmentation == null) {
        /**
         * If Source HA Global Node is not present
         * It means that both the child are disconnected/removed hence the parent is deleted.
         * @see org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener OnGLobalNode() delete function
         * So we should delete the existing config child node as cleanup
         */
        HwvtepHAUtil.deleteNodeIfPresent(tx, logicalDatastoreType, dstPath);
        return;
    }
    NodeBuilder haNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(dstPath);
    HwvtepGlobalAugmentationBuilder haBuilder = new HwvtepGlobalAugmentationBuilder();
    Optional<Node> existingDstGlobalNodeOptional = tx.read(logicalDatastoreType, dstPath).checkedGet();
    Node existingDstGlobalNode = existingDstGlobalNodeOptional.isPresent() ? existingDstGlobalNodeOptional.get() : null;
    HwvtepGlobalAugmentation existingHAGlobalData = HwvtepHAUtil.getGlobalAugmentationOfNode(existingDstGlobalNode);
    globalAugmentationMerger.mergeOperationalData(haBuilder, existingHAGlobalData, srcGlobalAugmentation, dstPath);
    globalNodeMerger.mergeOperationalData(haNodeBuilder, existingDstGlobalNode, srcGlobalNodeOptional.get(), dstPath);
    if (OPERATIONAL == logicalDatastoreType) {
        haBuilder.setManagers(HwvtepHAUtil.buildManagersForHANode(srcGlobalNodeOptional.get(), existingDstGlobalNodeOptional));
        // Also update the manager section in config which helps in cluster reboot scenarios
        haBuilder.getManagers().stream().forEach((manager) -> {
            InstanceIdentifier<Managers> managerIid = dstPath.augmentation(HwvtepGlobalAugmentation.class).child(Managers.class, manager.getKey());
            tx.put(CONFIGURATION, managerIid, manager, true);
        });
    }
    haBuilder.setDbVersion(srcGlobalAugmentation.getDbVersion());
    haNodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, haBuilder.build());
    Node haNode = haNodeBuilder.build();
    if (OPERATIONAL == logicalDatastoreType) {
        tx.merge(logicalDatastoreType, dstPath, haNode, true);
    } else {
        tx.put(logicalDatastoreType, dstPath, haNode, true);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) Optional(com.google.common.base.Optional) 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) HwvtepGlobalAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder) Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 5 with HwvtepGlobalAugmentationBuilder

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

the class LogicalSwitchesCmdTest method getData.

HwvtepGlobalAugmentation getData(LogicalSwitches[] elements) {
    HwvtepGlobalAugmentationBuilder newDataBuilder = new HwvtepGlobalAugmentationBuilder();
    List<LogicalSwitches> ls = new ArrayList<>();
    for (LogicalSwitches ele : elements) {
        ls.add(ele);
    }
    newDataBuilder.setLogicalSwitches(ls);
    return newDataBuilder.build();
}
Also used : HwvtepGlobalAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) ArrayList(java.util.ArrayList)

Aggregations

HwvtepGlobalAugmentationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder)8 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)4 ArrayList (java.util.ArrayList)3 HwvtepGlobalAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)3 LogicalSwitches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches)3 Optional (com.google.common.base.Optional)1 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 BatchedTransaction (org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction)1 HwvtepPhysicalSwitchRef (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef)1 Managers (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers)1 Switches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches)1 SwitchesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder)1 SwitchesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey)1