suryag1201 commented on code in PR #14243:
URL: https://github.com/apache/cloudstack/pull/14243#discussion_r4780531544
##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java:
##########
@@ -220,8 +235,229 @@ public void createAsync(DataStore dataStore, DataObject
dataObject, AsyncComplet
*/
private CloudStackVolume createCloudStackVolume(StoragePoolVO storagePool,
VolumeInfo volumeObject, Map<String, String> details) {
StorageStrategy storageStrategy =
OntapStorageUtils.getStrategyByStoragePoolDetails(details);
- CloudStackVolume cloudStackVolumeRequest =
OntapStorageUtils.createCloudStackVolumeRequestByProtocol(storagePool, details,
volumeObject);
- return storageStrategy.createCloudStackVolume(cloudStackVolumeRequest);
+ return
storageStrategy.createCloudStackVolume(createVolumeRequest(storagePool,
details, volumeObject));
+ }
+
+ /**
+ * Creates the backend object that caches a template on this pool's
FlexVolume.
+ *
+ * <p>Protocol-specific work is delegated to {@link
StorageStrategy#createTemplateCache}.
+ * This method maps the result to {@link CreateCmdResult} and records SAN
identity on
+ * {@code template_spool_ref} ({@code local_download_path} = LUN uuid).</p>
+ */
+ private CreateCmdResult createTemplateOnPrimary(StoragePoolVO storagePool,
TemplateInfo templateInfo, Map<String, String> details) {
+ StorageStrategy storageStrategy =
OntapStorageUtils.getStrategyByStoragePoolDetails(details);
+ long sizeInBytes =
getDataObjectSizeIncludingHypervisorSnapshotReserve(templateInfo, storagePool);
+ CloudStackVolume created = null;
+ try {
+ created = storageStrategy.createTemplateCache(storagePool,
templateInfo, details, sizeInBytes);
+ String path = recordTemplateCacheOnSpoolRef(storagePool,
templateInfo, created, sizeInBytes);
+ return new CreateCmdResult(path, new Answer(null, true, null));
+ } catch (Exception e) {
+ // Compensating delete for SAN: strategy cleans create-time LUN
failures; this covers
+ // post-create failures (e.g. template_spool_ref update) after a
LUN was returned.
+ if (created != null && created.getLun() != null) {
+ bestEffortDeleteTemplateCacheLun(storageStrategy,
details.get(OntapStorageConstants.SVM_NAME),
+ created.getLun().getName(),
created.getLun().getUuid());
+ }
+ if (e instanceof CloudRuntimeException) {
+ throw (CloudRuntimeException) e;
+ }
+ throw new CloudRuntimeException("Failed to create template cache
for template [" + templateInfo.getId()
+ + "]: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Persists SAN cache identity on {@code template_spool_ref} when a LUN
was created.
+ * NFS returns the template uuid as the create path; {@code install_path}
is filled later.
+ */
+ private String recordTemplateCacheOnSpoolRef(StoragePoolVO storagePool,
TemplateInfo templateInfo,
+ CloudStackVolume created,
long sizeInBytes) {
+ if (created == null || created.getLun() == null) {
+ return templateInfo.getUuid();
+ }
+ Lun lun = created.getLun();
+ VMTemplateStoragePoolVO templatePoolRef =
findTemplatePoolRef(storagePool.getId(), templateInfo.getId());
+ templatePoolRef.setLocalDownloadPath(lun.getUuid());
+ templatePoolRef.setTemplateSize(sizeInBytes);
+ vmTemplatePoolDao.update(templatePoolRef.getId(), templatePoolRef);
+ return lun.getName();
+ }
+
+ /**
+ * Clones the cached template into a new volume on the same FlexVolume.
+ *
+ * <p>Invoked when {@code StorageSystemDataMotionStrategy} has recorded a
+ * {@code cloneOfTemplate} detail on the volume.</p>
+ */
+ private CloudStackVolume cloneCloudStackVolumeFromTemplate(StoragePoolVO
storagePool, VolumeInfo volumeInfo,
+ Map<String,
String> details, long templateId) {
+ VMTemplateStoragePoolVO templatePoolRef =
findTemplatePoolRef(storagePool.getId(), templateId);
+ StorageStrategy storageStrategy =
OntapStorageUtils.getStrategyByStoragePoolDetails(details);
+ boolean iscsi = isIscsi(details);
+
+ long templateSize = templatePoolRef.getTemplateSize();
+ if (templateSize <= 0) {
+ throw new CloudRuntimeException("Template cache size is missing or
invalid (" + templateSize
+ + ") for template [" + templateId + "] on pool [" +
storagePool.getId()
+ + "]; cannot clone volume [" + volumeInfo.getId() + "]");
+ }
+
+ CloudStackVolume request = iscsi
+ ? createCloneLunRequest(storagePool, details, volumeInfo,
templatePoolRef, templateId)
+ : createCloneFileRequest(storagePool, volumeInfo,
templatePoolRef, templateId);
+
+ CloudStackVolume cloned =
storageStrategy.cloneCloudStackVolume(request);
+ // SAN cloneCloudStackVolume validates the Feign response (LUN name +
uuid) before returning
+ if (cloned == null) {
+ throw new CloudRuntimeException("ONTAP returned nothing when
cloning template [" + templateId
+ + "] for volume [" + volumeInfo.getId() + "]");
+ }
+
+ logger.info("cloneCloudStackVolumeFromTemplate: Cloned template [{}]
for volume [{}] on pool [{}]",
+ templateId, volumeInfo.getId(), storagePool.getId());
+
+ long requestedSize =
getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, storagePool);
+ if (requestedSize > templateSize) {
+ logger.info("cloneCloudStackVolumeFromTemplate: Growing clone of
template [{}] from {} to {} bytes for volume [{}]",
+ templateId, templateSize, requestedSize,
volumeInfo.getId());
+ storageStrategy.resizeCloudStackVolume(cloned, requestedSize);
Review Comment:
Thanks @rajiv-jain-netapp
--
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]