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;
}
}
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;
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations