Search in sources :

Example 1 with Site2SiteVpnServiceProvider

use of com.cloud.network.element.Site2SiteVpnServiceProvider in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method startVpnConnection.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "starting s2s vpn connection", async = true)
public Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException {
    Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
    if (conn == null) {
        throw new CloudRuntimeException("Unable to acquire lock on " + conn);
    }
    try {
        if (conn.getState() != State.Pending && conn.getState() != State.Disconnected) {
            throw new InvalidParameterValueException("Site to site VPN connection with specified connectionId not in correct state(pending or disconnected) to process!");
        }
        conn.setState(State.Pending);
        _vpnConnectionDao.persist(conn);
        boolean result = true;
        for (Site2SiteVpnServiceProvider element : _s2sProviders) {
            result = result & element.startSite2SiteVpn(conn);
        }
        if (result) {
            if (conn.isPassive()) {
                conn.setState(State.Disconnected);
            } else {
                conn.setState(State.Connected);
            }
            _vpnConnectionDao.persist(conn);
            return conn;
        }
        conn.setState(State.Error);
        _vpnConnectionDao.persist(conn);
        throw new ResourceUnavailableException("Failed to apply site-to-site VPN", Site2SiteVpnConnection.class, id);
    } finally {
        _vpnConnectionDao.releaseFromLockTable(conn.getId());
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Site2SiteVpnServiceProvider(com.cloud.network.element.Site2SiteVpnServiceProvider) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 2 with Site2SiteVpnServiceProvider

use of com.cloud.network.element.Site2SiteVpnServiceProvider in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method stopVpnConnection.

@DB
private void stopVpnConnection(Long id) throws ResourceUnavailableException {
    Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
    if (conn == null) {
        throw new CloudRuntimeException("Unable to acquire lock on " + conn);
    }
    try {
        if (conn.getState() == State.Pending) {
            throw new InvalidParameterValueException("Site to site VPN connection with specified id is currently Pending, unable to Disconnect!");
        }
        conn.setState(State.Disconnected);
        _vpnConnectionDao.persist(conn);
        boolean result = true;
        for (Site2SiteVpnServiceProvider element : _s2sProviders) {
            result = result & element.stopSite2SiteVpn(conn);
        }
        if (!result) {
            conn.setState(State.Error);
            _vpnConnectionDao.persist(conn);
            throw new ResourceUnavailableException("Failed to apply site-to-site VPN", Site2SiteVpnConnection.class, id);
        }
    } finally {
        _vpnConnectionDao.releaseFromLockTable(conn.getId());
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Site2SiteVpnServiceProvider(com.cloud.network.element.Site2SiteVpnServiceProvider) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) DB(com.cloud.utils.db.DB)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 Site2SiteVpnConnectionVO (com.cloud.network.dao.Site2SiteVpnConnectionVO)2 Site2SiteVpnServiceProvider (com.cloud.network.element.Site2SiteVpnServiceProvider)2 DB (com.cloud.utils.db.DB)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ActionEvent (com.cloud.event.ActionEvent)1