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());
}
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;
}
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);
}
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);
}
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;
}
Aggregations