-
Notifications
You must be signed in to change notification settings - Fork 1.2k
API: Add support to list all snapshot policies & backup schedules #11587
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8f806ff
API: Add support to list all snapshot policies & backup schedules
Pearl1594 619f01e
Add support for backup policy listing without tying it to the vmid
Pearl1594 0a6ac67
add tests for snapshot policy listing
Pearl1594 2e2c12d
update tests for listbackupschedules
Pearl1594 7ec4f5d
remove trailing spaces and fix lint failure
Pearl1594 1e91364
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 452b0e6
Add upgrade test
Pearl1594 a759acc
remove unused import
Pearl1594 7b9a1b4
add create policy - snap/backup in the list view with resource (volum…
Pearl1594 a0af6e7
add translations
Pearl1594 c31f278
refresh parent list
Pearl1594 e420927
remove unnecessary alert info
Pearl1594 7367a41
fix checks for UI backup schedule list view
Pearl1594 dbb2955
fix checks for UI backup schedule list view
Pearl1594 6dee31f
Merge branch 'support-list-policies' of https://github.com/apache/clo…
Pearl1594 376ac43
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 88d298f
add back access checks
Pearl1594 fd36bcb
add since param
Pearl1594 3882d33
fix failing test
Pearl1594 074d466
update snapshot policy and backup schedule ownership when VM is moved
Pearl1594 b71e323
fix issue with showing vm selection
Pearl1594 568178d
fix unit test failure
Pearl1594 82a2ef3
Update list snappolicy & backup schedule logic to list only those tha…
Pearl1594 5b8e568
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 def6dad
fix test
Pearl1594 b68b727
support snap / backup policy search using keyword
Pearl1594 7a73ebe
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 e29b752
fix tests
Pearl1594 24b2f73
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 016b608
Merge branch 'main' of https://github.com/apache/cloudstack into supp…
Pearl1594 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
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
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
98 changes: 98 additions & 0 deletions
98
...rc/test/java/org/apache/cloudstack/api/command/user/backup/ListBackupScheduleCmdTest.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,98 @@ | ||
| // 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.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.user.Account; | ||
| import org.apache.cloudstack.api.ResponseGenerator; | ||
| import org.apache.cloudstack.api.response.BackupScheduleResponse; | ||
| import org.apache.cloudstack.api.response.ListResponse; | ||
| import org.apache.cloudstack.backup.BackupManager; | ||
| import org.apache.cloudstack.backup.BackupSchedule; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class ListBackupScheduleCmdTest { | ||
|
|
||
| @Mock | ||
| private BackupManager backupManager; | ||
|
|
||
| @Mock | ||
| private ResponseGenerator responseGenerator; | ||
|
|
||
| private ListBackupScheduleCmd cmd; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| cmd = new ListBackupScheduleCmd(); | ||
| cmd.backupManager = backupManager; | ||
| cmd._responseGenerator = responseGenerator; | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecuteWithSchedules() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, NetworkRuleConflictException { | ||
| BackupSchedule schedule = Mockito.mock(BackupSchedule.class); | ||
| BackupScheduleResponse scheduleResponse = Mockito.mock(BackupScheduleResponse.class); | ||
| List<BackupSchedule> schedules = new ArrayList<>(); | ||
| schedules.add(schedule); | ||
|
|
||
| Mockito.when(backupManager.listBackupSchedules(cmd)).thenReturn(schedules); | ||
| Mockito.when(responseGenerator.createBackupScheduleResponse(schedule)).thenReturn(scheduleResponse); | ||
|
|
||
| Account mockAccount = Mockito.mock(Account.class); | ||
| CallContext callContext = Mockito.mock(CallContext.class); | ||
| try (org.mockito.MockedStatic<CallContext> mocked = Mockito.mockStatic(CallContext.class)) { | ||
| cmd.execute(); | ||
| } | ||
|
|
||
| ListResponse<?> response = (ListResponse<?>) cmd.getResponseObject(); | ||
| Assert.assertNotNull(response); | ||
| Assert.assertEquals(1, response.getResponses().size()); | ||
| Assert.assertEquals(scheduleResponse, response.getResponses().get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecuteWithNoSchedules() { | ||
| Mockito.when(backupManager.listBackupSchedules(cmd)).thenReturn(new ArrayList<>()); | ||
| CallContext callContext = Mockito.mock(CallContext.class); | ||
|
|
||
| try (org.mockito.MockedStatic<CallContext> mocked = Mockito.mockStatic(CallContext.class)) { | ||
| mocked.when(CallContext::current).thenReturn(callContext); | ||
| cmd.execute(); | ||
| } catch (ResourceUnavailableException | InsufficientCapacityException | ResourceAllocationException | | ||
| NetworkRuleConflictException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| ListResponse<?> response = (ListResponse<?>) cmd.getResponseObject(); | ||
| Assert.assertNotNull(response); | ||
| Assert.assertEquals(0, response.getResponses().size()); | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...est/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmdTest.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,79 @@ | ||
| // 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.snapshot; | ||
|
|
||
| import com.cloud.storage.snapshot.SnapshotApiService; | ||
| import com.cloud.storage.snapshot.SnapshotPolicy; | ||
| import com.cloud.utils.Pair; | ||
| import org.apache.cloudstack.api.ResponseGenerator; | ||
| import org.apache.cloudstack.api.response.ListResponse; | ||
| import org.apache.cloudstack.api.response.SnapshotPolicyResponse; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ListSnapshotPoliciesCmdTest { | ||
| private ListSnapshotPoliciesCmd cmd; | ||
| private SnapshotApiService snapshotService; | ||
| private ResponseGenerator responseGenerator; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| cmd = new ListSnapshotPoliciesCmd(); | ||
| snapshotService = Mockito.mock(SnapshotApiService.class); | ||
| responseGenerator = Mockito.mock(ResponseGenerator.class); | ||
|
|
||
| cmd._snapshotService = snapshotService; | ||
| cmd._responseGenerator = responseGenerator; | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecuteWithPolicies() { | ||
| SnapshotPolicy policy = Mockito.mock(SnapshotPolicy.class); | ||
| SnapshotPolicyResponse policyResponse = Mockito.mock(SnapshotPolicyResponse.class); | ||
| List<SnapshotPolicy> policies = new ArrayList<>(); | ||
| policies.add(policy); | ||
|
|
||
| Mockito.when(snapshotService.listSnapshotPolicies(cmd)) | ||
| .thenReturn(new Pair<>(policies, 1)); | ||
| Mockito.when(responseGenerator.createSnapshotPolicyResponse(policy)) | ||
| .thenReturn(policyResponse); | ||
|
|
||
| cmd.execute(); | ||
|
|
||
| ListResponse<?> response = (ListResponse<?>) cmd.getResponseObject(); | ||
| Assert.assertNotNull(response); | ||
| Assert.assertEquals(1, response.getResponses().size()); | ||
| Assert.assertEquals(policyResponse, response.getResponses().get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecuteWithNoPolicies() { | ||
| Mockito.when(snapshotService.listSnapshotPolicies(cmd)) | ||
| .thenReturn(new Pair<>(new ArrayList<>(), 0)); | ||
|
|
||
| cmd.execute(); | ||
|
|
||
| ListResponse<?> response = (ListResponse<?>) cmd.getResponseObject(); | ||
| Assert.assertNotNull(response); | ||
| Assert.assertTrue(response.getResponses().isEmpty()); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.