Skip to content
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

Support of snapshot copy to StorPool primary storage in different zones #9478

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

slavkap
Copy link
Contributor

@slavkap slavkap commented Aug 1, 2024

Description

This PR supports copying a snapshot to StorPool primary storage in different zones.

Added additional API param storageids in CloudStack API calls:

createSnapshot
copySnapshot
createSnapshotPolicy

The option snapshot.backup.to.secondary does not apply to the copy functionality. The snapshots will be copied only on the required primary storage in a different zone.
The user can create volumes/templates from the copied snapshots. The option to copy the snapshots to both primary and secondary storage is available by providing in the create/copy snapshot the destination zone IDs and storage IDs

image
image
image

For other storage plugins that want to adopt this functionality:

  • The Primary storage driver should have the capability CAN_COPY_SNAPSHOT_BETWEEN_ZONES
  • the respective plugin needs to implement the copySnapshot method in their SnapshotStrategy and that the driver can handle the COPY operation

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

How Has This Been Tested?

Manual and smoke tests with StorPool primary storage on multiple zones

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 4.60358% with 746 lines in your changes missing coverage. Please review.

Project coverage is 15.76%. Comparing base (019f2c6) to head (88d13d2).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 8.88% 155 Missing and 9 partials ⚠️
...ack/storage/snapshot/StorPoolSnapshotStrategy.java 0.00% 140 Missing ⚠️
...tastore/driver/StorPoolPrimaryDataStoreDriver.java 0.00% 73 Missing ⚠️
...age/collector/StorPoolAbandonObjectsCollector.java 0.00% 63 Missing ⚠️
...loudstack/storage/datastore/util/StorPoolUtil.java 0.00% 36 Missing ⚠️
...n/java/com/cloud/storage/VolumeApiServiceImpl.java 6.25% 29 Missing and 1 partial ⚠️
...org/apache/cloudstack/snapshot/SnapshotHelper.java 21.62% 24 Missing and 5 partials ⚠️
...oudstack/storage/snapshot/SnapshotServiceImpl.java 0.00% 27 Missing ⚠️
...udstack/storage/datastore/util/StorPoolHelper.java 0.00% 22 Missing ⚠️
...e/wrapper/StorPoolModifyStorageCommandWrapper.java 0.00% 21 Missing ⚠️
... and 24 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9478      +/-   ##
============================================
- Coverage     15.78%   15.76%   -0.02%     
- Complexity    12564    12566       +2     
============================================
  Files          5627     5627              
  Lines        492250   492863     +613     
  Branches      61405    62711    +1306     
============================================
+ Hits          77710    77712       +2     
- Misses       406066   406666     +600     
- Partials       8474     8485      +11     
Flag Coverage Δ
uitests 4.03% <ø> (-0.01%) ⬇️
unittests 16.58% <4.60%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@slavkap slavkap force-pushed the support-snapshot-copy-on-primary branch from 8cc7b49 to 0df6764 Compare August 14, 2024 09:14
@slavkap slavkap marked this pull request as ready for review August 14, 2024 09:51
@slavkap slavkap changed the title [WIP] Support of snapshot copy to StorPool primary storage in different zones Support of snapshot copy to StorPool primary storage in different zones Aug 14, 2024
Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10756

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-11155)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 51322 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr9478-t11155-kvm-ol8.zip
Smoke tests completed. 137 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_01_snapshot_usage Failure 38.32 test_usage.py
test_01_vpc_site2site_vpn Failure 308.08 test_vpc_vpn.py

Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Copy link

github-actions bot commented Sep 4, 2024

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

continue;
}
for (SnapshotDetailsVO snapshot : snapshotDetails) {
String name = snapshot.getValue().split(";")[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure the snapshot detail after .split() has length >= 2 & then get name and location from it (chance of Index Out of Bound error).

}
}

