Search in sources :

Example 16 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class RegisterIsoCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
        List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register iso");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 17 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class CopyTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        UserContext.current().setEventDetails(getEventDescription());
        VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 18 with TemplateResponse

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

Example 19 with TemplateResponse

use of com.cloud.api.response.TemplateResponse 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());
}
Also used : TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) TemplateResponse(com.cloud.api.response.TemplateResponse) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with TemplateResponse

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

the class TemplateJoinDaoImpl method newIsoResponse.

@Override
public TemplateResponse newIsoResponse(final TemplateJoinVO iso) {
    final 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, 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());
    // populate owner.
    ApiResponseHelper.populateOwner(isoResponse, iso);
    // populate domain
    isoResponse.setDomainId(iso.getDomainUuid());
    isoResponse.setDomainName(iso.getDomainName());
    final 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());
    }
    final Long isoSize = iso.getSize();
    if (isoSize > 0) {
        isoResponse.setSize(isoSize);
    }
    // update tag information
    final long tag_id = iso.getTagId();
    if (tag_id > 0) {
        final 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(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