Skip to content

Commit

Permalink
Merge pull request #277 from openbaton/issue-32
Browse files Browse the repository at this point in the history
Delete network if network creation (subnet and router) fails
  • Loading branch information
lorenzotomasini authored Apr 12, 2018
2 parents 8614868 + 8dd765b commit 1c50a8f
Showing 1 changed file with 85 additions and 13 deletions.
98 changes: 85 additions & 13 deletions vim-impl/src/main/java/org/openbaton/vim_impl/vim/GenericVIM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Subnet> createdSubnets = new HashSet<>();
for (Subnet subnet : osNetowork.getSubnets()) {
for (Subnet subnet : osNetwork.getSubnets()) {
try {
log.debug(
"Creating Subnet with name: "
Expand Down Expand Up @@ -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);
Expand All @@ -659,7 +731,7 @@ public BaseNetwork add(BaseVimInstance vimInstance, BaseNetwork network) throws
+ " on VimInstnace "
+ vimInstance.getName()
+ " -> Subnets: "
+ osNetowork.getSubnets());
+ osNetwork.getSubnets());
}
return createdNetwork;
}
Expand Down

0 comments on commit 1c50a8f

Please sign in to comment.