Skip to content

Commit 4083634

Browse files
author
Jayapal
committed
CLOUDSTACK-6578: Fixed issue in delete remote access vpn command
1 parent b9b623b commit 4083634

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

api/src/com/cloud/network/vpn/RemoteAccessVpnService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface RemoteAccessVpnService {
3333

3434
RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, Boolean forDisplay) throws NetworkRuleConflictException;
3535

36-
void destroyRemoteAccessVpnForIp(long vpnServerAddressId, Account caller) throws ResourceUnavailableException;
36+
boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException;
3737

3838
RemoteAccessVpn startRemoteAccessVpn(long vpnServerAddressId, boolean openFirewall) throws ResourceUnavailableException;
3939

api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import org.apache.cloudstack.api.APICommand;
2222
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.ApiErrorCode;
24+
import org.apache.cloudstack.api.ServerApiException;
2325
import org.apache.cloudstack.api.BaseAsyncCmd;
2426
import org.apache.cloudstack.api.Parameter;
2527
import org.apache.cloudstack.api.response.AccountResponse;
@@ -91,7 +93,9 @@ public String getEventType() {
9193

9294
@Override
9395
public void execute() throws ResourceUnavailableException {
94-
_ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount());
96+
if (! _ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount())) {
97+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete remote access vpn");
98+
}
9599
}
96100

97101
@Override

server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,16 @@ private void validateRemoteAccessVpnConfiguration() throws ConfigurationExceptio
285285

286286
@Override
287287
@DB
288-
public void destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
288+
public boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
289289
final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByPublicIpAddress(ipId);
290290
if (vpn == null) {
291291
s_logger.debug("there are no Remote access vpns for public ip address id=" + ipId);
292-
return;
292+
return true;
293293
}
294294

295295
_accountMgr.checkAccess(caller, AccessType.OperateEntry, vpn);
296296

297+
RemoteAccessVpn.State prevState = vpn.getState();
297298
vpn.setState(RemoteAccessVpn.State.Removed);
298299
_remoteAccessVpnDao.update(vpn.getId(), vpn);
299300

@@ -305,6 +306,12 @@ public void destroyRemoteAccessVpnForIp(long ipId, Account caller) throws Resour
305306
break;
306307
}
307308
}
309+
}catch (ResourceUnavailableException ex) {
310+
vpn.setState(prevState);
311+
_remoteAccessVpnDao.update(vpn.getId(), vpn);
312+
s_logger.debug("Failed to stop the vpn " + vpn.getId() + " , so reverted state to "+
313+
RemoteAccessVpn.State.Running);
314+
success = false;
308315
} finally {
309316
if (success) {
310317
//Cleanup corresponding ports
@@ -366,6 +373,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
366373
}
367374
}
368375
}
376+
return success;
369377
}
370378

371379
@Override

0 commit comments

Comments
 (0)