Search in sources :

Example 11 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse in project cloudstack by apache.

the class QueryManagerImpl method listTemplates.

@Override
public ListResponse<TemplateResponse> listTemplates(ListTemplatesCmd cmd) {
    Pair<List<TemplateJoinVO>, Integer> result = searchForTemplatesInternal(cmd);
    ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListTemplatesCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<TemplateResponse> templateResponses = ViewResponseHelper.createTemplateResponse(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) ListTemplatesCmdByAdmin(org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 12 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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)

Example 13 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse in project cloudstack by apache.

the class TemplateJoinDaoImpl method newIsoResponse.

@Override
public TemplateResponse newIsoResponse(TemplateJoinVO iso) {
    TemplateResponse isoResponse = new TemplateResponse();
    isoResponse.setId(iso.getUuid());
    isoResponse.setName(iso.getName());
    isoResponse.setDisplayText(iso.getDisplayText());
    isoResponse.setPublic(iso.isPublicTemplate());
    isoResponse.setExtractable(iso.isExtractable() && !(iso.getTemplateType() == TemplateType.PERHOST));
    isoResponse.setCreated(iso.getCreatedOnStore());
    isoResponse.setDynamicallyScalable(iso.isDynamicallyScalable());
    if (iso.getTemplateType() == TemplateType.PERHOST) {
        // for xs-tools.iso and vmware-tools.iso, we didn't download, but is ready to use.
        isoResponse.setReady(true);
    } else {
        isoResponse.setReady(iso.getState() == ObjectInDataStoreStateMachine.State.Ready);
    }
    isoResponse.setBootable(iso.isBootable());
    isoResponse.setFeatured(iso.isFeatured());
    isoResponse.setCrossZones(iso.isCrossZones());
    isoResponse.setPublic(iso.isPublicTemplate());
    isoResponse.setChecksum(iso.getChecksum());
    isoResponse.setOsTypeId(iso.getGuestOSUuid());
    isoResponse.setOsTypeName(iso.getGuestOSName());
    isoResponse.setBits(iso.getBits());
    // populate owner.
    ApiResponseHelper.populateOwner(isoResponse, iso);
    // populate domain
    isoResponse.setDomainId(iso.getDomainUuid());
    isoResponse.setDomainName(iso.getDomainName());
    Account caller = CallContext.current().getCallingAccount();
    boolean isAdmin = false;
    if ((caller == null) || _accountService.isAdmin(caller.getId())) {
        isAdmin = true;
    }
    // If the user is an admin, add the template download status
    if (isAdmin || caller.getId() == iso.getAccountId()) {
        // add download status
        if (iso.getDownloadState() != Status.DOWNLOADED) {
            String isoStatus = "Processing";
            if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
                isoStatus = "Download Complete";
            } else if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
                if (iso.getDownloadPercent() == 100) {
                    isoStatus = "Installing ISO";
                } else {
                    isoStatus = iso.getDownloadPercent() + "% Downloaded";
                }
            } else {
                isoStatus = iso.getErrorString();
            }
            isoResponse.setStatus(isoStatus);
        } else {
            isoResponse.setStatus("Successfully Installed");
        }
    }
    if (iso.getDataCenterId() > 0) {
        isoResponse.setZoneId(iso.getDataCenterUuid());
        isoResponse.setZoneName(iso.getDataCenterName());
    }
    Long isoSize = iso.getSize();
    if (isoSize > 0) {
        isoResponse.setSize(isoSize);
    }
    // update tag information
    long tag_id = iso.getTagId();
    if (tag_id > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            isoResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    isoResponse.setObjectName("iso");
    return isoResponse;
}
Also used : Account(com.cloud.user.Account) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 14 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse in project cloudstack by apache.

the class TemplateJoinDaoImpl method newUpdateResponse.

//TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
// compared to listTemplates and listIsos.
@Override
public TemplateResponse newUpdateResponse(TemplateJoinVO result) {
    TemplateResponse response = new TemplateResponse();
    response.setId(result.getUuid());
    response.setName(result.getName());
    response.setDisplayText(result.getDisplayText());
    response.setPublic(result.isPublicTemplate());
    response.setCreated(result.getCreated());
    response.setFormat(result.getFormat());
    response.setOsTypeId(result.getGuestOSUuid());
    response.setOsTypeName(result.getGuestOSName());
    response.setBootable(result.isBootable());
    response.setHypervisor(result.getHypervisorType().toString());
    // populate owner.
    ApiResponseHelper.populateOwner(response, result);
    // populate domain
    response.setDomainId(result.getDomainUuid());
    response.setDomainName(result.getDomainName());
    // set details map
    if (result.getDetailName() != null) {
        Map<String, String> details = new HashMap<String, String>();
        details.put(result.getDetailName(), result.getDetailValue());
        response.setDetails(details);
    }
    // update tag information
    long tag_id = result.getTagId();
    if (tag_id > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    response.setObjectName("iso");
    return response;
}
Also used : HashMap(java.util.HashMap) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 15 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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)

Aggregations

TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)21 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)13 ServerApiException (org.apache.cloudstack.api.ServerApiException)12 ListResponse (org.apache.cloudstack.api.response.ListResponse)7 TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)5 ArrayList (java.util.ArrayList)5 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)2 Account (com.cloud.user.Account)1 LinkedHashMap (java.util.LinkedHashMap)1 ListIsosCmdByAdmin (org.apache.cloudstack.api.command.admin.iso.ListIsosCmdByAdmin)1 ListTemplatesCmdByAdmin (org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin)1