Search in sources :

Example 1 with UserVmDetailVO

use of com.cloud.vm.UserVmDetailVO in project cloudstack by apache.

the class ConsoleProxyServlet method composeConsoleAccessUrl.

private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO hostVo) {
    StringBuffer sb = new StringBuffer(rootUrl);
    String host = hostVo.getPrivateIpAddress();
    Pair<String, Integer> portInfo = _ms.getVncPort(vm);
    if (s_logger.isDebugEnabled())
        s_logger.debug("Port info " + portInfo.first());
    Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
    int port = -1;
    if (portInfo.second() == -9) {
        //for hyperv
        port = Integer.parseInt(_ms.findDetail(hostVo.getId(), "rdp.server.port").getValue());
    } else {
        port = portInfo.second();
    }
    String sid = vm.getVncPassword();
    UserVmDetailVO details = _userVmDetailsDao.findDetail(vm.getId(), "keyboard");
    String tag = vm.getUuid();
    String ticket = genAccessTicket(parsedHostInfo.first(), String.valueOf(port), sid, tag);
    ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(getEncryptorPassword());
    ConsoleProxyClientParam param = new ConsoleProxyClientParam();
    param.setClientHostAddress(parsedHostInfo.first());
    param.setClientHostPort(port);
    param.setClientHostPassword(sid);
    param.setClientTag(tag);
    param.setTicket(ticket);
    if (details != null) {
        param.setLocale(details.getValue());
    }
    if (portInfo.second() == -9) {
        //For Hyperv Clinet Host Address will send Instance id
        param.setHypervHost(host);
        param.setUsername(_ms.findDetail(hostVo.getId(), "username").getValue());
        param.setPassword(_ms.findDetail(hostVo.getId(), "password").getValue());
    }
    if (parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
        param.setClientTunnelUrl(parsedHostInfo.second());
        param.setClientTunnelSession(parsedHostInfo.third());
    }
    sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
    // for console access, we need guest OS type to help implement keyboard
    long guestOs = vm.getGuestOSId();
    GuestOSVO guestOsVo = _ms.getGuestOs(guestOs);
    if (guestOsVo.getCategoryId() == 6)
        sb.append("&guest=windows");
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Compose console url: " + sb.toString());
    }
    return sb.toString();
}
Also used : UserVmDetailVO(com.cloud.vm.UserVmDetailVO) GuestOSVO(com.cloud.storage.GuestOSVO)

Example 2 with UserVmDetailVO

use of com.cloud.vm.UserVmDetailVO in project cloudstack by apache.

the class UserVmDaoImpl method saveDetails.

@Override
public void saveDetails(UserVmVO vm) {
    Map<String, String> detailsStr = vm.getDetails();
    if (detailsStr == null) {
        return;
    }
    List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
    for (String key : detailsStr.keySet()) {
        details.add(new UserVmDetailVO(vm.getId(), key, detailsStr.get(key), true));
    }
    _detailsDao.saveDetails(details);
}
Also used : UserVmDetailVO(com.cloud.vm.UserVmDetailVO) ArrayList(java.util.ArrayList)

Example 3 with UserVmDetailVO

use of com.cloud.vm.UserVmDetailVO in project cloudstack by apache.

the class UserVmJoinDaoImpl method newUserVmResponse.

