use of com.cloud.exception.OperationTimedoutException 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.findOne(vm.getDataCenterId());
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());
}
}
use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method orchestrateMigrateAway.
private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (vm == null) {
s_logger.debug("Unable to find a VM for " + vmUuid);
throw new CloudRuntimeException("Unable to find " + vmUuid);
}
final ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
final Long hostId = vm.getHostId();
if (hostId == null) {
s_logger.debug("Unable to migrate because the VM doesn't have a host id: " + vm);
throw new CloudRuntimeException("Unable to migrate " + vmUuid);
}
final Host host = _hostDao.findById(hostId);
Long poolId = null;
final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
for (final VolumeVO rootVolumeOfVm : vols) {
final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
if (rootDiskPool != null) {
poolId = rootDiskPool.getId();
}
}
final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, poolId, null);
final ExcludeList excludes = new ExcludeList();
excludes.addHost(hostId);
DeployDestination dest = null;
while (true) {
try {
dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
} catch (final AffinityConflictException e2) {
s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
}
if (dest != null) {
s_logger.debug("Found destination " + dest + " for migrating to.");
} else {
s_logger.debug("Unable to find destination for migrating the vm " + profile);
throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
}
excludes.addHost(dest.getHost().getId());
try {
migrate(vm, srcHostId, dest);
return;
} catch (final ResourceUnavailableException e) {
s_logger.debug("Unable to migrate to unavailable " + dest);
} catch (final ConcurrentOperationException e) {
s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
}
try {
advanceStop(vmUuid, true);
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final ResourceUnavailableException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final ConcurrentOperationException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final OperationTimedoutException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
}
}
}
use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.
the class KVMStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.
@Override
protected Answer migrateVmWithVolumesAcrossCluster(final VMInstanceVO instanceTo, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final Map<VolumeInfo, DataStore> volumeToPoolMap) throws AgentUnavailableException {
try {
final List<Pair<VolumeTO, StorageFilerTO>> volumeMapping = buildVolumeMapping(volumeToPoolMap);
final MigrateWithStorageAcrossClustersCommand command = new MigrateWithStorageAcrossClustersCommand(vmTo, volumeMapping, destHost.getPrivateIpAddress());
final MigrateWithStorageAcrossClustersAnswer answer = (MigrateWithStorageAcrossClustersAnswer) agentMgr.send(srcHost.getId(), command);
if (answer == null) {
final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s", instanceTo, destHost);
s_logger.error(errorMessage);
throw new CloudRuntimeException(errorMessage);
} else if (!answer.getResult()) {
final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s => Details: %s", instanceTo, destHost, answer.getDetails());
s_logger.error(errorMessage);
throw new CloudRuntimeException(errorMessage);
} else {
// Update the volume details after migration.
updateVolumePathsAfterMigration(volumeToPoolMap, answer.getVolumes());
}
return answer;
} catch (final OperationTimedoutException e) {
final String errorMessage = String.format("Operation timed out when attempting to migrate VM %s to host %s", instanceTo, destHost);
s_logger.error(errorMessage, e);
throw new AgentUnavailableException(errorMessage, srcHost.getId());
}
}
use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.
the class XcpServerDiscoverer method processConnect.
@Override
public void processConnect(final com.cloud.host.Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
final long agentId = agent.getId();
final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
final HostVO host = _hostDao.findById(agentId);
final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
} else if (!cluster.getGuid().equals(startup.getPool())) {
final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
final Map<String, String> details = startup.getHostDetails();
final String prodBrand = details.get("product_brand").trim();
final String prodVersion = details.get("product_version").trim();
final String hotfix = details.get(XenserverConfigs.XS620HotFix);
final String prodVersionTextShort = details.get("product_version_text_short");
final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
if (!resource.equals(host.getResource())) {
final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
s_logger.debug(msg);
host.setResource(resource);
host.setSetup(false);
_hostDao.update(agentId, host);
throw new HypervisorVersionChangedException(msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
final HostEnvironment env = new HostEnvironment();
final SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
final Answer answer = _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
host.setHypervisorVersion(prodVersion);
_hostDao.update(host.getId(), host);
if (((SetupAnswer) answer).needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
}
} catch (final AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (final OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.
the class DefaultVMSnapshotStrategy method takeVMSnapshot.
@Override
public VMSnapshot takeVMSnapshot(final VMSnapshot vmSnapshot) {
final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
final UserVm userVm = userVmDao.findById(vmSnapshot.getVmId());
final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested);
} catch (final NoTransitionException e) {
throw new CloudRuntimeException(e.getMessage());
}
CreateVMSnapshotAnswer answer = null;
boolean result = false;
try {
final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
VMSnapshotTO current = null;
final VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
if (currentSnapshot != null) {
current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
}
final VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
boolean quiescevm = true;
if (options != null) {
quiescevm = options.needQuiesceVM();
}
final VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false, current, quiescevm);
if (current == null) {
vmSnapshotVO.setParent(null);
} else {
vmSnapshotVO.setParent(current.getId());
}
final HostVO host = hostDao.findById(hostId);
final GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
final CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName());
if (guestOsMapping == null) {
ccmd.setPlatformEmulator(null);
} else {
ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
}
ccmd.setWait(_wait);
answer = (CreateVMSnapshotAnswer) agentMgr.send(hostId, ccmd);
if (answer != null && answer.getResult()) {
processAnswer(vmSnapshotVO, userVm, answer, hostId);
s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
result = true;
return vmSnapshot;
} else {
String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed";
if (answer != null && answer.getDetails() != null) {
errMsg = errMsg + " due to " + answer.getDetails();
}
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
} catch (final OperationTimedoutException e) {
s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
} catch (final AgentUnavailableException e) {
s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e);
throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
} finally {
if (!result) {
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
} catch (final NoTransitionException e1) {
s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
}
}
}
}
Aggregations