mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
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:
commit
3582c653f6
@ -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);
|
||||||
|
|
||||||
|
|||||||
@ -119,9 +119,13 @@ 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());
|
||||||
|
try {
|
||||||
if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
|
if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
|
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();
|
||||||
vpnResponse.setId(vpnUser.getUuid());
|
vpnResponse.setId(vpnUser.getUuid());
|
||||||
|
|||||||
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
|
if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal");
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user