@Override
public UserVmResponse newUserVmResponse(ResponseView view, String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
    UserVmResponse userVmResponse = new UserVmResponse();
    if (userVm.getHypervisorType() != null) {
        userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
    }
    userVmResponse.setId(userVm.getUuid());
    userVmResponse.setName(userVm.getName());
    if (userVm.getDisplayName() != null) {
        userVmResponse.setDisplayName(userVm.getDisplayName());
    } else {
        userVmResponse.setDisplayName(userVm.getName());
    }
    if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
        userVmResponse.setProjectId(userVm.getProjectUuid());
        userVmResponse.setProjectName(userVm.getProjectName());
    } else {
        userVmResponse.setAccountName(userVm.getAccountName());
    }
    User user = _userDao.getUser(userVm.getUserId());
    if (user != null) {
        userVmResponse.setUserId(user.getUuid());
        userVmResponse.setUserName(user.getUsername());
    }
    userVmResponse.setDomainId(userVm.getDomainUuid());
    userVmResponse.setDomainName(userVm.getDomainName());
    userVmResponse.setCreated(userVm.getCreated());
    userVmResponse.setDisplayVm(userVm.isDisplayVm());
    if (userVm.getState() != null) {
        userVmResponse.setState(userVm.getState().toString());
    }
    userVmResponse.setHaEnable(userVm.isHaEnabled());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) {
        userVmResponse.setGroupId(userVm.getInstanceGroupUuid());
        userVmResponse.setGroup(userVm.getInstanceGroupName());
    }
    userVmResponse.setZoneId(userVm.getDataCenterUuid());
    userVmResponse.setZoneName(userVm.getDataCenterName());
    if (view == ResponseView.Full) {
        userVmResponse.setInstanceName(userVm.getInstanceName());
        userVmResponse.setHostId(userVm.getHostUuid());
        userVmResponse.setHostName(userVm.getHostName());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) {
        userVmResponse.setTemplateId(userVm.getTemplateUuid());
        userVmResponse.setTemplateName(userVm.getTemplateName());
        userVmResponse.setTemplateDisplayText(userVm.getTemplateDisplayText());
        userVmResponse.setPasswordEnabled(userVm.isPasswordEnabled());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) {
        userVmResponse.setIsoId(userVm.getIsoUuid());
        userVmResponse.setIsoName(userVm.getIsoName());
        userVmResponse.setIsoDisplayText(userVm.getIsoDisplayText());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) {
        userVmResponse.setServiceOfferingId(userVm.getServiceOfferingUuid());
        userVmResponse.setServiceOfferingName(userVm.getServiceOfferingName());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.diskoff)) {
        userVmResponse.setDiskOfferingId(userVm.getDiskOfferingUuid());
        userVmResponse.setDiskOfferingName(userVm.getDiskOfferingName());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff) || details.contains(VMDetails.stats)) {
        userVmResponse.setCpuNumber(userVm.getCpu());
        userVmResponse.setCpuSpeed(userVm.getSpeed());
        userVmResponse.setMemory(userVm.getRamSize());
        ServiceOfferingDetailsVO serviceOfferingDetail = ApiDBUtils.findServiceOfferingDetail(userVm.getServiceOfferingId(), GPU.Keys.vgpuType.toString());
        if (serviceOfferingDetail != null) {
            userVmResponse.setVgpu(serviceOfferingDetail.getValue());
        }
    }
    userVmResponse.setGuestOsId(userVm.getGuestOsUuid());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) {
        userVmResponse.setRootDeviceId(userVm.getVolumeDeviceId());
        if (userVm.getVolumeType() != null) {
            userVmResponse.setRootDeviceType(userVm.getVolumeType().toString());
        }
    }
    userVmResponse.setPassword(userVm.getPassword());
    if (userVm.getJobId() != null) {
        userVmResponse.setJobId(userVm.getJobUuid());
        userVmResponse.setJobStatus(userVm.getJobStatus());
    }
    //userVmResponse.setForVirtualNetwork(userVm.getForVirtualNetwork());
    userVmResponse.setPublicIpId(userVm.getPublicIpUuid());
    userVmResponse.setPublicIp(userVm.getPublicIpAddress());
    userVmResponse.setKeyPairName(userVm.getKeypairName());
    userVmResponse.setOsTypeId(userVm.getGuestOsId());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) {
        // stats calculation
        VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
        if (vmStats != null) {
            userVmResponse.setCpuUsed(new DecimalFormat("#.##").format(vmStats.getCPUUtilization()) + "%");
            userVmResponse.setNetworkKbsRead((long) vmStats.getNetworkReadKBs());
            userVmResponse.setNetworkKbsWrite((long) vmStats.getNetworkWriteKBs());
            userVmResponse.setDiskKbsRead((long) vmStats.getDiskReadKBs());
            userVmResponse.setDiskKbsWrite((long) vmStats.getDiskWriteKBs());
            userVmResponse.setDiskIORead((long) vmStats.getDiskReadIOs());
            userVmResponse.setDiskIOWrite((long) vmStats.getDiskWriteIOs());
            userVmResponse.setMemoryKBs((long) vmStats.getMemoryKBs());
            userVmResponse.setMemoryIntFreeKBs((long) vmStats.getIntFreeMemoryKBs());
            userVmResponse.setMemoryTargetKBs((long) vmStats.getTargetMemoryKBs());
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) {
        Long securityGroupId = userVm.getSecurityGroupId();
        if (securityGroupId != null && securityGroupId.longValue() != 0) {
            SecurityGroupResponse resp = new SecurityGroupResponse();
            resp.setId(userVm.getSecurityGroupUuid());
            resp.setName(userVm.getSecurityGroupName());
            resp.setDescription(userVm.getSecurityGroupDescription());
            resp.setObjectName("securitygroup");
            if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
                resp.setProjectId(userVm.getProjectUuid());
                resp.setProjectName(userVm.getProjectName());
            } else {
                resp.setAccountName(userVm.getAccountName());
            }
            userVmResponse.addSecurityGroup(resp);
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) {
        long nic_id = userVm.getNicId();
        if (nic_id > 0) {
            NicResponse nicResponse = new NicResponse();
            nicResponse.setId(userVm.getNicUuid());
            nicResponse.setIpaddress(userVm.getIpAddress());
            nicResponse.setGateway(userVm.getGateway());
            nicResponse.setNetmask(userVm.getNetmask());
            nicResponse.setNetworkid(userVm.getNetworkUuid());
            nicResponse.setNetworkName(userVm.getNetworkName());
            nicResponse.setMacAddress(userVm.getMacAddress());
            nicResponse.setIp6Address(userVm.getIp6Address());
            nicResponse.setIp6Gateway(userVm.getIp6Gateway());
            nicResponse.setIp6Cidr(userVm.getIp6Cidr());
            if (userVm.getBroadcastUri() != null) {
                nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString());
            }
            if (userVm.getIsolationUri() != null) {
                nicResponse.setIsolationUri(userVm.getIsolationUri().toString());
            }
            if (userVm.getTrafficType() != null) {
                nicResponse.setTrafficType(userVm.getTrafficType().toString());
            }
            if (userVm.getGuestType() != null) {
                nicResponse.setType(userVm.getGuestType().toString());
            }
            nicResponse.setIsDefault(userVm.isDefaultNic());
            List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(userVm.getNicId());
            if (secondaryIps != null) {
                List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
                for (NicSecondaryIpVO ip : secondaryIps) {
                    NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
                    ipRes.setId(ip.getUuid());
                    ipRes.setIpAddr(ip.getIp4Address());
                    ipList.add(ipRes);
                }
                nicResponse.setSecondaryIps(ipList);
            }
            nicResponse.setObjectName("nic");
            userVmResponse.addNic(nicResponse);
        }
    }
    // update tag information
    long tag_id = userVm.getTagId();
    if (tag_id > 0 && !userVmResponse.containTag(tag_id)) {
        addTagInformation(userVm, userVmResponse);
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.affgrp)) {
        Long affinityGroupId = userVm.getAffinityGroupId();
        if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
            AffinityGroupResponse resp = new AffinityGroupResponse();
            resp.setId(userVm.getAffinityGroupUuid());
            resp.setName(userVm.getAffinityGroupName());
            resp.setDescription(userVm.getAffinityGroupDescription());
            resp.setObjectName("affinitygroup");
            resp.setAccountName(userVm.getAccountName());
            userVmResponse.addAffinityGroup(resp);
        }
    }
    // set resource details map
    // Allow passing details to end user
    List<UserVmDetailVO> vmDetails = _userVmDetailsDao.listDetails(userVm.getId());
    if (vmDetails != null) {
        Map<String, String> resourceDetails = new HashMap<String, String>();
        for (UserVmDetailVO userVmDetailVO : vmDetails) {
            resourceDetails.put(userVmDetailVO.getName(), userVmDetailVO.getValue());
        }
        userVmResponse.setDetails(resourceDetails);
    }
    userVmResponse.setObjectName(objectName);
    if (userVm.isDynamicallyScalable() == null) {
        userVmResponse.setDynamicallyScalable(false);
    } else {
        userVmResponse.setDynamicallyScalable(userVm.isDynamicallyScalable());
    }
    return userVmResponse;
}
Also used : User(com.cloud.user.User) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) AffinityGroupResponse(org.apache.cloudstack.affinity.AffinityGroupResponse) VmStats(com.cloud.vm.VmStats) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 4 with UserVmDetailVO

