Search in sources :

Example 41 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class ApiResponseHelper method createAutoScaleVmProfileResponse.

@Override
public AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile) {
    AutoScaleVmProfileResponse response = new AutoScaleVmProfileResponse();
    response.setId(profile.getUuid());
    if (profile.getZoneId() != null) {
        DataCenter zone = ApiDBUtils.findZoneById(profile.getZoneId());
        if (zone != null) {
            response.setZoneId(zone.getUuid());
        }
    }
    if (profile.getServiceOfferingId() != null) {
        ServiceOffering so = ApiDBUtils.findServiceOfferingById(profile.getServiceOfferingId());
        if (so != null) {
            response.setServiceOfferingId(so.getUuid());
        }
    }
    if (profile.getTemplateId() != null) {
        VMTemplateVO template = ApiDBUtils.findTemplateById(profile.getTemplateId());
        if (template != null) {
            response.setTemplateId(template.getUuid());
        }
    }
    response.setOtherDeployParams(profile.getOtherDeployParams());
    response.setCounterParams(profile.getCounterParams());
    response.setDestroyVmGraceperiod(profile.getDestroyVmGraceperiod());
    User user = ApiDBUtils.findUserById(profile.getAutoScaleUserId());
    if (user != null) {
        response.setAutoscaleUserId(user.getUuid());
    }
    response.setObjectName("autoscalevmprofile");
    // Populates the account information in the response
    populateOwner(response, profile);
    return response;
}
Also used : DataCenter(com.cloud.dc.DataCenter) User(com.cloud.user.User) VpnUser(com.cloud.network.VpnUser) ServiceOffering(com.cloud.offering.ServiceOffering) AutoScaleVmProfileResponse(org.apache.cloudstack.api.response.AutoScaleVmProfileResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 42 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class FirstFitAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    ServiceOffering offering = vmProfile.getServiceOffering();
    VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
    Account account = vmProfile.getOwner();
    List<Host> suitableHosts = new ArrayList<Host>();
    List<Host> hostsCopy = new ArrayList<Host>(hosts);
    if (type == Host.Type.Storage) {
        // routing or not.
        return suitableHosts;
    }
    String hostTagOnOffering = offering.getHostTag();
    String hostTagOnTemplate = template.getTemplateTag();
    boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
    boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
    String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (haVmTag != null) {
        hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
    } else {
        if (hostTagOnOffering == null && hostTagOnTemplate == null) {
            hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
        } else {
            if (hasSvcOfferingTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
                }
            }
            if (hasTemplateTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
                }
            }
        }
    }
    if (!hostsCopy.isEmpty()) {
        suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
    }
    return suitableHosts;
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Example 43 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class FirstFitAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    ServiceOffering offering = vmProfile.getServiceOffering();
    VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
    Account account = vmProfile.getOwner();
    if (type == Host.Type.Storage) {
        // FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not
        return new ArrayList<Host>();
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
    }
    String hostTagOnOffering = offering.getHostTag();
    String hostTagOnTemplate = template.getTemplateTag();
    boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
    boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
    List<HostVO> clusterHosts = new ArrayList<HostVO>();
    String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (haVmTag != null) {
        clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag);
    } else {
        if (hostTagOnOffering == null && hostTagOnTemplate == null) {
            clusterHosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId);
        } else {
            List<HostVO> hostsMatchingOfferingTag = new ArrayList<HostVO>();
            List<HostVO> hostsMatchingTemplateTag = new ArrayList<HostVO>();
            if (hasSvcOfferingTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
                }
                hostsMatchingOfferingTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering);
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsMatchingOfferingTag);
                }
            }
            if (hasTemplateTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
                }
                hostsMatchingTemplateTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsMatchingTemplateTag);
                }
            }
            if (hasSvcOfferingTag && hasTemplateTag) {
                hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag);
                clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found " + hostsMatchingOfferingTag.size() + " Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag);
                }
                clusterHosts = hostsMatchingOfferingTag;
            } else {
                if (hasSvcOfferingTag) {
                    clusterHosts = hostsMatchingOfferingTag;
                } else {
                    clusterHosts = hostsMatchingTemplateTag;
                }
            }
        }
    }
    // add all hosts that we are not considering to the avoid list
    List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
    allhostsInCluster.removeAll(clusterHosts);
    for (HostVO host : allhostsInCluster) {
        avoid.addHost(host.getId());
    }
    return allocateTo(plan, offering, template, avoid, clusterHosts, returnUpTo, considerReservedCapacity, account);
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO)

Example 44 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class StorageManagerImpl method getDiskWithThrottling.

@Override
public DiskTO getDiskWithThrottling(final DataTO volTO, final Volume.Type volumeType, final long deviceId, final String path, final long offeringId, final long diskOfferingId) {
    DiskTO disk = null;
    if (volTO != null && volTO instanceof VolumeObjectTO) {
        VolumeObjectTO volumeTO = (VolumeObjectTO) volTO;
        ServiceOffering offering = _entityMgr.findById(ServiceOffering.class, offeringId);
        DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
        if (volumeType == Volume.Type.ROOT) {
            setVolumeObjectTOThrottling(volumeTO, offering, diskOffering);
        } else {
            setVolumeObjectTOThrottling(volumeTO, null, diskOffering);
        }
        disk = new DiskTO(volumeTO, deviceId, path, volumeType);
    } else {
        disk = new DiskTO(volTO, deviceId, path, volumeType);
    }
    return disk;
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServiceOffering(com.cloud.offering.ServiceOffering) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 45 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class VolumeOrchestrator method createVolumeOnPrimaryStorage.

@Override
public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException {
    VirtualMachineTemplate rootDiskTmplt = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId());
    DataCenter dcVO = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
    Pod pod = _entityMgr.findById(Pod.class, storagePool.getPodId());
    ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId());
    DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    Long clusterId = storagePool.getClusterId();
    VolumeInfo vol = null;
    if (volume.getState() == Volume.State.Allocated) {
        vol = createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePool>(), volume.getSize(), rootDiskHyperType);
    } else if (volume.getState() == Volume.State.Uploaded) {
        vol = copyVolume(storagePool, volume, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType);
        if (vol != null) {
            // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account.
            _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, volume.getSize());
            _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.getSize());
        }
    }
    if (vol == null) {
        throw new CloudRuntimeException("Volume shouldn't be null " + volume.getId());
    }
    VolumeVO volVO = _volsDao.findById(vol.getId());
    if (volVO.getFormat() == null) {
        volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType));
    }
    _volsDao.update(volVO.getId(), volVO);
    return volFactory.getVolume(volVO.getId());
}
Also used : DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) Pod(com.cloud.dc.Pod) VolumeVO(com.cloud.storage.VolumeVO) ServiceOffering(com.cloud.offering.ServiceOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

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