use of com.cloud.exception.InsufficientServerCapacityException in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method migrateAway.
@Override
public void migrateAway(final String vmUuid, final long srcHostId) throws InsufficientServerCapacityException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
VmWorkJobVO placeHolder = null;
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
placeHolder = createPlaceHolderWork(vm.getId());
try {
try {
orchestrateMigrateAway(vmUuid, srcHostId, null);
} catch (final InsufficientServerCapacityException e) {
s_logger.warn("Failed to deploy vm " + vmUuid + " with original planner, sending HAPlanner");
orchestrateMigrateAway(vmUuid, srcHostId, _haMgr.getHAPlanner());
}
} finally {
_workJobDao.expunge(placeHolder.getId());
}
} else {
final Outcome<VirtualMachine> outcome = migrateVmAwayThroughJobQueue(vmUuid, srcHostId);
try {
final VirtualMachine vm = outcome.get();
} catch (final InterruptedException e) {
throw new RuntimeException("Operation is interrupted", e);
} catch (final java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
final Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
if (jobException != null) {
if (jobException instanceof InsufficientServerCapacityException) {
throw (InsufficientServerCapacityException) jobException;
} else if (jobException instanceof ConcurrentOperationException) {
throw (ConcurrentOperationException) jobException;
} else if (jobException instanceof RuntimeException) {
throw (RuntimeException) jobException;
} else if (jobException instanceof Throwable) {
throw new RuntimeException("Unexpected exception", (Throwable) jobException);
}
}
}
}
use of com.cloud.exception.InsufficientServerCapacityException in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method findHostAndMigrate.
@Override
public void findHostAndMigrate(final String vmUuid, final Long newSvcOfferingId, final ExcludeList excludes) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (vm == null) {
throw new CloudRuntimeException("Unable to find " + vmUuid);
}
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
final Long srcHostId = vm.getHostId();
final Long oldSvcOfferingId = vm.getServiceOfferingId();
if (srcHostId == null) {
throw new CloudRuntimeException("Unable to scale the vm because it doesn't have a host id");
}
final Host host = _hostDao.findById(srcHostId);
final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
excludes.addHost(vm.getHostId());
// Need to find the destination host based on new svc offering
vm.setServiceOfferingId(newSvcOfferingId);
DeployDestination dest = null;
try {
dest = _dpMgr.planDeployment(profile, plan, excludes, null);
} 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 " + dest + " for scaling the vm to.");
}
if (dest == null) {
throw new InsufficientServerCapacityException("Unable to find a server to scale the vm to.", host.getClusterId());
}
excludes.addHost(dest.getHost().getId());
try {
migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId);
} catch (final ResourceUnavailableException e) {
s_logger.debug("Unable to migrate to unavailable " + dest);
throw e;
} catch (final ConcurrentOperationException e) {
s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
throw e;
}
}
use of com.cloud.exception.InsufficientServerCapacityException in project cosmic by MissionCriticalCloud.
the class VMEntityManagerImpl method reserveVirtualMachine.
@Override
public String reserveVirtualMachine(final VMEntityVO vmEntityVO, final DeploymentPlanner plannerToUse, final DeploymentPlan planToDeploy, final ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException {
// call planner and get the deployDestination.
// load vm instance and offerings and call virtualMachineManagerImpl
// FIXME: profile should work on VirtualMachineEntity
final VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
vmProfile.setServiceOffering(_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()));
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
}
boolean planChangedByReadyVolume = false;
final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
if (!vols.isEmpty()) {
final VolumeVO vol = vols.get(0);
final StoragePool pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
if (!pool.isInMaintenance()) {
final long rootVolDcId = pool.getDataCenterId();
final Long rootVolPodId = pool.getPodId();
final Long rootVolClusterId = pool.getClusterId();
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
final Long clusterIdSpecified = planToDeploy.getClusterId();
if (clusterIdSpecified != null && rootVolClusterId != null) {
checkIfPlanIsDeployable(vm, rootVolClusterId, clusterIdSpecified);
}
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
} else {
plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
planChangedByReadyVolume = true;
}
}
}
while (true) {
DeployDestination dest = null;
try {
dest = _dpMgr.planDeployment(vmProfile, plan, exclude, plannerToUse);
} catch (final AffinityConflictException e) {
throw new CloudRuntimeException("Unable to create deployment, affinity rules associated to the VM conflict");
}
if (dest != null) {
final String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude, plannerToUse);
if (reservationId != null) {
return reservationId;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying");
}
exclude.addHost(dest.getHost().getId());
continue;
}
} else if (planChangedByReadyVolume) {
// call retry it.
return UUID.randomUUID().toString();
} else {
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
}
}
}
use of com.cloud.exception.InsufficientServerCapacityException in project cosmic by MissionCriticalCloud.
the class NetworkHelperImpl method getHypervisors.
protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientServerCapacityException {
final DeployDestination dest = routerDeploymentDefinition.getDest();
List<HypervisorType> hypervisors = new ArrayList<>();
if (dest.getCluster() != null) {
hypervisors.add(dest.getCluster().getHypervisorType());
} else {
final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getZone().getId());
if (defaults != HypervisorType.None) {
hypervisors.add(defaults);
} else {
// if there is no default hypervisor, get it from the cluster
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getZone().getId(), true, routerDeploymentDefinition.getPlan().getPodId());
}
}
filterSupportedHypervisors(hypervisors);
if (hypervisors.isEmpty()) {
if (routerDeploymentDefinition.getPodId() != null) {
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), Pod.class, routerDeploymentDefinition.getPodId());
}
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), DataCenter.class, dest.getZone().getId());
}
return hypervisors;
}
use of com.cloud.exception.InsufficientServerCapacityException in project cosmic by MissionCriticalCloud.
the class HighAvailabilityManagerImpl method migrate.
public Long migrate(final HaWorkVO work) {
final long vmId = work.getInstanceId();
final long srcHostId = work.getHostId();
try {
work.setStep(Step.Migrating);
_haDao.update(work.getId(), work);
final VMInstanceVO vm = _instanceDao.findById(vmId);
if (vm == null) {
return null;
}
// First try starting the vm with its original planner, if it doesn't succeed send HAPlanner as its an emergency.
_itMgr.migrateAway(vm.getUuid(), srcHostId);
return null;
} catch (final InsufficientServerCapacityException e) {
s_logger.warn("Insufficient capacity for migrating a VM.");
_resourceMgr.maintenanceFailed(srcHostId);
return (System.currentTimeMillis() >> 10) + _migrateRetryInterval;
}
}
Aggregations