Search in sources :

Example 6 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class HwvtepHAUtil method convertLogicalSwitchRef.

/**
 * Trnaform logical switch to nodepath passed .
 *
 * @param src {@link HwvtepLogicalSwitchRef} Logical Switch Ref which needs to be transformed
 * @param nodePath {@link InstanceIdentifier} src needs to be transformed to this path
 * @return ref {@link HwvtepLogicalSwitchRef} the transforrmed result
 */
public static HwvtepLogicalSwitchRef convertLogicalSwitchRef(HwvtepLogicalSwitchRef src, InstanceIdentifier<Node> nodePath) {
    InstanceIdentifier<LogicalSwitches> srcId = (InstanceIdentifier<LogicalSwitches>) src.getValue();
    HwvtepNodeName switchName = srcId.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
    InstanceIdentifier<LogicalSwitches> iid = nodePath.augmentation(HwvtepGlobalAugmentation.class).child(LogicalSwitches.class, new LogicalSwitchesKey(switchName));
    HwvtepLogicalSwitchRef ref = new HwvtepLogicalSwitchRef(iid);
    return ref;
}
Also used : LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) HwvtepLogicalSwitchRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef) HwvtepNodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName) LogicalSwitchesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey)

Example 7 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class HwvtepHAUtil method convertLocatorRef.

/**
 * Trnaform locator reference to nodepath passed .
 *
 * @param src {@link HwvtepPhysicalLocatorRef} Logical Switch Ref which needs to be transformed
 * @param nodePath {@link InstanceIdentifier} src needs to be transformed to this path
 * @return physicalLocatorRef {@link HwvtepPhysicalLocatorRef} the transforrmed result
 */
public static HwvtepPhysicalLocatorRef convertLocatorRef(HwvtepPhysicalLocatorRef src, InstanceIdentifier<Node> nodePath) {
    InstanceIdentifier<TerminationPoint> srcTepPath = (InstanceIdentifier<TerminationPoint>) src.getValue();
    TpId tpId = srcTepPath.firstKeyOf(TerminationPoint.class).getTpId();
    InstanceIdentifier<TerminationPoint> tpPath = nodePath.child(TerminationPoint.class, new TerminationPointKey(tpId));
    HwvtepPhysicalLocatorRef physicalLocatorRef = new HwvtepPhysicalLocatorRef(tpPath);
    return physicalLocatorRef;
}
Also used : TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) HwvtepPhysicalLocatorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef) TerminationPointKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)

Example 8 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class MergeCommandsAggregator method mergeUpdate.

public void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, LogicalDatastoreType datastoreType, ReadWriteTransaction tx) {
    if (mod == null) {
        return;
    }
    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 -> {
        MergeCommand mergeCommand = commands.get(modification.getDataType());
        boolean create = modification.getDataAfter() != null;
        DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
        InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
        DataObject transformedItem = mergeCommand.transform(dstPath, data);
        Optional<DataObject> existingDataOptional = null;
        try {
            existingDataOptional = tx.read(datastoreType, transformedId).checkedGet();
        } catch (ReadFailedException ex) {
            LOG.error("Failed to read data {} from {}", transformedId, datastoreType);
            return;
        }
        String destination = datastoreType == CONFIGURATION ? "child" : "parent";
        if (create) {
            if (isDataUpdated(existingDataOptional, transformedItem)) {
                LOG.debug("Copy to {} {} {}", destination, datastoreType, transformedId);
                tx.put(datastoreType, transformedId, transformedItem, true);
            } else {
                LOG.debug("Data not updated skip copy to {}", transformedId);
            }
        } else {
            if (existingDataOptional.isPresent()) {
                LOG.debug("Delete from {} {} {}", destination, datastoreType, transformedId);
                tx.delete(datastoreType, transformedId);
            } else {
                LOG.debug("Delete skipped for {}", transformedId);
            }
        }
    });
}
Also used : 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) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) CONFIGURATION(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION) HashMap(java.util.HashMap) SuperTypeUtil(org.opendaylight.genius.utils.SuperTypeUtil) LocalUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalUcastCmd) RemoteUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Map(java.util.Map) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) Builder(org.opendaylight.yangtools.concepts.Builder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)

Example 9 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class HAOpNodeListener method readAndCopyChildPsOpToParent.

