Skip to content
Open
12 changes: 12 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,18 @@ public class ApiConstants {
public static final String SCHEDULED_DATE = "scheduleddate";
public static final String BACKUP_PROVIDER = "backupprovider";
public static final String COMPRESS_ASYNC = "compressasync";
public static final String SCHEDULE_REPORT = "schedulereport";
public static final String DOMAIN_REPORT = "domainreport";
public static final String ACCOUNT_REPORT = "accountreport";
public static final String FAILURE_REASON = "failurereason";
public static final String SUCCESSFUL_BACKUP = "successfulbackup";
public static final String FAILED_BACKUP = "failedbackup";
public static final String DELETED_BACKUP = "deletedbackup";
public static final String PROVIDER_INFO = "providerinfo";
public static final String LOGID = "logid";
public static final String COMPRESSION_REPORT = "compressionreport";
public static final String VALIDATION_REPORT = "validationreport";
public static final String JOB_TYPE = "jobtype";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.api.command.user.backup;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.BackupReportResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.backup.BackupReportService;

import javax.inject.Inject;
import java.util.Date;

@APICommand(name = "getBackupReport",
description = "Get the backup report for the given period",
responseObject = BackupReportResponse.class, since = "24.0.0", authorized = {RoleType.Admin})
public class GetBackupReportCmd extends BaseCmd {

@Inject
private BackupReportService backupReportService;

@Parameter(name = ApiConstants.ZONE_ID,
type = CommandType.UUID,
entityType = ZoneResponse.class,
description = "Get backup report by zone ID.")
private Long zoneId;

@Parameter(name = ApiConstants.DOMAIN_ID,
type = CommandType.UUID,
entityType = DomainResponse.class,
description = "Get backup report by domain ID.")
private Long domainId;

@Parameter(name = ApiConstants.ACCOUNT_ID,
type = CommandType.UUID,
entityType = AccountResponse.class,
description = "Get backup report by account ID.")
private Long accountId;

@Parameter(name = ApiConstants.PROJECT_ID,
type = CommandType.UUID,
entityType = ProjectResponse.class,
description = "Get backup report by project ID.")
private Long projectId;

@Parameter(name = ApiConstants.START_DATE,
type = CommandType.DATE,
description = "Start date of the report.",
required = true)
private Date startDate;

@Parameter(name = ApiConstants.END_DATE,
type = CommandType.DATE,
description = "End date of the report.",
required = true)
private Date endDate;

public Long getZoneId() {
return zoneId;
}

public Long getDomainId() {
if (domainId != null && (accountId != null || projectId != null)) {
throw new InvalidParameterValueException("domainid and accountid or projectid cannot be informed at the same time.");
}
return domainId;
}

public Long getAccountId() {
if (projectId != null && accountId != null) {
throw new InvalidParameterValueException("accountid and projectid cannot be informed at the same time.");
}
return accountId;
}

public Long getProjectId() {
return projectId;
}

public Date getStartDate() {
return startDate;
}

public Date getEndDate() {
if (startDate.after(endDate)) {
throw new InvalidParameterValueException("End date must be after start date.");
}
return endDate;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
BackupReportResponse response = backupReportService.getBackupReport(getStartDate(), getEndDate(), getZoneId(), getDomainId(), getAccountId(), getProjectId());

response.setResponseName(getCommandName());
response.setObjectName("backupreport");
setResponseObject(response);
}

@Override
public long getEntityOwnerId() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.api.response;

import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;

import java.util.ArrayList;
import java.util.List;

public class BackupReportAccountResponse extends BaseResponse {

@SerializedName(ApiConstants.SUCCESSFUL_BACKUP)
@Param(description = "Successful backup.")
private List<BackupResponse> successfulBackups;

@SerializedName(ApiConstants.FAILED_BACKUP)
@Param(description = "Failed backup.")
private List<BackupResponse> failedBackups;

@SerializedName(ApiConstants.DELETED_BACKUP)
@Param(description = "Deleted backup.")
private List<BackupResponse> deletedBackups;

@SerializedName(ApiConstants.BACKUP_STORAGE_TOTAL)
@Param(description = "Backup storage usage increase for the Account during the period.")
private Double storageUsage;

@SerializedName(ApiConstants.ACCOUNT_ID)
@Param(description = "Account ID.")
private String accountId;

@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "Account name.")
private String accountName;

@SerializedName(ApiConstants.PROJECT_ID)
@Param(description = "Project ID.")
private String projectId;

@SerializedName(ApiConstants.PROJECT)
@Param(description = "Project name.")
private String projectName;

public BackupReportAccountResponse() {
this.successfulBackups = new ArrayList<>();
this.failedBackups = new ArrayList<>();
this.deletedBackups = new ArrayList<>();
this.storageUsage = 0D;
}

public void addSuccessfulBackup(BackupResponse successfulBackup) {
this.successfulBackups.add(successfulBackup);
}

public void addFailedBackup(BackupResponse failedBackup) {
this.failedBackups.add(failedBackup);
}

public void addDeletedBackup(BackupResponse deletedBackup) {
this.deletedBackups.add(deletedBackup);
}

public List<BackupResponse> getSuccessfulBackups() {
return successfulBackups;
}

public List<BackupResponse> getFailedBackups() {
return failedBackups;
}

public List<BackupResponse> getDeletedBackups() {
return deletedBackups;
}

public Double getStorageUsage() {
return storageUsage;
}

public void addStorageUsage(double storageUsage) {
this.storageUsage += storageUsage;
}

public String getAccountId() {
return accountId;
}

public void setAccountId(String accountId) {
this.accountId = accountId;
}

public String getAccountName() {
return accountName;
}

public void setAccountName(String accountName) {
this.accountName = accountName;
}

public String getProjectId() {
return projectId;
}

public void setProjectId(String projectId) {
this.projectId = projectId;
}

public String getProjectName() {
return projectName;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.api.response;

import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;

import java.util.ArrayList;
import java.util.List;

@EntityReference(value = BackupReportCompressionResponse.class)
public class BackupReportCompressionResponse extends BaseResponse {

@SerializedName(ApiConstants.COMPRESSION_REPORT)
@Param(description = "Compressed backups in the period.")
private List<BackupResponse> backupResponseList;

public BackupReportCompressionResponse() {
this.backupResponseList = new ArrayList<>();
}

public List<BackupResponse> getBackupResponseList() {
return backupResponseList;
}

public void addBackupResponse (BackupResponse backupResponse) {
this.backupResponseList.add(backupResponse);
}
}
Loading
Loading