Search in sources :

Example 16 with Site2SiteVpnConnectionVO

use of com.cloud.network.dao.Site2SiteVpnConnectionVO 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.Connecting);
            }
            _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 17 with Site2SiteVpnConnectionVO

use of com.cloud.network.dao.Site2SiteVpnConnectionVO in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method deleteVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_DELETE, eventDescription = "deleting s2s vpn connection", create = true)
public boolean deleteVpnConnection(DeleteVpnConnectionCmd cmd) throws ResourceUnavailableException {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    Account caller = CallContext.current().getCallingAccount();
    Long id = cmd.getId();
    Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
    if (conn == null) {
        throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id + " to delete!");
    }
    _accountMgr.checkAccess(caller, null, false, conn);
    if (conn.getState() != State.Pending) {
        stopVpnConnection(id);
    }
    _vpnConnectionDao.remove(id);
    return true;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent)

Example 18 with Site2SiteVpnConnectionVO

use of com.cloud.network.dao.Site2SiteVpnConnectionVO in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method searchForVpnConnections.

@Override
public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnections(ListVpnConnectionsCmd cmd) {
    Long id = cmd.getId();
    Long vpcId = cmd.getVpcId();
    Boolean display = cmd.getDisplay();
    Long domainId = cmd.getDomainId();
    boolean isRecursive = cmd.isRecursive();
    String accountName = cmd.getAccountName();
    boolean listAll = cmd.listAll();
    long startIndex = cmd.getStartIndex();
    long pageSizeVal = cmd.getPageSizeVal();
    Account caller = CallContext.current().getCallingAccount();
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(Site2SiteVpnConnectionVO.class, "id", false, startIndex, pageSizeVal);
    SearchBuilder<Site2SiteVpnConnectionVO> sb = _vpnConnectionDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
    if (vpcId != null) {
        SearchBuilder<Site2SiteVpnGatewayVO> gwSearch = _vpnGatewayDao.createSearchBuilder();
        gwSearch.and("vpcId", gwSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
        sb.join("gwSearch", gwSearch, sb.entity().getVpnGatewayId(), gwSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    }
    SearchCriteria<Site2SiteVpnConnectionVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (display != null) {
        sc.setParameters("display", display);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (vpcId != null) {
        sc.setJoinParameters("gwSearch", "vpcId", vpcId);
    }
    Pair<List<Site2SiteVpnConnectionVO>, Integer> result = _vpnConnectionDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends Site2SiteVpnConnection>, Integer>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Example 19 with Site2SiteVpnConnectionVO

use of com.cloud.network.dao.Site2SiteVpnConnectionVO in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method resetVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_RESET, eventDescription = "reseting s2s vpn connection", create = true)
public Site2SiteVpnConnection resetVpnConnection(ResetVpnConnectionCmd cmd) throws ResourceUnavailableException {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    Account caller = CallContext.current().getCallingAccount();
    Long id = cmd.getId();
    Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
    if (conn == null) {
        throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id + " to reset!");
    }
    _accountMgr.checkAccess(caller, null, false, conn);
    // Set vpn state to disconnected
    conn.setState(State.Disconnected);
    _vpnConnectionDao.persist(conn);
    // Stop and start the connection again
    stopVpnConnection(id);
    startVpnConnection(id);
    conn = _vpnConnectionDao.findById(id);
    return conn;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent)

Example 20 with Site2SiteVpnConnectionVO

use of com.cloud.network.dao.Site2SiteVpnConnectionVO 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

Site2SiteVpnConnectionVO (com.cloud.network.dao.Site2SiteVpnConnectionVO)21 ActionEvent (com.cloud.event.ActionEvent)11 Account (com.cloud.user.Account)11 DB (com.cloud.utils.db.DB)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)6 Site2SiteVpnServiceProvider (com.cloud.network.element.Site2SiteVpnServiceProvider)5 ArrayList (java.util.ArrayList)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Site2SiteCustomerGateway (com.cloud.network.Site2SiteCustomerGateway)4 Site2SiteCustomerGatewayVO (com.cloud.network.dao.Site2SiteCustomerGatewayVO)4 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)3 HostVO (com.cloud.host.HostVO)3 Site2SiteVpnConnection (com.cloud.network.Site2SiteVpnConnection)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 Answer (com.cloud.agent.api.Answer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2