use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class HypervisorHelperImpl method unquiesceVM.
@Override
public boolean unquiesceVM(VirtualMachine virtualMachine, VMSnapshotTO vmSnapshotTO) {
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(virtualMachine.getInstanceName(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
try {
Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
if (answer != null && answer.getResult()) {
return true;
} else {
String errMsg = (answer != null) ? answer.getDetails() : null;
throw new CloudRuntimeException("Failed to unquiesce vm, due to " + errMsg);
}
} catch (AgentUnavailableException e) {
throw new CloudRuntimeException("Failed to unquiesce vm", e);
} catch (OperationTimedoutException e) {
throw new CloudRuntimeException("Failed to unquiesce vm", e);
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class ManagementServerMock method createVM.
public UserVm createVM(String name, Network network) {
VMTemplateVO tmpl = getVMTemplate();
assertNotNull(tmpl);
ServiceOffering small = getServiceByName("Small Instance");
assertNotNull(small);
Answer<?> callback = new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
Commands cmds = (Commands) args[1];
if (cmds == null) {
return null;
}
PlugNicAnswer reply = new PlugNicAnswer(null, true, "PlugNic");
com.cloud.agent.api.Answer[] answers = { reply };
cmds.setAnswers(answers);
return null;
}
};
try {
Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long id = _userVmDao.getNextInSequence(Long.class, "id");
UserVmVO vm = new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM, 1, small.getId(), null, name, null);
vm.setState(com.cloud.vm.VirtualMachine.State.Running);
vm.setHostId(_hostId);
vm.setDataCenterId(network.getDataCenterId());
_userVmDao.persist(vm);
NicProfile profile = new NicProfile();
try {
_vmMgr.addVmToNetwork(vm, network, profile);
} catch (Exception ex) {
// TODO Auto-generated catch block
//ex.printStackTrace();
}
return vm;
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class ManagementServerMock method deleteVM.
public void deleteVM(UserVm vm, Network network) {
Answer<?> callback = new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
Commands cmds = (Commands) args[1];
if (cmds == null) {
return null;
}
UnPlugNicAnswer reply = new UnPlugNicAnswer(null, true, "PlugNic");
com.cloud.agent.api.Answer[] answers = { reply };
cmds.setAnswers(answers);
return null;
}
};
try {
Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback);
} catch (AgentUnavailableException e) {
e.printStackTrace();
} catch (OperationTimedoutException e) {
e.printStackTrace();
}
_userVmDao.remove(vm.getId());
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class CheckOnAgentInvestigator method isVmAlive.
@Override
public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM {
CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName());
try {
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 (AgentUnavailableException e) {
s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
throw new UnknownVM();
} catch (OperationTimedoutException e) {
s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage());
throw new UnknownVM();
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class HighAvailabilityManagerImpl method destroyVM.
protected Long destroyVM(final HaWorkVO work) {
final VirtualMachine vm = _itMgr.findById(work.getInstanceId());
s_logger.info("Destroying " + vm.toString());
try {
if (vm.getState() != State.Destroyed) {
s_logger.info("VM is no longer in Destroyed state " + vm.toString());
return null;
}
if (vm.getHostId() != null) {
_itMgr.destroy(vm.getUuid(), false);
s_logger.info("Successfully destroy " + vm);
return null;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(vm + " has already been stopped");
}
return null;
}
} catch (final AgentUnavailableException e) {
s_logger.debug("Agnet is not available" + e.getMessage());
} catch (OperationTimedoutException e) {
s_logger.debug("operation timed out: " + e.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.debug("concurrent operation: " + e.getMessage());
}
return (System.currentTimeMillis() >> 10) + _stopRetryInterval;
}
Aggregations