diff --git a/vim-impl/src/main/java/org/openbaton/vim_impl/vim/GenericVIM.java b/vim-impl/src/main/java/org/openbaton/vim_impl/vim/GenericVIM.java index 3f52e6e71..ef21c9678 100644 --- a/vim-impl/src/main/java/org/openbaton/vim_impl/vim/GenericVIM.java +++ b/vim-impl/src/main/java/org/openbaton/vim_impl/vim/GenericVIM.java @@ -588,16 +588,17 @@ public BaseNetwork add(BaseVimInstance vimInstance, BaseNetwork network) throws 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 createdSubnets = new HashSet<>(); - for (Subnet subnet : osNetowork.getSubnets()) { + for (Subnet subnet : osNetwork.getSubnets()) { try { log.debug( "Creating Subnet with name: " @@ -639,17 +640,88 @@ public BaseNetwork add(BaseVimInstance vimInstance, BaseNetwork network) throws + ". Caused by: " + e.getMessage()); } - throw new VimException( - "Not created Subnet with name: " - + subnet.getName() - + " successfully on Network with name: " + vimException = + new VimException( + "Not created Subnet with name: " + + subnet.getName() + + " successfully on Network with name: " + + network.getName() + + " on VimInstnace " + + vimInstance.getName() + + ". 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 VimInstnace " - + vimInstance.getName() - + ". Caused by: " - + e.getMessage(), - e); + + " 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 BaseNetwork add(BaseVimInstance vimInstance, BaseNetwork network) throws + " on VimInstnace " + vimInstance.getName() + " -> Subnets: " - + osNetowork.getSubnets()); + + osNetwork.getSubnets()); } return createdNetwork; }