use of com.cloud.vm.UserVmDetailVO 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)

Example 5 with UserVmDetailVO

use of com.cloud.vm.UserVmDetailVO in project cloudstack by apache.

the class VMSnapshotManagerImpl method revertUserVmDetailsFromVmSnapshot.

/**
     * Update or add user vm details from vm snapshot for vms with custom service offerings
     * @param userVm user vm
     * @param vmSnapshotVo vm snapshot
     */
protected void revertUserVmDetailsFromVmSnapshot(UserVmVO userVm, VMSnapshotVO vmSnapshotVo) {
    ServiceOfferingVO serviceOfferingVO = _serviceOfferingDao.findById(vmSnapshotVo.getServiceOfferingId());
    if (serviceOfferingVO.isDynamic()) {
        List<VMSnapshotDetailsVO> vmSnapshotDetails = _vmSnapshotDetailsDao.listDetails(vmSnapshotVo.getId());
        List<UserVmDetailVO> userVmDetails = new ArrayList<UserVmDetailVO>();
        for (VMSnapshotDetailsVO detail : vmSnapshotDetails) {
            userVmDetails.add(new UserVmDetailVO(userVm.getId(), detail.getName(), detail.getValue(), detail.isDisplay()));
        }
        _userVmDetailsDao.saveDetails(userVmDetails);
    }
}
Also used : UserVmDetailVO(com.cloud.vm.UserVmDetailVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Aggregations

UserVmDetailVO (com.cloud.vm.UserVmDetailVO)7 ArrayList (java.util.ArrayList)4 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)3 HashMap (java.util.HashMap)3 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)1 ClusterVO (com.cloud.dc.ClusterVO)1 ConnectionException (com.cloud.exception.ConnectionException)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 ServiceOfferingDetailsVO (com.cloud.service.ServiceOfferingDetailsVO)1 GuestOSVO (com.cloud.storage.GuestOSVO)1 User (com.cloud.user.User)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 UserVmVO (com.cloud.vm.UserVmVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VmStats (com.cloud.vm.VmStats)1 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)1 DecimalFormat (java.text.DecimalFormat)1