Search in sources :

Example 1 with ZoneResponse

use of org.apache.cloudstack.api.response.ZoneResponse 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 ZoneResponse

use of org.apache.cloudstack.api.response.ZoneResponse in project cloudstack by apache.

the class QueryManagerImpl method listDataCenters.

@Override
public ListResponse<ZoneResponse> listDataCenters(ListZonesCmd cmd) {
    Pair<List<DataCenterJoinVO>, Integer> result = listDataCentersInternal(cmd);
    ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListZonesCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<ZoneResponse> dcResponses = ViewResponseHelper.createDataCenterResponse(respView, cmd.getShowCapacities(), result.first().toArray(new DataCenterJoinVO[result.first().size()]));
    response.setResponses(dcResponses, result.second());
    return response;
}
Also used : ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) DataCenterJoinVO(com.cloud.api.query.vo.DataCenterJoinVO) ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ListZonesCmdByAdmin(org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin)

Example 3 with ZoneResponse

use of org.apache.cloudstack.api.response.ZoneResponse in project cloudstack by apache.

the class DataCenterJoinDaoImpl method newDataCenterResponse.

@Override
public ZoneResponse newDataCenterResponse(ResponseView view, DataCenterJoinVO dataCenter, Boolean showCapacities) {
    ZoneResponse zoneResponse = new ZoneResponse();
    zoneResponse.setId(dataCenter.getUuid());
    zoneResponse.setName(dataCenter.getName());
    zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId()));
    zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
    if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
        zoneResponse.setDescription(dataCenter.getDescription());
    }
    if (view == ResponseView.Full) {
        zoneResponse.setDns1(dataCenter.getDns1());
        zoneResponse.setDns2(dataCenter.getDns2());
        zoneResponse.setIp6Dns1(dataCenter.getIp6Dns1());
        zoneResponse.setIp6Dns2(dataCenter.getIp6Dns2());
        zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
        zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
        // FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
        zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
    }
    if (showCapacities != null && showCapacities) {
        zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
    }
    // set network domain info
    zoneResponse.setDomain(dataCenter.getDomain());
    // set domain info
    zoneResponse.setDomainId(dataCenter.getDomainUuid());
    zoneResponse.setDomainName(dataCenter.getDomainName());
    zoneResponse.setType(dataCenter.getNetworkType().toString());
    zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
    zoneResponse.setZoneToken(dataCenter.getZoneToken());
    zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
    // update tag information
    List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
    for (ResourceTagJoinVO resourceTag : resourceTags) {
        ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
        zoneResponse.addTag(tagResponse);
    }
    zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
    zoneResponse.setObjectName("zone");
    return zoneResponse;
}
Also used : ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 4 with ZoneResponse

use of org.apache.cloudstack.api.response.ZoneResponse in project cloudstack by apache.

the class CreateZoneCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Zone Name: " + getZoneName());
    DataCenter result = _configService.createZone(this);
    if (result != null) {
        ZoneResponse response = _responseGenerator.createZoneResponse(ResponseView.Full, result, false);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a zone");
    }
}
Also used : ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 5 with ZoneResponse

use of org.apache.cloudstack.api.response.ZoneResponse in project cloudstack by apache.

the class UpdateZoneCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Zone Id: " + getId());
    DataCenter result = _configService.editZone(this);
    if (result != null) {
        ZoneResponse response = _responseGenerator.createZoneResponse(ResponseView.Full, result, false);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update zone; internal error.");
    }
}
Also used : ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

ZoneResponse (org.apache.cloudstack.api.response.ZoneResponse)5 DataCenter (com.cloud.dc.DataCenter)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 ArrayList (java.util.ArrayList)2 DataCenterJoinVO (com.cloud.api.query.vo.DataCenterJoinVO)1 HostJoinVO (com.cloud.api.query.vo.HostJoinVO)1 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 CapacityDaoImpl (com.cloud.capacity.dao.CapacityDaoImpl)1 Cluster (com.cloud.org.Cluster)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListZonesCmdByAdmin (org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1 ZoneMetricsResponse (org.apache.cloudstack.response.ZoneMetricsResponse)1