Search in sources :

Example 6 with TemplateResponse

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

the class UpdateIsoCmdByAdmin method execute.

@Override
public void execute() {
    final VirtualMachineTemplate result = _templateService.updateTemplate(this);
    if (result != null) {
        final TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Full, 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 7 with TemplateResponse

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

the class CopyTemplateCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        final VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            final List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(ResponseView.Full, template, getDestinationZoneId(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (final StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.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 8 with TemplateResponse

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

the class PrepareTemplateCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final ListResponse<TemplateResponse> response = new ListResponse<>();
    final VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId, storageId);
    final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, vmTemplate, zoneId, true);
    response.setResponses(templateResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 9 with TemplateResponse

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

the class RegisterTemplateCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        final VirtualMachineTemplate template = _templateService.registerTemplate(this);
        if (template != null) {
            final ListResponse<TemplateResponse> response = new ListResponse<>();
            final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template, zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (final URISyntaxException ex1) {
        s_logger.info(ex1.toString());
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse) URISyntaxException(java.net.URISyntaxException)

Example 10 with TemplateResponse

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

the class CopyTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        final VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            final List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template, getDestinationZoneId(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (final StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.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)

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