Search in sources :

Example 1 with CheckS2SVpnConnectionsAnswer

use of com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer in project cosmic by MissionCriticalCloud.

the class VirtualRoutingResource method execute.

private CheckS2SVpnConnectionsAnswer execute(final CheckS2SVpnConnectionsCommand cmd) {
    final StringBuilder str = new StringBuilder();
    for (final String ip : cmd.getVpnIps()) {
        str.append(ip);
        str.append(" ");
    }
    final ExecutionResult result = this._vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.S2SVPN_CHECK, str.toString());
    return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails());
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) ExecutionResult(com.cloud.legacymodel.ExecutionResult)

Example 2 with CheckS2SVpnConnectionsAnswer

use of com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method updateSite2SiteVpnConnectionState.

@DB
protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers) {
    for (final DomainRouterVO router : routers) {
        final List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
        if (conns == null || conns.isEmpty()) {
            continue;
        }
        if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.MASTER) {
            continue;
        }
        if (router.getState() != VirtualMachine.State.Running) {
            for (final Site2SiteVpnConnectionVO conn : conns) {
                if (conn.getState() != Site2SiteVpnConnection.State.Error) {
                    conn.setState(Site2SiteVpnConnection.State.Disconnected);
                    _s2sVpnConnectionDao.persist(conn);
                }
            }
            continue;
        }
        final List<String> ipList = new ArrayList<>();
        for (final Site2SiteVpnConnectionVO conn : conns) {
            if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                continue;
            }
            final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
            ipList.add(gw.getGatewayIp());
        }
        final String privateIP = router.getPrivateIpAddress();
        final HostVO host = _hostDao.findById(router.getHostId());
        if (host == null || host.getState() != HostStatus.Up) {
            continue;
        } else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
            /* Only cover hosts managed by this management server */
            continue;
        } else if (privateIP != null) {
            final CheckS2SVpnConnectionsCommand command = new CheckS2SVpnConnectionsCommand(ipList);
            command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
            command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
            command.setWait(30);
            final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
            CheckS2SVpnConnectionsAnswer answer = null;
            if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
                answer = (CheckS2SVpnConnectionsAnswer) origAnswer;
            } else {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            if (!answer.getResult()) {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            for (final Site2SiteVpnConnectionVO conn : conns) {
                final Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
                if (lock == null) {
                    throw new CloudRuntimeException("Unable to acquire lock for site to site vpn connection id " + conn.getId());
                }
                try {
                    if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                        continue;
                    }
                    final Site2SiteVpnConnection.State oldState = conn.getState();
                    final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
                    if (answer.isIpPresent(gw.getGatewayIp())) {
                        if (answer.isConnected(gw.getGatewayIp())) {
                            conn.setState(Site2SiteVpnConnection.State.Connected);
                        } else {
                            conn.setState(Site2SiteVpnConnection.State.Disconnected);
                        }
                        _s2sVpnConnectionDao.persist(conn);
                        if (oldState != conn.getState()) {
                            final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switch from " + oldState + " to " + conn.getState();
                            final String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " + " just switch from " + oldState + " to " + conn.getState();
                            s_logger.info(context);
                            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
                        }
                    }
                } finally {
                    _s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
                }
            }
        }
    }
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) NetworkUsageAnswer(com.cloud.legacymodel.communication.answer.NetworkUsageAnswer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) CheckS2SVpnConnectionsCommand(com.cloud.legacymodel.communication.command.CheckS2SVpnConnectionsCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) DB(com.cloud.utils.db.DB)

Aggregations

CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)2 ManagementServerHostVO (com.cloud.cluster.ManagementServerHostVO)1 HostVO (com.cloud.host.HostVO)1 ExecutionResult (com.cloud.legacymodel.ExecutionResult)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)1 NetworkUsageAnswer (com.cloud.legacymodel.communication.answer.NetworkUsageAnswer)1 CheckS2SVpnConnectionsCommand (com.cloud.legacymodel.communication.command.CheckS2SVpnConnectionsCommand)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 Site2SiteCustomerGateway (com.cloud.network.Site2SiteCustomerGateway)1 Site2SiteVpnConnection (com.cloud.network.Site2SiteVpnConnection)1 Site2SiteVpnConnectionVO (com.cloud.network.dao.Site2SiteVpnConnectionVO)1 DB (com.cloud.utils.db.DB)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 ArrayList (java.util.ArrayList)1