private static List<String> snapshotsForRcovery(JsonArray arr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static List<String> snapshotsForRcovery(JsonArray arr) {
private static List<String> snapshotsForRecovery(JsonArray arr) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it's fixed in the latest commits

// logger.info(String.format("Cannot copy snapshot to another storage in different zone. It's not in the right state %s", snapshotOnStore.getStatus()));
// return false;
// }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these comments if not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it's removed in the latest commits

const listStoragePools = json.liststoragepoolsresponse.storagepool
if (listStoragePools) {
this.storagePools = listStoragePools
this.storagePools = this.storagePools.filter(pool => pool.storagecapabilities.CAN_COPY_SNAPSHOT_BETWEEN_ZONES && pool.zoneid !== this.resource.zoneid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.storagePools = this.storagePools.filter(pool => pool.storagecapabilities.CAN_COPY_SNAPSHOT_BETWEEN_ZONES && pool.zoneid !== this.resource.zoneid)
this.storagePools = this.storagePools.filter(pool => pool.storagecapabilities.CAN_COPY_SNAPSHOT_BETWEEN_ZONES_AND_SAME_POOL_TYPE && pool.zoneid !== this.resource.zoneid)

Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

…n zones

Added support to copy a snapshot to another StorPool primary storage in
different zones.
Added drop down to choose the primary storage pools to copy a snapshot
Small fixes
zone_found = True
break
if zone_found == False:
cls.fail("Unable to find snapshot entry for the zone ID: %s" % zone_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavkap , lint nitpicking on you (EOL before EOF needed)

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm, lots of style comments but no blockers

import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.collections.CollectionUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.CollectionUtils;

@@ -177,6 +107,74 @@
import com.cloud.vm.dao.UserVmCloneSettingDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import org.apache.cloudstack.api.ApiCommandResourceType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiCommandResourceType;

@@ -46,6 +28,22 @@
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UpdateBuilder;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;

import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
import org.apache.commons.collections.CollectionUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.CollectionUtils;

import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.NoTransitionException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.NoTransitionException;

Comment on lines +209 to +210
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
import org.apache.commons.collections.CollectionUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
import org.apache.commons.collections.CollectionUtils;

Comment on lines +3673 to +3677
if (CollectionUtils.isNotEmpty(poolIds)) {
throw new InvalidParameterValueException(String.format("%s can not be specified for snapshots linked with snapshot policy", ApiConstants.STORAGE_ID_LIST));
}
List<SnapshotPolicyDetailVO> poolDetails = snapshotPolicyDetailsDao.findDetails(policyId, ApiConstants.STORAGE_ID);
poolIds = poolDetails.stream().map(d -> Long.valueOf(d.getValue())).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method?

@@ -174,6 +108,73 @@
import com.cloud.vm.snapshot.VMSnapshotVO;
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao;
import org.apache.cloudstack.acl.SecurityChecker;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.acl.SecurityChecker;

Comment on lines +155 to +156
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.collections.CollectionUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.collections.CollectionUtils;

Comment on lines +2106 to +2137
private boolean canCopyOnPrimary(List<Long> poolIds, Snapshot snapshot) {
List<Long> poolsToBeRemoved = new ArrayList<>();
for (Long poolId : poolIds) {
PrimaryDataStore dataStore = (PrimaryDataStore) dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
if (dataStore == null) {
poolsToBeRemoved.add(poolId);
continue;
}
SnapshotInfo snapshotInfo = snapshotFactory.getSnapshot(snapshot.getId(), poolId, DataStoreRole.Primary);
if (snapshotInfo != null) {
logger.debug(String.format("Snapshot [%s] already exist on pool [%s]", snapshot.getUuid(), dataStore.getName()));
continue;
}

VolumeVO volume = _volsDao.findById(snapshot.getVolumeId());
if (volume == null) {
poolsToBeRemoved.add(poolId);
continue;
}
if (!dataStore.getDriver().getCapabilities()
.containsKey(DataStoreCapabilities.CAN_COPY_SNAPSHOT_BETWEEN_ZONES_AND_SAME_POOL_TYPE.toString())
&& dataStore.getPoolType() != volume.getPoolType()) {
poolsToBeRemoved.add(poolId);
logger.debug(String.format("The %s does not support copy to %s between zones", dataStore.getPoolType(), volume.getPoolType()));
}
}
poolIds.removeAll(poolsToBeRemoved);
if (CollectionUtils.isEmpty(poolIds)) {
return false;
}
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be further distilled into smaller methods. Surely some of those can than be reused for the actual copy method.

Copy link

github-actions bot commented Nov 4, 2024

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants