Search in sources :

Example 16 with ServiceOffering

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;
    }
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with ServiceOffering

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;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 18 with ServiceOffering

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");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 19 with ServiceOffering

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");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 20 with ServiceOffering

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);
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) JobInfo(org.apache.cloudstack.jobs.JobInfo) Pair(com.cloud.utils.Pair) ReflectionUse(com.cloud.utils.ReflectionUse)

Aggregations

ServiceOffering (com.cloud.offering.ServiceOffering)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 Account (com.cloud.user.Account)14 ArrayList (java.util.ArrayList)13 DataCenter (com.cloud.dc.DataCenter)11 VirtualMachine (com.cloud.vm.VirtualMachine)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)8 ServerApiException (com.cloud.api.ServerApiException)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 UserVm (com.cloud.uservm.UserVm)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 HashMap (java.util.HashMap)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Host (com.cloud.host.Host)4 HostVO (com.cloud.host.HostVO)4 DiskOffering (com.cloud.offering.DiskOffering)4 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 ServiceOfferingResponse (com.cloud.api.response.ServiceOfferingResponse)3