Search in sources :

Example 1 with StoragePoolJoinVO

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

the class QueryManagerImpl method searchForStoragePools.

@Override
public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsCmd cmd) {
    Pair<List<StoragePoolJoinVO>, Integer> result = searchForStoragePoolsInternal(cmd);
    ListResponse<StoragePoolResponse> response = new ListResponse<StoragePoolResponse>();
    List<StoragePoolResponse> poolResponses = ViewResponseHelper.createStoragePoolResponse(result.first().toArray(new StoragePoolJoinVO[result.first().size()]));
    for (StoragePoolResponse poolResponse : poolResponses) {
        DataStore store = dataStoreManager.getPrimaryDataStore(poolResponse.getId());
        if (store != null) {
            DataStoreDriver driver = store.getDriver();
            if (driver != null && driver.getCapabilities() != null) {
                poolResponse.setCaps(driver.getCapabilities());
            }
        }
    }
    response.setResponses(poolResponses, result.second());
    return response;
}
Also used : StoragePoolResponse(org.apache.cloudstack.api.response.StoragePoolResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with StoragePoolJoinVO

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

the class ViewResponseHelper method createStoragePoolForMigrationResponse.

public static List<StoragePoolResponse> createStoragePoolForMigrationResponse(StoragePoolJoinVO... pools) {
    Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
    // Initialise the vrdatalist with the input data
    for (StoragePoolJoinVO vr : pools) {
        StoragePoolResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newStoragePoolForMigrationResponse(vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillStoragePoolForMigrationDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<StoragePoolResponse>(vrDataList.values());
}
Also used : StoragePoolResponse(org.apache.cloudstack.api.response.StoragePoolResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO)

Example 3 with StoragePoolJoinVO

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

the class ViewResponseHelper method createStoragePoolResponse.

public static List<StoragePoolResponse> createStoragePoolResponse(StoragePoolJoinVO... pools) {
    Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
    // Initialise the vrdatalist with the input data
    for (StoragePoolJoinVO vr : pools) {
        StoragePoolResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newStoragePoolResponse(vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillStoragePoolDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<StoragePoolResponse>(vrDataList.values());
}
Also used : StoragePoolResponse(org.apache.cloudstack.api.response.StoragePoolResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO)

Example 4 with StoragePoolJoinVO

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

the class QueryManagerImpl method searchForStoragePoolsInternal.

private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) {
    ScopeType scopeType = null;
    if (cmd.getScope() != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, cmd.getScope().toUpperCase());
        } catch (Exception e) {
            throw new InvalidParameterValueException("Invalid scope type: " + cmd.getScope());
        }
    }
    Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    Object id = cmd.getId();
    Object name = cmd.getStoragePoolName();
    Object path = cmd.getPath();
    Object pod = cmd.getPodId();
    Object cluster = cmd.getClusterId();
    Object address = cmd.getIpAddress();
    Object keyword = cmd.getKeyword();
    Long startIndex = cmd.getStartIndex();
    Long pageSize = cmd.getPageSizeVal();
    Filter searchFilter = new Filter(StoragePoolJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    SearchBuilder<StoragePoolJoinVO> sb = _poolJoinDao.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.EQ);
    sb.and("path", sb.entity().getPath(), 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("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
    sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
    SearchCriteria<StoragePoolJoinVO> sc = sb.create();
    if (keyword != null) {
        SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("poolType", 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 (path != null) {
        sc.setParameters("path", path);
    }
    if (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (pod != null) {
        sc.setParameters("podId", pod);
    }
    if (address != null) {
        sc.setParameters("hostAddress", address);
    }
    if (cluster != null) {
        sc.setParameters("clusterId", cluster);
    }
    if (scopeType != null) {
        sc.setParameters("scope", scopeType.toString());
    }
    // search Pool details by ids
    Pair<List<StoragePoolJoinVO>, Integer> uniquePoolPair = _poolJoinDao.searchAndCount(sc, searchFilter);
    Integer count = uniquePoolPair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniquePoolPair;
    }
    List<StoragePoolJoinVO> uniquePools = uniquePoolPair.first();
    Long[] vrIds = new Long[uniquePools.size()];
    int i = 0;
    for (StoragePoolJoinVO v : uniquePools) {
        vrIds[i++] = v.getId();
    }
    List<StoragePoolJoinVO> vrs = _poolJoinDao.searchByIds(vrIds);
    return new Pair<List<StoragePoolJoinVO>, Integer>(vrs, count);
}
Also used : ScopeType(com.cloud.storage.ScopeType) CloudAuthenticationException(com.cloud.exception.CloudAuthenticationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

StoragePoolJoinVO (com.cloud.api.query.vo.StoragePoolJoinVO)4 ArrayList (java.util.ArrayList)4 StoragePoolResponse (org.apache.cloudstack.api.response.StoragePoolResponse)3 Hashtable (java.util.Hashtable)2 List (java.util.List)2 CloudAuthenticationException (com.cloud.exception.CloudAuthenticationException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ScopeType (com.cloud.storage.ScopeType)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Pair (com.cloud.utils.Pair)1 Filter (com.cloud.utils.db.Filter)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