Search in sources :

Example 1 with VgpuTypesInfo

use of com.cloud.agent.api.VgpuTypesInfo in project cloudstack by apache.

the class XenServer620SP1Resource method getGPUGroupDetails.

@Override
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final Connection conn) throws XenAPIException, XmlRpcException {
    final HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<PGPU> pgpus = host.getPGPUs(conn);
    final Iterator<PGPU> iter = pgpus.iterator();
    while (iter.hasNext()) {
        final PGPU pgpu = iter.next();
        final GPUGroup gpuGroup = pgpu.getGPUGroup(conn);
        final Set<VGPUType> enabledVGPUTypes = gpuGroup.getEnabledVGPUTypes(conn);
        final String groupName = gpuGroup.getNameLabel(conn);
        HashMap<String, VgpuTypesInfo> gpuCapacity = new HashMap<String, VgpuTypesInfo>();
        if (groupDetails.get(groupName) != null) {
            gpuCapacity = groupDetails.get(groupName);
        }
        // Get remaining capacity of all the enabled VGPU in a PGPU
        if (enabledVGPUTypes != null) {
            final Iterator<VGPUType> it = enabledVGPUTypes.iterator();
            while (it.hasNext()) {
                final VGPUType type = it.next();
                final Record record = type.getRecord(conn);
                Long remainingCapacity = pgpu.getRemainingCapacity(conn, type);
                Long maxCapacity = pgpu.getSupportedVGPUMaxCapacities(conn).get(type);
                VgpuTypesInfo entry;
                if ((entry = gpuCapacity.get(record.modelName)) != null) {
                    remainingCapacity += entry.getRemainingCapacity();
                    maxCapacity += entry.getMaxCapacity();
                    entry.setRemainingCapacity(remainingCapacity);
                    entry.setMaxVmCapacity(maxCapacity);
                    gpuCapacity.put(record.modelName, entry);
                } else {
                    final VgpuTypesInfo vgpuTypeRecord = new VgpuTypesInfo(null, record.modelName, record.framebufferSize, record.maxHeads, record.maxResolutionX, record.maxResolutionY, maxCapacity, remainingCapacity, maxCapacity);
                    gpuCapacity.put(record.modelName, vgpuTypeRecord);
                }
            }
        }
        groupDetails.put(groupName, gpuCapacity);
    }
    return groupDetails;
}
Also used : HashMap(java.util.HashMap) VGPUType(com.xensource.xenapi.VGPUType) Host(com.xensource.xenapi.Host) PGPU(com.xensource.xenapi.PGPU) Record(com.xensource.xenapi.VGPUType.Record) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo) GPUGroup(com.xensource.xenapi.GPUGroup)

Example 2 with VgpuTypesInfo

use of com.cloud.agent.api.VgpuTypesInfo in project cloudstack by apache.

the class VGPUTypesDaoImpl method persist.

