If anything in the creation of the network/subnet/router fails or if the attach of the subnet to the router fails delete the entire network/subnet/router chain that was just created.
@@ -588,16 +588,17 @@ public class GenericVIM extends Vim {
e);
}
if (network instanceof Network) {
- Network osNetowork = (Network) network;
+ Network osNetwork = (Network) network;
log.debug(
"Creating Subnets for Network with name: "
+ network.getName()
+ " on VimInstance "
+ vimInstance.getName()
+ " -> Subnets: "
- + osNetowork.getSubnets());
+ + osNetwork.getSubnets());
+ VimException vimException = null;
Set<Subnet> createdSubnets = new HashSet<>();
- for (Subnet subnet : osNetowork.getSubnets()) {
+ for (Subnet subnet : osNetwork.getSubnets()) {
try {
log.debug(
"Creating Subnet with name: "
@@ -639,7 +640,8 @@ public class GenericVIM extends Vim {
+ ". Caused by: "
+ e.getMessage());
}
- throw new VimException(
+ vimException =
+ new VimException(
"Not created Subnet with name: "
+ subnet.getName()
+ " successfully on Network with name: "
@@ -649,7 +651,77 @@ public class GenericVIM extends Vim {
+ ". Caused by: "
+ e.getMessage(),
e);
+ break;
+ }
+ }
+
+ // if there was an error creating the subnets delete any subnets that were created
+ if (null != vimException) {
+ for (Subnet subnet : createdSubnets) {
+ try {
+ log.debug(
+ "Deleting Subnet with name: "
+ + subnet.getName()
+ + " on Network with name: "
+ + network.getName()
+ + " on VimInstance "
+ + vimInstance.getName());
+ client.deleteSubnet(vimInstance, subnet.getExtId());
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.error(
+ "Not deleted Subnet with name: "
+ + subnet.getName()
+ + " successfully on Network with name: "
+ + network.getName()
+ + " on VimInstnace "
+ + vimInstance.getName()
+ + ". Caused by: "
+ + e.getMessage(),
+ e);
+ } else {
+ log.error(
+ "Not deleted Subnet with name: "
+ + subnet.getName()
+ + " successfully on Network with name: "
+ + network.getName()
+ + " on VimInstnace "
+ + vimInstance.getName()
+ + ". Caused by: "
+ + e.getMessage());
+ }
+ }
+ }
+
+ try {
+ log.debug(
+ "Deleting Network with name: "
+ + network.getName()
+ + " on VimInstance "
+ + vimInstance.getName());
+ client.deleteNetwork(vimInstance, createdNetwork.getExtId());
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.error(
+ "Not deleted Network with name: "
+ + network.getName()
+ + " successfully on VimInstance "
+ + vimInstance.getName()
+ + ". Caused by: "
+ + e.getMessage(),
+ e);
+ } else {
+ log.error(
+ "Not deleted Network with name: "
+ + network.getName()
+ + " successfully on VimInstance "
+ + vimInstance.getName()
+ + ". Caused by: "
+ + e.getMessage());
+ }
}
+
+ throw vimException;
}
((Network) createdNetwork).setSubnets(createdSubnets);
@@ -659,7 +731,7 @@ public class GenericVIM extends Vim {
+ " on VimInstnace "
+ vimInstance.getName()
+ " -> Subnets: "
- + osNetowork.getSubnets());
+ + osNetwork.getSubnets());
}
return createdNetwork;
}
