Search in sources :

Example 6 with MaintainCommand

use of com.cloud.legacymodel.communication.command.MaintainCommand in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method doMaintain.

private boolean doMaintain(final long hostId) {
    final HostVO host = this._hostDao.findById(hostId);
    final MaintainAnswer answer = (MaintainAnswer) this._agentMgr.easySend(hostId, new MaintainCommand());
    if (answer == null || !answer.getResult()) {
        s_logger.warn("Unable to send MaintainCommand to host: " + hostId);
        return false;
    }
    try {
        resourceStateTransitTo(host, ResourceState.Event.AdminAskMaintenace, this._nodeId);
    } catch (final NoTransitionException e) {
        final String err = "Cannot transmit resource state of host " + host.getId() + " to " + ResourceState.Maintenance;
        s_logger.debug(err, e);
        throw new CloudRuntimeException(err + e.getMessage());
    }
    ActionEventUtils.onStartedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventTypes.EVENT_MAINTENANCE_PREPARE, "starting maintenance for host " + hostId, true, 0);
    this._agentMgr.pullAgentToMaintenance(hostId);
    /* TODO: move below to listener */
    if (host.getType() == HostType.Routing) {
        final List<VMInstanceVO> vms = this._vmDao.listByHostId(hostId);
        if (vms.size() == 0) {
            return true;
        }
        final List<HostVO> hosts = listAllUpAndEnabledHosts(HostType.Routing, host.getClusterId(), host.getPodId(), host.getDataCenterId());
        for (final VMInstanceVO vm : vms) {
            if (hosts == null || hosts.isEmpty() || !answer.getMigrate() || this._serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.vgpuType.toString()) != null) {
                // Migration is not supported for VGPU Vms so stop them.
                // for the last host in this cluster, stop all the VMs
                this._haMgr.scheduleStop(vm, hostId, HaWork.HaWorkType.ForceStop);
            } else {
                this._haMgr.scheduleMigration(vm);
            }
        }
    }
    return true;
}
Also used : MaintainCommand(com.cloud.legacymodel.communication.command.MaintainCommand) MaintainAnswer(com.cloud.legacymodel.communication.answer.MaintainAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) VMInstanceVO(com.cloud.vm.VMInstanceVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

MaintainCommand (com.cloud.legacymodel.communication.command.MaintainCommand)6 Answer (com.cloud.legacymodel.communication.answer.Answer)4 Test (org.junit.Test)3 HostVO (com.cloud.host.HostVO)2 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)2 MaintainAnswer (com.cloud.legacymodel.communication.answer.MaintainAnswer)2 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)2 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 IAgentControlListener (com.cloud.common.agent.IAgentControlListener)1 Response (com.cloud.common.transport.Response)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)1 Command (com.cloud.legacymodel.communication.command.Command)1 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)1 PingCommand (com.cloud.legacymodel.communication.command.PingCommand)1