Search in sources :

Example 6 with BackupOffering

use of org.apache.cloudstack.backup.BackupOffering 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 7 with BackupOffering

use of org.apache.cloudstack.backup.BackupOffering in project cloudstack by apache.

the class BackupDaoImpl method newBackupResponse.

@Override
public BackupResponse newBackupResponse(Backup backup) {
    VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(backup.getVmId());
    AccountVO account = accountDao.findByIdIncludingRemoved(vm.getAccountId());
    DomainVO domain = domainDao.findByIdIncludingRemoved(vm.getDomainId());
    DataCenterVO zone = dataCenterDao.findByIdIncludingRemoved(vm.getDataCenterId());
    BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(vm.getBackupOfferingId());
    BackupResponse response = new BackupResponse();
    response.setId(backup.getUuid());
    response.setVmId(vm.getUuid());
    response.setVmName(vm.getHostName());
    response.setExternalId(backup.getExternalId());
    response.setType(backup.getType());
    response.setDate(backup.getDate());
    response.setSize(backup.getSize());
    response.setProtectedSize(backup.getProtectedSize());
    response.setStatus(backup.getStatus());
    response.setVolumes(new Gson().toJson(vm.getBackupVolumeList().toArray(), Backup.VolumeInfo[].class));
    response.setBackupOfferingId(offering.getUuid());
    response.setBackupOffering(offering.getName());
    response.setAccountId(account.getUuid());
    response.setAccount(account.getAccountName());
    response.setDomainId(domain.getUuid());
    response.setDomain(domain.getName());
    response.setZoneId(zone.getUuid());
    response.setZone(zone.getName());
    response.setObjectName("backup");
    return response;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DomainVO(com.cloud.domain.DomainVO) BackupOffering(org.apache.cloudstack.backup.BackupOffering) Backup(org.apache.cloudstack.backup.Backup) VMInstanceVO(com.cloud.vm.VMInstanceVO) Gson(com.google.gson.Gson) BackupResponse(org.apache.cloudstack.api.response.BackupResponse) AccountVO(com.cloud.user.AccountVO)

Aggregations

BackupOffering (org.apache.cloudstack.backup.BackupOffering)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 BackupOfferingResponse (org.apache.cloudstack.api.response.BackupOfferingResponse)3 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 ArrayList (java.util.ArrayList)2 DataCenter (com.cloud.dc.DataCenter)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 Domain (com.cloud.domain.Domain)1 DomainVO (com.cloud.domain.DomainVO)1 HostVO (com.cloud.host.HostVO)1 VpnUserVO (com.cloud.network.VpnUserVO)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 VirtualRouter (com.cloud.network.router.VirtualRouter)1 PortForwardingRuleVO (com.cloud.network.rules.PortForwardingRuleVO)1 SecurityGroupVO (com.cloud.network.security.SecurityGroupVO)1