Search in sources :

Example 1 with HostJoinVO

use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.

the class MetricsServiceImpl method listZoneMetrics.

@Override
public List<ZoneMetricsResponse> listZoneMetrics(List<ZoneResponse> zoneResponses) {
    final List<ZoneMetricsResponse> metricsResponses = new ArrayList<>();
    for (final ZoneResponse zoneResponse : zoneResponses) {
        ZoneMetricsResponse metricsResponse = new ZoneMetricsResponse();
        try {
            BeanUtils.copyProperties(metricsResponse, zoneResponse);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate zone metrics response");
        }
        final DataCenter zone = dataCenterDao.findByUuid(zoneResponse.getId());
        if (zone == null) {
            continue;
        }
        final Long zoneId = zone.getId();
        // Thresholds
        final Double cpuThreshold = AlertManager.CPUCapacityThreshold.value();
        final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.value();
        final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.value();
        final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.value();
        // CPU and memory capacities
        final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, zoneId, null);
        final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, zoneId, null);
        final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
        for (final Cluster cluster : clusterDao.listClustersByDcId(zoneId)) {
            metrics.incrTotalResources();
            if (cluster.getAllocationState() == Grouping.AllocationState.Enabled && cluster.getManagedState() == Managed.ManagedState.Managed) {
                metrics.incrUpResources();
            }
            for (final HostJoinVO host : hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) {
                updateHostMetrics(metrics, host);
            }
        }
        metricsResponse.setState(zoneResponse.getAllocationState());
        metricsResponse.setResource(metrics.getUpResources(), metrics.getTotalResources());
        // CPU
        metricsResponse.setCpuTotal(metrics.getTotalCpu());
        metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), metrics.getTotalCpu());
        if (metrics.getCpuUsedPercentage() > 0L) {
            metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
            metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
        }
        // Memory
        metricsResponse.setMemTotal(metrics.getTotalMemory());
        metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), metrics.getTotalMemory());
        if (metrics.getMemoryUsed() > 0L) {
            metricsResponse.setMemUsed(metrics.getMemoryUsed(), metrics.getTotalMemory());
            metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), metrics.getMemoryUsed(), metrics.getTotalHosts());
        }
        // CPU thresholds
        metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
        metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
        metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuThreshold);
        metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuDisableThreshold);
        // Memory thresholds
        metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
        metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
        metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryThreshold);
        metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryDisableThreshold);
        metricsResponses.add(metricsResponse);
    }
    return metricsResponses;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.cloud.org.Cluster) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) InvocationTargetException(java.lang.reflect.InvocationTargetException) ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) ZoneMetricsResponse(org.apache.cloudstack.response.ZoneMetricsResponse) CapacityDaoImpl(com.cloud.capacity.dao.CapacityDaoImpl)

Example 2 with HostJoinVO

use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.

the class ViewResponseHelper method createHostForMigrationResponse.

public static List<HostForMigrationResponse> createHostForMigrationResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
    Hashtable<Long, HostForMigrationResponse> vrDataList = new Hashtable<Long, HostForMigrationResponse>();
    // Initialise the vrdatalist with the input data
    for (HostJoinVO vr : hosts) {
        HostForMigrationResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newHostForMigrationResponse(vr, details);
        } else {
            // update tags
            vrData = ApiDBUtils.fillHostForMigrationDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<HostForMigrationResponse>(vrDataList.values());
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) HostForMigrationResponse(org.apache.cloudstack.api.response.HostForMigrationResponse)

Example 3 with HostJoinVO

use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.

the class ViewResponseHelper method createHostResponse.

public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
    Hashtable<Long, HostResponse> vrDataList = new Hashtable<Long, HostResponse>();
    // Initialise the vrdatalist with the input data
    for (HostJoinVO vr : hosts) {
        HostResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newHostResponse(vr, details);
        } else {
            // update tags
            vrData = ApiDBUtils.fillHostDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<HostResponse>(vrDataList.values());
}
Also used : Hashtable(java.util.Hashtable) HostResponse(org.apache.cloudstack.api.response.HostResponse) ArrayList(java.util.ArrayList) HostJoinVO(com.cloud.api.query.vo.HostJoinVO)

