Search in sources :

Example 16 with VolumeResponse

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

the class ViewResponseHelper method createVolumeResponse.

public static List<VolumeResponse> createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) {
    Hashtable<Long, VolumeResponse> vrDataList = new Hashtable<Long, VolumeResponse>();
    for (VolumeJoinVO vr : volumes) {
        VolumeResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this volume
            vrData = ApiDBUtils.newVolumeResponse(view, vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillVolumeDetails(view, vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<VolumeResponse>(vrDataList.values());
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) VolumeJoinVO(com.cloud.api.query.vo.VolumeJoinVO)

Example 17 with VolumeResponse

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

the class MetricsServiceImpl method listVolumeMetrics.

@Override
public List<VolumeMetricsResponse> listVolumeMetrics(List<VolumeResponse> volumeResponses) {
    final List<VolumeMetricsResponse> metricsResponses = new ArrayList<>();
    for (final VolumeResponse volumeResponse : volumeResponses) {
        VolumeMetricsResponse metricsResponse = new VolumeMetricsResponse();
        try {
            BeanUtils.copyProperties(metricsResponse, volumeResponse);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate volume metrics response");
        }
        metricsResponse.setDiskSizeGB(volumeResponse.getSize());
        metricsResponse.setStorageType(volumeResponse.getStorageType(), volumeResponse.getVolumeType());
        metricsResponses.add(metricsResponse);
    }
    return metricsResponses;
}
Also used : VolumeMetricsResponse(org.apache.cloudstack.response.VolumeMetricsResponse) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with VolumeResponse

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

the class QueryManagerImpl method searchForVolumes.

@Override
public ListResponse<VolumeResponse> searchForVolumes(ListVolumesCmd cmd) {
    Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
    ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListVolumesCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(respView, result.first().toArray(new VolumeJoinVO[result.first().size()]));
    for (VolumeResponse vr : volumeResponses) {
        String poolId = vr.getStoragePoolId();
        if (poolId == null) {
            continue;
        }
        DataStore store = dataStoreManager.getPrimaryDataStore(poolId);
        if (store == null) {
            continue;
        }
        DataStoreDriver driver = store.getDriver();
        if (driver == null) {
            continue;
        }
        Map<String, String> caps = driver.getCapabilities();
        if (caps != null) {
            boolean quiescevm = Boolean.parseBoolean(caps.get(DataStoreCapabilities.VOLUME_SNAPSHOT_QUIESCEVM.toString()));
            vr.setNeedQuiescevm(quiescevm);
        }
    }
    response.setResponses(volumeResponses, result.second());
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) ListVolumesCmdByAdmin(org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin) ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) List(java.util.List) VolumeJoinVO(com.cloud.api.query.vo.VolumeJoinVO)

Aggregations

VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)18 ServerApiException (org.apache.cloudstack.api.ServerApiException)15 Volume (com.cloud.storage.Volume)14 ArrayList (java.util.ArrayList)3 VolumeJoinVO (com.cloud.api.query.vo.VolumeJoinVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Snapshot (com.cloud.storage.Snapshot)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListVolumesCmdByAdmin (org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)1 VolumeMetricsResponse (org.apache.cloudstack.response.VolumeMetricsResponse)1