use of com.cloud.agent.api.CheckVirtualMachineCommand in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method checkVmOnHost.
protected boolean checkVmOnHost(final VirtualMachine vm, final long hostId) throws AgentUnavailableException, OperationTimedoutException {
final Answer answer = _agentMgr.send(hostId, new CheckVirtualMachineCommand(vm.getInstanceName()));
if (answer == null || !answer.getResult()) {
return false;
}
if (answer instanceof CheckVirtualMachineAnswer) {
final CheckVirtualMachineAnswer vmAnswer = (CheckVirtualMachineAnswer) answer;
if (vmAnswer.getState() == PowerState.PowerOff) {
return false;
}
}
UserVmVO userVm = _userVmDao.findById(vm.getId());
if (userVm != null) {
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vm.getId());
RestoreVMSnapshotCommand command = _vmSnapshotMgr.createRestoreCommand(userVm, vmSnapshots);
if (command != null) {
RestoreVMSnapshotAnswer restoreVMSnapshotAnswer = (RestoreVMSnapshotAnswer) _agentMgr.send(hostId, command);
if (restoreVMSnapshotAnswer == null || !restoreVMSnapshotAnswer.getResult()) {
s_logger.warn("Unable to restore the vm snapshot from image file after live migration of vm with vmsnapshots: " + restoreVMSnapshotAnswer.getDetails());
}
}
}
return true;
}
use of com.cloud.agent.api.CheckVirtualMachineCommand in project cosmic by MissionCriticalCloud.
the class CheckOnAgentInvestigator method isVmAlive.
@Override
public boolean isVmAlive(final VirtualMachine vm, final Host host) throws UnknownVM {
final CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName());
try {
final CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(vm.getHostId(), cmd);
if (!answer.getResult()) {
s_logger.debug("Unable to get vm state on " + vm.toString());
throw new UnknownVM();
}
s_logger.debug("Agent responded with state " + answer.getState().toString());
return answer.getState() == PowerState.PowerOn;
} catch (final AgentUnavailableException e) {
s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
throw new UnknownVM();
} catch (final OperationTimedoutException e) {
s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage());
throw new UnknownVM();
}
}
use of com.cloud.agent.api.CheckVirtualMachineCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testExceptionCheckVirtualMachineCommand.
@SuppressWarnings("unchecked")
@Test
public void testExceptionCheckVirtualMachineCommand() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String vmName = "Test";
final CheckVirtualMachineCommand command = new CheckVirtualMachineCommand(vmName);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(libvirtComputingResource.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.api.CheckVirtualMachineCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testCheckVirtualMachineCommand.
@Test
public void testCheckVirtualMachineCommand() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String vmName = "Test";
final CheckVirtualMachineCommand command = new CheckVirtualMachineCommand(vmName);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(libvirtComputingResource.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.api.CheckVirtualMachineCommand in project cloudstack by apache.
the class Ovm3HypervisorSupportTest method CheckVirtualMachineCommandTest.
@Test
public void CheckVirtualMachineCommandTest() throws ConfigurationException {
con = prepare();
CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(xen.getVmName());
Answer ra = hypervisor.executeRequest(cmd);
results.basicBooleanTest(ra.getResult());
}
Aggregations