Search in sources :

Example 1 with ApiErrorCode

use of org.apache.cloudstack.api.ApiErrorCode 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)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ApiErrorCode (org.apache.cloudstack.api.ApiErrorCode)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 BackupOfferingResponse (org.apache.cloudstack.api.response.BackupOfferingResponse)1 BackupOffering (org.apache.cloudstack.backup.BackupOffering)1