Modernizer is flaggin callers, use better alternatives.
Change-Id: I79b3a5c64e28b2fd5a8de5b6010cfe7b1d38719b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
public HwvtepConnectionInstance getConnectionInstance(final HwvtepPhysicalSwitchAttributes node) {
Optional<HwvtepGlobalAugmentation> optional = HwvtepSouthboundUtil.getManagingNode(db, node);
if (optional.isPresent()) {
- return getConnectionInstance(optional.get().getConnectionInfo());
+ return getConnectionInstance(optional.orElseThrow().getConnectionInfo());
} else {
return null;
}
java.util.Optional<EntityOwnershipState> ownershipStateOpt =
entityOwnershipService.getOwnershipState(candidateEntity);
if (ownershipStateOpt.isPresent()) {
- EntityOwnershipState ownershipState = ownershipStateOpt.get();
+ EntityOwnershipState ownershipState = ownershipStateOpt.orElseThrow();
putConnectionInstance(hwvtepConnectionInstance.getMDConnectionInfo(), hwvtepConnectionInstance);
if (ownershipState != EntityOwnershipState.NO_OWNER) {
hwvtepConnectionInstance.setHasDeviceOwnership(ownershipState == EntityOwnershipState.IS_OWNER);
@Override
public void onSuccess(final Optional<Node> node) {
if (node.isPresent()) {
- HwvtepGlobalAugmentation augmentation = node.get()
+ HwvtepGlobalAugmentation augmentation = node.orElseThrow()
.augmentation(HwvtepGlobalAugmentation.class);
if (augmentation == null || augmentation.getConnectionInfo() == null) {
return;
Optional<Node> optional = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, path);
if (optional != null && optional.isPresent()) {
HwvtepGlobalAugmentation hwvtepNode = null;
- Node node = optional.get();
+ Node node = optional.orElseThrow();
if (node instanceof HwvtepGlobalAugmentation) {
hwvtepNode = (HwvtepGlobalAugmentation) node;
} else if (node != null) {
public UUID getLsUuid(InstanceIdentifier lsIid) {
UUID lsUUID = connectionInstance.getDeviceInfo().getUUID(LogicalSwitches.class, lsIid);
if (lsUUID == null) {
- Optional<TypedBaseTable> optional =
- getHwvtepTableEntryUUID(LogicalSwitches.class, lsIid, null);
+ Optional<TypedBaseTable> optional = getHwvtepTableEntryUUID(LogicalSwitches.class, lsIid, null);
if (optional.isPresent()) {
- lsUUID = optional.get().getUuid();
+ return optional.orElseThrow().getUuid();
}
}
return lsUUID;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
-import java.util.Optional;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
import org.opendaylight.mdsal.binding.api.ReadTransaction;
private static Node readNode(ReadTransaction transaction,
LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<Node> iid) {
- Optional<Node> optional = HwvtepSouthboundUtil.readNode(transaction, logicalDatastoreType, iid);
- if (optional.isPresent()) {
- return optional.get();
- }
- return null;
+ return HwvtepSouthboundUtil.readNode(transaction, logicalDatastoreType, iid).orElse(null);
}
}
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
HwvtepDeviceInfo.DeviceData deviceData = getDeviceOpData(cls, key);
if (deviceData == null) {
LOG.debug("Could not find data for key {}", getNodeKeyStr(key));
- java.util.Optional<TypedBaseTable> optional =
- getTableReader().getHwvtepTableEntryUUID(cls, key, null);
+ Optional<TypedBaseTable> optional = getTableReader().getHwvtepTableEntryUUID(cls, key, null);
if (optional.isPresent()) {
+ TypedBaseTable table = optional.orElseThrow();
LOG.debug("Found the data for key from device {} ", getNodeKeyStr(key));
- getDeviceInfo().updateDeviceOperData(cls, key, optional.get().getUuid(), optional.get());
+ getDeviceInfo().updateDeviceOperData(cls, key, table.getUuid(), table);
return getDeviceOpData(cls, key);
} else {
LOG.info("Could not Find the data for key from device {} ", getNodeKeyStr(key));
Optional<TypedBaseTable> latestDeviceStatus = deviceInfo.getConnectionInstance()
.getHwvtepTableReader().getHwvtepTableEntryUUID(cls, iid, controllerData.getUuid());
- TypedBaseTable latestDeviceData = latestDeviceStatus.isPresent() ? latestDeviceStatus.get() : null;
+ TypedBaseTable latestDeviceData = latestDeviceStatus.orElse(null);
if (INTRANSIT_DATA_CREATED.test(controllerData, latestDeviceStatus)) {
LOG.info("Intransit expired key is actually created but update is missed/delayed {}", iid);
- deviceInfo.updateDeviceOperData(cls, iid, latestDeviceStatus.get().getUuid(), latestDeviceData);
+ deviceInfo.updateDeviceOperData(cls, iid, latestDeviceData.getUuid(), latestDeviceData);
} else if (INTRANSIT_DATA_NOT_CREATED.test(controllerData, latestDeviceStatus)) {
LOG.info("Intransit expired key is actually not created but update is missed/delayed {}", iid);
} else if (INTRANSIT_DATA_NOT_DELETED.test(controllerData, latestDeviceStatus)) {
//not deleted from device we will reuse existing uuid
LOG.info("Intransit expired key is actually not deleted but update is missed/delayed {}", iid);
- deviceInfo.updateDeviceOperData(cls, iid, latestDeviceStatus.get().getUuid(), latestDeviceData);
+ deviceInfo.updateDeviceOperData(cls, iid, latestDeviceData.getUuid(), latestDeviceData);
}
} else if (DATA_INTRANSIT.test(controllerData)) {
//device status is still in transit
Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
connectionInstance.getInstanceIdentifier());
if (readNode.isPresent()) {
- operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
+ operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.orElseThrow());
}
}
//for example, when creating physical port, logical switch is needed
//but logical switch is in HwvtepGlobalAugmentation rather than PhysicalSwitchAugmentation
if (readNode.isPresent()) {
- operationalNodes.put(entry.getKey(), readNode.get());
- HwvtepGlobalAugmentation hgAugmentation =
- readNode.get().augmentation(HwvtepGlobalAugmentation.class);
- PhysicalSwitchAugmentation psAugmentation =
- readNode.get().augmentation(PhysicalSwitchAugmentation.class);
- if (hgAugmentation != null && hgAugmentation.getSwitches() != null) {
- for (Switches pswitch : hgAugmentation.getSwitches().values()) {
+ Node rdNode = readNode.orElseThrow();
+ operationalNodes.put(entry.getKey(), rdNode);
+ HwvtepGlobalAugmentation hgAugmentation = rdNode.augmentation(HwvtepGlobalAugmentation.class);
+ PhysicalSwitchAugmentation psAugmentation = rdNode.augmentation(PhysicalSwitchAugmentation.class);
+ if (hgAugmentation != null) {
+ for (Switches pswitch : hgAugmentation.nonnullSwitches().values()) {
@SuppressWarnings("unchecked")
InstanceIdentifier<Node> psNodeIid =
(InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
Optional<Node> psNode =
new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, psNodeIid);
if (psNode.isPresent()) {
- operationalNodes.put(psNodeIid, psNode.get());
+ operationalNodes.put(psNodeIid, psNode.orElseThrow());
}
}
}
Optional<Node> hgNode = new MdsalUtils(db).readOptional(
LogicalDatastoreType.OPERATIONAL, hgNodeIid);
if (hgNode.isPresent()) {
- operationalNodes.put(hgNodeIid, hgNode.get());
+ operationalNodes.put(hgNodeIid, hgNode.orElseThrow());
}
}
}
}
public Optional<HwvtepGlobalAugmentation> getHwvtepGlobalAugmentation(final InstanceIdentifier<?> iid) {
- Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- return Optional.ofNullable(nodeOptional.get().augmentation(HwvtepGlobalAugmentation.class));
- }
- return Optional.empty();
+ return getGlobalNode(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.augmentation(HwvtepGlobalAugmentation.class)));
}
public Optional<PhysicalSwitchAugmentation> getPhysicalSwitchAugmentation(final InstanceIdentifier<?> iid) {
- Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- return Optional.ofNullable(nodeOptional.get().augmentation(PhysicalSwitchAugmentation.class));
- }
- return Optional.empty();
+ return getGlobalNode(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.augmentation(PhysicalSwitchAugmentation.class)));
}
public Optional<Map<TerminationPointKey, TerminationPoint>> getTerminationPointList(
final InstanceIdentifier<?> iid) {
- Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
- if (nodeOptional.isPresent() && nodeOptional.get().getTerminationPoint() != null) {
- return Optional.ofNullable(nodeOptional.get().getTerminationPoint());
- }
- return Optional.empty();
+ return getGlobalNode(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.getTerminationPoint()));
}
public Optional<LogicalSwitches> getLogicalSwitches(final InstanceIdentifier<?> iid,
final LogicalSwitchesKey logicalSwitchesKey) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- LogicalSwitches lswitch = nodeOptional.get().nonnullLogicalSwitches().get(logicalSwitchesKey);
- if (lswitch != null) {
- return Optional.of(lswitch);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullLogicalSwitches().get(logicalSwitchesKey)));
}
public Optional<LogicalSwitches> getLogicalSwitches(final InstanceIdentifier<LogicalSwitches> iid) {
}
public Optional<Tunnels> getTunnels(final InstanceIdentifier<?> iid, final TunnelsKey tunnelsKey) {
- Optional<PhysicalSwitchAugmentation> psOptional = getPhysicalSwitchAugmentation(requireNonNull(iid));
- if (psOptional.isPresent()) {
- Tunnels tunnel = psOptional.get().nonnullTunnels().get(tunnelsKey);
- if (tunnel != null) {
- return Optional.of(tunnel);
- }
- }
- return Optional.empty();
+ return getPhysicalSwitchAugmentation(requireNonNull(iid))
+ .flatMap(ps -> Optional.ofNullable(ps.nonnullTunnels().get(tunnelsKey)));
}
public Optional<Tunnels> getTunnels(final InstanceIdentifier<Tunnels> iid) {
Optional<Map<TerminationPointKey, TerminationPoint>> nodeOptional =
getTerminationPointList(requireNonNull(iid));
if (nodeOptional.isPresent()) {
- for (TerminationPoint tp : nodeOptional.get().values()) {
+ for (TerminationPoint tp : nodeOptional.orElseThrow().values()) {
HwvtepPhysicalPortAugmentation hppAugmentation =
tp.augmentation(HwvtepPhysicalPortAugmentation.class);
if (hppAugmentation != null && hppAugmentation.getHwvtepNodeName().equals(hwvtepNodeName)) {
- return Optional.ofNullable(hppAugmentation);
+ return Optional.of(hppAugmentation);
}
}
}
Optional<Map<TerminationPointKey, TerminationPoint>> nodeOptional =
getTerminationPointList(requireNonNull(iid));
if (nodeOptional.isPresent()) {
- for (TerminationPoint tp : nodeOptional.get().values()) {
+ for (TerminationPoint tp : nodeOptional.orElseThrow().values()) {
HwvtepPhysicalLocatorAugmentation hppAugmentation =
tp.augmentation(HwvtepPhysicalLocatorAugmentation.class);
if (hppAugmentation != null && hppAugmentation.getDstIp().equals(dstIp)
public Optional<HwvtepPhysicalLocatorAugmentation>
getPhysicalLocatorAugmentation(final InstanceIdentifier<TerminationPoint> iid) {
- Optional<TerminationPoint> tp =
- new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
- if (tp.isPresent()) {
- return Optional.ofNullable(tp.get().augmentation(HwvtepPhysicalLocatorAugmentation.class));
- }
- return Optional.empty();
+ Optional<TerminationPoint> optTp = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+ return optTp.flatMap(tp -> Optional.ofNullable(tp.augmentation(HwvtepPhysicalLocatorAugmentation.class)));
}
public Optional<LocalMcastMacs> getLocalMcastMacs(final InstanceIdentifier<?> iid, final LocalMcastMacsKey key) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- LocalMcastMacs mac = nodeOptional.get().nonnullLocalMcastMacs().get(key);
- if (mac != null) {
- return Optional.of(mac);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullLocalMcastMacs().get(key)));
}
public Optional<RemoteMcastMacs> getRemoteMcastMacs(final InstanceIdentifier<?> iid, final RemoteMcastMacsKey key) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- RemoteMcastMacs mac = nodeOptional.get().nonnullRemoteMcastMacs().get(key);
- if (mac != null) {
- return Optional.of(mac);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullRemoteMcastMacs().get(key)));
}
public Optional<LocalUcastMacs> getLocalUcastMacs(final InstanceIdentifier<?> iid, final LocalUcastMacsKey key) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- LocalUcastMacs mac = nodeOptional.get().nonnullLocalUcastMacs().get(key);
- if (mac != null) {
- return Optional.of(mac);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullLocalUcastMacs().get(key)));
}
public Optional<RemoteUcastMacs> getRemoteUcastMacs(final InstanceIdentifier<?> iid, final RemoteUcastMacsKey key) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- RemoteUcastMacs mac = nodeOptional.get().nonnullRemoteUcastMacs().get(key);
- if (mac != null) {
- return Optional.of(mac);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullRemoteUcastMacs().get(key)));
}
public Optional<LogicalRouters> getLogicalRouters(final InstanceIdentifier<?> iid,
final LogicalRoutersKey logicalRoutersKey) {
- Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
- if (nodeOptional.isPresent()) {
- LogicalRouters lrouter = nodeOptional.get().nonnullLogicalRouters().get(logicalRoutersKey);
- if (lrouter != null) {
- return Optional.of(lrouter);
- }
- }
- return Optional.empty();
+ return getHwvtepGlobalAugmentation(requireNonNull(iid))
+ .flatMap(node -> Optional.ofNullable(node.nonnullLogicalRouters().get(logicalRoutersKey)));
}
public Optional<Acls> getAcls(final InstanceIdentifier<Acls> iid) {
- Optional<Acls> acl = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
- return acl;
+ return new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
}
public ReadWriteTransaction getReadWriteTransaction() {
getOperationalState().getLogicalRouters(instanceIdentifier, lrouter.key());
if (operationalRouterOptional.isPresent()
- && operationalRouterOptional.get().getLogicalRouterUuid() != null) {
+ && operationalRouterOptional.orElseThrow().getLogicalRouterUuid() != null) {
LogicalRouter logicalRouter = transaction.getTypedRowSchema(LogicalRouter.class);
- UUID logicalRouterUuid = new UUID(operationalRouterOptional.get().getLogicalRouterUuid().getValue());
+ UUID logicalRouterUuid = new UUID(
+ operationalRouterOptional.orElseThrow().getLogicalRouterUuid().getValue());
transaction.add(op.delete(logicalRouter.getSchema())
.where(logicalRouter.getUuidColumn().getSchema().opEqual(logicalRouterUuid)).build());
transaction.add(op.comment("Logical Router: Deleting " + lrouter.getHwvtepNodeName().getValue()));
updateCurrentTxData(LogicalRouters.class, routerKey, lrUuid, lrouter);
updateControllerTxHistory(TransactionType.ADD, logicalRouter);
} else {
- LogicalRouters updatedLRouter = operationalRouterOptional.get();
+ LogicalRouters updatedLRouter = operationalRouterOptional.orElseThrow();
String existingLogicalRouterName = updatedLRouter.getHwvtepNodeName().getValue();
LogicalRouter extraLogicalRouter = transaction.getTypedRowWrapper(LogicalRouter.class);
extraLogicalRouter.setName("");
final Optional<LogicalRouters> inputRouterOptional) {
if (inputRouter.getHwvtepNodeName() != null) {
logicalRouter.setName(inputRouter.getHwvtepNodeName().getValue());
- } else if (inputRouterOptional.isPresent() && inputRouterOptional.get().getHwvtepNodeName() != null) {
- logicalRouter.setName(inputRouterOptional.get().getHwvtepNodeName().getValue());
+ } else if (inputRouterOptional.isPresent() && inputRouterOptional.orElseThrow().getHwvtepNodeName() != null) {
+ logicalRouter.setName(inputRouterOptional.orElseThrow().getHwvtepNodeName().getValue());
}
}
Optional<LogicalSwitches> operationalSwitchOptional =
getOperationalState().getLogicalSwitches(lswitchIid);
if (operationalSwitchOptional.isPresent()) {
- Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
+ Uuid logicalSwitchUuid = operationalSwitchOptional.orElseThrow().getLogicalSwitchUuid();
bindingMap.put(switchBinding.getDestinationAddress().getIpv4Prefix().getValue(),
new UUID(logicalSwitchUuid.getValue()));
} else {
Optional<Acls> operationalAclOptional =
getOperationalState().getAcls(aclIid);
if (operationalAclOptional.isPresent()) {
- Uuid aclUuid = operationalAclOptional.get().getAclUuid();
- bindingMap.put(aclBinding.getRouterInterface().stringValue(),
- new UUID(aclUuid.getValue()));
+ Uuid aclUuid = operationalAclOptional.orElseThrow().getAclUuid();
+ bindingMap.put(aclBinding.getRouterInterface().stringValue(), new UUID(aclUuid.getValue()));
} else {
- bindingMap.put(aclBinding.getRouterInterface().stringValue(),
- TransactUtils.getAclUUID(aclIid));
+ bindingMap.put(aclBinding.getRouterInterface().stringValue(), TransactUtils.getAclUUID(aclIid));
}
}
logicalRouter.setAclBinding(bindingMap);
Optional<LocalMcastMacs> operationalMacOptional =
getOperationalState().getLocalMcastMacs(instanceIdentifier, mac.key());
McastMacsLocal mcastMacsLocal = transaction.getTypedRowSchema(McastMacsLocal.class);
- if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
+ if (operationalMacOptional.isPresent() && operationalMacOptional.orElseThrow().getMacEntryUuid() != null) {
//when mac entry is deleted, its referenced locator set and locators are deleted automatically.
//TODO: locator in config DS is not deleted
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ UUID macEntryUUID = new UUID(operationalMacOptional.orElseThrow().getMacEntryUuid().getValue());
mcastMacsLocal.getUuidColumn().setData(macEntryUUID);
transaction.add(op.delete(mcastMacsLocal.getSchema())
.where(mcastMacsLocal.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
LOG.trace("execute: create LocalMcastMac entry: {}", mcastMacsLocal);
transaction.add(op.insert(mcastMacsLocal));
transaction.add(op.comment("McastMacLocal: Creating " + localMcastMac.getMacEntryKey().getValue()));
- } else if (operationalMacOptional.get().getMacEntryUuid() != null) {
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ } else if (operationalMacOptional.orElseThrow().getMacEntryUuid() != null) {
+ UUID macEntryUUID = new UUID(operationalMacOptional.orElseThrow().getMacEntryUuid().getValue());
McastMacsLocal extraMac = transaction.getTypedRowSchema(McastMacsLocal.class);
extraMac.getUuidColumn().setData(macEntryUUID);
LOG.trace("execute: update LocalMcastMac entry: {}", mcastMacsLocal);
Optional<LogicalSwitches> operationalSwitchOptional =
getOperationalState().getLogicalSwitches(lswitchIid);
if (operationalSwitchOptional.isPresent()) {
- Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
+ Uuid logicalSwitchUuid = operationalSwitchOptional.orElseThrow().getLogicalSwitchUuid();
UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
mcastMacsLocal.setLogicalSwitch(logicalSwitchUUID);
} else {
} else {
mcastMacsLocal.setMac(inputMac.getMacEntryKey().getValue());
}
- } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
- mcastMacsLocal.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
+ } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.orElseThrow().getMacEntryKey() != null) {
+ mcastMacsLocal.setMac(inputSwitchOptional.orElseThrow().getMacEntryKey().getValue());
}
}
if (operationalPhysicalPortOptional.isPresent()) {
PhysicalPort physicalPort = transaction.getTypedRowWrapper(PhysicalPort.class);
physicalPort.setVlanBindings(new HashMap<>());
- HwvtepPhysicalPortAugmentation updatedPhysicalPort = operationalPhysicalPortOptional.get();
+ HwvtepPhysicalPortAugmentation updatedPhysicalPort = operationalPhysicalPortOptional.orElseThrow();
String existingPhysicalPortName = updatedPhysicalPort.getHwvtepNodeName().getValue();
PhysicalPort extraPhyscialPort = transaction.getTypedRowWrapper(PhysicalPort.class);
extraPhyscialPort.setName("");
getOperationalState().getPhysicalSwitchAugmentation(iid);
PhysicalSwitch physicalSwitch = transaction.getTypedRowSchema(PhysicalSwitch.class);
if (operationalPhysicalSwitchOptional.isPresent()
- && operationalPhysicalSwitchOptional.get().getPhysicalSwitchUuid() != null) {
- UUID physicalSwitchUuid = new UUID(operationalPhysicalSwitchOptional.get()
+ && operationalPhysicalSwitchOptional.orElseThrow().getPhysicalSwitchUuid() != null) {
+ UUID physicalSwitchUuid = new UUID(operationalPhysicalSwitchOptional.orElseThrow()
.getPhysicalSwitchUuid().getValue());
Global global = transaction.getTypedRowSchema(Global.class);
transaction.add(op.delete(physicalSwitch.getSchema())
PhysicalSwitch physicalSwitch = transaction.getTypedRowWrapper(PhysicalSwitch.class);
setDescription(physicalSwitch, physicalSwitchAugmentation);
setManagementIps(physicalSwitch, physicalSwitchAugmentation);
- setTunnuleIps(physicalSwitch, operationalPhysicalSwitchOptional.get());
+ setTunnuleIps(physicalSwitch, operationalPhysicalSwitchOptional.orElseThrow());
try {
setTunnels(transaction, iid, physicalSwitch, physicalSwitchAugmentation,
operationalPhysicalSwitchOptional.isPresent());
transaction.add(op.comment("Global: Mutating "
+ physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + pswitchUuid));
} else {
- PhysicalSwitchAugmentation updatedPhysicalSwitch = operationalPhysicalSwitchOptional.get();
+ PhysicalSwitchAugmentation updatedPhysicalSwitch = operationalPhysicalSwitchOptional.orElseThrow();
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) {
- existingPhysicalSwitchName = operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue();
+ existingPhysicalSwitchName = operationalPhysicalSwitchOptional.orElseThrow()
+ .getHwvtepNodeName().getValue();
}
// Name is immutable, and so we *can't* update it. So we use extraPhysicalSwitch for the schema stuff
PhysicalSwitch extraPhysicalSwitch = transaction.getTypedRowWrapper(PhysicalSwitch.class);
if (physicalSwitchAugmentation.getHwvtepNodeName() != null) {
physicalSwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
} else if (operationalPhysicalSwitchOptional.isPresent()
- && operationalPhysicalSwitchOptional.get().getHwvtepNodeName() != null) {
- physicalSwitch.setName(operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue());
+ && operationalPhysicalSwitchOptional.orElseThrow().getHwvtepNodeName() != null) {
+ physicalSwitch.setName(operationalPhysicalSwitchOptional.orElseThrow().getHwvtepNodeName().getValue());
}
}
transaction.add(op.comment("PhysicalSwitch: Mutating " + tunnelUuid));
}
} else {
- UUID uuid = new UUID(opTunnelOpt.get().getTunnelUuid().getValue());
+ UUID uuid = new UUID(opTunnelOpt.orElseThrow().getTunnelUuid().getValue());
Tunnel extraTunnel = transaction.getTypedRowSchema(Tunnel.class);
extraTunnel.getUuidColumn().setData(uuid);
transaction.add(op.update(newTunnel)
getOperationalState().getPhysicalLocatorAugmentation(iid);
if (opLocOptional.isPresent()) {
// Get Locator UUID from operational
- HwvtepPhysicalLocatorAugmentation locatorAug = opLocOptional.get();
+ HwvtepPhysicalLocatorAugmentation locatorAug = opLocOptional.orElseThrow();
locatorUUID = new UUID(locatorAug.getPhysicalLocatorUuid().getValue());
} else {
// TODO/FIXME: Not in operational, do we create a new one?
Optional<LocalUcastMacs> operationalMacOptional =
getOperationalState().getLocalUcastMacs(instanceIdentifier, mac.key());
UcastMacsLocal ucastMacsLocal = transaction.getTypedRowSchema(UcastMacsLocal.class);
- if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
+ if (operationalMacOptional.isPresent() && operationalMacOptional.orElseThrow().getMacEntryUuid() != null) {
//when mac entry is deleted, its referenced locators are deleted automatically.
//locators in config DS is not deleted and user need to be removed explicitly by user.
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ UUID macEntryUUID = new UUID(operationalMacOptional.orElseThrow().getMacEntryUuid().getValue());
ucastMacsLocal.getUuidColumn().setData(macEntryUUID);
transaction.add(op.delete(ucastMacsLocal.getSchema())
.where(ucastMacsLocal.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
setIpAddress(ucastMacsLocal, localUcastMac);
setLocator(transaction, ucastMacsLocal, localUcastMac);
setLogicalSwitch(ucastMacsLocal, localUcastMac);
- if (!operationalMacOptional.isPresent()) {
+ if (operationalMacOptional.isEmpty()) {
setMac(ucastMacsLocal, localUcastMac, operationalMacOptional);
LOG.trace("execute: creating LocalUcastMac entry: {}", ucastMacsLocal);
transaction.add(op.insert(ucastMacsLocal));
transaction.add(op.comment("UcastMacLocal: Creating " + localUcastMac.getMacEntryKey().getValue()));
- } else if (operationalMacOptional.get().getMacEntryUuid() != null) {
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ } else if (operationalMacOptional.orElseThrow().getMacEntryUuid() != null) {
+ UUID macEntryUUID = new UUID(operationalMacOptional.orElseThrow().getMacEntryUuid().getValue());
UcastMacsLocal extraMac = transaction.getTypedRowSchema(UcastMacsLocal.class);
extraMac.getUuidColumn().setData(macEntryUUID);
LOG.trace("execute: updating LocalUcastMac entry: {}", ucastMacsLocal);
Optional<LogicalSwitches> operationalSwitchOptional =
getOperationalState().getLogicalSwitches(lswitchIid);
if (operationalSwitchOptional.isPresent()) {
- Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
+ Uuid logicalSwitchUuid = operationalSwitchOptional.orElseThrow().getLogicalSwitchUuid();
UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
ucastMacsLocal.setLogicalSwitch(logicalSwitchUUID);
} else {
getOperationalState().getPhysicalLocatorAugmentation(iid);
if (operationalLocatorOptional.isPresent()) {
//if exist, get uuid
- HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.get();
+ HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.orElseThrow();
locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
} else {
//if no, get it from config DS and create id
getOperationalState().getDataBroker()).readOptional(LogicalDatastoreType.CONFIGURATION, iid);
if (configLocatorOptional.isPresent()) {
HwvtepPhysicalLocatorAugmentation locatorAugmentation =
- configLocatorOptional.get().augmentation(HwvtepPhysicalLocatorAugmentation.class);
+ configLocatorOptional.orElseThrow().augmentation(HwvtepPhysicalLocatorAugmentation.class);
locatorUuid = TransactUtils.createPhysicalLocator(transaction, locatorAugmentation,
getOperationalState());
} else {
final Optional<LocalUcastMacs> inputSwitchOptional) {
if (inputMac.getMacEntryKey() != null) {
ucastMacsLocal.setMac(inputMac.getMacEntryKey().getValue());
- } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
- ucastMacsLocal.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
+ } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.orElseThrow().getMacEntryKey() != null) {
+ ucastMacsLocal.setMac(inputSwitchOptional.orElseThrow().getMacEntryKey().getValue());
}
}
DataBroker db = opState.getConnectionInstance().getDataBroker();
Optional data = HwvtepSouthboundUtil.readNode(db, LogicalDatastoreType.CONFIGURATION, key);
if (data.isPresent()) {
- opState.getDeviceInfo().updateConfigData(cls, key, data.get());
+ opState.getDeviceInfo().updateConfigData(cls, key, data.orElseThrow());
return true;
}
return false;
try {
Optional<Node> hwvtepGlobalOptional = hwvtepGlobalFuture.get();
if (hwvtepGlobalOptional.isPresent()) {
- Node hwvtepNode = hwvtepGlobalOptional.get();
+ Node hwvtepNode = hwvtepGlobalOptional.orElseThrow();
HwvtepGlobalAugmentation hgAugmentation = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class);
if (checkIfOnlyConnectedManager(hgAugmentation)) {
if (hgAugmentation != null) {
final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
Optional<Node> connection = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
if (connection.isPresent()) {
- LOG.debug("Connection {} is present", connection.get());
+ LOG.debug("Connection {} is present", connection.orElseThrow());
Node connectionNode = buildConnectionNode(manager);
transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
addToDeviceUpdate(TransactionType.ADD, manager);
}
Optional<Node> node = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
if (node.isPresent()) {
- updateTerminationPoints(transaction, node.get());
+ updateTerminationPoints(transaction, node.orElseThrow());
}
}
for (Entry<UUID, PhysicalPort> portUpdateEntry : updatedPPRows.entrySet()) {
Optional<InstanceIdentifier<Node>> switchIid = getTerminationPointSwitch(portUpdateEntry.getKey());
if (switchIid.isPresent()) {
- if (getDeviceInfo().getDeviceOperData(Node.class, switchIid.get()) == null) {
+ if (getDeviceInfo().getDeviceOperData(Node.class, switchIid.orElseThrow()) == null) {
//This is the first update from switch do not have to do reconciliation of this port
//it is taken care by switch reconciliation
skipReconciliationPorts.add(portUpdateEntry.getKey());
LOG.trace("PhysicalPortTable updated: {}", updatedPPRows);
Optional<Node> node = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
if (node.isPresent()) {
- updateTerminationPoints(transaction, node.get());
+ updateTerminationPoints(transaction, node.orElseThrow());
// TODO: Handle Deletion of VLAN Bindings
}
}
TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
tpBuilder.withKey(tpKey);
tpBuilder.setTpId(tpKey.getTpId());
- InstanceIdentifier<TerminationPoint> tpPath = getInstanceIdentifier(switchIid.get(), portUpdate);
+ InstanceIdentifier<TerminationPoint> tpPath =
+ getInstanceIdentifier(switchIid.orElseThrow(), portUpdate);
HwvtepPhysicalPortAugmentationBuilder tpAugmentationBuilder =
new HwvtepPhysicalPortAugmentationBuilder();
buildTerminationPoint(tpAugmentationBuilder, portUpdate);
for (Switches managedNodeEntry : switchNodes.values()) {
@SuppressWarnings("unchecked")
Node switchNode = HwvtepSouthboundUtil.readNode(transaction,
- (InstanceIdentifier<Node>) managedNodeEntry.getSwitchRef().getValue()).get();
+ (InstanceIdentifier<Node>) managedNodeEntry.getSwitchRef().getValue()).orElseThrow();
TerminationPointKey tpKey = new TerminationPointKey(new TpId(tpName));
TerminationPoint terminationPoint = switchNode.nonnullTerminationPoint().get(tpKey);
if (terminationPoint != null) {
// Update the Physical Switch with whatever data we are getting
InstanceIdentifier<Node> psIid = getInstanceIdentifier(phySwitch);
- Node psNode = buildPhysicalSwitchNode(connection.get(), phySwitch);
+ Node psNode = buildPhysicalSwitchNode(connection.orElseThrow(), phySwitch);
transaction.merge(LogicalDatastoreType.OPERATIONAL, psIid, psNode);
addToDeviceUpdate(TransactionType.ADD, phySwitch);
LOG.info("DEVICE - {} {}", TransactionType.ADD, phySwitch);
.map(entry -> entry.getKey())
.findFirst();
if (clientOptional.isPresent()) {
- LOG.info("Sending notification for client {}", clientOptional.get().getConnectionInfo());
- pendingClients.remove(clientOptional.get());
- clientNotificationCallback.apply(clientOptional.get());
+ OvsdbClient client = clientOptional.orElseThrow();
+ LOG.info("Sending notification for client {}", client.getConnectionInfo());
+ pendingClients.remove(client);
+ clientNotificationCallback.apply(client);
}
}
public OvsdbConnectionInstance getConnectionInstance(final OvsdbBridgeAttributes mn) {
Optional<OvsdbNodeAugmentation> optional = SouthboundUtil.getManagingNode(db, mn);
if (optional.isPresent()) {
- return getConnectionInstance(optional.get().getConnectionInfo());
+ return getConnectionInstance(optional.orElseThrow().getConnectionInfo());
} else {
return null;
}
transaction.close();
Optional<Node> optional = nodeFuture.get();
if (optional.isPresent()) {
- return this.getConnectionInstance(optional.get());
+ return this.getConnectionInstance(optional.orElseThrow());
} else {
LOG.debug("Node was not found on the path in the operational DS: {}", nodePath);
return null;
txInvoker.invoke(transaction -> {
Optional<Node> ovsdbNodeOpt = SouthboundUtil.readNode(transaction, nodeIid);
if (ovsdbNodeOpt.isPresent()) {
- Node ovsdbNode = ovsdbNodeOpt.get();
+ Node ovsdbNode = ovsdbNodeOpt.orElseThrow();
OvsdbNodeAugmentation nodeAugmentation = ovsdbNode.augmentation(OvsdbNodeAugmentation.class);
if (nodeAugmentation != null) {
Map<ManagedNodeEntryKey, ManagedNodeEntry> entries = nodeAugmentation.getManagedNodeEntry();
java.util.Optional<EntityOwnershipState> ownershipStateOpt =
entityOwnershipService.getOwnershipState(candidateEntity);
if (ownershipStateOpt.isPresent()) {
- EntityOwnershipState ownershipState = ownershipStateOpt.get();
+ EntityOwnershipState ownershipState = ownershipStateOpt.orElseThrow();
if (ownershipState == EntityOwnershipState.OWNED_BY_OTHER) {
ovsdbConnectionInstance.setHasDeviceOwnership(false);
} else if (ownershipState == EntityOwnershipState.IS_OWNER) {
try {
OvsdbNodeRef ref = mn.getManagedBy();
if (ref != null && ref.getValue() != null) {
- ReadTransaction transaction = db.newReadOnlyTransaction();
- @SuppressWarnings("unchecked")
- // Note: erasure makes this safe in combination with the typecheck below
- InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue();
+ FluentFuture<Optional<Node>> nf;
+ try (ReadTransaction transaction = db.newReadOnlyTransaction()) {
+ @SuppressWarnings("unchecked")
+ // Note: erasure makes this safe in combination with the typecheck below
+ InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue();
+ nf = transaction.read(LogicalDatastoreType.OPERATIONAL, path);
+ }
- FluentFuture<Optional<Node>> nf = transaction.read(LogicalDatastoreType.OPERATIONAL, path);
- transaction.close();
Optional<Node> optional = nf.get();
if (optional != null && optional.isPresent()) {
OvsdbNodeAugmentation ovsdbNode = null;
- Node node = optional.get();
+ Node node = optional.orElseThrow();
if (node instanceof OvsdbNodeAugmentation) {
ovsdbNode = (OvsdbNodeAugmentation) node;
} else if (node != null) {
return;
}
final OvsdbNodeAugmentation currentOvsdbNode =
- state.getBridgeNode(ovsdbNodeIid).get().augmentation(OvsdbNodeAugmentation.class);
+ state.getBridgeNode(ovsdbNodeIid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
final Map<AutoattachKey, Autoattach> currentAutoAttach = currentOvsdbNode.getAutoattach();
for (final Autoattach origAutoattach : origAutoattachList.values()) {
deleteAutoAttach(transaction, ovsdbNodeIid, getAutoAttachUuid(currentAutoAttach,
final Optional<Node> nodeOptional = SouthboundUtil.readNode(transaction, nodeIid);
if (nodeOptional.isPresent()) {
final Map<ManagedNodeEntryKey, ManagedNodeEntry> managedNodes =
- nodeOptional.get().augmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
+ nodeOptional.orElseThrow().augmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
for (final ManagedNodeEntry managedNode : managedNodes.values()) {
final OvsdbBridgeRef ovsdbBridgeRef = managedNode.getBridgeRef();
final InstanceIdentifier<OvsdbBridgeAugmentation> brIid = ovsdbBridgeRef.getValue()
.firstIdentifierOf(Node.class).augmentation(OvsdbBridgeAugmentation.class);
final Optional<OvsdbBridgeAugmentation> optionalBridge =
transaction.read(LogicalDatastoreType.OPERATIONAL, brIid).get();
- bridge = optionalBridge.get();
+ bridge = optionalBridge.orElseThrow();
if (bridge != null && bridge.getAutoAttach() != null
&& bridge.getAutoAttach().equals(aaUuid)) {
return bridge;
}
final OvsdbNodeAugmentation currentOvsdbNode =
- state.getBridgeNode(iid).get().augmentation(OvsdbNodeAugmentation.class);
+ state.getBridgeNode(iid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
final Map<AutoattachKey, Autoattach> currentAutoAttach = currentOvsdbNode.getAutoattach();
for (final Autoattach autoAttach : autoAttachList.values()) {
final AutoAttach autoAttachWrapper = transaction.getTypedRowWrapper(AutoAttach.class);
final Optional<OvsdbBridgeAugmentation> bridgeOptional =
transaction.read(LogicalDatastoreType.OPERATIONAL, bridgeIid).get();
if (bridgeOptional.isPresent()) {
- bridge = bridgeOptional.get();
+ bridge = bridgeOptional.orElseThrow();
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Error reading from datastore", e);
}
public Optional<OvsdbBridgeAugmentation> getOvsdbBridgeAugmentation(InstanceIdentifier<?> iid) {
- Optional<Node> nodeOptional = getBridgeNode(iid);
- if (nodeOptional.isPresent()) {
- return Optional.ofNullable(nodeOptional.get().augmentation(OvsdbBridgeAugmentation.class));
- }
- return Optional.empty();
+ return getBridgeNode(iid)
+ .flatMap(node -> Optional.ofNullable(node.augmentation(OvsdbBridgeAugmentation.class)));
}
public Optional<TerminationPoint> getBridgeTerminationPoint(InstanceIdentifier<?> iid) {
if (iid != null) {
Optional<Node> nodeOptional = getBridgeNode(iid);
- if (nodeOptional.isPresent() && nodeOptional.get().getTerminationPoint() != null) {
+ if (nodeOptional.isPresent()) {
+ Node node = nodeOptional.orElseThrow();
TerminationPointKey key = iid.firstKeyOf(TerminationPoint.class);
if (key != null) {
- final TerminationPoint tp = nodeOptional.get().nonnullTerminationPoint().get(key);
+ final TerminationPoint tp = node.nonnullTerminationPoint().get(key);
if (tp != null) {
return Optional.of(tp);
}
}
public Optional<OvsdbTerminationPointAugmentation> getOvsdbTerminationPointAugmentation(InstanceIdentifier<?> iid) {
- Optional<TerminationPoint> tpOptional = getBridgeTerminationPoint(iid);
- if (tpOptional.isPresent()) {
- return Optional.ofNullable(tpOptional.get().augmentation(OvsdbTerminationPointAugmentation.class));
- }
- return Optional.empty();
+ return getBridgeTerminationPoint(iid)
+ .flatMap(tp -> Optional.ofNullable(tp.augmentation(OvsdbTerminationPointAugmentation.class)));
}
public Optional<ControllerEntry> getControllerEntry(InstanceIdentifier<?> iid) {
if (iid != null) {
Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional = getOvsdbBridgeAugmentation(iid);
if (ovsdbBridgeOptional.isPresent()) {
- Map<ControllerEntryKey, ControllerEntry> entries = ovsdbBridgeOptional.get().getControllerEntry();
+ Map<ControllerEntryKey, ControllerEntry> entries =
+ ovsdbBridgeOptional.orElseThrow().getControllerEntry();
if (entries != null) {
ControllerEntryKey key = iid.firstKeyOf(ControllerEntry.class);
if (key != null) {
if (iid != null) {
Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional = getOvsdbBridgeAugmentation(iid);
if (ovsdbBridgeOptional.isPresent()) {
- Map<ProtocolEntryKey, ProtocolEntry> entries = ovsdbBridgeOptional.get().getProtocolEntry();
+ Map<ProtocolEntryKey, ProtocolEntry> entries = ovsdbBridgeOptional.orElseThrow().getProtocolEntry();
if (entries != null) {
ProtocolEntryKey key = iid.firstKeyOf(ProtocolEntry.class);
if (key != null) {
Bridge bridge = transaction.getTypedRowSchema(Bridge.class);
Optional<OvsdbBridgeAugmentation> ovsdbAugmentationOptional = state
.getOvsdbBridgeAugmentation(ovsdbManagedNodeIid);
- if (ovsdbAugmentationOptional.isPresent() && ovsdbAugmentationOptional.get().getBridgeUuid() != null) {
- UUID bridgeUuid = new UUID(ovsdbAugmentationOptional.get().getBridgeUuid().getValue());
+ if (ovsdbAugmentationOptional.isPresent()
+ && ovsdbAugmentationOptional.orElseThrow().getBridgeUuid() != null) {
+ UUID bridgeUuid = new UUID(ovsdbAugmentationOptional.orElseThrow().getBridgeUuid().getValue());
OpenVSwitch ovs = transaction.getTypedRowSchema(OpenVSwitch.class);
transaction.add(op.delete(bridge.getSchema())
.where(bridge.getUuidColumn().getSchema().opEqual(bridgeUuid)).build());
ovsdbManagedNode.getBridgeName(),
ovsdbManagedNode.getBridgeUuid());
} else {
- String existingBridgeName = operationalBridgeOptional.get().getBridgeName().getValue();
+ String existingBridgeName = operationalBridgeOptional.orElseThrow().getBridgeName().getValue();
LOG.debug("Bridge {} already exists in device updating {}", existingBridgeName, iid);
// Name is immutable, and so we *can't* update it. So we use extraBridge for the schema stuff
Bridge extraBridge = transaction.getTypedRowWrapper(Bridge.class);
final Optional<OvsdbBridgeAugmentation> operationalBridgeOptional) {
if (ovsdbManagedNode.getBridgeName() != null) {
bridge.setName(ovsdbManagedNode.getBridgeName().getValue());
- } else if (operationalBridgeOptional.isPresent() && operationalBridgeOptional.get().getBridgeName() != null) {
- bridge.setName(operationalBridgeOptional.get().getBridgeName().getValue());
+ } else if (operationalBridgeOptional.isPresent()
+ && operationalBridgeOptional.orElseThrow().getBridgeName() != null) {
+ bridge.setName(operationalBridgeOptional.orElseThrow().getBridgeName().getValue());
}
}
OvsdbBridgeAugmentation ovsdbBridge = modifiedBridges.get(bridgeIid);
Optional<ControllerEntry> controllerEntryOptional = state.getControllerEntry(controllerIid);
if (ovsdbBridge != null && controllerEntryOptional.isPresent()) {
- ControllerEntry controllerEntry = controllerEntryOptional.get();
+ ControllerEntry controllerEntry = controllerEntryOptional.orElseThrow();
Bridge bridge = transaction.getTypedRowWrapper(Bridge.class);
bridge.setController(Collections.singleton(new UUID(controllerEntry.getControllerUuid().getValue())));
transaction.add(op.mutate(bridge).addMutation(bridge.getControllerColumn().getSchema(),
Optional<OvsdbBridgeAugmentation> bridgeOptional =
state.getOvsdbBridgeAugmentation(bridgeIid);
OvsdbBridgeAugmentation ovsdbBridge = bridgeOptional.isPresent()
- ? bridgeOptional.get() : bridges.get(bridgeIid);
+ ? bridgeOptional.orElseThrow() : bridges.get(bridgeIid);
if (ovsdbBridge != null
&& ovsdbBridge.getBridgeName() != null
&& entry.getValue() != null
InstanceIdentifier<Node> nodeEntryIid = bridgeIid.firstIdentifierOf(Node.class);
Optional<?> bridgeNode = SouthboundUtil.readNode(db.newReadWriteTransaction(),nodeEntryIid);
- if (bridgeNode.isPresent() && bridgeNode.get() instanceof Node) {
- Node node = (Node)bridgeNode.get();
+ if (bridgeNode.isPresent() && bridgeNode.orElseThrow() instanceof Node node) {
OvsdbBridgeAugmentation bridge = node.augmentation(OvsdbBridgeAugmentation.class);
if (bridge != null && bridge.getManagedBy() != null) {
return bridge.getManagedBy().getValue();
Optional<ProtocolEntry> protocolEntryOptional = state.getProtocolEntry(protocolIid);
if (ovsdbBridge != null
&& protocolEntryOptional.isPresent()) {
- ProtocolEntry protocolEntry = protocolEntryOptional.get();
+ ProtocolEntry protocolEntry = protocolEntryOptional.orElseThrow();
if (protocolEntry != null && protocolEntry.getProtocol() != null) {
Bridge bridge = transaction.getTypedRowWrapper(Bridge.class);
String protocolString = SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocolEntry.getProtocol());
state.getOvsdbBridgeAugmentation(bridgeIid);
OvsdbBridgeAugmentation ovsdbBridge;
if (bridgeOptional.isPresent()) {
- ovsdbBridge = bridgeOptional.get();
+ ovsdbBridge = bridgeOptional.orElseThrow();
} else {
ovsdbBridge = bridges.get(bridgeIid);
}
Map<QosEntriesKey, QosEntries> updatedQosEntries = update.getQosEntries();
if (origQosEntries != null && !origQosEntries.isEmpty()) {
for (QosEntries origQosEntry : origQosEntries.values()) {
- OvsdbNodeAugmentation operNode =
- state.getBridgeNode(ovsdbNodeIid).get().augmentation(OvsdbNodeAugmentation.class);
+ OvsdbNodeAugmentation operNode = state.getBridgeNode(ovsdbNodeIid).orElseThrow()
+ .augmentation(OvsdbNodeAugmentation.class);
if (updatedQosEntries == null || !updatedQosEntries.containsKey(origQosEntry.key())) {
LOG.debug("Received request to delete QoS entry {}", origQosEntry.getQosId());
Uuid qosUuid = getQosEntryUuid(operNode.getQosEntries(), origQosEntry.key());
return;
}
OvsdbNodeAugmentation operNode =
- state.getBridgeNode(iid).get().augmentation(OvsdbNodeAugmentation.class);
+ state.getBridgeNode(iid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
QosEntries qosEntry = qosMapEntry.getValue();
Qos qos = transaction.getTypedRowWrapper(Qos.class);
if (origQueues != null && !origQueues.isEmpty()) {
for (Queues origQueue : origQueues.values()) {
OvsdbNodeAugmentation operNode =
- state.getBridgeNode(ovsdbNodeIid).get().augmentation(
+ state.getBridgeNode(ovsdbNodeIid).orElseThrow().augmentation(
OvsdbNodeAugmentation.class);
if (updatedQueues == null || !updatedQueues.containsKey(origQueue.key())) {
LOG.debug("Received request to delete Queue entry {}", origQueue.getQueueId());
}
OvsdbNodeAugmentation operNode =
- state.getBridgeNode(iid).get().augmentation(OvsdbNodeAugmentation.class);
+ state.getBridgeNode(iid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
Uuid operQueueUuid = getQueueEntryUuid(operNode.getQueues(), queueEntry.key());
if (operQueueUuid == null) {
UUID namedUuid = new UUID(SouthboundConstants.QUEUE_NAMED_UUID_PREFIX
Optional<OvsdbTerminationPointAugmentation> tpAugmentation =
state.getOvsdbTerminationPointAugmentation(removedTpIid);
if (tpAugmentation.isPresent()) {
- OvsdbTerminationPointAugmentation tp = tpAugmentation.get();
+ OvsdbTerminationPointAugmentation tp = tpAugmentation.orElseThrow();
if (tp.getPortUuid() != null) {
UUID portUuid = new UUID(tp.getPortUuid().getValue());
Bridge bridge = transaction.getTypedRowSchema(Bridge.class);
// Bug#6136
Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional = state.getOvsdbBridgeAugmentation(iid);
if (ovsdbBridgeOptional != null && ovsdbBridgeOptional.isPresent()) {
- OvsdbBridgeAugmentation operBridge = ovsdbBridgeOptional.get();
+ OvsdbBridgeAugmentation operBridge = ovsdbBridgeOptional.orElseThrow();
if (operBridge != null) {
Port port = transaction.getTypedRowWrapper(Port.class);
updatePort(terminationPoint, port, operBridge, opendaylightIid);
try (ReadTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction()) {
Optional<Node> nodeOptional = SouthboundUtil.readNode(transaction, iidNode);
if (nodeOptional.isPresent()) {
- operNode = nodeOptional.get().augmentation(OvsdbNodeAugmentation.class);
+ operNode = nodeOptional.orElseThrow().augmentation(OvsdbNodeAugmentation.class);
}
} catch (Exception exp) {
LOG.error("Error in getting the brideNode for {}", iidNode, exp);
@Override
public void onSuccess(@Nullable final Optional<Topology> optionalTopology) {
if (optionalTopology != null && optionalTopology.isPresent()) {
- Map<NodeKey, Node> nodes = optionalTopology.get().getNode();
+ Map<NodeKey, Node> nodes = optionalTopology.orElseThrow().getNode();
if (nodes != null) {
for (Node node : nodes.values()) {
String bridgeNodeIid = node.getNodeId().getValue();
@Override
public void onSuccess(@Nullable final Optional<Node> optionalTopology) {
if (optionalTopology != null && optionalTopology.isPresent()) {
- Node node = optionalTopology.get();
+ Node node = optionalTopology.orElseThrow();
if (node != null) {
bridgeNodeList.add(node);
}
SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
// FIXME: Iterate on external_ids instead of uuid when Open vSwitch supports external_ids column
for (final UUID autoAttachUuid : removedAutoAttachRows.keySet()) {
- final AutoattachKey autoAttachKey = getAutoAttachKeyToRemove(ovsdbNode.get(), autoAttachUuid);
+ final AutoattachKey autoAttachKey = getAutoAttachKeyToRemove(ovsdbNode.orElseThrow(), autoAttachUuid);
if (autoAttachKey != null) {
final InstanceIdentifier<Autoattach> iid = ovsdbNodeIid
.augmentation(OvsdbNodeAugmentation.class)
.child(Autoattach.class, autoAttachKey);
transaction.delete(LogicalDatastoreType.OPERATIONAL, iid);
LOG.debug("AutoAttach table {} for Ovsdb Node {} is deleted", autoAttachUuid,
- ovsdbNode.get().getNodeId());
+ ovsdbNode.orElseThrow().getNodeId());
} else {
LOG.warn("AutoAttach table {} not found for Ovsdb Node {} to delete", autoAttachUuid,
- ovsdbNode.get().getNodeId());
+ ovsdbNode.orElseThrow().getNodeId());
}
}
}
final Optional<Autoattach> optionalAutoattach =
transaction.read(LogicalDatastoreType.OPERATIONAL, currentIid).get();
if (optionalAutoattach.isPresent()) {
- currentAutoattach = optionalAutoattach.get();
+ currentAutoattach = optionalAutoattach.orElseThrow();
}
} catch (final InterruptedException | ExecutionException e) {
LOG.debug("AutoAttach table entries not found in operational datastore, need to create it.", e);
final Autoattach autoAttachEntry = autoAttachBuilder.build();
LOG.trace("Update Ovsdb Node {} with AutoAttach table entries {}",
- ovsdbNode.get().getNodeId(), autoAttachEntry);
+ ovsdbNode.orElseThrow().getNodeId(), autoAttachEntry);
final InstanceIdentifier<Autoattach> iid = nodeIId
.augmentation(OvsdbNodeAugmentation.class)
.child(Autoattach.class, autoAttachEntry.key());
final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, connectionIId);
if (ovsdbNode.isPresent()) {
- OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.get().augmentation(OvsdbNodeAugmentation.class);
+ OvsdbNodeAugmentation ovsdbNodeAugmentation =
+ ovsdbNode.orElseThrow().augmentation(OvsdbNodeAugmentation.class);
if (ovsdbNodeAugmentation != null) {
- final Map<ManagedNodeEntryKey, ManagedNodeEntry> managedNodeEntries
- = ovsdbNodeAugmentation.getManagedNodeEntry();
+ final Map<ManagedNodeEntryKey, ManagedNodeEntry> managedNodeEntries =
+ ovsdbNodeAugmentation.getManagedNodeEntry();
for (ManagedNodeEntry managedNodeEntry : managedNodeEntries.values()) {
final InstanceIdentifier<Node> bridgeIid =
(InstanceIdentifier<Node>) managedNodeEntry.getBridgeRef().getValue();
final Optional<Node> bridgeNode = SouthboundUtil.readNode(transaction, bridgeIid);
if (bridgeNode.isPresent()) {
- bridgeNodes.put(bridgeIid, bridgeNode.get());
+ bridgeNodes.put(bridgeIid, bridgeNode.orElseThrow());
} else {
LOG.warn("OVSDB bridge node was not found: {}", bridgeIid);
}
final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, connectionIId);
if (ovsdbNode.isPresent()) {
final List<ManagerEntry> managerEntries =
- SouthboundMapper.createManagerEntries(ovsdbNode.get(), newUpdatedManagerRows);
+ SouthboundMapper.createManagerEntries(ovsdbNode.orElseThrow(), newUpdatedManagerRows);
- LOG.debug("Update Ovsdb Node : {} with manager entries : {}",
- ovsdbNode.get(), managerEntries);
+ LOG.debug("Update Ovsdb Node : {} with manager entries : {}", ovsdbNode.orElseThrow(), managerEntries);
for (ManagerEntry managerEntry : managerEntries) {
InstanceIdentifier<ManagerEntry> iid = connectionIId
.augmentation(OvsdbNodeAugmentation.class)
try {
ovsdbNodeOptional = ovsdbNodeFuture.get();
if (ovsdbNodeOptional.isPresent()) {
- Node ovsdbNode = ovsdbNodeOptional.get();
+ Node ovsdbNode = ovsdbNodeOptional.orElseThrow();
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.augmentation(OvsdbNodeAugmentation.class);
if (checkIfOnlyConnectedManager(ovsdbNodeAugmentation)) {
if (ovsdbNodeAugmentation != null) {
}
Optional<Node> node = readNode(transaction, connectionIId);
if (node.isPresent()) {
- updateTerminationPoints(transaction, node.get());
+ updateTerminationPoints(transaction, node.orElseThrow());
}
}
for (Entry<UUID, Port> portUpdate : portUpdatedRows.entrySet()) {
String portName = null;
portName = portUpdate.getValue().getNameColumn().getData();
- Optional<InstanceIdentifier<Node>> bridgeIid = getTerminationPointBridge(portUpdate.getKey());
- if (!bridgeIid.isPresent()) {
- bridgeIid = getTerminationPointBridge(transaction, node, portName);
+ Optional<InstanceIdentifier<Node>> optBridgeIid = getTerminationPointBridge(portUpdate.getKey());
+ if (optBridgeIid.isEmpty()) {
+ optBridgeIid = getTerminationPointBridge(transaction, node, portName);
}
- if (bridgeIid.isPresent()) {
- NodeId bridgeId = SouthboundMapper.createManagedNodeId(bridgeIid.get());
+ if (optBridgeIid.isPresent()) {
+ InstanceIdentifier<Node> bridgeIid = optBridgeIid.orElseThrow();
+ NodeId bridgeId = SouthboundMapper.createManagedNodeId(bridgeIid);
TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName));
- getOvsdbConnectionInstance().updatePortInterface(portName, bridgeIid.get());
+ getOvsdbConnectionInstance().updatePortInterface(portName, bridgeIid);
TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
tpBuilder.withKey(tpKey);
tpBuilder.setTpId(tpKey.getTpId());
InstanceIdentifier<TerminationPoint> tpPath =
- getInstanceIdentifier(bridgeIid.get(), portUpdate.getValue());
+ getInstanceIdentifier(bridgeIid, portUpdate.getValue());
OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
new OvsdbTerminationPointAugmentationBuilder();
buildTerminationPoint(transaction, tpPath, tpAugmentationBuilder, node, portUpdate);
if (getOvsdbConnectionInstance().getPortInterface(interfaceName) != null) {
bridgeIid = Optional.of(getOvsdbConnectionInstance().getPortInterface(interfaceName));
}
- if (!bridgeIid.isPresent()) {
+ if (bridgeIid.isEmpty()) {
bridgeIid = getTerminationPointBridge(transaction, node, interfaceName);
}
if (bridgeIid.isPresent()) {
new OvsdbTerminationPointAugmentationBuilder();
buildTerminationPoint(tpAugmentationBuilder, interfaceUpdate.getValue());
tpBuilder.addAugmentation(tpAugmentationBuilder.build());
- NodeId bridgeId = SouthboundMapper.createManagedNodeId(bridgeIid.get());
+ NodeId bridgeId = SouthboundMapper.createManagedNodeId(bridgeIid.orElseThrow());
InstanceIdentifier<TerminationPoint> tpPath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
protected void updateToDataStore(ReadWriteTransaction transaction, TerminationPointBuilder tpBuilder,
InstanceIdentifier<TerminationPoint> tpPath, boolean merge) {
if (merge) {
- transaction.merge(LogicalDatastoreType.OPERATIONAL,
- tpPath, tpBuilder.build());
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, tpPath, tpBuilder.build());
} else {
- transaction.put(LogicalDatastoreType.OPERATIONAL,
- tpPath, tpBuilder.build());
+ transaction.put(LogicalDatastoreType.OPERATIONAL, tpPath, tpBuilder.build());
}
}
Optional<Node> optManagedNode = SouthboundUtil.readNode(transaction,
(InstanceIdentifier<Node>)managedNodeEntry.getBridgeRef().getValue());
if (optManagedNode.isPresent()) {
- Node managedNode = optManagedNode.get();
+ Node managedNode = optManagedNode.orElseThrow();
Map<TerminationPointKey, TerminationPoint> tpEntrys = managedNode.getTerminationPoint();
if (tpEntrys != null) {
TerminationPoint tpEntry = tpEntrys.get(new TerminationPointKey(tpId));
InstanceIdentifier<Node> ovsdbNodeIid =
SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
for (UUID qosUuid : removedQosRows.keySet()) {
- QosEntriesKey qosKey = getQosEntriesKey(ovsdbNode.get(), qosUuid);
+ QosEntriesKey qosKey = getQosEntriesKey(ovsdbNode.orElseThrow(), qosUuid);
if (qosKey != null) {
InstanceIdentifier<QosEntries> iid = ovsdbNodeIid
.augmentation(OvsdbNodeAugmentation.class)
QosEntriesBuilder qosEntryBuilder = new QosEntriesBuilder();
qosEntryBuilder.setQosId(new Uri(getQosId(qos)));
qosEntryBuilder.setQosUuid(new Uuid(entry.getKey().toString()));
- qosEntryBuilder.setQosType(
- SouthboundMapper.createQosType(qos.getTypeColumn().getData()));
+ qosEntryBuilder.setQosType(SouthboundMapper.createQosType(qos.getTypeColumn().getData()));
Qos oldQos = oldQosRows.get(entry.getKey());
setOtherConfig(transaction, qosEntryBuilder, oldQos, qos, nodeIId);
setExternalIds(transaction, qosEntryBuilder, oldQos, qos, nodeIId);
- setQueueList(transaction, qosEntryBuilder, oldQos, qos, nodeIId, ovsdbNode.get());
+ setQueueList(transaction, qosEntryBuilder, oldQos, qos, nodeIId, ovsdbNode.orElseThrow());
QosEntries qosEntry = qosEntryBuilder.build();
- LOG.debug("Update Ovsdb Node {} with qos entries {}",ovsdbNode.get(), qosEntry);
+ LOG.debug("Update Ovsdb Node {} with qos entries {}", ovsdbNode.orElseThrow(), qosEntry);
InstanceIdentifier<QosEntries> iid = nodeIId
.augmentation(OvsdbNodeAugmentation.class)
.child(QosEntries.class, qosEntry.key());
- transaction.merge(LogicalDatastoreType.OPERATIONAL,
- iid, qosEntry);
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, iid, qosEntry);
}
}
}
InstanceIdentifier<Node> ovsdbNodeIid =
SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
for (UUID queueUuid : removedQueueRows.keySet()) {
- QueuesKey queueKey = getQueueKey(ovsdbNode.get(), queueUuid);
+ QueuesKey queueKey = getQueueKey(ovsdbNode.orElseThrow(), queueUuid);
if (queueKey != null) {
InstanceIdentifier<Queues> iid = ovsdbNodeIid
.augmentation(OvsdbNodeAugmentation.class)
setExternalIds(transaction, queuesBuilder, oldQueue, queue, nodeIId);
Queues queues = queuesBuilder.build();
- LOG.debug("Update Ovsdb Node {} with queue entries {}",ovsdbNode.get(), queues);
+ LOG.debug("Update Ovsdb Node {} with queue entries {}",ovsdbNode.orElseThrow(), queues);
InstanceIdentifier<Queues> iid = nodeIId
.augmentation(OvsdbNodeAugmentation.class)
.child(Queues.class, queues.key());
@Test
public void testGetBridgeNode() {
- Optional<Node> optNodes = briOperationState.getBridgeNode(nodeIid);
- assertEquals(brNode, optNodes.get());
+ assertEquals(Optional.of(brNode), briOperationState.getBridgeNode(nodeIid));
}
@Test
Optional<OvsdbBridgeAugmentation> ovsdbBriAugOptional = briOperationState.getOvsdbBridgeAugmentation(
InstanceIdentifier.create(NetworkTopology.class));
assertNotNull(ovsdbBriAugOptional);
- assertTrue(ovsdbBriAugOptional.get() instanceof OvsdbBridgeAugmentation);
+ assertTrue(ovsdbBriAugOptional.orElseThrow() instanceof OvsdbBridgeAugmentation);
}
@Test
Optional<OvsdbTerminationPointAugmentation> ovsdbTermPointOpt = briOperationState
.getOvsdbTerminationPointAugmentation(InstanceIdentifier.create(NetworkTopology.class));
assertNotNull(ovsdbTermPointOpt);
- assertTrue(ovsdbTermPointOpt.get() instanceof OvsdbTerminationPointAugmentation);
+ assertTrue(ovsdbTermPointOpt.orElseThrow() instanceof OvsdbTerminationPointAugmentation);
}
@Test
final LogicalDatastoreType store, final InstanceIdentifier<? extends DataObject> path) {
Optional<D> optionalDataObject = readOptional(store, path);
if (optionalDataObject.isPresent()) {
- return optionalDataObject.get();
+ return optionalDataObject.orElseThrow();
}
LOG.debug("{}: Failed to read {}",
Thread.currentThread().getStackTrace()[1], path);
Optional<Node> optNode;
try {
optNode = future.get();
- if (optNode.isPresent()) {
- assertEquals(DATA, optNode.get());
- } else {
- fail("Couldn't read node");
- }
+ assertEquals(Optional.of(DATA), optNode);
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
final Optional<Node> result = databroker.newReadOnlyTransaction().read(
LogicalDatastoreType.CONFIGURATION, TEST_IID).get();
if (result.isPresent()) {
- return result.get();
+ return result.orElseThrow();
}
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());