Skip to content

Commit af657b3

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. Conflicts: api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java server/src/com/cloud/user/DomainManagerImpl.java
1 parent 470f251 commit af657b3

10 files changed

Lines changed: 25 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long ne
6464

6565
Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd cmd);
6666

67-
boolean deleteNetwork(long networkId);
67+
boolean deleteNetwork(long networkId, boolean forced);
6868

6969
boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
7070

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class DeleteNetworkCmd extends BaseAsyncCmd {
4545
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = NetworkResponse.class, required = true, description = "the ID of the network")
4646
private Long id;
4747

48+
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a network." +
49+
" Network will be marked as 'Destroy' even when commands to shutdown and cleanup to the backend fails.")
50+
private Boolean forced;
51+
4852
/////////////////////////////////////////////////////
4953
/////////////////// Accessors ///////////////////////
5054
/////////////////////////////////////////////////////
@@ -53,6 +57,10 @@ public Long getId() {
5357
return id;
5458
}
5559

60+
public boolean isForced() {
61+
return (forced != null) ? forced : false;
62+
}
63+
5664
/////////////////////////////////////////////////////
5765
/////////////// API Implementation///////////////////
5866
/////////////////////////////////////////////////////
@@ -65,7 +73,7 @@ public String getCommandName() {
6573
@Override
6674
public void execute() {
6775
CallContext.current().setEventDetails("Network Id: " + id);
68-
boolean result = _networkService.deleteNetwork(id);
76+
boolean result = _networkService.deleteNetwork(id, isForced());
6977
if (result) {
7078
SuccessResponse response = new SuccessResponse(getCommandName());
7179
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
@@ -125,7 +125,7 @@ void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationC
125125

126126
boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements);
127127

128-
boolean destroyNetwork(long networkId, ReservationContext context);
128+
boolean destroyNetwork(long networkId, ReservationContext context, boolean forced);
129129

130130
Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner,
131131
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
@@ -2068,7 +2068,7 @@ public boolean shutdownNetworkElementsAndResources(ReservationContext context, b
20682068

20692069
@Override
20702070
@DB
2071-
public boolean destroyNetwork(long networkId, final ReservationContext context) {
2071+
public boolean destroyNetwork(long networkId, final ReservationContext context, boolean forced) {
20722072
final Account callerAccount = context.getAccount();
20732073

20742074
NetworkVO network = _networksDao.findById(networkId);
@@ -2111,7 +2111,7 @@ public boolean destroyNetwork(long networkId, final ReservationContext context)
21112111

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

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
@@ -179,7 +179,7 @@ private void purgeTestNetwork() {
179179
List<? extends Network> list = _networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system);
180180
for (Network net : list) {
181181
s_logger.debug("Delete network " + net.getName());
182-
_networkService.deleteNetwork(net.getId());
182+
_networkService.deleteNetwork(net.getId(), false);
183183
}
184184
}
185185

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

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

17631763
@Override
17641764
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_DELETE, eventDescription = "deleting network", async = true)
1765-
public boolean deleteNetwork(long networkId) {
1765+
public boolean deleteNetwork(long networkId, boolean forced) {
17661766

17671767
Account caller = CallContext.current().getCallingAccount();
17681768

@@ -1788,10 +1788,14 @@ public boolean deleteNetwork(long networkId) {
17881788
// Perform permission check
17891789
_accountMgr.checkAccess(caller, null, true, network);
17901790

1791+
if (forced && !_accountMgr.isRootAdmin(caller.getType())) {
1792+
throw new InvalidParameterValueException("Delete network with 'forced' option can only be called by root admins");
1793+
}
1794+
17911795
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
17921796
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
17931797

1794-
return _networkMgr.destroyNetwork(networkId, context);
1798+
return _networkMgr.destroyNetwork(networkId, context, forced);
17951799
}
17961800

17971801
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
15651565
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
15661566
Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
15671567
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
1568-
_ntwkMgr.destroyNetwork(networkId, context);
1568+
_ntwkMgr.destroyNetwork(networkId, context, false);
15691569
s_logger.debug("Deleted private network id=" + networkId);
15701570
}
15711571

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ private boolean cleanupDomain(Long domainId, Long ownerId) throws ConcurrentOper
395395
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), ctx.getCallingAccount());
396396
for (Long networkId : networkIds) {
397397
s_logger.debug("Deleting network id=" + networkId + " as a part of domain id=" + domainId + " cleanup");
398-
399-
if (!_networkMgr.destroyNetwork(networkId, context)) {
398+
if (!_networkMgr.destroyNetwork(networkId, context, false)) {
400399
s_logger.warn("Unable to destroy network id=" + networkId + " as a part of domain id=" + domainId + " cleanup.");
401400
networksDeleted = false;
402401
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd
203203
* @see com.cloud.network.NetworkService#deleteNetwork(long)
204204
*/
205205
@Override
206-
public boolean deleteNetwork(long networkId) {
206+
public boolean deleteNetwork(long networkId, boolean forced) {
207207
// TODO Auto-generated method stub
208208
return false;
209209
}
@@ -597,7 +597,7 @@ public boolean shutdownNetwork(long networkId, ReservationContext context, boole
597597
* @see com.cloud.network.NetworkManager#destroyNetwork(long, com.cloud.vm.ReservationContext)
598598
*/
599599
@Override
600-
public boolean destroyNetwork(long networkId, ReservationContext context) {
600+
public boolean destroyNetwork(long networkId, ReservationContext context, boolean forced) {
601601
// TODO Auto-generated method stub
602602
return false;
603603
}

0 commit comments

Comments
 (0)