-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add new backup report feature #13939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoaoJandre
wants to merge
1
commit into
apache:main
Choose a base branch
from
scclouds:add-backup-report-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
api/src/main/java/org/apache/cloudstack/api/command/user/backup/GetBackupReportCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = "4.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; | ||
| } | ||
| } | ||
132 changes: 132 additions & 0 deletions
132
api/src/main/java/org/apache/cloudstack/api/response/BackupReportAccountResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
api/src/main/java/org/apache/cloudstack/api/response/BackupReportCompressionResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.