Search in sources :

Example 1 with ExtractResponse

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

the class ExtractTemplateCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        String uploadUrl = _templateService.extract(this);
        if (uploadUrl != null) {
            ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template");
        }
    } catch (InternalErrorException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 2 with ExtractResponse

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

the class ExtractVolumeCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId()));
    String uploadUrl = _volumeService.extractVolume(this);
    if (uploadUrl != null) {
        ExtractResponse response = new ExtractResponse();
        response.setResponseName(getCommandName());
        response.setObjectName("volume");
        Volume vol = _entityMgr.findById(Volume.class, id);
        response.setId(vol.getUuid());
        response.setName(vol.getName());
        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
        response.setMode(mode);
        response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
        Account account = _entityMgr.findById(Account.class, getEntityOwnerId());
        response.setAccountId(account.getUuid());
        response.setUrl(uploadUrl);
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume");
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 3 with ExtractResponse

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

the class ExtractIsoCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        String uploadUrl = _templateService.extract(this);
        if (uploadUrl != null) {
            ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
            response.setResponseName(getCommandName());
            response.setObjectName("iso");
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract ISO");
        }
    } catch (InternalErrorException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 4 with ExtractResponse

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

the class ApiResponseHelper method createExtractResponse.

@Override
public ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url) {
    ExtractResponse response = new ExtractResponse();
    response.setObjectName("template");
    VMTemplateVO template = ApiDBUtils.findTemplateById(id);
    response.setId(template.getUuid());
    response.setName(template.getName());
    if (zoneId != null) {
        DataCenter zone = ApiDBUtils.findZoneById(zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setMode(mode);
    if (uploadId == null) {
        // region-wide image store
        response.setUrl(url);
        response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
    } else {
        UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
        response.setUploadId(uploadInfo.getUuid());
        response.setState(uploadInfo.getUploadState().toString());
        response.setUrl(uploadInfo.getUploadUrl());
    }
    Account account = ApiDBUtils.findAccountById(accountId);
    response.setAccountId(account.getUuid());
    return response;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO) UploadVO(com.cloud.storage.UploadVO)

Aggregations

ExtractResponse (org.apache.cloudstack.api.response.ExtractResponse)4 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 DataCenter (com.cloud.dc.DataCenter)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 Account (com.cloud.user.Account)2 ProjectAccount (com.cloud.projects.ProjectAccount)1 UploadVO (com.cloud.storage.UploadVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 Volume (com.cloud.storage.Volume)1 UserAccount (com.cloud.user.UserAccount)1