@@ -231,6 +231,9 @@ public void deleteCloudStackVolume(CloudStackVolume cloudstackVolume) {
231231 *
232232 * <p>The resulting LUN shares blocks with its source and is created in constant time.
233233 * It is a sis-clone, so it stays readable after the source LUN is deleted.</p>
234+ *
235+ * <p>The create response includes the LUN uuid. That uuid is confirmed with repeated
236+ * {@code GET /api/storage/luns/{uuid}} calls while ONTAP returns 404.</p>
234237 */
235238 @ Override
236239 public CloudStackVolume cloneCloudStackVolume (CloudStackVolume cloudstackVolume ) {
@@ -249,12 +252,15 @@ public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume)
249252 lunRequest .getClone ().getSource ().getUuid ());
250253 try {
251254 String authHeader = OntapStorageUtils .generateAuthHeader (storage .getUsername (), storage .getPassword ());
252- OntapResponse <Lun > clonedLun = sanFeignClient .createLun (authHeader , true , lunRequest );
253- if (clonedLun == null || CollectionUtils .isEmpty (clonedLun .getRecords ())) {
255+ OntapResponse <Lun > created = sanFeignClient .createLun (authHeader , true , lunRequest );
256+ if (created == null || created .getRecords () == null || created .getRecords ().isEmpty ()
257+ || created .getRecords ().get (0 ) == null
258+ || StringUtils .isBlank (created .getRecords ().get (0 ).getUuid ())) {
254259 logger .error ("cloneCloudStackVolume: LUN clone returned no records for Lun {}" , lunRequest .getName ());
255260 throw new CloudRuntimeException ("Failed to clone Lun: " + lunRequest .getName ());
256261 }
257- Lun lun = clonedLun .getRecords ().get (0 );
262+ String lunUuid = created .getRecords ().get (0 ).getUuid ();
263+ Lun lun = getLunByUuidUntilVisible (authHeader , lunUuid , lunRequest .getName ());
258264 validateCreatedLun (lun , lunRequest .getName (), "cloneCloudStackVolume" );
259265 logger .debug ("cloneCloudStackVolume: LUN cloned successfully. Lun: {}" , lun );
260266
@@ -274,6 +280,50 @@ public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume)
274280 }
275281 }
276282
283+ /**
284+ * Confirms a clone uuid by reading that LUN directly.
285+ *
286+ * <p>{@code GET /api/storage/luns/{uuid}} returns 404 until the clone is visible. Those
287+ * 404s are retried. Any other GET failure is returned to the caller.</p>
288+ */
289+ private Lun getLunByUuidUntilVisible (String authHeader , String lunUuid , String lunName ) {
290+ for (int attempt = 1 ; attempt <= OntapStorageConstants .ONTAP_LUN_CLONE_GET_MAX_RETRIES ; attempt ++) {
291+ try {
292+ Lun lun = sanFeignClient .getLunByUUID (authHeader , lunUuid );
293+ if (lun != null ) {
294+ if (StringUtils .isBlank (lun .getUuid ())) {
295+ lun .setUuid (lunUuid );
296+ }
297+ if (lun .getName () == null ) {
298+ lun .setName (lunName );
299+ }
300+ logger .debug ("cloneCloudStackVolume: LUN uuid [{}] is visible on attempt {}/{}" ,
301+ lunUuid , attempt , OntapStorageConstants .ONTAP_LUN_CLONE_GET_MAX_RETRIES );
302+ return lun ;
303+ }
304+ logger .info ("cloneCloudStackVolume: LUN uuid [{}] is not visible yet (attempt {}/{})" ,
305+ lunUuid , attempt , OntapStorageConstants .ONTAP_LUN_CLONE_GET_MAX_RETRIES );
306+ } catch (FeignException e ) {
307+ if (e .status () != 404 ) {
308+ logger .error ("cloneCloudStackVolume: GET LUN uuid [{}] failed, Status: {}, Exception: {}" ,
309+ lunUuid , e .status (), e .getMessage ());
310+ throw new CloudRuntimeException ("Failed to fetch cloned Lun: " + e .getMessage ());
311+ }
312+ logger .info ("cloneCloudStackVolume: GET LUN uuid [{}] returned 404 (attempt {}/{})" ,
313+ lunUuid , attempt , OntapStorageConstants .ONTAP_LUN_CLONE_GET_MAX_RETRIES );
314+ }
315+ if (attempt < OntapStorageConstants .ONTAP_LUN_CLONE_GET_MAX_RETRIES ) {
316+ try {
317+ Thread .sleep (OntapStorageConstants .ONTAP_LUN_CLONE_GET_POLL_INTERVAL_MS );
318+ } catch (InterruptedException interrupted ) {
319+ Thread .currentThread ().interrupt ();
320+ throw new CloudRuntimeException ("Interrupted while waiting for cloned Lun " + lunName , interrupted );
321+ }
322+ }
323+ }
324+ throw new CloudRuntimeException ("Cloned Lun uuid was not visible for: " + lunUuid );
325+ }
326+
277327 /**
278328 * Ensures ONTAP returned a usable LUN identity from create/clone. Callers in the datastore
279329 * driver rely on non-null name and uuid, so reject incomplete records at the Feign boundary.
0 commit comments