Search in sources :

Example 6 with RebootCommand

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

the class SecondaryStorageManagerImpl method rebootSecStorageVm.

@Override
public boolean rebootSecStorageVm(final long secStorageVmId) {
    final SecondaryStorageVmVO secStorageVm = this._secStorageVmDao.findById(secStorageVmId);
    if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
        return false;
    }
    if (secStorageVm.getState() == Running && secStorageVm.getHostId() != null) {
        final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName(), this._itMgr.getExecuteInSequence(secStorageVm.getHypervisorType()));
        final Answer answer = this._agentMgr.easySend(secStorageVm.getHostId(), cmd);
        if (answer != null && answer.getResult()) {
            logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
            return true;
        } else {
            final String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
            logger.debug(msg);
            return false;
        }
    } else {
        return startSecStorageVm(secStorageVmId) != null;
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CheckSshAnswer(com.cloud.legacymodel.communication.answer.CheckSshAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand)

Example 7 with RebootCommand

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

the class ConsoleProxyManagerImpl method rebootProxy.

@Override
public boolean rebootProxy(final long proxyVmId) {
    final ConsoleProxyVO proxy = this._consoleProxyDao.findById(proxyVmId);
    if (proxy == null || proxy.getState() == State.Destroyed) {
        return false;
    }
    if (proxy.getState() == State.Running && proxy.getHostId() != null) {
        final RebootCommand cmd = new RebootCommand(proxy.getInstanceName(), this._itMgr.getExecuteInSequence(proxy.getHypervisorType()));
        final Answer answer = this._agentMgr.easySend(proxy.getHostId(), cmd);
        if (answer != null && answer.getResult()) {
            logger.debug("Successfully reboot console proxy " + proxy.getHostName());
            SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_REBOOTED, proxy.getDataCenterId(), proxy.getId(), proxy, null));
            return true;
        } else {
            logger.debug("failed to reboot console proxy : " + proxy.getHostName());
            return false;
        }
    } else {
        return startProxy(proxyVmId, false) != null;
    }
}
Also used : ConsoleProxyLoadAnswer(com.cloud.legacymodel.communication.answer.ConsoleProxyLoadAnswer) CheckSshAnswer(com.cloud.legacymodel.communication.answer.CheckSshAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Example 8 with RebootCommand

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

the class LibvirtComputingResourceTest method testRebootCommand.

@Test
public void testRebootCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootCommand command = new RebootCommand(vmName, true);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 9 with RebootCommand

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

the class LibvirtRebootRouterCommandWrapper method execute.

@Override
public Answer execute(final RebootRouterCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    final RebootCommand rebootCommand = new RebootCommand(command.getVmName(), true);
    final Answer answer = wrapper.execute(rebootCommand, libvirtComputingResource);
    final VirtualRoutingResource virtualRouterResource = libvirtComputingResource.getVirtRouterResource();
    if (virtualRouterResource.connect(command.getPrivateIpAddress())) {
        libvirtComputingResource.networkUsage(command.getPrivateIpAddress(), "create", null);
        return answer;
    } else {
        return new Answer(command, false, "Failed to connect to virtual router " + command.getVmName());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource)

Example 10 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand 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

Answer (com.cloud.legacymodel.communication.answer.Answer)10 RebootCommand (com.cloud.legacymodel.communication.command.RebootCommand)10 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 Test (org.junit.Test)5 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 LibvirtException (org.libvirt.LibvirtException)4 Connect (org.libvirt.Connect)3 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)2 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)2 Commands (com.cloud.agent.manager.Commands)1 VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)1 Zone (com.cloud.db.model.Zone)1 DeployDestination (com.cloud.deploy.DeployDestination)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 CheckVirtualMachineAnswer (com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer)1 ClusterVMMetaDataSyncAnswer (com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer)1 ConsoleProxyLoadAnswer (com.cloud.legacymodel.communication.answer.ConsoleProxyLoadAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1