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