Search in sources :

Example 1 with GetDomRVersionAnswer

use of com.cloud.agent.api.GetDomRVersionAnswer in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
    boolean result = true;
    Answer answer = cmds.getAnswer("checkSsh");
    if (answer != null && answer instanceof CheckSshAnswer) {
        final CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
        if (sshAnswer == null || !sshAnswer.getResult()) {
            s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
            result = false;
        }
    } else {
        result = false;
    }
    if (result == false) {
        return result;
    }
    // Get guest network info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final List<? extends Nic> internalLbVmNics = _nicDao.listByVmId(profile.getId());
    for (final Nic internalLbVmNic : internalLbVmNics) {
        final Network network = _ntwkModel.getNetwork(internalLbVmNic.getNetworkId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
        }
    }
    answer = cmds.getAnswer("getDomRVersion");
    if (answer != null && answer instanceof GetDomRVersionAnswer) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) answer;
        if (answer == null || !answer.getResult()) {
            s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails());
            result = false;
        } else {
            internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion());
            internalLbVm.setScriptsVersion(versionAnswer.getScriptsVersion());
            internalLbVm = _internalLbVmDao.persist(internalLbVm, guestNetworks);
        }
    } else {
        result = false;
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with GetDomRVersionAnswer

use of com.cloud.agent.api.GetDomRVersionAnswer in project cloudstack by apache.

the class VirtualRoutingResource method execute.

private Answer execute(GetDomRVersionCmd cmd) {
    final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.VERSION, null);
    if (!result.isSuccess()) {
        return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
    }
    String[] lines = result.getDetails().split("&");
    if (lines.length != 2) {
        return new GetDomRVersionAnswer(cmd, result.getDetails());
    }
    return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer)

Example 3 with GetDomRVersionAnswer

use of com.cloud.agent.api.GetDomRVersionAnswer in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    // process all the answers
    for (final Answer answer : cmds.getAnswers()) {
        // handle any command failures
        if (!answer.getResult()) {
            final String cmdClassName = answer.getClass().getCanonicalName().replace("Answer", "Command");
            final String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router";
            final String errorDetails = "Details: " + answer.getDetails() + " " + answer.toString();
            // add alerts for the failed commands
            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), errorMessage, errorDetails);
            s_logger.error(answer.getDetails());
            s_logger.warn(errorMessage);
            // Stop the router if any of the commands failed
            return false;
        }
    }
    // at this point, all the router command are successful.
    boolean result = true;
    // Get guest networks info
    final List<Network> guestNetworks = new ArrayList<>();
    final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
    for (final Nic nic : routerNics) {
        final Network network = _networkModel.getNetwork(nic.getNetworkId());
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
            if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(zone);
                try {
                    result = networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStart: ", e);
                }
            }
        }
    }
    if (result) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) cmds.getAnswer("getDomRVersion");
        router.setTemplateVersion(versionAnswer.getTemplateVersion());
        router.setScriptsVersion(versionAnswer.getScriptsVersion());
        _routerDao.persist(router, guestNetworks);
    }
    final List<DomainRouterVO> routers = _routerDao.listByVpcId(router.getVpcId());
    for (final DomainRouterVO domainRouterVO : routers) {
        s_logger.info("Updating the redundant state of router " + domainRouterVO);
        updateRoutersRedundantState(domainRouterVO);
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) Network(com.cloud.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 4 with GetDomRVersionAnswer

use of com.cloud.agent.api.GetDomRVersionAnswer in project cosmic by MissionCriticalCloud.

the class VirtualRoutingResource method execute.

private Answer execute(final GetDomRVersionCmd cmd) {
    final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.VERSION, null);
    if (!result.isSuccess()) {
        return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
    }
    final String[] lines = result.getDetails().split("&");
    if (lines.length != 2) {
        return new GetDomRVersionAnswer(cmd, result.getDetails());
    }
    return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer)

Example 5 with GetDomRVersionAnswer

use of com.cloud.agent.api.GetDomRVersionAnswer in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    // process all the answers
    for (final Answer answer : cmds.getAnswers()) {
        // handle any command failures
        if (!answer.getResult()) {
            final String cmdClassName = answer.getClass().getCanonicalName().replace("Answer", "Command");
            final String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router";
            final String errorDetails = "Details: " + answer.getDetails() + " " + answer.toString();
            // add alerts for the failed commands
            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), errorMessage, errorDetails);
            s_logger.error(answer.getDetails());
            s_logger.warn(errorMessage);
            // Stop the router if any of the commands failed
            return false;
        }
    }
    // at this point, all the router command are successful.
    boolean result = true;
    // Get guest networks info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) cmds.getAnswer("getDomRVersion");
    router.setTemplateVersion(versionAnswer.getTemplateVersion());
    router.setScriptsVersion(versionAnswer.getScriptsVersion());
    _routerDao.persist(router, guestNetworks);
    final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
    for (final Nic nic : routerNics) {
        final Network network = _networkModel.getNetwork(nic.getNetworkId());
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
            if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
                try {
                    result = networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStart: ", e);
                }
            }
        }
    }
    if (result) {
        for (Network guestNetwork : guestNetworks) {
            _routerDao.addRouterToGuestNetwork(router, guestNetwork);
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) Network(com.cloud.network.Network) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)6 Answer (com.cloud.agent.api.Answer)3 Network (com.cloud.network.Network)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)3 Nic (com.cloud.vm.Nic)3 ArrayList (java.util.ArrayList)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 ExecutionResult (com.cloud.utils.ExecutionResult)2 NicProfile (com.cloud.vm.NicProfile)2 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)1 GetRouterMonitorResultsAnswer (com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer)1 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)1 Zone (com.cloud.db.model.Zone)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 NetworkTopology (com.cloud.network.topology.NetworkTopology)1