@Override
public void persist(long hostId, HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails) {
    Iterator<Entry<String, HashMap<String, VgpuTypesInfo>>> it1 = groupDetails.entrySet().iterator();
    while (it1.hasNext()) {
        Entry<String, HashMap<String, VgpuTypesInfo>> entry = it1.next();
        HostGpuGroupsVO gpuGroup = _hostGpuGroupsDao.findByHostIdGroupName(hostId, entry.getKey());
        HashMap<String, VgpuTypesInfo> values = entry.getValue();
        Iterator<Entry<String, VgpuTypesInfo>> it2 = values.entrySet().iterator();
        while (it2.hasNext()) {
            Entry<String, VgpuTypesInfo> record = it2.next();
            VgpuTypesInfo details = record.getValue();
            VGPUTypesVO vgpuType = null;
            if ((vgpuType = findByGroupIdVGPUType(gpuGroup.getId(), record.getKey())) == null) {
                persist(new VGPUTypesVO(gpuGroup.getId(), record.getKey(), details.getVideoRam(), details.getMaxHeads(), details.getMaxResolutionX(), details.getMaxResolutionY(), details.getMaxVpuPerGpu(), details.getRemainingCapacity(), details.getMaxCapacity()));
            } else {
                vgpuType.setRemainingCapacity(details.getRemainingCapacity());
                vgpuType.setMaxCapacity(details.getMaxCapacity());
                update(vgpuType.getId(), vgpuType);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) VGPUTypesVO(com.cloud.gpu.VGPUTypesVO) HashMap(java.util.HashMap) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo) HostGpuGroupsVO(com.cloud.gpu.HostGpuGroupsVO)

Example 3 with VgpuTypesInfo

use of com.cloud.agent.api.VgpuTypesInfo in project cloudstack by apache.

the class XenServer620SP1GetGPUStatsCommandWrapper method execute.

@Override
public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Resource xenServer620SP1Resource) {
    final Connection conn = xenServer620SP1Resource.getConnection();
    HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
    try {
        groupDetails = xenServer620SP1Resource.getGPUGroupDetails(conn);
    } catch (final Exception e) {
        final String msg = "Unable to get GPU stats" + e.toString();
        s_logger.warn(msg, e);
        return new GetGPUStatsAnswer(command, false, msg);
    }
    return new GetGPUStatsAnswer(command, groupDetails);
}
Also used : GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Example 4 with VgpuTypesInfo

use of com.cloud.agent.api.VgpuTypesInfo in project cloudstack by apache.

the class VGPUTypesDaoImpl method listGPUCapacities.

@Override
public List<VgpuTypesInfo> listGPUCapacities(Long dcId, Long podId, Long clusterId) {
    StringBuilder finalQuery = new StringBuilder();
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    List<Long> resourceIdList = new ArrayList<Long>();
    ArrayList<VgpuTypesInfo> result = new ArrayList<VgpuTypesInfo>();
    resourceIdList.add(dcId);
    finalQuery.append(LIST_ZONE_POD_CLUSTER_WIDE_GPU_CAPACITIES);
    if (podId != null) {
        finalQuery.append(" AND host.pod_id = ?");
        resourceIdList.add(podId);
    }
    if (clusterId != null) {
        finalQuery.append(" AND host.cluster_id = ?");
        resourceIdList.add(clusterId);
    }
    finalQuery.append(" GROUP BY host_gpu_groups.group_name, vgpu_type");
    try {
        pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
        for (int i = 0; i < resourceIdList.size(); i++) {
            pstmt.setLong(1 + i, resourceIdList.get(i));
        }
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            VgpuTypesInfo gpuCapacity = new VgpuTypesInfo(rs.getString(1), rs.getString(2), null, null, null, null, rs.getLong(3), rs.getLong(4), rs.getLong(5));
            result.add(gpuCapacity);
        }
        return result;
    } catch (SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + finalQuery, e);
    } catch (Throwable e) {
        throw new CloudRuntimeException("Caught: " + finalQuery, e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Example 5 with VgpuTypesInfo

use of com.cloud.agent.api.VgpuTypesInfo in project cloudstack by apache.

the class ApiResponseHelper method createCapacityResponse.

@Override
public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
    List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
    for (Capacity summedCapacity : result) {
        CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
        capacityResponse.setCapacityType(summedCapacity.getCapacityType());
        capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
        if (summedCapacity.getPodId() != null) {
            capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid());
            HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
            if (pod != null) {
                capacityResponse.setPodId(pod.getUuid());
                capacityResponse.setPodName(pod.getName());
            }
        }
        if (summedCapacity.getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
            if (cluster != null) {
                capacityResponse.setClusterId(cluster.getUuid());
                capacityResponse.setClusterName(cluster.getName());
                if (summedCapacity.getPodId() == null) {
                    HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
                    capacityResponse.setPodId(pod.getUuid());
                    capacityResponse.setPodName(pod.getName());
                }
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(summedCapacity.getDataCenterId());
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (summedCapacity.getUsedPercentage() != null) {
            capacityResponse.setPercentUsed(format.format(summedCapacity.getUsedPercentage() * 100f));
        } else if (summedCapacity.getTotalCapacity() != 0) {
            capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
        } else {
            capacityResponse.setPercentUsed(format.format(0L));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    List<VgpuTypesInfo> gpuCapacities;
    if (result.size() > 1 && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
        HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
        float capacityUsed = 0;
        long capacityMax = 0;
        for (VgpuTypesInfo capacity : gpuCapacities) {
            if (vgpuVMs.containsKey(capacity.getGroupName().concat(capacity.getModelName()))) {
                capacityUsed += (float) vgpuVMs.get(capacity.getGroupName().concat(capacity.getModelName())) / capacity.getMaxVpuPerGpu();
            }
            if (capacity.getModelName().equals(GPU.GPUType.passthrough.toString())) {
                capacityMax += capacity.getMaxCapacity();
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(result.get(0).getDataCenterId());
        CapacityResponse capacityResponse = new CapacityResponse();
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (result.get(0).getPodId() != null) {
            HostPodVO pod = ApiDBUtils.findPodById(result.get(0).getPodId());
            capacityResponse.setPodId(pod.getUuid());
            capacityResponse.setPodName(pod.getName());
        }
        if (result.get(0).getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(result.get(0).getClusterId());
            capacityResponse.setClusterId(cluster.getUuid());
            capacityResponse.setClusterName(cluster.getName());
        }
        capacityResponse.setCapacityType(Capacity.CAPACITY_TYPE_GPU);
        capacityResponse.setCapacityUsed((long) Math.ceil(capacityUsed));
        capacityResponse.setCapacityTotal(capacityMax);
        if (capacityMax > 0) {
            capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
        } else {
            capacityResponse.setPercentUsed(format.format(0));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) CapacityResponse(org.apache.cloudstack.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) Capacity(com.cloud.capacity.Capacity) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Aggregations

VgpuTypesInfo (com.cloud.agent.api.VgpuTypesInfo)5 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 GetGPUStatsAnswer (com.cloud.agent.api.GetGPUStatsAnswer)1 Capacity (com.cloud.capacity.Capacity)1 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)1 ClusterVO (com.cloud.dc.ClusterVO)1 DataCenter (com.cloud.dc.DataCenter)1 HostPodVO (com.cloud.dc.HostPodVO)1 HostGpuGroupsVO (com.cloud.gpu.HostGpuGroupsVO)1 VGPUTypesVO (com.cloud.gpu.VGPUTypesVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Connection (com.xensource.xenapi.Connection)1 GPUGroup (com.xensource.xenapi.GPUGroup)1 Host (com.xensource.xenapi.Host)1 PGPU (com.xensource.xenapi.PGPU)1 VGPUType (com.xensource.xenapi.VGPUType)1 Record (com.xensource.xenapi.VGPUType.Record)1 PreparedStatement (java.sql.PreparedStatement)1