Copilot commented on code in PR #13897:
URL: https://github.com/apache/cloudstack/pull/13897#discussion_r3794230122
##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageUtils.java:
##########
@@ -159,4 +177,103 @@ public static String getLunName(String volName, String
lunName) {
return OntapStorageConstants.VOLUME_PATH_PREFIX + volName +
OntapStorageConstants.SLASH + lunName;
}
+ /**
+ * Builds an ONTAP-safe name token from user-provided snapshot text.
+ */
+ public static String getOntapSnapshotName(String cloudStackSnapshotName) {
+ if (cloudStackSnapshotName == null ||
cloudStackSnapshotName.trim().isEmpty()) {
+ throw new InvalidParameterValueException("Snapshot name cannot be
null or blank");
+ }
+ String normalized = cloudStackSnapshotName.replaceAll("[^a-zA-Z0-9_]",
"_");
+ if (normalized.isEmpty()) {
+ normalized = "snapshot";
+ }
+ if (!Character.isLetter(normalized.charAt(0))) {
+ normalized = "s_" + normalized;
+ }
+ if (normalized.length() >
OntapStorageConstants.MAX_SNAPSHOT_NAME_LENGTH) {
+ normalized = normalized.substring(0,
OntapStorageConstants.MAX_SNAPSHOT_NAME_LENGTH);
+ }
+ return normalized;
+ }
+
+ /**
+ * Builds an ONTAP-safe snapshot name that preserves the CloudStack UI
snapshot name
+ * and appends a uniqueness suffix.
+ */
+ public static String buildOntapSnapshotName(String cloudStackSnapshotName,
String uniquenessSuffix) {
+ String normalizedBase = (cloudStackSnapshotName == null ||
cloudStackSnapshotName.trim().isEmpty())
+ ? "snapshot"
+ : getOntapSnapshotName(cloudStackSnapshotName);
+ String suffix = (uniquenessSuffix == null ||
uniquenessSuffix.isEmpty())
+ ? ""
+ : "_" + uniquenessSuffix.replaceAll("[^a-zA-Z0-9_]", "_");
+ int maxLength = OntapStorageConstants.MAX_SNAPSHOT_NAME_LENGTH;
+ int maxBaseLength = maxLength - suffix.length();
+ if (maxBaseLength <= 0) {
+ return normalizedBase.substring(0, maxLength);
+ }
Review Comment:
buildOntapSnapshotName can throw StringIndexOutOfBoundsException when the
uniqueness suffix length is >= MAX_SNAPSHOT_NAME_LENGTH (maxBaseLength <= 0)
and the normalized base is shorter than maxLength.
##########
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java:
##########
@@ -1634,18 +1635,22 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume)
throws ResourceAllocationExc
boolean isKvmAndFileBasedStorage =
isHypervisorKvmAndFileBasedStorage(volume, storagePool);
boolean backupSnapToSecondary =
isBackupSnapshotToSecondaryForZone(volume.getDataCenterId());
- StoragePoolType poolType = volume.getStoragePoolType();
+ updateSnapshotPayload(volume.getPoolId(), payload,
isKvmAndFileBasedStorage, clusterId);
Review Comment:
The call to updateSnapshotPayload no longer matches the private method
signature (it still expects a StoragePoolType argument). This will not compile
as-is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]