Search in sources :

Example 1 with RebootAnswer

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

the class LibvirtRebootCommandWrapper method execute.

@Override
public Answer execute(final RebootCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
    try {
        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        final String result = libvirtComputingResource.rebootVm(conn, command.getVmName());
        if (result == null) {
            Integer vncPort = null;
            try {
                vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName());
            } catch (final LibvirtException e) {
                s_logger.trace("Ignoring libvirt error.", e);
            }
            return new RebootAnswer(command, null, vncPort);
        } else {
            return new RebootAnswer(command, result, false);
        }
    } catch (final LibvirtException e) {
        return new RebootAnswer(command, e.getMessage(), false);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer)

Example 2 with RebootAnswer

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

the class CitrixRebootCommandWrapper method execute.

@Override
public Answer execute(final RebootCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    s_logger.debug("7. The VM " + command.getVmName() + " is in Starting state");
    try {
        Set<VM> vms = null;
        try {
            vms = VM.getByNameLabel(conn, command.getVmName());
        } catch (final XenAPIException e0) {
            s_logger.debug("getByNameLabel failed " + e0.toString());
            return new RebootAnswer(command, "getByNameLabel failed " + e0.toString(), false);
        } catch (final Exception e0) {
            s_logger.debug("getByNameLabel failed " + e0.getMessage());
            return new RebootAnswer(command, "getByNameLabel failed", false);
        }
        for (final VM vm : vms) {
            try {
                citrixResourceBase.rebootVM(conn, vm, vm.getNameLabel(conn));
            } catch (final Exception e) {
                final String msg = e.toString();
                s_logger.warn(msg, e);
                return new RebootAnswer(command, msg, false);
            }
        }
        return new RebootAnswer(command, "reboot succeeded", true);
    } finally {
        s_logger.debug("8. The VM " + command.getVmName() + " is in Running state");
    }
}
Also used : VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Example 3 with RebootAnswer

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

the class VirtualMachineManagerImpl method orchestrateReboot.

private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    // if there are active vm snapshots task, state change is not allowed
    if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
        s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
        throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
    }
    final Zone zone = _zoneRepository.findById(vm.getDataCenterId()).orElse(null);
    final Host host = _hostDao.findById(vm.getHostId());
    if (host == null) {
        // Should findById throw an Exception is the host is not found?
        throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
    }
    final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
    final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host);
    try {
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())));
        _agentMgr.send(host.getId(), cmds);
        final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
        if (rebootAnswer != null && rebootAnswer.getResult()) {
            return;
        }
        s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
        throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost());
    }
}
Also used : UnPlugNicAnswer(com.cloud.legacymodel.communication.answer.UnPlugNicAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) PlugNicAnswer(com.cloud.legacymodel.communication.answer.PlugNicAnswer) CheckVirtualMachineAnswer(com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer) StopAnswer(com.cloud.legacymodel.communication.answer.StopAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) Pod(com.cloud.legacymodel.dc.Pod) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) TimeZone(java.util.TimeZone) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) Cluster(com.cloud.legacymodel.dc.Cluster) Host(com.cloud.legacymodel.dc.Host)

Aggregations

RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)3 Commands (com.cloud.agent.manager.Commands)1 Zone (com.cloud.db.model.Zone)1 DeployDestination (com.cloud.deploy.DeployDestination)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 CheckVirtualMachineAnswer (com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer)1 ClusterVMMetaDataSyncAnswer (com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer)1 PlugNicAnswer (com.cloud.legacymodel.communication.answer.PlugNicAnswer)1 RestoreVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer)1 StartAnswer (com.cloud.legacymodel.communication.answer.StartAnswer)1 StopAnswer (com.cloud.legacymodel.communication.answer.StopAnswer)1 UnPlugNicAnswer (com.cloud.legacymodel.communication.answer.UnPlugNicAnswer)1 RebootCommand (com.cloud.legacymodel.communication.command.RebootCommand)1 Cluster (com.cloud.legacymodel.dc.Cluster)1 Host (com.cloud.legacymodel.dc.Host)1 Pod (com.cloud.legacymodel.dc.Pod)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)1 Connection (com.xensource.xenapi.Connection)1