Search in sources :

Example 1 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class NodeConnectedHandler method handleNodeConnected.

/**
 * Takes care of merging the data when a node gets connected.
 * When a ha child node gets connected , we perform the following.
 * Merge the ha parent config data to child node.
 * Merge the ha parent physical node config data to child physical node.
 * Merge the child operational data to parent operational data.
 * Merge the child physical switch node operational data to parent physical switch operational node .
 *
 * @param childNode   Ha child node
 * @param childNodePath Ha child Iid
 * @param haNodePath  Ha Iid
 * @param haGlobalCfg Ha Global Config Node
 * @param haPSCfg Ha Physical Config Node
 * @param tx Transaction
 * @throws ReadFailedException  Exception thrown if read fails
 */
public void handleNodeConnected(Node childNode, InstanceIdentifier<Node> childNodePath, InstanceIdentifier<Node> haNodePath, Optional<Node> haGlobalCfg, Optional<Node> haPSCfg, ReadWriteTransaction tx) throws ReadFailedException {
    HwvtepHAUtil.buildGlobalConfigForHANode(tx, childNode, haNodePath, haGlobalCfg);
    copyChildOpToHA(childNode, haNodePath, tx);
    readAndCopyChildPSOpToHAPS(childNode, haNodePath, tx);
    if (haGlobalCfg.isPresent()) {
        // copy ha config to newly connected child case of reconnected child
        if (haPSCfg.isPresent()) {
            /*
                 copy task of physical switch node is done in the next transaction
                 The reason being if it is done in the same transaction,
                 hwvtep plugin is not able to proess this update and send vlanbindings to device
                 as it is expecting the logical switch to be already present in operational ds
                 (created in the device)
                 */
            HAJobScheduler.getInstance().submitJob(() -> {
                try {
                    hwvtepHACache.updateConnectedNodeStatus(childNodePath);
                    LOG.info("HA child reconnected handleNodeReConnected {}", childNode.getNodeId().getValue());
                    ReadWriteTransaction tx1 = db.newReadWriteTransaction();
                    copyHAPSConfigToChildPS(haPSCfg.get(), childNodePath, tx1);
                    tx1.submit().checkedGet();
                } catch (TransactionCommitFailedException e) {
                    LOG.error("Failed to process ", e);
                }
            });
        }
        copyHANodeConfigToChild(haGlobalCfg.get(), childNodePath, tx);
    }
    deleteChildPSConfigIfHAPSConfigIsMissing(haGlobalCfg, childNode, tx);
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 2 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method addDpnToSubnet.

private SubnetToDpn addDpnToSubnet(Uuid subnetId, BigInteger dpnId) {
    try {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (optionalSubDpn.isPresent()) {
            LOG.error("addDpnToSubnet: Cannot create, SubnetToDpn for subnet {} as DPN {}" + " already seen in datastore", subnetId.getValue(), dpnId);
            return null;
        }
        SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder().setKey(new SubnetToDpnKey(dpnId));
        List<VpnInterfaces> vpnIntfList = new ArrayList<>();
        subDpnBuilder.setVpnInterfaces(vpnIntfList);
        SubnetToDpn subDpn = subDpnBuilder.build();
        SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
        LOG.info("addDpnToSubnet: Created SubnetToDpn entry for subnet {} with DPNId {} ", subnetId.getValue(), dpnId);
        return subDpn;
    } catch (TransactionCommitFailedException ex) {
        LOG.error("addDpnToSubnet: Creation of SubnetToDpn for subnet {} with DpnId {} failed", subnetId.getValue(), dpnId, ex);
        return null;
    }
}
Also used : SubnetToDpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces) ArrayList(java.util.ArrayList) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)

Example 3 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method removeDpnFromSubnet.

private void removeDpnFromSubnet(Uuid subnetId, BigInteger dpnId) {
    try {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (!optionalSubDpn.isPresent()) {
            LOG.warn("removeDpnFromSubnet: Cannot delete, SubnetToDpn for subnet {} DPN {} not available" + " in datastore", subnetId.getValue(), dpnId);
            return;
        }
        LOG.trace("removeDpnFromSubnet: Deleting SubnetToDpn entry for subnet {} with DPNId {}", subnetId.getValue(), dpnId);
        SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("removeDpnFromSubnet: Deletion of SubnetToDpn for subnet {} with DPN {} failed", subnetId.getValue(), dpnId, ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)

Example 4 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method removeInterfaceFromDpn.

public boolean removeInterfaceFromDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
    boolean dpnRemoved = false;
    try {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (!optionalSubDpn.isPresent()) {
            LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}" + " not available in datastore", intfName, subnetId.getValue(), dpnId);
            return false;
        }
        SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
        List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
        VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
        vpnIntfList.remove(vpnIntfs);
        if (vpnIntfList.isEmpty()) {
            // Remove the DPN as well
            removeDpnFromSubnet(subnetId, dpnId);
            dpnRemoved = true;
        } else {
            subDpnBuilder.setVpnInterfaces(vpnIntfList);
            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build());
        }
        LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}", intfName, subnetId.getValue(), dpnId);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}" + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
        return false;
    }
    return dpnRemoved;
}
Also used : SubnetToDpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces) VpnInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)

Example 5 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method addInterfaceToDpn.

public SubnetToDpn addInterfaceToDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
    SubnetToDpn subDpn = null;
    try {
        // Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        // Please use a synchronize block here as we donot need a cluster-wide lock
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (!optionalSubDpn.isPresent()) {
            // Create a new DPN Entry
            subDpn = addDpnToSubnet(subnetId, dpnId);
        } else {
            subDpn = optionalSubDpn.get();
        }
        SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
        List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
        VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
        vpnIntfList.add(vpnIntfs);
        subDpnBuilder.setVpnInterfaces(vpnIntfList);
        subDpn = subDpnBuilder.build();
        SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
        LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
        return null;
    }
    return subDpn;
}
Also used : SubnetToDpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces) VpnInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)

Aggregations

TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)117 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)32 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)21 Test (org.junit.Test)19 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)16 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)13 ArrayList (java.util.ArrayList)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)11 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)9 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)9 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)8 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)8 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)8 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 Optional (com.google.common.base.Optional)6 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)6 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)6 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)6