ONOS-6382 fail removal of non-existent virtual network with IllegalStateException
Change-Id: I50a81f79660ff6fc63a5426368f2edbcec993155
diff --git a/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java b/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
index 81a9a3c..529a0cd 100644
--- a/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
+++ b/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
@@ -353,35 +353,35 @@
@Override
public void removeNetwork(NetworkId networkId) {
// Make sure that the virtual network exists before attempting to remove it.
- if (networkExists(networkId)) {
- //Remove all the devices of this network
- Set<VirtualDevice> deviceSet = getDevices(networkId);
- if (deviceSet != null) {
- deviceSet.forEach(virtualDevice -> removeDevice(networkId, virtualDevice.id()));
- }
- //TODO update both maps in one transaction.
+ checkState(networkExists(networkId), "The network does not exist.");
- VirtualNetwork virtualNetwork = networkIdVirtualNetworkMap.remove(networkId);
- if (virtualNetwork == null) {
- return;
- }
- TenantId tenantId = virtualNetwork.tenantId();
-
- Set<NetworkId> networkIdSet = new HashSet<>();
- tenantIdNetworkIdSetMap.get(tenantId).forEach(networkId1 -> {
- if (networkId1.id().equals(networkId.id())) {
- networkIdSet.add(networkId1);
- }
- });
-
- tenantIdNetworkIdSetMap.compute(virtualNetwork.tenantId(), (id, existingNetworkIds) -> {
- if (existingNetworkIds == null || existingNetworkIds.isEmpty()) {
- return new HashSet<>();
- } else {
- return new HashSet<>(Sets.difference(existingNetworkIds, networkIdSet));
- }
- });
+ //Remove all the devices of this network
+ Set<VirtualDevice> deviceSet = getDevices(networkId);
+ if (deviceSet != null) {
+ deviceSet.forEach(virtualDevice -> removeDevice(networkId, virtualDevice.id()));
}
+ //TODO update both maps in one transaction.
+
+ VirtualNetwork virtualNetwork = networkIdVirtualNetworkMap.remove(networkId);
+ if (virtualNetwork == null) {
+ return;
+ }
+ TenantId tenantId = virtualNetwork.tenantId();
+
+ Set<NetworkId> networkIdSet = new HashSet<>();
+ tenantIdNetworkIdSetMap.get(tenantId).forEach(networkId1 -> {
+ if (networkId1.id().equals(networkId.id())) {
+ networkIdSet.add(networkId1);
+ }
+ });
+
+ tenantIdNetworkIdSetMap.compute(virtualNetwork.tenantId(), (id, existingNetworkIds) -> {
+ if (existingNetworkIds == null || existingNetworkIds.isEmpty()) {
+ return new HashSet<>();
+ } else {
+ return new HashSet<>(Sets.difference(existingNetworkIds, networkIdSet));
+ }
+ });
}
/**
@@ -395,6 +395,7 @@
return (networkIdVirtualNetworkMap.containsKey(networkId));
}
+
@Override
public VirtualDevice addDevice(NetworkId networkId, DeviceId deviceId) {
checkState(networkExists(networkId), "The network has not been added.");