Search in sources :

Example 1 with ImageStoreJoinVO

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

the class QueryManagerImpl method searchForImageStoresInternal.

private Pair<List<ImageStoreJoinVO>, Integer> searchForImageStoresInternal(ListImageStoresCmd cmd) {
    Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    Object id = cmd.getId();
    Object name = cmd.getStoreName();
    String provider = cmd.getProvider();
    String protocol = cmd.getProtocol();
    Object keyword = cmd.getKeyword();
    Long startIndex = cmd.getStartIndex();
    Long pageSize = cmd.getPageSizeVal();
    Boolean readonly = cmd.getReadonly();
    Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    SearchBuilder<ImageStoreJoinVO> sb = _imageStoreJoinDao.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("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("protocol", sb.entity().getProtocol(), SearchCriteria.Op.EQ);
    sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ);
    sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ);
    sb.and("readonly", sb.entity().isReadonly(), Op.EQ);
    SearchCriteria<ImageStoreJoinVO> sc = sb.create();
    sc.setParameters("role", DataStoreRole.Image);
    if (keyword != null) {
        SearchCriteria<ImageStoreJoinVO> ssc = _imageStoreJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("providerName", 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 (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (provider != null) {
        sc.setParameters("provider", provider);
    }
    if (protocol != null) {
        sc.setParameters("protocol", protocol);
    }
    if (readonly != null) {
        sc.setParameters("readonly", readonly);
    }
    // search Store details by ids
    Pair<List<ImageStoreJoinVO>, Integer> uniqueStorePair = _imageStoreJoinDao.searchAndCount(sc, searchFilter);
    Integer count = uniqueStorePair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueStorePair;
    }
    List<ImageStoreJoinVO> uniqueStores = uniqueStorePair.first();
    Long[] vrIds = new Long[uniqueStores.size()];
    int i = 0;
    for (ImageStoreJoinVO v : uniqueStores) {
        vrIds[i++] = v.getId();
    }
    List<ImageStoreJoinVO> vrs = _imageStoreJoinDao.searchByIds(vrIds);
    return new Pair<List<ImageStoreJoinVO>, Integer>(vrs, count);
}
Also used : ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 2 with ImageStoreJoinVO

use of com.cloud.api.query.vo.ImageStoreJoinVO in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method searchForImageStoresInternal.

private Pair<List<ImageStoreJoinVO>, Integer> searchForImageStoresInternal(final ListImageStoresCmd cmd) {
    final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    final Object id = cmd.getId();
    final Object name = cmd.getStoreName();
    final String provider = cmd.getProvider();
    final String protocol = cmd.getProtocol();
    final Object keyword = cmd.getKeyword();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSize = cmd.getPageSizeVal();
    final Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    final SearchBuilder<ImageStoreJoinVO> sb = _imageStoreJoinDao.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("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("protocol", sb.entity().getProtocol(), SearchCriteria.Op.EQ);
    sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ);
    sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ);
    final SearchCriteria<ImageStoreJoinVO> sc = sb.create();
    sc.setParameters("role", DataStoreRole.Image);
    if (keyword != null) {
        final SearchCriteria<ImageStoreJoinVO> ssc = _imageStoreJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("providerName", 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 (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (provider != null) {
        sc.setParameters("provider", provider);
    }
    if (protocol != null) {
        sc.setParameters("protocol", protocol);
    }
    // search Store details by ids
    final Pair<List<ImageStoreJoinVO>, Integer> uniqueStorePair = _imageStoreJoinDao.searchAndCount(sc, searchFilter);
    final Integer count = uniqueStorePair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueStorePair;
    }
    final List<ImageStoreJoinVO> uniqueStores = uniqueStorePair.first();
    final Long[] vrIds = new Long[uniqueStores.size()];
    int i = 0;
    for (final ImageStoreJoinVO v : uniqueStores) {
        vrIds[i++] = v.getId();
    }
    final List<ImageStoreJoinVO> vrs = _imageStoreJoinDao.searchByIds(vrIds);
    return new Pair<>(vrs, count);
}
Also used : ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 3 with ImageStoreJoinVO

use of com.cloud.api.query.vo.ImageStoreJoinVO in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method searchForCacheStoresInternal.

private Pair<List<ImageStoreJoinVO>, Integer> searchForCacheStoresInternal(final ListSecondaryStagingStoresCmd cmd) {
    final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    final Object id = cmd.getId();
    final Object name = cmd.getStoreName();
    final String provider = cmd.getProvider();
    final String protocol = cmd.getProtocol();
    final Object keyword = cmd.getKeyword();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSize = cmd.getPageSizeVal();
    final Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    final SearchBuilder<ImageStoreJoinVO> sb = _imageStoreJoinDao.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("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("protocol", sb.entity().getProtocol(), SearchCriteria.Op.EQ);
    sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ);
    sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ);
    final SearchCriteria<ImageStoreJoinVO> sc = sb.create();
    sc.setParameters("role", DataStoreRole.ImageCache);
    if (keyword != null) {
        final SearchCriteria<ImageStoreJoinVO> ssc = _imageStoreJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("provider", 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 (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (provider != null) {
        sc.setParameters("provider", provider);
    }
    if (protocol != null) {
        sc.setParameters("protocol", protocol);
    }
    // search Store details by ids
    final Pair<List<ImageStoreJoinVO>, Integer> uniqueStorePair = _imageStoreJoinDao.searchAndCount(sc, searchFilter);
    final Integer count = uniqueStorePair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueStorePair;
    }
    final List<ImageStoreJoinVO> uniqueStores = uniqueStorePair.first();
    final Long[] vrIds = new Long[uniqueStores.size()];
    int i = 0;
    for (final ImageStoreJoinVO v : uniqueStores) {
        vrIds[i++] = v.getId();
    }
    final List<ImageStoreJoinVO> vrs = _imageStoreJoinDao.searchByIds(vrIds);
    return new Pair<>(vrs, count);
}
Also used : ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 4 with ImageStoreJoinVO

use of com.cloud.api.query.vo.ImageStoreJoinVO in project cosmic by MissionCriticalCloud.

the class ViewResponseHelper method createImageStoreResponse.

public static List<ImageStoreResponse> createImageStoreResponse(final ImageStoreJoinVO... stores) {
    final Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<>();
    // Initialise the vrdatalist with the input data
    for (final ImageStoreJoinVO vr : stores) {
        ImageStoreResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newImageStoreResponse(vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillImageStoreDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<>(vrDataList.values());
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO)

Example 5 with ImageStoreJoinVO

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

the class QueryManagerImpl method searchForCacheStoresInternal.

private Pair<List<ImageStoreJoinVO>, Integer> searchForCacheStoresInternal(ListSecondaryStagingStoresCmd cmd) {
    Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    Object id = cmd.getId();
    Object name = cmd.getStoreName();
    String provider = cmd.getProvider();
    String protocol = cmd.getProtocol();
    Object keyword = cmd.getKeyword();
    Long startIndex = cmd.getStartIndex();
    Long pageSize = cmd.getPageSizeVal();
    Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    SearchBuilder<ImageStoreJoinVO> sb = _imageStoreJoinDao.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("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("protocol", sb.entity().getProtocol(), SearchCriteria.Op.EQ);
    sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ);
    sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ);
    SearchCriteria<ImageStoreJoinVO> sc = sb.create();
    sc.setParameters("role", DataStoreRole.ImageCache);
    if (keyword != null) {
        SearchCriteria<ImageStoreJoinVO> ssc = _imageStoreJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("provider", 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 (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (provider != null) {
        sc.setParameters("provider", provider);
    }
    if (protocol != null) {
        sc.setParameters("protocol", protocol);
    }
    // search Store details by ids
    Pair<List<ImageStoreJoinVO>, Integer> uniqueStorePair = _imageStoreJoinDao.searchAndCount(sc, searchFilter);
    Integer count = uniqueStorePair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueStorePair;
    }
    List<ImageStoreJoinVO> uniqueStores = uniqueStorePair.first();
    Long[] vrIds = new Long[uniqueStores.size()];
    int i = 0;
    for (ImageStoreJoinVO v : uniqueStores) {
        vrIds[i++] = v.getId();
    }
    List<ImageStoreJoinVO> vrs = _imageStoreJoinDao.searchByIds(vrIds);
    return new Pair<List<ImageStoreJoinVO>, Integer>(vrs, count);
}
Also used : ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

ImageStoreJoinVO (com.cloud.api.query.vo.ImageStoreJoinVO)6 ArrayList (java.util.ArrayList)6 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)4 Pair (com.cloud.utils.Pair)4 Filter (com.cloud.utils.db.Filter)4 List (java.util.List)4 Hashtable (java.util.Hashtable)2 ImageStoreResponse (com.cloud.api.response.ImageStoreResponse)1 ImageStoreResponse (org.apache.cloudstack.api.response.ImageStoreResponse)1