Skip to content

Commit dddc648

Browse files
Jayapalyadvr
authored andcommitted
CLOUDSTACK-6578: Fixed issue in delete remote access vpn command
(cherry picked from commit 4083634) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Conflicts: api/src/com/cloud/network/vpn/RemoteAccessVpnService.java server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
1 parent 6ad3ae7 commit dddc648

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

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

3434
RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall)
3535
throws NetworkRuleConflictException;
36-
void destroyRemoteAccessVpnForIp(long vpnServerAddressId, Account caller) throws ResourceUnavailableException;
36+
37+
boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException;
38+
3739
RemoteAccessVpn startRemoteAccessVpn(long vpnServerAddressId, boolean openFirewall) throws ResourceUnavailableException;
3840

3941
VpnUser addVpnUser(long vpnOwnerId, String userName, String password);

‎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
@@ -18,6 +18,8 @@
1818

1919
import org.apache.cloudstack.api.APICommand;
2020
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.ApiErrorCode;
22+
import org.apache.cloudstack.api.ServerApiException;
2123
import org.apache.cloudstack.api.BaseAsyncCmd;
2224
import org.apache.cloudstack.api.Parameter;
2325
import org.apache.cloudstack.api.response.AccountResponse;
@@ -85,7 +87,9 @@ public String getEventType() {
8587

8688
@Override
8789
public void execute() throws ResourceUnavailableException {
88-
_ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount());
90+
if (! _ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount())) {
91+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete remote access vpn");
92+
}
8993
}
9094

9195
@Override

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,18 @@ private void validateRemoteAccessVpnConfiguration() throws ConfigurationExceptio
261261
}
262262
}
263263

264-
@Override @DB
265-
public void destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
264+
@Override
265+
@DB
266+
public boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
266267
final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByPublicIpAddress(ipId);
267268
if (vpn == null) {
268269
s_logger.debug("there are no Remote access vpns for public ip address id=" + ipId);
269-
return;
270+
return true;
270271
}
271272

272273
_accountMgr.checkAccess(caller, null, true, vpn);
273274

275+
RemoteAccessVpn.State prevState = vpn.getState();
274276
vpn.setState(RemoteAccessVpn.State.Removed);
275277
_remoteAccessVpnDao.update(vpn.getId(), vpn);
276278

@@ -282,6 +284,12 @@ public void destroyRemoteAccessVpnForIp(long ipId, Account caller) throws Resour
282284
break;
283285
}
284286
}
287+
}catch (ResourceUnavailableException ex) {
288+
vpn.setState(prevState);
289+
_remoteAccessVpnDao.update(vpn.getId(), vpn);
290+
s_logger.debug("Failed to stop the vpn " + vpn.getId() + " , so reverted state to "+
291+
RemoteAccessVpn.State.Running);
292+
success = false;
285293
} finally {
286294
if (success) {
287295
//Cleanup corresponding ports
@@ -342,6 +350,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
342350
}
343351
}
344352
}
353+
return success;
345354
}
346355

347356
@Override

0 commit comments

Comments
 (0)