CLOUDSTACK-6578: Fixed issue in delete remote access vpn command

This commit is contained in:
Jayapal 2014-05-05 13:56:59 +05:30
parent b9b623bccc
commit 40836344de
3 changed files with 16 additions and 4 deletions

View File

@ -33,7 +33,7 @@ public interface RemoteAccessVpnService {
RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, Boolean forDisplay) throws NetworkRuleConflictException;
void destroyRemoteAccessVpnForIp(long vpnServerAddressId, Account caller) throws ResourceUnavailableException;
boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException;
RemoteAccessVpn startRemoteAccessVpn(long vpnServerAddressId, boolean openFirewall) throws ResourceUnavailableException;

View File

@ -20,6 +20,8 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.AccountResponse;
@ -91,7 +93,9 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
@Override
public void execute() throws ResourceUnavailableException {
_ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount());
if (! _ravService.destroyRemoteAccessVpnForIp(publicIpId, CallContext.current().getCallingAccount())) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete remote access vpn");
}
}
@Override

View File

@ -285,15 +285,16 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@Override
@DB
public void destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
public boolean destroyRemoteAccessVpnForIp(long ipId, Account caller) throws ResourceUnavailableException {
final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByPublicIpAddress(ipId);
if (vpn == null) {
s_logger.debug("there are no Remote access vpns for public ip address id=" + ipId);
return;
return true;
}
_accountMgr.checkAccess(caller, AccessType.OperateEntry, vpn);
RemoteAccessVpn.State prevState = vpn.getState();
vpn.setState(RemoteAccessVpn.State.Removed);
_remoteAccessVpnDao.update(vpn.getId(), vpn);
@ -305,6 +306,12 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
break;
}
}
}catch (ResourceUnavailableException ex) {
vpn.setState(prevState);
_remoteAccessVpnDao.update(vpn.getId(), vpn);
s_logger.debug("Failed to stop the vpn " + vpn.getId() + " , so reverted state to "+
RemoteAccessVpn.State.Running);
success = false;
} finally {
if (success) {
//Cleanup corresponding ports
@ -366,6 +373,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
}
}
}
return success;
}
@Override