use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class FirstFitPlanner method scanClustersForDestinationInZoneOrPod.
private List<Long> scanClustersForDestinationInZoneOrPod(final long id, final boolean isZone, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final ServiceOffering offering = vmProfile.getServiceOffering();
final int requiredCpu = offering.getCpu();
final long requiredRam = offering.getRamSize() * 1024L * 1024L;
// list clusters under this zone by cpu and ram capacity
final Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
final List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
if (!prioritizedClusterIds.isEmpty()) {
if (avoid.getClustersToAvoid() != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the clusterId list these clusters from avoid set: " + avoid.getClustersToAvoid());
}
prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
}
if (!isRootAdmin(vmProfile)) {
List<Long> disabledClusters = new ArrayList<>();
if (isZone) {
disabledClusters = listDisabledClusters(plan.getDataCenterId(), null);
} else {
disabledClusters = listDisabledClusters(plan.getDataCenterId(), id);
}
if (!disabledClusters.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: " + disabledClusters);
}
prioritizedClusterIds.removeAll(disabledClusters);
}
}
removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found having a host with enough capacity, returning.");
}
return null;
}
if (!prioritizedClusterIds.isEmpty()) {
// return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
return reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
}
return null;
}
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class FirstFitPlanner method orderClusters.
@Override
public List<Long> orderClusters(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) throws InsufficientServerCapacityException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Zone zone = zoneRepository.findOne(vm.getDataCenterId());
// check if datacenter is in avoid set
if (avoid.shouldAvoid(zone)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("DataCenter id = '" + zone.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
}
return null;
}
List<Long> clusterList = new ArrayList<>();
if (plan.getClusterId() != null) {
final Long clusterIdSpecified = plan.getClusterId();
s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
final ClusterVO cluster = clusterDao.findById(plan.getClusterId());
if (cluster != null) {
if (avoid.shouldAvoid(cluster)) {
s_logger.debug("The specified cluster is in avoid set, returning.");
} else {
clusterList.add(clusterIdSpecified);
removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
}
} else {
s_logger.debug("The specified cluster cannot be found, returning.");
avoid.addCluster(plan.getClusterId());
return null;
}
} else if (plan.getPodId() != null) {
// consider clusters under this pod only
final Long podIdSpecified = plan.getPodId();
s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
final HostPodVO pod = podDao.findById(podIdSpecified);
if (pod != null) {
if (avoid.shouldAvoid(pod)) {
s_logger.debug("The specified pod is in avoid set, returning.");
} else {
clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
if (clusterList == null) {
avoid.addPod(plan.getPodId());
}
}
} else {
s_logger.debug("The specified Pod cannot be found, returning.");
avoid.addPod(plan.getPodId());
return null;
}
} else {
s_logger.debug("Searching all possible resources under this Zone: " + plan.getDataCenterId());
final boolean applyAllocationAtPods = Boolean.parseBoolean(configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
if (applyAllocationAtPods) {
// start scan at all pods under this zone.
clusterList = scanPodsForDestination(vmProfile, plan, avoid);
} else {
// start scan at clusters under this zone.
clusterList = scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(), true, vmProfile, plan, avoid);
}
}
if (clusterList != null && !clusterList.isEmpty()) {
final ServiceOffering offering = vmProfile.getServiceOffering();
// In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
if ((serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) && !(hostGpuGroupsDao.listHostIds().isEmpty())) {
final int requiredCpu = offering.getCpu();
final long requiredRam = offering.getRamSize() * 1024L * 1024L;
reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
}
}
return clusterList;
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class HypervisorGuruBase method toVirtualMachineTO.
protected VirtualMachineTO toVirtualMachineTO(final VirtualMachineProfile vmProfile) {
final ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Long minMemory = (long) (offering.getRamSize() / vmProfile.getMemoryOvercommitRatio());
final VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
to.setBootArgs(vmProfile.getBootArgs());
final List<NicProfile> nicProfiles = vmProfile.getNics();
final NicTO[] nics = new NicTO[nicProfiles.size()];
int i = 0;
for (final NicProfile nicProfile : nicProfiles) {
nics[i++] = toNicTO(nicProfile);
}
to.setNics(nics);
to.setDisks(vmProfile.getDisks().toArray(new DiskTO[vmProfile.getDisks().size()]));
if (vmProfile.getTemplate().getBits() == 32) {
to.setArch("i686");
} else {
to.setArch("x86_64");
}
final Map<String, String> detailsInVm = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (detailsInVm != null) {
to.setDetails(detailsInVm);
}
// Set GPU details
ServiceOfferingDetailsVO offeringDetail;
if ((offeringDetail = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
final ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
to.setGpuDevice(_resourceMgr.getGPUDevice(vm.getHostId(), groupName.getValue(), offeringDetail.getValue()));
}
// Workaround to make sure the TO has the UUID we need for Niciri integration
final VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId());
// check if XStools tools are present in the VM and dynamic scaling feature is enabled (per zone/global)
final Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && UserVmManager.EnableDynamicallyScaleVm.valueIn(vm.getDataCenterId());
to.setEnableDynamicallyScaleVm(isDynamicallyScalable);
to.setUuid(vmInstance.getUuid());
to.setVmData(vmProfile.getVmData());
to.setConfigDriveLabel(vmProfile.getConfigDriveLabel());
to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder());
to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile());
final MetadataTO metadataTO = new MetadataTO();
final DomainVO domain = _domainDao.findById(vm.getDomainId());
metadataTO.setDomainUuid(domain.getUuid());
to.setMetadata(metadataTO);
return to;
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class ScaleSystemVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("SystemVm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
VirtualMachine result = null;
try {
result = _mgr.upgradeSystemVM(this);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (ManagementServerException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (VirtualMachineMigrationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade system vm");
}
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class UpgradeSystemVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
VirtualMachine result = _mgr.upgradeSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to reboot system vm");
}
}
Aggregations