Search in sources :

Example 1 with BackupOfferingResponse

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

the class ImportBackupOfferingCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BackupOffering policy = backupManager.importBackupOffering(this);
        if (policy != null) {
            BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(policy);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a backup offering");
        }
    } catch (InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
    } catch (CloudRuntimeException e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BackupOffering(org.apache.cloudstack.backup.BackupOffering) BackupOfferingResponse(org.apache.cloudstack.api.response.BackupOfferingResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with BackupOfferingResponse

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

the class BaseBackupListCmd method setupResponseBackupOfferingsList.

protected void setupResponseBackupOfferingsList(final List<BackupOffering> offerings, final Integer count) {
    final ListResponse<BackupOfferingResponse> response = new ListResponse<>();
    final List<BackupOfferingResponse> responses = new ArrayList<>();
    for (final BackupOffering offering : offerings) {
        if (offering == null) {
            continue;
        }
        BackupOfferingResponse backupOfferingResponse = _responseGenerator.createBackupOfferingResponse(offering);
        responses.add(backupOfferingResponse);
    }
    response.setResponses(responses, count);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : BackupOffering(org.apache.cloudstack.backup.BackupOffering) BackupOfferingResponse(org.apache.cloudstack.api.response.BackupOfferingResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 3 with BackupOfferingResponse

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

the class UpdateBackupOfferingCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    try {
        if (StringUtils.isAllEmpty(name, description)) {
            throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there is no change in name or description.", id));
        }
        BackupOffering result = backupManager.updateBackupOffering(this);
        if (result == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to update backup offering [id: %s, name: %s, description: %s].", id, name, description));
        }
        BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (CloudRuntimeException e) {
        ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
        LOGGER.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e);
        throw new ServerApiException(paramError, e.getMessage());
    }
}
Also used : BackupOffering(org.apache.cloudstack.backup.BackupOffering) BackupOfferingResponse(org.apache.cloudstack.api.response.BackupOfferingResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiErrorCode(org.apache.cloudstack.api.ApiErrorCode)

Example 4 with BackupOfferingResponse

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

the class BackupOfferingDaoImpl method newBackupOfferingResponse.

@Override
public BackupOfferingResponse newBackupOfferingResponse(BackupOffering offering) {
    DataCenterVO zone = dataCenterDao.findById(offering.getZoneId());
    BackupOfferingResponse response = new BackupOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDescription(offering.getDescription());
    response.setExternalId(offering.getExternalId());
    response.setUserDrivenBackups(offering.isUserDrivenBackupAllowed());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setCreated(offering.getCreated());
    response.setObjectName("backupoffering");
    return response;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) BackupOfferingResponse(org.apache.cloudstack.api.response.BackupOfferingResponse)

Aggregations

BackupOfferingResponse (org.apache.cloudstack.api.response.BackupOfferingResponse)4 BackupOffering (org.apache.cloudstack.backup.BackupOffering)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 ArrayList (java.util.ArrayList)1 ApiErrorCode (org.apache.cloudstack.api.ApiErrorCode)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1