Search in sources :

Example 16 with TemplateJoinVO

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

the class ViewResponseHelper method createTemplateResponse.

public static List<TemplateResponse> createTemplateResponse(final ResponseView view, final TemplateJoinVO... templates) {
    final LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
    for (final TemplateJoinVO vr : templates) {
        TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
        if (vrData == null) {
            // first time encountering this volume
            vrData = ApiDBUtils.newTemplateResponse(view, vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillTemplateDetails(view, vrData, vr);
        }
        vrDataList.put(vr.getTempZonePair(), vrData);
    }
    return new ArrayList<>(vrDataList.values());
}
Also used : TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) TemplateResponse(com.cloud.api.response.TemplateResponse) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with TemplateJoinVO

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

the class TemplateJoinDaoImpl method searchByTemplateZonePair.

@Override
public List<TemplateJoinVO> searchByTemplateZonePair(final Boolean showRemoved, final String... idPairs) {
    // set detail batch query size
    int DETAILS_BATCH_SIZE = 2000;
    final String batchCfg = _configDao.getValue("detail.batch.query.size");
    if (batchCfg != null) {
        DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
    }
    // query details by batches
    Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
    isAscending = isAscending == null ? Boolean.TRUE : isAscending;
    final Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, null, null);
    searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", isAscending);
    final List<TemplateJoinVO> uvList = new ArrayList<>();
    // query details by batches
    int curr_index = 0;
    if (idPairs.length > DETAILS_BATCH_SIZE) {
        while (curr_index + DETAILS_BATCH_SIZE <= idPairs.length) {
            final String[] labels = new String[DETAILS_BATCH_SIZE];
            for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
                labels[k] = idPairs[j];
            }
            final SearchCriteria<TemplateJoinVO> sc = tmpltIdPairSearch.create();
            if (!showRemoved) {
                sc.setParameters("templateState", VirtualMachineTemplate.State.Active);
            }
            sc.setParameters("tempZonePairIN", labels);
            final List<TemplateJoinVO> vms = searchIncludingRemoved(sc, searchFilter, null, false);
            if (vms != null) {
                uvList.addAll(vms);
            }
            curr_index += DETAILS_BATCH_SIZE;
        }
    }
    if (curr_index < idPairs.length) {
        final int batch_size = idPairs.length - curr_index;
        final String[] labels = new String[batch_size];
        for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
            labels[k] = idPairs[j];
        }
        final SearchCriteria<TemplateJoinVO> sc = tmpltIdPairSearch.create();
        if (!showRemoved) {
            sc.setParameters("templateState", VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
        }
        sc.setParameters("tempZonePairIN", labels);
        final List<TemplateJoinVO> vms = searchIncludingRemoved(sc, searchFilter, null, false);
        if (vms != null) {
            uvList.addAll(vms);
        }
    }
    return uvList;
}
Also used : Filter(com.cloud.utils.db.Filter) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList)

Example 18 with TemplateJoinVO

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

the class KubernetesVersionServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    overrideDefaultConfigValue(KubernetesClusterService.KubernetesServiceEnabled, "_defaultValue", "true");
    final SearchBuilder<KubernetesSupportedVersionVO> versionSearchBuilder = Mockito.mock(SearchBuilder.class);
    final SearchCriteria<KubernetesSupportedVersionVO> versionSearchCriteria = Mockito.mock(SearchCriteria.class);
    when(kubernetesSupportedVersionDao.createSearchBuilder()).thenReturn(versionSearchBuilder);
    final KubernetesSupportedVersionVO kubernetesSupportedVersionVO = Mockito.mock(KubernetesSupportedVersionVO.class);
    when(versionSearchBuilder.entity()).thenReturn(kubernetesSupportedVersionVO);
    when(versionSearchBuilder.entity()).thenReturn(kubernetesSupportedVersionVO);
    when(versionSearchBuilder.create()).thenReturn(versionSearchCriteria);
    when(kubernetesSupportedVersionDao.createSearchCriteria()).thenReturn(versionSearchCriteria);
    DataCenterVO zone = Mockito.mock(DataCenterVO.class);
    when(zone.getId()).thenReturn(1L);
    when(dataCenterDao.findById(Mockito.anyLong())).thenReturn(zone);
    TemplateJoinVO templateJoinVO = Mockito.mock(TemplateJoinVO.class);
    when(templateJoinVO.getId()).thenReturn(1L);
    when(templateJoinVO.getUrl()).thenReturn("https://download.cloudstack.com");
    when(templateJoinVO.getState()).thenReturn(ObjectInDataStoreStateMachine.State.Ready);
    when(templateJoinDao.findById(Mockito.anyLong())).thenReturn(templateJoinVO);
    KubernetesSupportedVersionVO versionVO = Mockito.mock(KubernetesSupportedVersionVO.class);
    when(versionVO.getSemanticVersion()).thenReturn(KubernetesVersionService.MIN_KUBERNETES_VERSION);
    when(kubernetesSupportedVersionDao.persist(Mockito.any(KubernetesSupportedVersionVO.class))).thenReturn(versionVO);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) Before(org.junit.Before)

Example 19 with TemplateJoinVO

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

the class TemplateJoinDaoImpl method findByDistinctIds.

@Override
public List<TemplateJoinVO> findByDistinctIds(Long... ids) {
    if (ids == null || ids.length == 0) {
        return new ArrayList<TemplateJoinVO>();
    }
    Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
    searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", true);
    SearchCriteria<TemplateJoinVO> sc = tmpltIdsSearch.create();
    sc.setParameters("idsIN", ids);
    return searchIncludingRemoved(sc, searchFilter, null, false);
}
Also used : Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO)

Example 20 with TemplateJoinVO

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

the class QueryManagerImpl method listIsos.

@Override
public ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd) {
    Pair<List<TemplateJoinVO>, Integer> result = searchForIsosInternal(cmd);
    ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListIsosCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<TemplateResponse> templateResponses = ViewResponseHelper.createIsoResponse(respView, result.first().toArray(new TemplateJoinVO[result.first().size()]));
    response.setResponses(templateResponses, result.second());
    return response;
}
Also used : ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) ListResponse(org.apache.cloudstack.api.response.ListResponse) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) ListIsosCmdByAdmin(org.apache.cloudstack.api.command.admin.iso.ListIsosCmdByAdmin)

Aggregations

TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)21 ArrayList (java.util.ArrayList)17 List (java.util.List)6 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)6 TemplateResponse (com.cloud.api.response.TemplateResponse)5 Filter (com.cloud.utils.db.Filter)5 Hashtable (java.util.Hashtable)4 SearchCriteria (com.cloud.utils.db.SearchCriteria)3 LinkedHashMap (java.util.LinkedHashMap)3 ResponseView (com.cloud.api.ResponseObject.ResponseView)2 ListResponse (com.cloud.api.response.ListResponse)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 DomainVO (com.cloud.domain.DomainVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 Account (com.cloud.user.Account)2 Pair (com.cloud.utils.Pair)2 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)2