use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class FirstFitPlanner method scanPodsForDestination.
private List<Long> scanPodsForDestination(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) {
ServiceOffering offering = vmProfile.getServiceOffering();
int requiredCpu = offering.getCpu() * offering.getSpeed();
long requiredRam = offering.getRamSize() * 1024L * 1024L;
//list pods under this zone by cpu and ram capacity
List<Long> prioritizedPodIds = new ArrayList<Long>();
Pair<List<Long>, Map<Long, Double>> podCapacityInfo = listPodsByCapacity(plan.getDataCenterId(), requiredCpu, requiredRam);
List<Long> podsWithCapacity = podCapacityInfo.first();
if (!podsWithCapacity.isEmpty()) {
if (avoid.getPodsToAvoid() != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the podId list these pods from avoid set: " + avoid.getPodsToAvoid());
}
podsWithCapacity.removeAll(avoid.getPodsToAvoid());
}
if (!isRootAdmin(vmProfile)) {
List<Long> disabledPods = listDisabledPods(plan.getDataCenterId());
if (!disabledPods.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the podId list these pods that are disabled: " + disabledPods);
}
podsWithCapacity.removeAll(disabledPods);
}
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No pods found having a host with enough capacity, returning.");
}
return null;
}
if (!podsWithCapacity.isEmpty()) {
prioritizedPodIds = reorderPods(podCapacityInfo, vmProfile, plan);
if (prioritizedPodIds == null || prioritizedPodIds.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found for destination, returning.");
}
return null;
}
List<Long> clusterList = new ArrayList<Long>();
//loop over pods
for (Long podId : prioritizedPodIds) {
s_logger.debug("Checking resources under Pod: " + podId);
List<Long> clustersUnderPod = scanClustersForDestinationInZoneOrPod(podId, false, vmProfile, plan, avoid);
if (clustersUnderPod != null) {
clusterList.addAll(clustersUnderPod);
}
}
return clusterList;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found after removing disabled pods and pods in avoid list, returning.");
}
return null;
}
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class ConfigurationManagerImpl method getServiceOfferingNetworkRate.
@Override
public Integer getServiceOfferingNetworkRate(final long serviceOfferingId, final Long dataCenterId) {
// validate network offering information
final ServiceOffering offering = _serviceOfferingDao.findById(serviceOfferingId);
if (offering == null) {
throw new InvalidParameterValueException("Unable to find service offering by id=" + serviceOfferingId);
}
Integer networkRate;
if (offering.getRateMbps() != null) {
networkRate = offering.getRateMbps();
} else {
// for domain router service offering, get network rate from
if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) {
networkRate = NetworkOrchestrationService.NetworkThrottlingRate.valueIn(dataCenterId);
} else {
networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key()));
}
}
// all our other resources where -1 means unlimited
if (networkRate == 0) {
networkRate = -1;
}
return networkRate;
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class UpgradeVMCmdByAdmin method execute.
@Override
public void execute() throws ResourceAllocationException {
CallContext.current().setEventDetails("Vm Id: " + getId());
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
UserVm result = _userVmService.upgradeVirtualMachine(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
}
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class UpgradeVMCmd method execute.
@Override
public void execute() throws ResourceAllocationException {
CallContext.current().setEventDetails("Vm Id: " + getId());
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
UserVm result = _userVmService.upgradeVirtualMachine(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
}
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateReconfigure.
@ReflectionUse
private Pair<JobInfo.Status, String> orchestrateReconfigure(final VmWorkReconfigure work) throws Exception {
final VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, work.getVmId());
if (vm == null) {
s_logger.info("Unable to find vm " + work.getVmId());
}
assert vm != null;
final ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), work.getNewServiceOfferingId());
reConfigureVm(vm.getUuid(), newServiceOffering, work.isSameHost());
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
}
Aggregations