private void readAndCopyChildPsOpToParent(Node childNode, ReadWriteTransaction tx) {
    String childGlobalNodeId = childNode.getNodeId().getValue();
    List<InstanceIdentifier> childPsIids = new ArrayList<>();
    HwvtepGlobalAugmentation hwvtepGlobalAugmentation = childNode.getAugmentation(HwvtepGlobalAugmentation.class);
    if (hwvtepGlobalAugmentation == null || HwvtepHAUtil.isEmpty(hwvtepGlobalAugmentation.getSwitches())) {
        haOpClusteredListener.getConnectedNodes().stream().filter((connectedIid) -> IS_PS_CHILD_TO_GLOBAL_NODE.test(childGlobalNodeId, connectedIid)).forEach((connectedIid) -> childPsIids.add(connectedIid));
    } else {
        hwvtepGlobalAugmentation.getSwitches().forEach((switches) -> childPsIids.add(switches.getSwitchRef().getValue()));
    }
    if (childPsIids.isEmpty()) {
        LOG.info("No child ps found for global {}", childGlobalNodeId);
    }
    childPsIids.forEach((psIid) -> {
        try {
            InstanceIdentifier<Node> childPsIid = psIid;
            Optional<Node> childPsNode = tx.read(LogicalDatastoreType.OPERATIONAL, childPsIid).checkedGet();
            if (childPsNode.isPresent()) {
                LOG.debug("Child oper PS node found");
                onPsNodeAdd(childPsIid, childPsNode.get(), tx);
            } else {
                LOG.debug("Child oper ps node not found {}", childPsIid);
            }
        } catch (ReadFailedException e) {
            LOG.error("Failed to read child ps node {}", psIid);
        }
    });
}
Also used : IHAEventHandler(org.opendaylight.netvirt.elan.l2gw.ha.handlers.IHAEventHandler) HAEventHandler(org.opendaylight.netvirt.elan.l2gw.ha.handlers.HAEventHandler) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) BiPredicate(java.util.function.BiPredicate) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) Optional(com.google.common.base.Optional) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) NodeCopier(org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeCopier) 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) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 10 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class InterfaceStateChangeListener method update.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
    final String ifName = update.getName();
    try {
        OperStatus originalOperStatus = original.getOperStatus();
        OperStatus updateOperStatus = update.getOperStatus();
        if (originalOperStatus.equals(Interface.OperStatus.Unknown) || updateOperStatus.equals(Interface.OperStatus.Unknown)) {
            LOG.debug("Interface {} state change is from/to null/UNKNOWN. Ignoring the update event.", ifName);
            return;
        }
        if (update.getIfIndex() == null) {
            return;
        }
        if (L2vlan.class.equals(update.getType())) {
            LOG.info("VPN Interface update event - intfName {} from InterfaceStateChangeListener", update.getName());
            jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
                List<ListenableFuture<Void>> futures = new ArrayList<>(3);
                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
                        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
                            final VpnInterface vpnIf = VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
                            if (vpnIf != null) {
                                final int ifIndex = update.getIfIndex();
                                BigInteger dpnId = BigInteger.ZERO;
                                try {
                                    dpnId = InterfaceUtils.getDpIdFromInterface(update);
                                } catch (Exception e) {
                                    LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
                                    return;
                                }
                                if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
                                    for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
                                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                        String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
                                        if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
                                            LOG.error("VPN Interface update event - intfName {} onto vpnName {} " + "running oper-driven UP, VpnInstance not ready," + " holding on", vpnIf.getName(), vpnName);
                                        } else if (VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
                                            LOG.error("update: Ignoring UP event for vpnInterface {}, as " + "vpnInstance {} with primaryRd {} is already marked for" + " deletion", vpnIf.getName(), vpnName, primaryRd);
                                        } else {
                                            vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn, update, vpnName);
                                        }
                                    }
                                } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
                                    for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
                                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                        LOG.info("VPN Interface update event - intfName {} onto vpnName {}" + " running oper-driven DOWN", vpnIf.getName(), vpnName);
                                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, vpnIf.getName(), vpnName);
                                        if (optVpnInterface.isPresent()) {
                                            VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
                                            vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(), ifIndex, update.getPhysAddress().getValue(), vpnOpInterface, true, writeConfigTxn, writeOperTxn, writeInvTxn);
                                        } else {
                                            LOG.error("InterfaceStateChangeListener Update DOWN - vpnInterface {}" + " not available, ignoring event", vpnIf.getName());
                                            continue;
                                        }
                                    }
                                }
                            } else {
                                LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
                            }
                        }));
                    }));
                }));
                return futures;
            });
        }
    } catch (Exception e) {
        LOG.error("Exception observed in handling updation of VPN Interface {}. ", update.getName(), e);
    }
}
Also used : InterfacesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) Optional(com.google.common.base.Optional) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) Logger(org.slf4j.Logger) OperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BigInteger(java.math.BigInteger) OperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Aggregations

InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)142 Logger (org.slf4j.Logger)57 LoggerFactory (org.slf4j.LoggerFactory)57 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)52 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)52 ArrayList (java.util.ArrayList)47 List (java.util.List)47 Collections (java.util.Collections)40 Optional (com.google.common.base.Optional)39 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)37 BigInteger (java.math.BigInteger)36 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)35 Inject (javax.inject.Inject)34 Singleton (javax.inject.Singleton)34 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)30 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)29 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)28 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)26 PostConstruct (javax.annotation.PostConstruct)24 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)24