Example 4 with HostJoinVO

use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.

the class MetricsServiceImpl method listClusterMetrics.

@Override
public List<ClusterMetricsResponse> listClusterMetrics(List<ClusterResponse> clusterResponses) {
    final List<ClusterMetricsResponse> metricsResponses = new ArrayList<>();
    for (final ClusterResponse clusterResponse : clusterResponses) {
        ClusterMetricsResponse metricsResponse = new ClusterMetricsResponse();
        try {
            BeanUtils.copyProperties(metricsResponse, clusterResponse);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate cluster metrics response");
        }
        final Cluster cluster = clusterDao.findByUuid(clusterResponse.getId());
        if (cluster == null) {
            continue;
        }
        final Long clusterId = cluster.getId();
        // Thresholds
        final Double cpuThreshold = AlertManager.CPUCapacityThreshold.valueIn(clusterId);
        final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.valueIn(clusterId);
        final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
        final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
        final Double cpuOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "cpuOvercommitRatio"));
        final Double memoryOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "memoryOvercommitRatio"));
        // CPU and memory capacities
        final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, null, clusterId);
        final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId);
        final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
        for (final HostJoinVO host : hostJoinDao.findByClusterId(clusterId, Host.Type.Routing)) {
            if (host.getStatus() == Status.Up) {
                metrics.incrUpResources();
            }
            metrics.incrTotalResources();
            updateHostMetrics(metrics, host);
        }
        metricsResponse.setState(clusterResponse.getAllocationState(), clusterResponse.getManagedState());
        metricsResponse.setResources(metrics.getUpResources(), metrics.getTotalResources());
        // CPU
        metricsResponse.setCpuTotal(metrics.getTotalCpu());
        metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), metrics.getTotalCpu());
        if (metrics.getCpuUsedPercentage() > 0L) {
            metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
            metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
        }
        // Memory
        metricsResponse.setMemTotal(metrics.getTotalMemory());
        metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), metrics.getTotalMemory());
        if (metrics.getMemoryUsed() > 0L) {
            metricsResponse.setMemUsed(metrics.getMemoryUsed(), metrics.getTotalMemory());
            metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), metrics.getMemoryUsed(), metrics.getTotalHosts());
        }
        // CPU thresholds
        metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
        metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
        metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuThreshold);
        metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuDisableThreshold);
        // Memory thresholds
        metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
        metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
        metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryThreshold);
        metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryDisableThreshold);
        metricsResponses.add(metricsResponse);
    }
    return metricsResponses;
}
Also used : ArrayList(java.util.ArrayList) ClusterResponse(org.apache.cloudstack.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClusterMetricsResponse(org.apache.cloudstack.response.ClusterMetricsResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) CapacityDaoImpl(com.cloud.capacity.dao.CapacityDaoImpl)

Example 5 with HostJoinVO

use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.

the class QueryManagerImpl method searchForServersInternal.

public Pair<List<HostJoinVO>, Integer> searchForServersInternal(ListHostsCmd cmd) {
    Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    Object name = cmd.getHostName();
    Object type = cmd.getType();
    Object state = cmd.getState();
    Object pod = cmd.getPodId();
    Object cluster = cmd.getClusterId();
    Object id = cmd.getId();
    Object keyword = cmd.getKeyword();
    Object outOfBandManagementEnabled = cmd.isOutOfBandManagementEnabled();
    Object powerState = cmd.getHostOutOfBandManagementPowerState();
    Object resourceState = cmd.getResourceState();
    Object haHosts = cmd.getHaHost();
    Long startIndex = cmd.getStartIndex();
    Long pageSize = cmd.getPageSizeVal();
    Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
    Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    SearchBuilder<HostJoinVO> sb = _hostJoinDao.createSearchBuilder();
    // select distinct
    sb.select(null, Func.DISTINCT, sb.entity().getId());
    // ids
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
    sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
    sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
    sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
    sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
    sb.and("oobmEnabled", sb.entity().isOutOfBandManagementEnabled(), SearchCriteria.Op.EQ);
    sb.and("powerState", sb.entity().getOutOfBandManagementPowerState(), SearchCriteria.Op.EQ);
    sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
    sb.and("hypervisor_type", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
    String haTag = _haMgr.getHaTag();
    if (haHosts != null && haTag != null && !haTag.isEmpty()) {
        if ((Boolean) haHosts) {
            sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
        } else {
            sb.and().op("tag", sb.entity().getTag(), SearchCriteria.Op.NEQ);
            sb.or("tagNull", sb.entity().getTag(), SearchCriteria.Op.NULL);
            sb.cp();
        }
    }
    SearchCriteria<HostJoinVO> sc = sb.create();
    if (keyword != null) {
        SearchCriteria<HostJoinVO> ssc = _hostJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (name != null) {
        sc.setParameters("name", "%" + name + "%");
    }
    if (type != null) {
        sc.setParameters("type", "%" + type);
    }
    if (state != null) {
        sc.setParameters("status", state);
    }
    if (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (pod != null) {
        sc.setParameters("podId", pod);
    }
    if (cluster != null) {
        sc.setParameters("clusterId", cluster);
    }
    if (outOfBandManagementEnabled != null) {
        sc.setParameters("oobmEnabled", outOfBandManagementEnabled);
    }
    if (powerState != null) {
        sc.setParameters("powerState", powerState);
    }
    if (resourceState != null) {
        sc.setParameters("resourceState", resourceState);
    }
    if (haHosts != null && haTag != null && !haTag.isEmpty()) {
        sc.setParameters("tag", haTag);
    }
    if (hypervisorType != HypervisorType.None && hypervisorType != HypervisorType.Any) {
        sc.setParameters("hypervisor_type", hypervisorType);
    }
    // search host details by ids
    Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
    Integer count = uniqueHostPair.second();
    if (count.intValue() == 0) {
        // handle empty result cases
        return uniqueHostPair;
    }
    List<HostJoinVO> uniqueHosts = uniqueHostPair.first();
    Long[] hostIds = new Long[uniqueHosts.size()];
    int i = 0;
    for (HostJoinVO v : uniqueHosts) {
        hostIds[i++] = v.getId();
    }
    List<HostJoinVO> hosts = _hostJoinDao.searchByIds(hostIds);
    return new Pair<List<HostJoinVO>, Integer>(hosts, count);
}
Also used : Hypervisor(com.cloud.hypervisor.Hypervisor) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Pair(com.cloud.utils.Pair)

Aggregations

HostJoinVO (com.cloud.api.query.vo.HostJoinVO)5 ArrayList (java.util.ArrayList)5 CapacityDaoImpl (com.cloud.capacity.dao.CapacityDaoImpl)2 Cluster (com.cloud.org.Cluster)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Hashtable (java.util.Hashtable)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenter (com.cloud.dc.DataCenter)1 Hypervisor (com.cloud.hypervisor.Hypervisor)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Pair (com.cloud.utils.Pair)1 Filter (com.cloud.utils.db.Filter)1 List (java.util.List)1 ClusterResponse (org.apache.cloudstack.api.response.ClusterResponse)1 HostForMigrationResponse (org.apache.cloudstack.api.response.HostForMigrationResponse)1 HostResponse (org.apache.cloudstack.api.response.HostResponse)1 ZoneResponse (org.apache.cloudstack.api.response.ZoneResponse)1 ClusterMetricsResponse (org.apache.cloudstack.response.ClusterMetricsResponse)1 ZoneMetricsResponse (org.apache.cloudstack.response.ZoneMetricsResponse)1