Search in sources :

Example 1 with Managers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers 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 2 with Managers

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

the class HwvtepHAUtil method buildManagersForHANode.

/**
 * Transform child managers (Source) to HA managers using HA node path.
 *
 * @param childNode Child Node
 * @param haGlobalCfg HA global config node
 * @return Transformed managers
 */
public static List<Managers> buildManagersForHANode(Node childNode, Optional<Node> haGlobalCfg) {
    Set<NodeId> nodeIds = new HashSet<>();
    nodeIds.add(childNode.getNodeId());
    List<NodeId> childNodeIds = getChildNodeIdsFromManagerOtherConfig(haGlobalCfg);
    nodeIds.addAll(childNodeIds);
    ManagersBuilder builder1 = new ManagersBuilder();
    builder1.setKey(new ManagersKey(new Uri(MANAGER_KEY)));
    List<ManagerOtherConfigs> otherConfigses = new ArrayList<>();
    StringBuffer stringBuffer = new StringBuffer();
    for (NodeId nodeId : nodeIds) {
        stringBuffer.append(nodeId.getValue());
        stringBuffer.append(",");
    }
    String children = stringBuffer.substring(0, stringBuffer.toString().length() - 1);
    otherConfigses.add(getOtherConfigBuilder(HA_CHILDREN, children).build());
    builder1.setManagerOtherConfigs(otherConfigses);
    List<Managers> managers = new ArrayList<>();
    managers.add(builder1.build());
    return managers;
}
Also used : ArrayList(java.util.ArrayList) ManagersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersBuilder) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) ManagerOtherConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigs) Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) ManagersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersKey) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) HashSet(java.util.HashSet)

Example 3 with Managers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers 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 4 with Managers

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

the class TestBuilders method buildManagers.

public static List<Managers> buildManagers() {
    ManagersBuilder builder1 = new ManagersBuilder();
    builder1.setKey(new ManagersKey(new Uri("test")));
    List<ManagerOtherConfigs> otherConfigses = new ArrayList<>();
    otherConfigses.add(buildOtherConfig("ha_enabled", "true"));
    otherConfigses.add(buildOtherConfig("ha_id", "switchxyz"));
    builder1.setManagerOtherConfigs(otherConfigses);
    List<Managers> managers = new ArrayList<>();
    managers.add(builder1.build());
    return managers;
}
Also used : Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) ManagersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersKey) ArrayList(java.util.ArrayList) ManagersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersBuilder) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) ManagerOtherConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigs)

Example 5 with Managers

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

the class HAOpClusteredListener method addToHACacheIfBecameHAChild.

/**
 * If Normal non-ha node changes to HA node , its added to HA cache.
 *
 * @param childPath HA child path which got converted to HA node
 * @param updatedChildNode updated Child node
 * @param beforeChildNode non-ha node before updated to HA node
 */
public static void addToHACacheIfBecameHAChild(InstanceIdentifier<Node> childPath, Node updatedChildNode, Node beforeChildNode) {
    HwvtepGlobalAugmentation updatedAugmentaion = updatedChildNode.getAugmentation(HwvtepGlobalAugmentation.class);
    HwvtepGlobalAugmentation beforeAugmentaion = null;
    if (beforeChildNode != null) {
        beforeAugmentaion = beforeChildNode.getAugmentation(HwvtepGlobalAugmentation.class);
    }
    List<Managers> up = null;
    List<Managers> be = null;
    if (updatedAugmentaion != null) {
        up = updatedAugmentaion.getManagers();
    }
    if (beforeAugmentaion != null) {
        be = beforeAugmentaion.getManagers();
    }
    if (up != null) {
        if (be != null) {
            if (up.size() > 0) {
                if (be.size() > 0) {
                    Managers m1 = up.get(0);
                    Managers m2 = be.get(0);
                    if (!m1.equals(m2)) {
                        LOG.trace("Manager entry updated for node {} ", updatedChildNode.getNodeId().getValue());
                        addToCacheIfHAChildNode(childPath, updatedChildNode);
                    }
                }
            }
        }
    // TODO handle unhaed case
    }
}
Also used : Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)

Aggregations

Managers (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers)5 ArrayList (java.util.ArrayList)3 HwvtepGlobalAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)3 ManagerOtherConfigs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigs)3 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 ManagersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersBuilder)2 ManagersKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersKey)2 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)2 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)2 Optional (com.google.common.base.Optional)1 HashSet (java.util.HashSet)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 HwvtepGlobalAugmentationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder)1 HwvtepGlobalRef (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef)1 PhysicalSwitchAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation)1 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)1