*/
package org.opendaylight.netvirt.neutronvpn;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import javax.inject.Singleton;
import org.apache.commons.lang3.ObjectUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
+import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
if (origSecurityEnabled || updatedSecurityEnabled) {
InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
jobCoordinator.enqueueJob("PORT- " + portName,
- () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(confTx -> {
- Optional<Interface> optionalInf =
- confTx.read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier).checkedGet();
- if (optionalInf.isPresent()) {
- InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
- InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
- origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
- interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
- LOG.info("update: Of-port-interface updation for port {}", portName);
- // Update OFPort interface for this neutron port
- confTx.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
- interfaceBuilder.build());
- } else {
- LOG.warn("update: Interface {} is not present", portName);
- }
- })));
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ confTx -> {
+ Optional<Interface> optionalInf =
+ confTx.read(interfaceIdentifier).get();
+ if (optionalInf.isPresent()) {
+ InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
+ InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
+ origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
+ interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+ LOG.info("update: Of-port-interface updation for port {}", portName);
+ // Update OFPort interface for this neutron port
+ confTx.put(interfaceIdentifier, interfaceBuilder.build());
+ } else {
+ LOG.warn("update: Interface {} is not present", portName);
+ }
+ })));
}
}
}
nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
- String portInterfaceName = createOfPortInterface(routerPort, confTx);
- createElanInterface(routerPort, portInterfaceName, confTx);
- }), LOG, "Error creating ELAN interface for {}", routerPort);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ confTx -> {
+ String portInterfaceName = createOfPortInterface(routerPort, confTx);
+ createElanInterface(routerPort, portInterfaceName, confTx);
+ }), LOG, "Error creating ELAN interface for {}", routerPort);
} else {
LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}"
+ " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(),
null /* vpn-id */, null /* wrtConfigTxn*/);
// update RouterInterfaces map
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
- boolean vpnInstanceIpVersionRemoved = false;
- IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
- for (FixedIps portIP : portIps) {
- Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
- // router Port have either IPv4 or IPv6, never both
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
- vpnInstanceIpVersionRemoved = true;
- vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ confTx -> {
+ boolean vpnInstanceIpVersionRemoved = false;
+ IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
+ for (FixedIps portIP : portIps) {
+ Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
+ // router Port have either IPv4 or IPv6, never both
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
+ vpnInstanceIpVersionRemoved = true;
+ vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ }
+ String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+ neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
+ // NOTE: Please donot change the order of calls to removeSubnetFromVpn and
+ // and updateSubnetNodeWithFixedIP
+ nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
+ sn != null ? sn.getInternetVpnId() : null);
+ nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null,
+ null, null, null);
}
- String ipValue = String.valueOf(portIP.getIpAddress().getValue());
- neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
- // NOTE: Please donot change the order of calls to removeSubnetFromVpn and
- // and updateSubnetNodeWithFixedIP
- nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
- sn != null ? sn.getInternetVpnId() : null);
- nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
- }
- nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
- deleteElanInterface(routerPort.getUuid().getValue(), confTx);
- deleteOfPortInterface(routerPort, confTx);
- nvpnNatManager.handleSubnetsForExternalRouter(routerId);
- if (vpnInstanceIpVersionRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
- false);
- }
- }), LOG, "Error handling interface removal");
+ nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
+ deleteElanInterface(routerPort.getUuid().getValue(), confTx);
+ deleteOfPortInterface(routerPort, confTx);
+ nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+ if (vpnInstanceIpVersionRemoved) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
+ false);
+ }
+ }), LOG, "Error handling interface removal");
if (vpnInstanceInternetIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
IpVersionChoice.IPV6, false);
+ "OF Port interfaces are not created", portName);
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.info("Of-port-interface creation for port {}", portName);
// Create of-port interface for this neutron port
String portInterfaceName = createOfPortInterface(port, tx);
final Uuid portId = port.getUuid();
final List<FixedIps> portIpsList = port.getFixedIps();
jobCoordinator.enqueueJob("PORT- " + portName,
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
for (FixedIps ip : portIpsList) {
// remove direct port from subnetMaps config DS
return;
}
jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
.collect(Collectors.toList());
final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId)
return interfaceAclBuilder;
}
- private String createOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
+ private String createOfPortInterface(Port port, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
Interface inf = createInterface(port);
String infName = inf.getName();
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
interfaceIdentifier);
if (!optionalInf.isPresent()) {
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
+ wrtConfigTxn.put(interfaceIdentifier, inf);
} else {
LOG.warn("Interface {} is already present", infName);
}
return interfaceBuilder.build();
}
- private void deleteOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
+ private void deleteOfPortInterface(Port port, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
String name = port.getUuid().getValue();
LOG.debug("Removing OFPort Interface {}", name);
InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
interfaceIdentifier);
if (optionalInf.isPresent()) {
- wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
+ wrtConfigTxn.delete(interfaceIdentifier);
} else {
LOG.warn("deleteOfPortInterface: Interface {} is not present", name);
}
}
}
- private void createElanInterface(Port port, String name, WriteTransaction wrtConfigTxn) {
+ private void createElanInterface(Port port, String name,
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
String elanInstanceName = port.getNetworkId().getValue();
List<StaticMacEntries> staticMacEntries = NeutronvpnUtils.buildStaticMacEntry(port);
.class, new ElanInterfaceKey(name)).build();
ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
.setName(name).setStaticMacEntries(staticMacEntries).withKey(new ElanInterfaceKey(name)).build();
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface);
+ wrtConfigTxn.put(id, elanInterface);
LOG.debug("Creating new ELan Interface {}", elanInterface);
}
- private void deleteElanInterface(String name, WriteTransaction wrtConfigTxn) {
+ private void deleteElanInterface(String name, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
.class, new ElanInterfaceKey(name)).build();
- wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, id);
+ wrtConfigTxn.delete(id);
}
// TODO Clean up the exception handling
/*
- * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2017, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.netvirt.neutronvpn;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collections;
* Interface is already created for parent NeutronPort. We're updating parent refs
* and VLAN Information
*/
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- tx.merge(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, newIface);
- LOG.trace("Creating trunk member interface {}", newIface);
- }));
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ CONFIGURATION, tx -> {
+ tx.merge(interfaceIdentifier, newIface);
+ LOG.trace("Creating trunk member interface {}", newIface);
+ }));
});
}
* and this being subport delete path, don't expect any significant changes to
* corresponding Neutron Port. Deletion of NeutronPort should follow soon enough.
*/
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- tx.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, newIface);
- LOG.trace("Resetting trunk member interface {}", newIface);
- }));
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ CONFIGURATION, tx -> {
+ tx.put(interfaceIdentifier, newIface);
+ LOG.trace("Resetting trunk member interface {}", newIface);
+ }));
});
}
/*
- * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.neutronvpn;
import static java.util.Collections.singletonList;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
import static org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.KeyedLocks;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
}
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface,
- WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn,
+ Subnetmap sn, VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = vpnIface.augmentation(Adjacencies.class).getAdjacency();
return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
- protected void createVpnInterface(Collection<Uuid> vpnIds, Port port, WriteTransaction wrtConfigTxn) {
+ protected void createVpnInterface(Collection<Uuid> vpnIds, Port port,
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
boolean isRouterInterface = false;
if (port.getDeviceOwner() != null) {
isRouterInterface = NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner());
}
protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId,
- Port port, Subnetmap sn, WriteTransaction wrtConfigTxn) {
+ Port port, Subnetmap sn, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
+ protected void deleteVpnInterface(String infName, @Nullable String vpnId,
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
ListenableFutures.addErrorLogging(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> deleteVpnInterface(infName, vpnId, tx)),
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> deleteVpnInterface(infName, vpnId, tx)),
LOG, "Error deleting VPN interface {} {}", infName, vpnId);
return;
}
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get())
.setVpnInstanceNames(vpnList);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder
.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
- wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+ wrtConfigTxn.delete(vpnIfIdentifier);
}
protected void removeVpnFromVpnInterface(Uuid vpnId, Port port,
- WriteTransaction writeConfigTxn, Subnetmap sm) {
+ TypedWriteTransaction<Datastore.Configuration> writeConfigTxn,
+ Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
}
deleteVpnInterface(port.getUuid().getValue(), null /* vpn-id */, writeConfigTxn);
} else {
- writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
- .build());
+ writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated,
- boolean isSubnetIp, WriteTransaction writeConfigTxn) {
+ boolean isSubnetIp,
+ TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
if (vpnId == null || port == null) {
return;
}
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port
.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
}
- writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
- .build());
+ writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
} else {
LOG.error("VPN Interface {} not found", infName);
}
final Boolean isRouterInterface = port.getDeviceOwner()
.equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn,
vpnIface);
if (vpnIface == null) {
LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
final Port port = neutronvpnUtils.getNeutronPort(portId);
jobCoordinator.enqueueJob("PORT-" + portId.getValue(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- if (port != null) {
- withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, tx);
- } else {
- LOG.warn(
- "Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since "
- + "port is absent in Neutron config DS", portId.getValue(),
- subnet.getValue());
- }
- })));
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ CONFIGURATION, tx -> {
+ if (port != null) {
+ withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, tx);
+ } else {
+ LOG.warn(
+ "Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since "
+ + "port is absent in Neutron config DS", portId.getValue(),
+ subnet.getValue());
+ }
+ })));
}
}
//update subnet-vpn association
}
jobCoordinator.enqueueJob("VPN-" + vpn.getValue(), () -> singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(
sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}",
port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- if (isBeingAssociated) {
- updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port),
- true, false, tx);
- } else {
- removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), tx, sm);
- }
- })));
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ if (isBeingAssociated) {
+ updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port),
+ true, false, tx);
+ } else {
+ removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), tx, sm);
+ }
+ })));
}
}
}
//Update Router Interface first synchronously.
//CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
ListenableFuture<Void> future =
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> updateVpnInterface(newVpnId, oldVpnId,
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()),
isBeingAssociated, true, tx));
Futures.addCallback(future, new FutureCallback<Void>() {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}",
port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> Collections.singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false,
tx))));
result.add("-------------------------------------------------------------------------------------------");
InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
- Optional<Ports> ports = syncReadOptional(dataBroker, CONFIGURATION, portidentifier);
+ Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
if (ports.isPresent() && ports.get().getPort() != null) {
for (Port port : ports.get().getPort()) {
List<FixedIps> fixedIPs = port.getFixedIps();
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
createExternalVpnInterface(extNetId, elanInterface, tx);
}
LOG.error("No external ports attached for external network {}", extNetId.getValue());
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils
.buildVpnInterfaceIdentifier(elanInterface);
LOG.info("Removing vpn interface {}", elanInterface);
- tx.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+ tx.delete(vpnIfIdentifier);
}
}), LOG, "Error removing external VPN interfaces for {}", extNetId);
}
- private void createExternalVpnInterface(Uuid vpnId, String infName, WriteTransaction wrtConfigTxn) {
+ private void createExternalVpnInterface(Uuid vpnId, String infName,
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
writeVpnInterfaceToDs(Collections.singletonList(vpnId), infName, null,
false /* not a router iface */, wrtConfigTxn);
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies,
- Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
+ Boolean isRouterInterface, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, isRouterInterface, tx)), LOG,
"Error writing VPN interface");
return;
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
}
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies,
- WriteTransaction wrtConfigTxn) {
+ TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataOptional;
try {
vpnInstanceOpDataOptional = SingleTransactionDataBroker
- .syncReadOptional(dataBroker, OPERATIONAL, neutronvpnUtils.getVpnOpDataIdentifier(primaryRd));
+ .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ neutronvpnUtils.getVpnOpDataIdentifier(primaryRd));
} catch (ReadFailedException e) {
LOG.error("getExistingOperationalVpn: Exception while checking operational status of vpn with rd {}",
primaryRd, e);
/*
- * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.neutronvpn;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createVpnPortFixedIpToPort(String vpnName, String fixedIp, String portName, String macAddress,
- boolean isSubnetIp, WriteTransaction writeConfigTxn) {
+ boolean isSubnetIp, TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
InstanceIdentifier<VpnPortipToPort> id = NeutronvpnUtils.buildVpnPortipToPortIdentifier(vpnName, fixedIp);
VpnPortipToPortBuilder builder = new VpnPortipToPortBuilder()
.withKey(new VpnPortipToPortKey(fixedIp, vpnName))
.setPortName(portName).setMacAddress(macAddress).setSubnetIp(isSubnetIp);
try {
if (writeConfigTxn != null) {
- writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, builder.build());
+ writeConfigTxn.put(id, builder.build());
} else {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void removeVpnPortFixedIpToPort(String vpnName, String fixedIp, WriteTransaction writeConfigTxn) {
+ protected void removeVpnPortFixedIpToPort(String vpnName, String fixedIp,
+ TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
InstanceIdentifier<VpnPortipToPort> id = NeutronvpnUtils.buildVpnPortipToPortIdentifier(vpnName, fixedIp);
try {
if (writeConfigTxn != null) {
- writeConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, id);
+ writeConfigTxn.delete(id);
} else {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
}
if (isFinalVpnInstanceIpv6Changed) {
builder.setIpv6Configured(finalIsIpv6Configured);
}
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class)
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ OPERATIONAL, tx -> {
+ InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class)
.child(VpnInstanceOpDataEntry.class,
new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
- tx.merge(LogicalDatastoreType.OPERATIONAL, id, builder.build(), false);
- LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}",
- add ? "added" : "removed",
- ipVersion.toString(), vpnName);
- }));
+ tx.merge(id, builder.build(), false);
+ LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}",
+ add ? "added" : "removed",
+ ipVersion.toString(), vpnName);
+ }));
});
}
}
VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
builder.setBgpvpnType(choice);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- tx.merge(LogicalDatastoreType.OPERATIONAL, id, builder.build(), false);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
+ tx.merge(id, builder.build(), false);
LOG.debug("updateVpnInstanceOpWithType: sent merge to operDS BgpvpnType {} for {}", choice, vpn.getValue());
}), LOG, "Error updating VPN instance op {} with type {}", vpn, choice);
}
/*
- * Copyright © 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2017, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.netvirt.neutronvpn.evpn.utils;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import java.util.Collections;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
public void updateElanWithVpnInfo(String elanInstanceName, VpnInstance vpnInstance, Operation operation) {
String vpnName = vpnInstance.getVpnInstanceName();
InstanceIdentifier<ElanInstance> elanIid = ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
Optional<ElanInstance> elanInstanceOptional =
- tx.read(LogicalDatastoreType.CONFIGURATION, elanIid).checkedGet();
+ tx.read(elanIid).get();
if (!elanInstanceOptional.isPresent()) {
return;
}
}
elanInstanceBuilder.addAugmentation(EvpnAugmentation.class, evpnAugmentationBuilder.build());
- tx.put(LogicalDatastoreType.CONFIGURATION, elanIid, elanInstanceBuilder.build(),
- WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(elanIid, elanInstanceBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
}), LOG, "Error updating ELAN with VPN info {}, {}, {}", elanInstanceName, vpnInstance, operation);
}
InstanceIdentifier<EvpnRdToNetwork> rdToNetworkIdentifier = getRdToNetworkIdentifier(rd);
jobCoordinator.enqueueJob("EVPN_ASSOCIATE-" + rd,
- () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
if (operation == Operation.DELETE) {
LOG.debug("Deleting Evpn-Network with key {}", rd);
- tx.delete(LogicalDatastoreType.CONFIGURATION, rdToNetworkIdentifier);
+ tx.delete(rdToNetworkIdentifier);
} else {
EvpnRdToNetworkBuilder evpnRdToNetworkBuilder = new EvpnRdToNetworkBuilder().withKey(
new EvpnRdToNetworkKey(rd));
evpnRdToNetworkBuilder.setNetworkId(elanInstanceName);
LOG.info("updating Evpn {} with elaninstance {} and rd {}",
vpnInstance.getVpnInstanceName(), elanInstanceName, rd);
- tx.put(LogicalDatastoreType.CONFIGURATION, rdToNetworkIdentifier,
+ tx.put(rdToNetworkIdentifier,
evpnRdToNetworkBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
}
})));
/*
- * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.netvirt.neutronvpn.l2gw;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
LOG.info("Removing L2gateway with ID: {}", input.getUuid());
List<L2gatewayConnection> connections = l2gwService
.getL2GwConnectionsByL2GatewayId(input.getUuid());
- Futures.addCallback(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ Futures.addCallback(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (L2gatewayConnection connection : connections) {
InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class)
.child(L2gatewayConnections.class).child(L2gatewayConnection.class, connection.key());
- tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+ tx.delete(iid);
}
}), new FutureCallback<Void>() {
@Override
return;
}
jobCoordinator.enqueueJob("l2gw.update", () -> {
- ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
original.getDevices()
.stream()