Merge pull request #1874 from Accelerite/RAvpn

CLOUDSTACK-9711: Fixed error reporting while adding vpn user
If configuring vpn user in one of the network fails the failure is ignored, failure should be shown in API response.

* pr/1874:
  CLOUDSTACK-9711: Fixed error reporting while adding vpn user

Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
This commit is contained in:
Rajani Karuturi 2017-02-21 05:41:09 +05:30
commit 3582c653f6
4 changed files with 23 additions and 6 deletions

View File

@ -43,7 +43,7 @@ public interface RemoteAccessVpnService {
List<? extends VpnUser> listVpnUsers(long vpnOwnerId, String userName); List<? extends VpnUser> listVpnUsers(long vpnOwnerId, String userName);
boolean applyVpnUsers(long vpnOwnerId, String userName); boolean applyVpnUsers(long vpnOwnerId, String userName) throws ResourceUnavailableException;
Pair<List<? extends RemoteAccessVpn>, Integer> searchForRemoteAccessVpns(ListRemoteAccessVpnsCmd cmd); Pair<List<? extends RemoteAccessVpn>, Integer> searchForRemoteAccessVpns(ListRemoteAccessVpnsCmd cmd);

View File

@ -119,8 +119,12 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd {
public void execute() { public void execute() {
VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId()); VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId()); Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) { try {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user"); if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
}
}catch (Exception ex) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user due to resource unavailable");
} }
VpnUsersResponse vpnResponse = new VpnUsersResponse(); VpnUsersResponse vpnResponse = new VpnUsersResponse();

View File

@ -115,9 +115,14 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user");
} }
if (!_ravService.applyVpnUsers(owner.getId(), userName)) { try {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal"); if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal");
}
}catch (Exception ex) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user due to resource unavailable");
} }
SuccessResponse response = new SuccessResponse(getCommandName()); SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response); setResponseObject(response);
} }

View File

@ -501,13 +501,14 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@DB @DB
@Override @Override
public boolean applyVpnUsers(long vpnOwnerId, String userName) { public boolean applyVpnUsers(long vpnOwnerId, String userName) throws ResourceUnavailableException {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
Account owner = _accountDao.findById(vpnOwnerId); Account owner = _accountDao.findById(vpnOwnerId);
_accountMgr.checkAccess(caller, null, true, owner); _accountMgr.checkAccess(caller, null, true, owner);
s_logger.debug("Applying vpn users for " + owner); s_logger.debug("Applying vpn users for " + owner);
List<RemoteAccessVpnVO> vpns = _remoteAccessVpnDao.findByAccount(vpnOwnerId); List<RemoteAccessVpnVO> vpns = _remoteAccessVpnDao.findByAccount(vpnOwnerId);
RemoteAccessVpnVO vpnTemp = null;
List<VpnUserVO> users = _vpnUsersDao.listByAccount(vpnOwnerId); List<VpnUserVO> users = _vpnUsersDao.listByAccount(vpnOwnerId);
@ -537,12 +538,14 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
} else { } else {
finals[i] = false; finals[i] = false;
success = false; success = false;
vpnTemp = vpn;
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
s_logger.warn("Unable to apply vpn users ", e); s_logger.warn("Unable to apply vpn users ", e);
success = false; success = false;
vpnTemp = vpn;
for (int i = 0; i < finals.length; i++) { for (int i = 0; i < finals.length; i++) {
finals[i] = false; finals[i] = false;
@ -575,6 +578,11 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
} }
} }
if (!success) {
throw new ResourceUnavailableException("Failed add vpn user due to Resource unavailable ",
RemoteAccessVPNServiceProvider.class, vpnTemp.getId());
}
return success; return success;
} }