Search in sources :

Example 11 with TransactionCommitFailedException

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

the class NeutronUtils method deletePortStatus.

/**
 * Delete a Neutron Port status entry from the operational data store.
 * @param uuid The uuid of the Neutron port
 * @param dataBroker DataBroker instance
 * @return true if transaction submitted successfully
 */
public static boolean deletePortStatus(String uuid, DataBroker dataBroker) {
    Uuid uuidObj = new Uuid(uuid);
    InstanceIdentifier iid = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class, new PortKey(uuidObj));
    SingleTransactionDataBroker tx = new SingleTransactionDataBroker(dataBroker);
    try {
        tx.syncDelete(LogicalDatastoreType.OPERATIONAL, iid);
    } catch (TransactionCommitFailedException e) {
        LOG.error("deletePortStatus: failed neutron port status delete", e);
        return false;
    }
    return true;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker)

Example 12 with TransactionCommitFailedException

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

the class NeutronvpnNatManager method handleExternalFixedIpsForRouter.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleExternalFixedIpsForRouter(Router update) {
    Uuid routerId = update.getUuid();
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating External Fixed IPs Routers node {}", routerId.getValue());
        if (optionalRouters.isPresent()) {
            RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
            List<ExternalIps> externalIps = new ArrayList<>();
            for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
                addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
            }
            builder.setExternalIps(externalIps);
            updateExternalSubnetsForRouter(routerId, update.getExternalGatewayInfo().getExternalNetworkId(), update.getExternalGatewayInfo().getExternalFixedIps());
            Routers routerss = builder.build();
            LOG.trace("Updating external fixed ips for router {} with value {}", routerId.getValue(), routerss);
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
            LOG.trace("Added External Fixed IPs successfully for Routers to CONFIG Datastore");
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updating extfixedips for {} in extrouters failed", routerId.getValue(), ex);
    }
}
Also used : ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ArrayList(java.util.ArrayList) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 13 with TransactionCommitFailedException

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

the class NeutronvpnNatManager method removeExternalRouter.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void removeExternalRouter(Router update) {
    Uuid routerId = update.getUuid();
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace(" Removing Routers node {}", routerId.getValue());
        if (optionalRouters.isPresent()) {
            RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
            builder.setExternalIps(null);
            builder.setSubnetIds(null);
            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
            LOG.trace("Removed router {} from extrouters", routerId.getValue());
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Removing extrouter {} from extrouters failed", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 14 with TransactionCommitFailedException

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

the class NeutronvpnNatManager method handleSnatSettingChangeForRouter.

private void handleSnatSettingChangeForRouter(Router update) {
    Uuid routerId = update.getUuid();
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating Internal subnets for Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            LOG.trace("No Routers element found for router name {}", routerId.getValue());
            return;
        }
        builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
        Routers routerss = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Updating extrouters for snat change {}", routerss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
        LOG.trace("Updated successfully Routers to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updation of snat for extrouters failed for router {}", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 15 with TransactionCommitFailedException

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

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList == null) {
            rtrList = new ArrayList<>();
        }
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
        // get vpn external form this network external to setup vpnInternet for ipv6
        Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
        if (vpnExternal == null) {
            LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
        }
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
        // get subnetmap associate to the router, any subnetmap "external" could be existing
        List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
        for (Subnetmap sn : snList) {
            if (sn.getInternetVpnId() == null) {
                continue;
            }
            IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            if (ipVers == IpVersionChoice.IPV6) {
                LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
                nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
            }
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

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