Skip to content

Commit b6698f3

Browse files
committed
CLOUDSTACK-5861: networks that failed to implement can not be destroyed
introduces a force option in delete network to forcifully delete a network. This comes handy in rare cases where network fails to implenet and network is in shutdown state, but network shutdown to rollback implement process fails as well.
1 parent e1a15ea commit b6698f3

10 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎api/src/com/cloud/network/NetworkService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityExce
6666

6767
Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd cmd);
6868

69-
boolean deleteNetwork(long networkId);
69+
boolean deleteNetwork(long networkId, boolean forced);
7070

7171
boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException,
7272
ResourceUnavailableException, InsufficientCapacityException;

‎api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class DeleteNetworkCmd extends BaseAsyncCmd{
4646
required=true, description="the ID of the network")
4747
private Long id;
4848

49+
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a network." +
50+
" Network will be marked as 'Destroy' even when commands to shutdown and cleanup to the backend fails.")
51+
private Boolean forced;
4952

5053
/////////////////////////////////////////////////////
5154
/////////////////// Accessors ///////////////////////
@@ -55,6 +58,9 @@ public Long getId() {
5558
return id;
5659
}
5760

61+
public boolean isForced() {
62+
return (forced != null) ? forced : false;
63+
}
5864

5965
/////////////////////////////////////////////////////
6066
/////////////// API Implementation///////////////////
@@ -68,7 +74,7 @@ public String getCommandName() {
6874
@Override
6975
public void execute(){
7076
CallContext.current().setEventDetails("Network Id: " + id);
71-
boolean result = _networkService.deleteNetwork(id);
77+
boolean result = _networkService.deleteNetwork(id, isForced());
7278
if (result) {
7379
SuccessResponse response = new SuccessResponse(getCommandName());
7480
this.setResponseObject(response);

‎engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationC
123123

124124
boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements);
125125

126-
boolean destroyNetwork(long networkId, ReservationContext context);
126+
boolean destroyNetwork(long networkId, ReservationContext context, boolean forced);
127127

128128
Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner,
129129
Long domainId, PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,

‎engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ public boolean shutdownNetworkElementsAndResources(ReservationContext context, b
20702070

20712071
@Override
20722072
@DB
2073-
public boolean destroyNetwork(long networkId, final ReservationContext context) {
2073+
public boolean destroyNetwork(long networkId, final ReservationContext context, boolean forced) {
20742074
final Account callerAccount = context.getAccount();
20752075

20762076
NetworkVO network = _networksDao.findById(networkId);
@@ -2113,7 +2113,7 @@ public boolean destroyNetwork(long networkId, final ReservationContext context)
21132113

21142114
// get updated state for the network
21152115
network = _networksDao.findById(networkId);
2116-
if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup) {
2116+
if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup && !forced) {
21172117
s_logger.debug("Network is not not in the correct state to be destroyed: " + network.getState());
21182118
return false;
21192119
}

‎plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private void purgeTestNetwork() {
177177
_networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system);
178178
for (Network net : list) {
179179
s_logger.debug("Delete network " + net.getName());
180-
_networkService.deleteNetwork(net.getId());
180+
_networkService.deleteNetwork(net.getId(), false);
181181
}
182182
}
183183

‎server/src/com/cloud/network/NetworkServiceImpl.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ private List<NetworkVO> listDomainSpecificNetworksByDomainPath(SearchCriteria<Ne
17701770

17711771
@Override
17721772
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_DELETE, eventDescription = "deleting network", async = true)
1773-
public boolean deleteNetwork(long networkId) {
1773+
public boolean deleteNetwork(long networkId, boolean forced) {
17741774

17751775
Account caller = CallContext.current().getCallingAccount();
17761776

@@ -1796,10 +1796,14 @@ public boolean deleteNetwork(long networkId) {
17961796
// Perform permission check
17971797
_accountMgr.checkAccess(caller, null, true, network);
17981798

1799+
if (forced && !_accountMgr.isRootAdmin(caller.getType())) {
1800+
throw new InvalidParameterValueException("Delete network with 'forced' option can only be called by root admins");
1801+
}
1802+
17991803
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
18001804
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
18011805

1802-
return _networkMgr.destroyNetwork(networkId, context);
1806+
return _networkMgr.destroyNetwork(networkId, context, forced);
18031807
}
18041808

18051809
@Override

‎server/src/com/cloud/network/vpc/VpcManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
16051605
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
16061606
Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
16071607
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
1608-
_ntwkMgr.destroyNetwork(networkId, context);
1608+
_ntwkMgr.destroyNetwork(networkId, context, false);
16091609
s_logger.debug("Deleted private network id=" + networkId);
16101610
}
16111611

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ protected boolean cleanupAccount(AccountVO account, long callerUserId, Account c
679679

680680
ReservationContext context = new ReservationContextImpl(null, null, getActiveUser(callerUserId), caller);
681681

682-
if (!_networkMgr.destroyNetwork(network.getId(), context)) {
682+
if (!_networkMgr.destroyNetwork(network.getId(), context, false)) {
683683
s_logger.warn("Unable to destroy network " + network + " as a part of account id=" + accountId + " cleanup.");
684684
accountCleanupNeeded = true;
685685
networksDeleted = false;

‎server/src/com/cloud/user/DomainManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private boolean cleanupDomain(Long domainId, Long ownerId) throws ConcurrentOper
390390
for (Long networkId : networkIds) {
391391
s_logger.debug("Deleting network id=" + networkId + " as a part of domain id=" + domainId + " cleanup");
392392

393-
if (!_networkMgr.destroyNetwork(networkId, context)) {
393+
if (!_networkMgr.destroyNetwork(networkId, context, false)) {
394394
s_logger.warn("Unable to destroy network id=" + networkId + " as a part of domain id=" + domainId + " cleanup.");
395395
networksDeleted = false;
396396
} else {

‎server/test/com/cloud/vpc/MockNetworkManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd
237237
* @see com.cloud.network.NetworkService#deleteNetwork(long)
238238
*/
239239
@Override
240-
public boolean deleteNetwork(long networkId) {
240+
public boolean deleteNetwork(long networkId, boolean forced) {
241241
// TODO Auto-generated method stub
242242
return false;
243243
}
@@ -792,7 +792,7 @@ public boolean shutdownNetwork(long networkId, ReservationContext context, boole
792792
* @see com.cloud.network.NetworkManager#destroyNetwork(long, com.cloud.vm.ReservationContext)
793793
*/
794794
@Override
795-
public boolean destroyNetwork(long networkId, ReservationContext context) {
795+
public boolean destroyNetwork(long networkId, ReservationContext context, boolean forced) {
796796
// TODO Auto-generated method stub
797797
return false;
798798
}

0 commit comments

Comments
 (0)