sandeeplocharla commented on code in PR #14243:
URL: https://github.com/apache/cloudstack/pull/14243#discussion_r4632227873


##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java:
##########
@@ -155,26 +166,27 @@ public void createAsync(DataStore dataStore, DataObject 
dataObject, AsyncComplet
                 // Update CloudStack volume record with storage pool 
association and protocol-specific details
                 VolumeVO volumeVO = volumeDao.findById(volInfo.getId());
                 if (volumeVO != null) {
-                    // Create the backend storage object (LUN for iSCSI, no-op 
for NFS)
-                    CloudStackVolume created = 
createCloudStackVolume(storagePool, volInfo, details);
+                    // Create the backend storage object: a clone of the 
cached template when the
+                    // orchestrator asked for one, otherwise a blank LUN 
(iSCSI) or qcow2 file (NFS).
+                    Long cloneOfTemplateId = 
getTemplateIdForCloning(volInfo.getId());
+                    CloudStackVolume clonedCloudStackVolume = 
cloneOfTemplateId != null
+                            ? cloneCloudStackVolumeFromTemplate(storagePool, 
volInfo, details, cloneOfTemplateId)
+                            : createCloudStackVolume(storagePool, volInfo, 
details);
 
                     volumeVO.setPoolType(storagePool.getPoolType());
                     volumeVO.setPoolId(storagePool.getId());
                     
volumeVO.setFormat(getImageFormatByHypervisorAndProtocol(storagePool.getHypervisor(),
 details.get(OntapStorageConstants.PROTOCOL)));
                     logger.info("createAsync: Volume format set to [{}] for 
hypervisor [{}] and protocol [{}]", volumeVO.getFormat(), 
storagePool.getHypervisor(), details.get(OntapStorageConstants.PROTOCOL));
 
                     if 
(ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL)))
 {
-                        String lunName = created != null && created.getLun() 
!= null ? created.getLun().getName() : null;
-                        if (lunName == null) {
-                            throw new CloudRuntimeException("Missing LUN name 
for volume " + volInfo.getId());
-                        }
+                        // createCloudStackVolume validates the Feign response 
(LUN name + uuid) before returning
+                        Lun createdLun = clonedCloudStackVolume.getLun();
+                        String lunName = createdLun.getName();
 
                         // Persist LUN details for future operations (delete, 
grant/revoke access)
-                        volumeDetailsDao.addDetail(volInfo.getId(), 
OntapStorageConstants.LUN_DOT_UUID, created.getLun().getUuid(), false);
+                        volumeDetailsDao.addDetail(volInfo.getId(), 
OntapStorageConstants.LUN_DOT_UUID, createdLun.getUuid(), false);
                         volumeDetailsDao.addDetail(volInfo.getId(), 
OntapStorageConstants.LUN_DOT_NAME, lunName, false);
-                        if (created.getLun().getUuid() != null) {

Review Comment:
   Isn't it better to have this to avoid NPE?



-- 
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]

Reply via email to