From c0eafe22072817c90e775822b7bd6e643a40c221 Mon Sep 17 00:00:00 2001 From: Ruth Devlaeminck Date: Wed, 28 Feb 2018 19:26:18 +0000 Subject: [PATCH] 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. --- .../openbaton/vim_impl/vim/GenericVIM.java | 98 ++++++++++++++++--- 1 file changed, 85 insertions(+), 13 deletions(-) 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 dc7fa2e21..dc8131c03 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; }