Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete network if network creation (subnet and router) fails #277

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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