Search in sources :

Example 31 with ServiceOffering

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

the class FirstFitPlanner method orderClusters.

@Override
public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    //check if datacenter is in avoid set
    if (avoid.shouldAvoid(dc)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DataCenter id = '" + dc.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
        }
        return null;
    }
    List<Long> clusterList = new ArrayList<Long>();
    if (plan.getClusterId() != null) {
        Long clusterIdSpecified = plan.getClusterId();
        s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
        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
        Long podIdSpecified = plan.getPodId();
        s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
        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());
        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()) {
        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())) {
            int requiredCpu = offering.getCpu() * offering.getSpeed();
            long requiredRam = offering.getRamSize() * 1024L * 1024L;
            reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
        }
    }
    return clusterList;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ClusterVO(com.cloud.dc.ClusterVO) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 32 with ServiceOffering

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

the class HypervisorGuruBase method toVirtualMachineTO.

protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) {
    ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
    VirtualMachine vm = vmProfile.getVirtualMachine();
    Long minMemory = (long) (offering.getRamSize() / vmProfile.getMemoryOvercommitRatio());
    int minspeed = (int) (offering.getSpeed() / vmProfile.getCpuOvercommitRatio());
    int maxspeed = (offering.getSpeed());
    VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed, minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
    to.setBootArgs(vmProfile.getBootArgs());
    List<NicProfile> nicProfiles = vmProfile.getNics();
    NicTO[] nics = new NicTO[nicProfiles.size()];
    int i = 0;
    for (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");
    }
    Map<String, String> detailsInVm = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
    if (detailsInVm != null) {
        to.setDetails(detailsInVm);
    }
    // Set GPU details
    ServiceOfferingDetailsVO offeringDetail = null;
    if ((offeringDetail = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
        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
    VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId());
    // check if XStools/VMWare tools are present in the VM and dynamic scaling feature is enabled (per zone/global)
    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());
    return to;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) VirtualMachine(com.cloud.vm.VirtualMachine) NicTO(com.cloud.agent.api.to.NicTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 33 with ServiceOffering

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

the class ConfigurationManagerImpl method updateServiceOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_EDIT, eventDescription = "updating service offering")
public ServiceOffering updateServiceOffering(final UpdateServiceOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getServiceOfferingName();
    final Integer sortKey = cmd.getSortKey();
    Long userId = CallContext.current().getCallingUserId();
    if (userId == null) {
        userId = Long.valueOf(User.UID_SYSTEM);
    }
    // Verify input parameters
    final ServiceOffering offeringHandle = _entityMgr.findById(ServiceOffering.class, id);
    if (offeringHandle == null) {
        throw new InvalidParameterValueException("unable to find service offering " + id);
    }
    final User user = _userDao.findById(userId);
    if (user == null || user.getRemoved() != null) {
        throw new InvalidParameterValueException("Unable to find active user by id " + userId);
    }
    final Account account = _accountDao.findById(user.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        if (offeringHandle.getDomainId() == null) {
            throw new InvalidParameterValueException("Unable to update public service offering by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), offeringHandle.getDomainId())) {
            throw new InvalidParameterValueException("Unable to update service offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to update service offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    final boolean updateNeeded = name != null || displayText != null || sortKey != null;
    if (!updateNeeded) {
        return _serviceOfferingDao.findById(id);
    }
    ServiceOfferingVO offering = _serviceOfferingDao.createForUpdate(id);
    if (name != null) {
        offering.setName(name);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        offering.setSortKey(sortKey);
    }
    if (_serviceOfferingDao.update(id, offering)) {
        offering = _serviceOfferingDao.findById(id);
        CallContext.current().setEventDetails("Service offering id=" + offering.getId());
        return offering;
    } else {
        return null;
    }
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 34 with ServiceOffering

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

the class UserVmManagerImpl method upgradeStoppedVirtualMachine.

private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String, String> customParameters) throws ResourceAllocationException {
    Account caller = CallContext.current().getCallingAccount();
    // Verify input parameters
    //UserVmVO vmInstance = _vmDao.findById(vmId);
    VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
    if (vmInstance == null) {
        throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
    }
    _accountMgr.checkAccess(caller, null, true, vmInstance);
    // Check resource limits for CPU and Memory.
    ServiceOfferingVO newServiceOffering = _offeringDao.findById(svcOffId);
    if (newServiceOffering.isDynamic()) {
        newServiceOffering.setDynamicFlag(true);
        validateCustomParameters(newServiceOffering, customParameters);
        newServiceOffering = _offeringDao.getcomputeOffering(newServiceOffering, customParameters);
    }
    ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
    int newCpu = newServiceOffering.getCpu();
    int newMemory = newServiceOffering.getRamSize();
    int currentCpu = currentServiceOffering.getCpu();
    int currentMemory = currentServiceOffering.getRamSize();
    if (newCpu > currentCpu) {
        _resourceLimitMgr.checkResourceLimit(caller, ResourceType.cpu, newCpu - currentCpu);
    }
    if (newMemory > currentMemory) {
        _resourceLimitMgr.checkResourceLimit(caller, ResourceType.memory, newMemory - currentMemory);
    }
    // Check that the specified service offering ID is valid
    _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
    // Check if the new service offering can be applied to vm instance
    ServiceOffering newSvcOffering = _offeringDao.findById(svcOffId);
    Account owner = _accountMgr.getActiveAccountById(vmInstance.getAccountId());
    _accountMgr.checkAccess(owner, newSvcOffering);
    _itMgr.upgradeVmDb(vmId, svcOffId);
    if (newServiceOffering.isDynamic()) {
        //save the custom values to the database.
        saveCustomOfferingDetails(vmId, newServiceOffering);
    }
    if (currentServiceOffering.isDynamic() && !newServiceOffering.isDynamic()) {
        removeCustomOfferingDetails(vmId);
    }
    // Increment or decrement CPU and Memory count accordingly.
    if (newCpu > currentCpu) {
        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long(newCpu - currentCpu));
    } else if (currentCpu > newCpu) {
        _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long(currentCpu - newCpu));
    }
    if (newMemory > currentMemory) {
        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long(newMemory - currentMemory));
    } else if (currentMemory > newMemory) {
        _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long(currentMemory - newMemory));
    }
    return _vmDao.findById(vmInstance.getId());
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 35 with ServiceOffering

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

the class CapacityManagerImpl method updateCapacityForHost.

@DB
@Override
public void updateCapacityForHost(final Host host) {
    // prepare the service offerings
    List<ServiceOfferingVO> offerings = _offeringsDao.listAllIncludingRemoved();
    Map<Long, ServiceOfferingVO> offeringsMap = new HashMap<Long, ServiceOfferingVO>();
    for (ServiceOfferingVO offering : offerings) {
        offeringsMap.put(offering.getId(), offering);
    }
    long usedCpu = 0;
    long usedMemory = 0;
    long reservedMemory = 0;
    long reservedCpu = 0;
    final CapacityState capacityState = (host.getResourceState() == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled;
    List<VMInstanceVO> vms = _vmDao.listUpByHostId(host.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Found " + vms.size() + " VMs on host " + host.getId());
    }
    ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    ClusterDetailsVO clusterDetailCpu = _clusterDetailsDao.findDetail(cluster.getId(), "cpuOvercommitRatio");
    ClusterDetailsVO clusterDetailRam = _clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio");
    Float clusterCpuOvercommitRatio = Float.parseFloat(clusterDetailCpu.getValue());
    Float clusterRamOvercommitRatio = Float.parseFloat(clusterDetailRam.getValue());
    Float cpuOvercommitRatio = 1f;
    Float ramOvercommitRatio = 1f;
    for (VMInstanceVO vm : vms) {
        Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        String vmDetailCpu = vmDetails.get("cpuOvercommitRatio");
        String vmDetailRam = vmDetails.get("memoryOvercommitRatio");
        if (vmDetailCpu != null) {
            //if vmDetail_cpu is not null it means it is running in a overcommited cluster.
            cpuOvercommitRatio = Float.parseFloat(vmDetailCpu);
            ramOvercommitRatio = Float.parseFloat(vmDetailRam);
        }
        ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
        if (so.isDynamic()) {
            usedMemory += ((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
            usedCpu += ((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()))) / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
        } else {
            usedMemory += ((so.getRamSize() * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
            usedCpu += ((so.getCpu() * so.getSpeed()) / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
        }
    }
    List<VMInstanceVO> vmsByLastHostId = _vmDao.listByLastHostId(host.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Found " + vmsByLastHostId.size() + " VM, not running on host " + host.getId());
    }
    for (VMInstanceVO vm : vmsByLastHostId) {
        long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime()) / 1000;
        if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
            UserVmDetailVO vmDetailCpu = _userVmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio");
            UserVmDetailVO vmDetailRam = _userVmDetailsDao.findDetail(vm.getId(), "memoryOvercommitRatio");
            if (vmDetailCpu != null) {
                //if vmDetail_cpu is not null it means it is running in a overcommited cluster.
                cpuOvercommitRatio = Float.parseFloat(vmDetailCpu.getValue());
                ramOvercommitRatio = Float.parseFloat(vmDetailRam.getValue());
            }
            ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
            Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
            if (so.isDynamic()) {
                reservedMemory += ((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
                reservedCpu += ((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()))) / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
            } else {
                reservedMemory += ((so.getRamSize() * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
                reservedCpu += (so.getCpu() * so.getSpeed() / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
            }
        } else {
            // signal if not done already, that the VM has been stopped for skip.counting.hours,
            // hence capacity will not be reserved anymore.
            UserVmDetailVO messageSentFlag = _userVmDetailsDao.findDetail(vm.getId(), MESSAGE_RESERVED_CAPACITY_FREED_FLAG);
            if (messageSentFlag == null || !Boolean.valueOf(messageSentFlag.getValue())) {
                _messageBus.publish(_name, "VM_ReservedCapacity_Free", PublishScope.LOCAL, vm);
                if (vm.getType() == VirtualMachine.Type.User) {
                    UserVmVO userVM = _userVMDao.findById(vm.getId());
                    _userVMDao.loadDetails(userVM);
                    userVM.setDetail(MESSAGE_RESERVED_CAPACITY_FREED_FLAG, "true");
                    _userVMDao.saveDetails(userVM);
                }
            }
        }
    }
    CapacityVO cpuCap = _capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
    CapacityVO memCap = _capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
    if (cpuCap != null && memCap != null) {
        if (host.getTotalMemory() != null) {
            memCap.setTotalCapacity(host.getTotalMemory());
        }
        long hostTotalCpu = host.getCpus().longValue() * host.getSpeed().longValue();
        if (cpuCap.getTotalCapacity() != hostTotalCpu) {
            s_logger.debug("Calibrate total cpu for host: " + host.getId() + " old total CPU:" + cpuCap.getTotalCapacity() + " new total CPU:" + hostTotalCpu);
            cpuCap.setTotalCapacity(hostTotalCpu);
        }
        // Set the capacity state as per the host allocation state.
        if (capacityState != cpuCap.getCapacityState()) {
            s_logger.debug("Calibrate cpu capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
            cpuCap.setCapacityState(capacityState);
        }
        memCap.setCapacityState(capacityState);
        if (cpuCap.getUsedCapacity() == usedCpu && cpuCap.getReservedCapacity() == reservedCpu) {
            s_logger.debug("No need to calibrate cpu capacity, host:" + host.getId() + " usedCpu: " + cpuCap.getUsedCapacity() + " reservedCpu: " + cpuCap.getReservedCapacity());
        } else {
            if (cpuCap.getReservedCapacity() != reservedCpu) {
                s_logger.debug("Calibrate reserved cpu for host: " + host.getId() + " old reservedCpu:" + cpuCap.getReservedCapacity() + " new reservedCpu:" + reservedCpu);
                cpuCap.setReservedCapacity(reservedCpu);
            }
            if (cpuCap.getUsedCapacity() != usedCpu) {
                s_logger.debug("Calibrate used cpu for host: " + host.getId() + " old usedCpu:" + cpuCap.getUsedCapacity() + " new usedCpu:" + usedCpu);
                cpuCap.setUsedCapacity(usedCpu);
            }
        }
        if (memCap.getTotalCapacity() != host.getTotalMemory()) {
            s_logger.debug("Calibrate total memory for host: " + host.getId() + " old total memory:" + memCap.getTotalCapacity() + " new total memory:" + host.getTotalMemory());
            memCap.setTotalCapacity(host.getTotalMemory());
        }
        // Set the capacity state as per the host allocation state.
        if (capacityState != memCap.getCapacityState()) {
            s_logger.debug("Calibrate memory capacity state for host: " + host.getId() + " old capacity state:" + memCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
            memCap.setCapacityState(capacityState);
        }
        if (memCap.getUsedCapacity() == usedMemory && memCap.getReservedCapacity() == reservedMemory) {
            s_logger.debug("No need to calibrate memory capacity, host:" + host.getId() + " usedMem: " + memCap.getUsedCapacity() + " reservedMem: " + memCap.getReservedCapacity());
        } else {
            if (memCap.getReservedCapacity() != reservedMemory) {
                s_logger.debug("Calibrate reserved memory for host: " + host.getId() + " old reservedMem:" + memCap.getReservedCapacity() + " new reservedMem:" + reservedMemory);
                memCap.setReservedCapacity(reservedMemory);
            }
            if (memCap.getUsedCapacity() != usedMemory) {
                /*
                     * Didn't calibrate for used memory, because VMs can be in
                     * state(starting/migrating) that I don't know on which host
                     * they are allocated
                     */
                s_logger.debug("Calibrate used memory for host: " + host.getId() + " old usedMem: " + memCap.getUsedCapacity() + " new usedMem: " + usedMemory);
                memCap.setUsedCapacity(usedMemory);
            }
        }
        try {
            _capacityDao.update(cpuCap.getId(), cpuCap);
            _capacityDao.update(memCap.getId(), memCap);
        } catch (Exception e) {
            s_logger.error("Caught exception while updating cpu/memory capacity for the host " + host.getId(), e);
        }
    } else {
        final long usedMemoryFinal = usedMemory;
        final long reservedMemoryFinal = reservedMemory;
        final long usedCpuFinal = usedCpu;
        final long reservedCpuFinal = reservedCpu;
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemoryFinal, host.getTotalMemory(), Capacity.CAPACITY_TYPE_MEMORY);
                capacity.setReservedCapacity(reservedMemoryFinal);
                capacity.setCapacityState(capacityState);
                _capacityDao.persist(capacity);
                capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedCpuFinal, host.getCpus().longValue() * host.getSpeed().longValue(), Capacity.CAPACITY_TYPE_CPU);
                capacity.setReservedCapacity(reservedCpuFinal);
                capacity.setCapacityState(capacityState);
                _capacityDao.persist(capacity);
            }
        });
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) ServiceOffering(com.cloud.offering.ServiceOffering) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConnectionException(com.cloud.exception.ConnectionException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) DB(com.cloud.utils.db.DB)

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