import static org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil.schemaMismatchLog;
import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-
public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchUpdateCommand.class);
LOG.debug("Creating a physical switch named: {}", physicalSwitchAugmentation.getHwvtepNodeName());
Optional<PhysicalSwitchAugmentation> operationalPhysicalSwitchOptional =
getOperationalState().getPhysicalSwitchAugmentation(iid);
- PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalSwitch.class);
+ PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ PhysicalSwitch.class);
setDescription(physicalSwitch, physicalSwitchAugmentation);
setManagementIps(physicalSwitch, physicalSwitchAugmentation);
setTunnuleIps(physicalSwitch, operationalPhysicalSwitchOptional.get());
setName(physicalSwitch, physicalSwitchAugmentation, operationalPhysicalSwitchOptional);
String pswitchUuid = "PhysicalSwitch_" + HwvtepSouthboundMapper.getRandomUUID();
transaction.add(op.insert(physicalSwitch).withId(pswitchUuid));
- transaction.add(op.comment("Physical Switch: Creating " +
- physicalSwitchAugmentation.getHwvtepNodeName().getValue()));
+ transaction.add(op.comment("Physical Switch: Creating "
+ + physicalSwitchAugmentation.getHwvtepNodeName().getValue()));
//update global table
Global global = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Global.class);
global.setSwitches(Collections.singleton(new UUID(pswitchUuid)));
transaction.add(op.mutate(global)
.addMutation(global.getSwitchesColumn().getSchema(), Mutator.INSERT,
global.getSwitchesColumn().getData()));
- transaction.add(op.comment("Global: Mutating " +
- physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + pswitchUuid));
+ transaction.add(op.comment("Global: Mutating "
+ + physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + pswitchUuid));
} else {
PhysicalSwitchAugmentation updatedPhysicalSwitch = operationalPhysicalSwitchOptional.get();
String existingPhysicalSwitchName = updatedPhysicalSwitch.getHwvtepNodeName().getValue();
/* In case TOR devices don't allow creation of PhysicalSwitch name might be null
* as user is only adding configurable parameters to MDSAL like BFD params
- *
+ *
* TODO Note: Consider handling tunnel udpate/remove in separate command
*/
- if(existingPhysicalSwitchName == null) {
+ if (existingPhysicalSwitchName == null) {
existingPhysicalSwitchName = operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue();
}
// Name is immutable, and so we *can't* update it. So we use extraPhysicalSwitch for the schema stuff
- PhysicalSwitch extraPhysicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalSwitch.class);
+ PhysicalSwitch extraPhysicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ PhysicalSwitch.class);
extraPhysicalSwitch.setName("");
LOG.trace("execute: updating physical switch: {}", physicalSwitch);
transaction.add(op.update(physicalSwitch)
Optional<PhysicalSwitchAugmentation> operationalPhysicalSwitchOptional) {
if (physicalSwitchAugmentation.getHwvtepNodeName() != null) {
physicalSwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
- } else if (operationalPhysicalSwitchOptional.isPresent() && operationalPhysicalSwitchOptional.get().getHwvtepNodeName() != null) {
+ } else if (operationalPhysicalSwitchOptional.isPresent()
+ && operationalPhysicalSwitchOptional.get().getHwvtepNodeName() != null) {
physicalSwitch.setName(operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue());
}
}
}
}
- private void setManagementIps(PhysicalSwitch physicalSwitch, PhysicalSwitchAugmentation physicalSwitchAugmentation) {
+ private void setManagementIps(PhysicalSwitch physicalSwitch,
+ PhysicalSwitchAugmentation physicalSwitchAugmentation) {
Set<String> ipSet = new HashSet<>();
if (physicalSwitchAugmentation.getManagementIps() != null) {
for (ManagementIps ip: physicalSwitchAugmentation.getManagementIps()) {
@SuppressWarnings("unchecked")
private void setTunnels(TransactionBuilder transaction, InstanceIdentifier<Node> iid,
PhysicalSwitch physicalSwitch, PhysicalSwitchAugmentation physicalSwitchAugmentation,
- boolean pSwitchExists) {
+ boolean switchExists) {
//TODO: revisit this code for optimizations
//TODO: needs more testing
- if(physicalSwitchAugmentation.getTunnels() != null) {
- for(Tunnels tunnel: physicalSwitchAugmentation.getTunnels()) {
+ if (physicalSwitchAugmentation.getTunnels() != null) {
+ for (Tunnels tunnel : physicalSwitchAugmentation.getTunnels()) {
Optional<Tunnels> opTunnelOpt = getOperationalState().getTunnels(iid, tunnel.getKey());
Tunnel newTunnel = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Tunnel.class);
(InstanceIdentifier<TerminationPoint>) tunnel.getLocalLocatorRef().getValue());
UUID remoteUUID = getLocatorUUID(transaction,
(InstanceIdentifier<TerminationPoint>) tunnel.getRemoteLocatorRef().getValue());
- if(localUUID != null && remoteUUID != null) {
+ if (localUUID != null && remoteUUID != null) {
UUID uuid;
// local and remote must exist
newTunnel.setLocal(localUUID);
setBfdParams(newTunnel, tunnel);
setBfdLocalConfigs(newTunnel, tunnel);
setBfdRemoteConfigs(newTunnel, tunnel);
- if(!opTunnelOpt.isPresent()) {
+ if (!opTunnelOpt.isPresent()) {
String tunnelUuid = "Tunnel_" + HwvtepSouthboundMapper.getRandomUUID();
transaction.add(op.insert(newTunnel).withId(tunnelUuid));
transaction.add(op.comment("Tunnel: Creating " + tunnelUuid));
- if(!pSwitchExists) {
+ if (!switchExists) {
//TODO: Figure out a way to handle this
LOG.warn("Tunnel configuration requires pre-existing physicalSwitch");
} else {
// TODO: Can we reuse physicalSwitch instead?
- PhysicalSwitch pSwitch =
+ PhysicalSwitch phySwitch =
TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
PhysicalSwitch.class);
- pSwitch.setTunnels(Collections.singleton(new UUID(tunnelUuid)));
- pSwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
- transaction.add(op.mutate(pSwitch)
- .addMutation(pSwitch.getTunnels().getSchema(), Mutator.INSERT,
- pSwitch.getTunnels().getData())
- .where(pSwitch.getNameColumn().getSchema().
- opEqual(pSwitch.getNameColumn().getData()))
+ phySwitch.setTunnels(Collections.singleton(new UUID(tunnelUuid)));
+ phySwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
+ transaction.add(op.mutate(phySwitch)
+ .addMutation(phySwitch.getTunnels().getSchema(), Mutator.INSERT,
+ phySwitch.getTunnels().getData())
+ .where(phySwitch.getNameColumn().getSchema()
+ .opEqual(phySwitch.getNameColumn().getData()))
.build());
transaction.add(op.comment("PhysicalSwitch: Mutating " + tunnelUuid));
}
uuid = new UUID(tunnelUuid);
} else {
- uuid = new UUID (opTunnelOpt.get().getTunnelUuid().getValue());
+ uuid = new UUID(opTunnelOpt.get().getTunnelUuid().getValue());
Tunnel extraTunnel =
TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Tunnel.class, null);
extraTunnel.getUuidColumn().setData(uuid);
private void setBfdParams(Tunnel tunnel, Tunnels psAugTunnel) {
List<BfdParams> bfdParams = psAugTunnel.getBfdParams();
- if(bfdParams != null) {
+ if (bfdParams != null) {
Map<String, String> bfdParamMap = new HashMap<>();
- for(BfdParams bfdParam : bfdParams) {
+ for (BfdParams bfdParam : bfdParams) {
bfdParamMap.put(bfdParam.getBfdParamKey(), bfdParam.getBfdParamValue());
}
try {
private void setBfdLocalConfigs(Tunnel tunnel, Tunnels psAugTunnel) {
List<BfdLocalConfigs> bfdLocalConfigs = psAugTunnel.getBfdLocalConfigs();
- if(bfdLocalConfigs != null) {
+ if (bfdLocalConfigs != null) {
Map<String, String> configLocalMap = new HashMap<>();
- for(BfdLocalConfigs localConfig : bfdLocalConfigs) {
+ for (BfdLocalConfigs localConfig : bfdLocalConfigs) {
configLocalMap.put(localConfig.getBfdLocalConfigKey(), localConfig.getBfdLocalConfigValue());
}
try {
private void setBfdRemoteConfigs(Tunnel tunnel, Tunnels psAugTunnel) {
List<BfdRemoteConfigs> bfdRemoteConfigs = psAugTunnel.getBfdRemoteConfigs();
- if(bfdRemoteConfigs != null) {
+ if (bfdRemoteConfigs != null) {
Map<String, String> configRemoteMap = new HashMap<>();
- for(BfdRemoteConfigs remoteConfig : bfdRemoteConfigs) {
+ for (BfdRemoteConfigs remoteConfig : bfdRemoteConfigs) {
configRemoteMap.put(remoteConfig.getBfdRemoteConfigKey(), remoteConfig.getBfdRemoteConfigValue());
}
try {
final DataObjectModification<Node> mod = change.getRootNode();
Node created = TransactUtils.getCreated(mod);
if (created != null) {
- PhysicalSwitchAugmentation physicalSwitch = created.getAugmentation(PhysicalSwitchAugmentation.class);
+ PhysicalSwitchAugmentation physicalSwitch =
+ created.getAugmentation(PhysicalSwitchAugmentation.class);
if (physicalSwitch != null) {
result.put(key, physicalSwitch);
}
final DataObjectModification<Node> mod = change.getRootNode();
Node updated = TransactUtils.getUpdated(mod);
if (updated != null) {
- PhysicalSwitchAugmentation physicalSwitch = updated.getAugmentation(PhysicalSwitchAugmentation.class);
+ PhysicalSwitchAugmentation physicalSwitch =
+ updated.getAugmentation(PhysicalSwitchAugmentation.class);
if (physicalSwitch != null) {
result.put(key, physicalSwitch);
}