use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class OvmFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.Ovm) {
s_logger.debug("Don't know how to fence non Ovm hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() != HypervisorType.Ovm) {
continue;
}
if (h.getStatus() != Status.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class VmwareStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.
private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
// Initiate migration of a virtual machine with it's volumes.
try {
List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volume = entry.getKey();
VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
}
// Migration across cluster needs to be done in three phases.
// 1. Send a migrate command to source resource to initiate migration
// Run validations against target!!
// 2. Complete the process. Update the volume details.
MigrateWithStorageCommand migrateWithStorageCmd = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
MigrateWithStorageAnswer migrateWithStorageAnswer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), migrateWithStorageCmd);
if (migrateWithStorageAnswer == null) {
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!migrateWithStorageAnswer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + migrateWithStorageAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + migrateWithStorageAnswer.getDetails());
} else {
// Update the volume details after migration.
updateVolumesAfterMigration(volumeToPool, migrateWithStorageAnswer.getVolumeTos());
}
s_logger.debug("Storage migration of VM " + vm.getInstanceName() + " completed successfully. Migrated to host " + destHost.getName());
return migrateWithStorageAnswer;
} catch (OperationTimedoutException e) {
s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class ResourceManagerImpl method maintain.
@Override
public Host maintain(final PrepareForMaintenanceCmd cmd) {
final Long hostId = cmd.getId();
final HostVO host = _hostDao.findById(hostId);
if (host == null) {
s_logger.debug("Unable to find host " + hostId);
throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID.");
}
if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) {
throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + host.getClusterId());
}
if (_storageMgr.isLocalStorageActiveOnHost(host.getId())) {
throw new InvalidParameterValueException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
}
try {
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
if (maintain(hostId)) {
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, hostId);
return _hostDao.findById(hostId);
} else {
throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
}
} catch (final AgentUnavailableException e) {
throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class ResourceManagerImpl method propagateResourceEvent.
public Boolean propagateResourceEvent(final long agentId, final ResourceState.Event event) throws AgentUnavailableException {
final String msPeer = getPeerName(agentId);
if (msPeer == null) {
return null;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Propagating agent change request event:" + event.toString() + " to agent:" + agentId);
}
final Command[] cmds = new Command[1];
cmds[0] = new PropagateResourceEventCommand(agentId, event);
final String AnsStr = _clusterMgr.execute(msPeer, agentId, _gson.toJson(cmds), true);
if (AnsStr == null) {
throw new AgentUnavailableException(agentId);
}
final Answer[] answers = _gson.fromJson(AnsStr, Answer[].class);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Result for agent change is " + answers[0].getResult());
}
return answers[0].getResult();
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class XenServerStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.
private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
try {
List<Pair<VolumeTO, String>> volumeToStorageUuid = new ArrayList<>();
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volumeInfo = entry.getKey();
StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
VolumeTO volumeTo = new VolumeTO(volumeInfo, storagePool);
if (storagePool.isManaged()) {
String iqn = handleManagedVolumePreMigration(volumeInfo, storagePool, destHost);
volumeToStorageUuid.add(new Pair<>(volumeTo, iqn));
} else {
volumeToStorageUuid.add(new Pair<>(volumeTo, ((StoragePool) entry.getValue()).getPath()));
}
}
// Migration across cluster needs to be done in three phases.
// 1. Send a migrate receive command to the destination host so that it is ready to receive a vm.
// 2. Send a migrate send command to the source host. This actually migrates the vm to the destination.
// 3. Complete the process. Update the volume details.
MigrateWithStorageReceiveCommand receiveCmd = new MigrateWithStorageReceiveCommand(to, volumeToStorageUuid);
MigrateWithStorageReceiveAnswer receiveAnswer = (MigrateWithStorageReceiveAnswer) agentMgr.send(destHost.getId(), receiveCmd);
if (receiveAnswer == null) {
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!receiveAnswer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
}
MigrateWithStorageSendCommand sendCmd = new MigrateWithStorageSendCommand(to, receiveAnswer.getVolumeToSr(), receiveAnswer.getNicToNetwork(), receiveAnswer.getToken());
MigrateWithStorageSendAnswer sendAnswer = (MigrateWithStorageSendAnswer) agentMgr.send(srcHost.getId(), sendCmd);
if (sendAnswer == null) {
handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!sendAnswer.getResult()) {
handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
}
MigrateWithStorageCompleteCommand command = new MigrateWithStorageCompleteCommand(to);
MigrateWithStorageCompleteAnswer answer = (MigrateWithStorageCompleteAnswer) agentMgr.send(destHost.getId(), command);
if (answer == null) {
s_logger.error("Migration with storage of vm " + vm + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!answer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else {
// Update the volume details after migration.
updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos(), srcHost);
}
return answer;
} catch (OperationTimedoutException e) {
s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
}
}
Aggregations