-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add backup file extraction feature #13935
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
3
commits into
apache:main
Choose a base branch
from
scclouds:add-kboss-file-extraction
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
57 changes: 57 additions & 0 deletions
57
api/src/main/java/com/cloud/agent/api/to/FilesystemInfoTO.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,57 @@ | ||
| /* | ||
| * 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 com.cloud.agent.api.to; | ||
|
|
||
| import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | ||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||
|
|
||
| public class FilesystemInfoTO { | ||
| private final String name; | ||
| private final String filesystem; | ||
| private final long size; | ||
| private final long volumeId; | ||
|
|
||
| public FilesystemInfoTO(String name, String filesystem, long size, long volumeId) { | ||
| this.name = name; | ||
| this.filesystem = filesystem; | ||
| this.size = size; | ||
| this.volumeId = volumeId; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getFilesystem() { | ||
| return filesystem; | ||
| } | ||
|
|
||
| public long getSize() { | ||
| return size; | ||
| } | ||
|
|
||
| public long getVolumeId() { | ||
| return volumeId; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE); | ||
| } | ||
| } |
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
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
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
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
123 changes: 123 additions & 0 deletions
123
api/src/main/java/org/apache/cloudstack/api/command/user/backup/DownloadBackupFileCmd.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,123 @@ | ||
| // 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.event.EventTypes; | ||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.user.Account; | ||
| import org.apache.cloudstack.api.ACL; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiArgValidator; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseAsyncCmd; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.BackupResponse; | ||
| import org.apache.cloudstack.api.response.ExtractResponse; | ||
| import org.apache.cloudstack.api.response.VolumeResponse; | ||
| import org.apache.cloudstack.backup.Backup; | ||
| import org.apache.cloudstack.backup.BackupManager; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| @APICommand(name = "downloadBackupFile", | ||
| description = "Download a file from a backup", | ||
| responseObject = ExtractResponse.class, since = "4.24.0.0") | ||
| public class DownloadBackupFileCmd extends BaseAsyncCmd { | ||
|
|
||
| @Inject | ||
| private BackupManager backupManager; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @ACL | ||
| @Parameter(name = ApiConstants.BACKUP_ID, type = BaseCmd.CommandType.UUID, entityType = BackupResponse.class, required = true, | ||
| description = "ID of the backup to download the file.") | ||
| private Long backupId; | ||
|
|
||
| @ACL | ||
| @Parameter(name = ApiConstants.VOLUME_ID, type = BaseCmd.CommandType.UUID, entityType = VolumeResponse.class, required = true, | ||
| description = "ID of the volume. If not informed, we will return every filesystem of every volume.") | ||
| private Long volumeId; | ||
|
|
||
| @Parameter(name = ApiConstants.FILESYSTEM, type = BaseCmd.CommandType.STRING, required = true, | ||
| description = "Filesystem to list the files in.", validations = {ApiArgValidator.LimitedSpecialCharacters}) | ||
| private String filesystem; | ||
|
|
||
| @Parameter(name = ApiConstants.PATH, type = BaseCmd.CommandType.STRING, required = true, | ||
| description = "Path to the file to be downloaded in the backed-up volume.", validations = {ApiArgValidator.LimitedSpecialCharacters}) | ||
| private String path; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public Long getBackupId() { | ||
| return backupId; | ||
| } | ||
|
|
||
| public Long getVolumeId() { | ||
| return volumeId; | ||
| } | ||
|
|
||
| public String getFilesystem() { | ||
| return filesystem.trim(); | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path.trim(); | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////// API Implementation ////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Override | ||
| public String getEventType() { | ||
| return EventTypes.EVENT_BACKUP_FILE_DOWNLOAD; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| Backup backup = _entityMgr.findById(Backup.class, getBackupId()); | ||
| if (backup == null) { | ||
| throw new InvalidParameterValueException(String.format("Unable to find backup with ID [%s].", getBackupId())); | ||
| } | ||
| return "Downloading a file from backup " + backup.getUuid(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| Backup backup = _entityMgr.findById(Backup.class, getBackupId()); | ||
| if (backup != null) { | ||
| return backup.getAccountId(); | ||
| } | ||
|
|
||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| ExtractResponse response = backupManager.downloadBackupFile(getBackupId(), getVolumeId(), getFilesystem(), getPath()); | ||
|
|
||
| response.setResponseName(getCommandName()); | ||
| response.setObjectName(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } | ||
| } | ||
118 changes: 118 additions & 0 deletions
118
api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupFilesCmd.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,118 @@ | ||||||
| // 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.user.Account; | ||||||
| import org.apache.cloudstack.api.ACL; | ||||||
| import org.apache.cloudstack.api.APICommand; | ||||||
| import org.apache.cloudstack.api.ApiArgValidator; | ||||||
| import org.apache.cloudstack.api.ApiConstants; | ||||||
| import org.apache.cloudstack.api.BaseListCmd; | ||||||
| import org.apache.cloudstack.api.Parameter; | ||||||
| import org.apache.cloudstack.api.response.BackupResponse; | ||||||
| import org.apache.cloudstack.api.response.ListResponse; | ||||||
| import org.apache.cloudstack.api.response.VolumeResponse; | ||||||
| import org.apache.cloudstack.backup.Backup; | ||||||
| import org.apache.cloudstack.backup.BackupManager; | ||||||
| import org.apache.cloudstack.storage.browser.DataStoreObjectResponse; | ||||||
|
|
||||||
| import javax.inject.Inject; | ||||||
| import java.util.List; | ||||||
|
|
||||||
| @APICommand(name = "listBackupFiles", | ||||||
| description = "List a backup inner files", | ||||||
| responseObject = DataStoreObjectResponse.class, since = "4.24.0.0") | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| public class ListBackupFilesCmd extends BaseListCmd { | ||||||
|
|
||||||
| @Inject | ||||||
| private BackupManager backupManager; | ||||||
|
|
||||||
| ///////////////////////////////////////////////////// | ||||||
| //////////////// API parameters ///////////////////// | ||||||
| ///////////////////////////////////////////////////// | ||||||
|
|
||||||
| @ACL | ||||||
| @Parameter(name = ApiConstants.BACKUP_ID, type = CommandType.UUID, entityType = BackupResponse.class, required = true, | ||||||
| description = "ID of the backup to list the files.") | ||||||
| private Long backupId; | ||||||
|
|
||||||
| @ACL | ||||||
| @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.UUID, entityType = VolumeResponse.class, required = true, | ||||||
| description = "ID of the volume.") | ||||||
| private Long volumeId; | ||||||
|
|
||||||
| @Parameter(name = ApiConstants.FILESYSTEM, type = CommandType.STRING, required = true, | ||||||
| description = "Filesystem to list the files in.", validations = {ApiArgValidator.LimitedSpecialCharacters}) | ||||||
| private String filesystem; | ||||||
|
|
||||||
| @Parameter(name = ApiConstants.PATH, type = CommandType.STRING, required = true, | ||||||
| description = "Path to list files in the backed-up volume.", validations = {ApiArgValidator.LimitedSpecialCharacters}) | ||||||
| private String path; | ||||||
|
|
||||||
| @Parameter(name = ApiConstants.IS_SYMLINK, type = CommandType.BOOLEAN, | ||||||
| description = "Path to list files in the backed-up volume.") | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| private Boolean isSymlink; | ||||||
|
|
||||||
| ///////////////////////////////////////////////////// | ||||||
| /////////////////// Accessors /////////////////////// | ||||||
| ///////////////////////////////////////////////////// | ||||||
|
|
||||||
| public Long getBackupId() { | ||||||
| return backupId; | ||||||
| } | ||||||
|
|
||||||
| public Long getVolumeId() { | ||||||
| return volumeId; | ||||||
| } | ||||||
|
|
||||||
| public String getFilesystem() { | ||||||
| return filesystem.trim(); | ||||||
| } | ||||||
|
|
||||||
| public String getPath() { | ||||||
| return path.trim(); | ||||||
| } | ||||||
|
|
||||||
| public Boolean getSymlink() { | ||||||
| return isSymlink; | ||||||
| } | ||||||
|
|
||||||
| ///////////////////////////////////////////////////// | ||||||
| /////////////// API Implementation/////////////////// | ||||||
| ///////////////////////////////////////////////////// | ||||||
|
|
||||||
| @Override | ||||||
| public long getEntityOwnerId() { | ||||||
| Backup backup = _entityMgr.findById(Backup.class, getBackupId()); | ||||||
| if (backup != null) { | ||||||
| return backup.getAccountId(); | ||||||
| } | ||||||
|
|
||||||
| return Account.ACCOUNT_ID_SYSTEM; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void execute() { | ||||||
| List<DataStoreObjectResponse> responseList = backupManager.listBackupFiles(getBackupId(), getVolumeId(), getFilesystem(), getPath(), getSymlink()); | ||||||
|
|
||||||
| ListResponse<DataStoreObjectResponse> response = new ListResponse<>(); | ||||||
| response.setResponses(responseList); | ||||||
| response.setResponseName(getCommandName()); | ||||||
| response.setObjectName(getCommandName()); | ||||||
| this.setResponseObject(response); | ||||||
| } | ||||||
| } | ||||||
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.