Search in sources :

Example 11 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.

the class UpdateIsoCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final VirtualMachineTemplate result = _templateService.updateTemplate(this);
    if (result != null) {
        final TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update ISO");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 12 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listIsos.

@Override
public ListResponse<TemplateResponse> listIsos(final ListIsosCmd cmd) {
    final Pair<List<TemplateJoinVO>, Integer> result = searchForIsosInternal(cmd);
    final ListResponse<TemplateResponse> response = new ListResponse<>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListIsosCmdByAdmin) {
        respView = ResponseView.Full;
    }
    final List<TemplateResponse> templateResponses = ViewResponseHelper.createIsoResponse(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) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) TemplateResponse(com.cloud.api.response.TemplateResponse) ListIsosCmdByAdmin(com.cloud.api.command.admin.iso.ListIsosCmdByAdmin)

Example 13 with TemplateResponse

use of com.cloud.api.response.TemplateResponse 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 14 with TemplateResponse

use of com.cloud.api.response.TemplateResponse 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 15 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.

the class TemplateJoinDaoImpl method newTemplateResponse.

@Override
public TemplateResponse newTemplateResponse(final ResponseView view, final TemplateJoinVO template) {
    final TemplateResponse templateResponse = new TemplateResponse();
    templateResponse.setId(template.getUuid());
    templateResponse.setName(template.getName());
    templateResponse.setDisplayText(template.getDisplayText());
    templateResponse.setPublic(template.isPublicTemplate());
    templateResponse.setCreated(template.getCreatedOnStore());
    templateResponse.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
    templateResponse.setFeatured(template.isFeatured());
    templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
    templateResponse.setPasswordEnabled(template.isEnablePassword());
    templateResponse.setDynamicallyScalable(template.isDynamicallyScalable());
    templateResponse.setSshKeyEnabled(template.isEnableSshKey());
    templateResponse.setCrossZones(template.isCrossZones());
    templateResponse.setFormat(template.getFormat());
    templateResponse.setUrl(template.getUrl());
    if (template.getTemplateType() != null) {
        templateResponse.setTemplateType(template.getTemplateType().toString());
    }
    templateResponse.setHypervisor(template.getHypervisorType().toString());
    templateResponse.setOsTypeId(template.getGuestOSUuid());
    templateResponse.setOsTypeName(template.getGuestOSName());
    // populate owner.
    ApiResponseHelper.populateOwner(templateResponse, template);
    // populate domain
    templateResponse.setDomainId(template.getDomainUuid());
    templateResponse.setDomainName(template.getDomainName());
    // If the user is an 'Admin' or 'the owner of template', add the template download status
    final Account caller = CallContext.current().getCallingAccount();
    if (view == ResponseView.Full || _accountMgr.isDomainAdmin(caller.getId()) || template.getAccountId() == CallContext.current().getCallingAccount().getId()) {
        final String templateStatus = getTemplateStatus(template);
        if (templateStatus != null) {
            templateResponse.setStatus(templateStatus);
        }
    }
    if (template.getDataCenterId() > 0) {
        templateResponse.setZoneId(template.getDataCenterUuid());
        templateResponse.setZoneName(template.getDataCenterName());
    }
    final Long templateSize = template.getSize();
    if (templateSize > 0) {
        templateResponse.setSize(templateSize);
    }
    templateResponse.setChecksum(template.getChecksum());
    if (template.getSourceTemplateId() != null) {
        templateResponse.setSourceTemplateId(template.getSourceTemplateUuid());
    }
    templateResponse.setTemplateTag(template.getTemplateTag());
    // set details map
    if (template.getDetailName() != null) {
        final Map<String, String> details = new HashMap<>();
        details.put(template.getDetailName(), template.getDetailValue());
        templateResponse.setDetails(details);
    }
    // update tag information
    final long tag_id = template.getTagId();
    if (tag_id > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            templateResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    templateResponse.setObjectName("template");
    return templateResponse;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) TemplateResponse(com.cloud.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Aggregations

TemplateResponse (com.cloud.api.response.TemplateResponse)28 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)20 ServerApiException (com.cloud.api.ServerApiException)18 ListResponse (com.cloud.api.response.ListResponse)10 TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)5 ArrayList (java.util.ArrayList)5 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 URISyntaxException (java.net.URISyntaxException)3 ResponseView (com.cloud.api.ResponseObject.ResponseView)2 Account (com.cloud.user.Account)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 ListIsosCmdByAdmin (com.cloud.api.command.admin.iso.ListIsosCmdByAdmin)1 ListTemplatesCmdByAdmin (com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin)1 LinkedHashMap (java.util.LinkedHashMap)1