Skip to content

Commit d7b792c

Browse files
committed
CLOUDSTACK-9711: Fixed error reporting while adding vpn user
1 parent 8bd33d3 commit d7b792c

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

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

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

4444
List<? extends VpnUser> listVpnUsers(long vpnOwnerId, String userName);
4545

46-
boolean applyVpnUsers(long vpnOwnerId, String userName);
46+
boolean applyVpnUsers(long vpnOwnerId, String userName) throws ResourceUnavailableException;
4747

4848
Pair<List<? extends RemoteAccessVpn>, Integer> searchForRemoteAccessVpns(ListRemoteAccessVpnsCmd cmd);
4949

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ public String getEventType() {
119119
public void execute() {
120120
VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
121121
Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
122-
if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
123-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
122+
try {
123+
if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
124+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
125+
}
126+
}catch (Exception ex) {
127+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user due to resource unavailable");
124128
}
125129

126130
VpnUsersResponse vpnResponse = new VpnUsersResponse();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,14 @@ public void execute() {
115115
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user");
116116
}
117117

118-
if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
119-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal");
118+
try {
119+
if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
120+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal");
121+
}
122+
}catch (Exception ex) {
123+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user due to resource unavailable");
120124
}
125+
121126
SuccessResponse response = new SuccessResponse(getCommandName());
122127
setResponseObject(response);
123128
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
501501

502502
@DB
503503
@Override
504-
public boolean applyVpnUsers(long vpnOwnerId, String userName) {
504+
public boolean applyVpnUsers(long vpnOwnerId, String userName) throws ResourceUnavailableException {
505505
Account caller = CallContext.current().getCallingAccount();
506506
Account owner = _accountDao.findById(vpnOwnerId);
507507
_accountMgr.checkAccess(caller, null, true, owner);
508508

509509
s_logger.debug("Applying vpn users for " + owner);
510510
List<RemoteAccessVpnVO> vpns = _remoteAccessVpnDao.findByAccount(vpnOwnerId);
511+
RemoteAccessVpnVO vpnTemp = null;
511512

512513
List<VpnUserVO> users = _vpnUsersDao.listByAccount(vpnOwnerId);
513514

@@ -537,12 +538,14 @@ public boolean applyVpnUsers(long vpnOwnerId, String userName) {
537538
} else {
538539
finals[i] = false;
539540
success = false;
541+
vpnTemp = vpn;
540542
}
541543
}
542544
}
543545
} catch (Exception e) {
544546
s_logger.warn("Unable to apply vpn users ", e);
545547
success = false;
548+
vpnTemp = vpn;
546549

547550
for (int i = 0; i < finals.length; i++) {
548551
finals[i] = false;
@@ -575,6 +578,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
575578
}
576579
}
577580

581+
if (!success) {
582+
throw new ResourceUnavailableException("Failed add vpn user due to Resource unavailable ",
583+
RemoteAccessVPNServiceProvider.class, vpnTemp.getId());
584+
}
585+
578586
return success;
579587
}
580588

0 commit comments

Comments
 (0)