Search in sources :

Example 11 with TemplateJoinVO

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

the class QueryManagerImpl method listTemplates.

@Override
public ListResponse<TemplateResponse> listTemplates(final ListTemplatesCmd cmd) {
    final Pair<List<TemplateJoinVO>, Integer> result = searchForTemplatesInternal(cmd);
    final ListResponse<TemplateResponse> response = new ListResponse<>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListTemplatesCmdByAdmin) {
        respView = ResponseView.Full;
    }
    final List<TemplateResponse> templateResponses = ViewResponseHelper.createTemplateResponse(respView, result.first().toArray(new TemplateJoinVO[result.first().size()]));
    response.setResponses(templateResponses, result.second());
    return response;
}
Also used : ResponseView(com.cloud.api.ResponseObject.ResponseView) ListResponse(com.cloud.api.response.ListResponse) ListTemplatesCmdByAdmin(com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 12 with TemplateJoinVO

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

the class ViewResponseHelper method createIsoResponse.

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

Example 13 with TemplateJoinVO

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

the class StorageManagerImpl method deleteImageStore.

@Override
public boolean deleteImageStore(final DeleteImageStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that image store exists
    final ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the image
    // store to be deleted
    final List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
    }
    final List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
    }
    // search if there are user templates stored on this image store, excluding system, builtin templates
    final List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 14 with TemplateJoinVO

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

the class ViewResponseHelper method createTemplateResponse.

public static List<TemplateResponse> createTemplateResponse(ResponseView view, TemplateJoinVO... templates) {
    LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<String, TemplateResponse>();
    for (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<TemplateResponse>(vrDataList.values());
}
Also used : TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with TemplateJoinVO

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

the class ViewResponseHelper method createTemplateUpdateResponse.

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

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