Skip to content

Commit 182b07b

Browse files
committed
Fix ONTAP LUN clone visibility using GET retry
1 parent c5210eb commit 182b07b

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/SANFeignClient.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface SANFeignClient {
4646
@Headers({"Authorization: {authHeader}"})
4747
OntapResponse<Lun> getLunResponse(@Param("authHeader") String authHeader, @QueryMap Map<String, Object> queryMap);
4848

49-
@RequestLine("GET /{uuid}")
49+
@RequestLine("GET /api/storage/luns/{uuid}")
5050
@Headers({"Authorization: {authHeader}"})
5151
Lun getLunByUUID(@Param("authHeader") String authHeader, @Param("uuid") String uuid);
5252

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public class OntapStorageConstants {
175175
public static final int ONTAP_VOLUME_JOB_POLL_INTERVAL_MS = 1000;
176176
public static final int ONTAP_FLEXVOL_JOB_POLL_INTERVAL_MS = 2000;
177177
public static final int ONTAP_FLEXVOL_RESOLVE_MAX_RETRIES = 30;
178+
/** GET-by-UUID retries after LUN clone response. */
179+
public static final int ONTAP_LUN_CLONE_GET_MAX_RETRIES = 5;
180+
public static final int ONTAP_LUN_CLONE_GET_POLL_INTERVAL_MS = 1000;
178181

179182
/** vm_snapshot_details key for ONTAP FlexVolume-level VM snapshots. */
180183
public static final String ONTAP_FLEXVOL_SNAPSHOT = "ontapFlexVolSnapshot";

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,15 @@ void testCloneCloudStackVolume_Success() {
10251025

10261026
when(sanFeignClient.createLun(eq(authHeader), eq(true), any(Lun.class)))
10271027
.thenReturn(response);
1028+
when(sanFeignClient.getLunByUUID(eq(authHeader), eq("cloned-lun-uuid"))).thenReturn(clonedLun);
10281029

10291030
CloudStackVolume result = unifiedSANStrategy.cloneCloudStackVolume(request);
10301031

10311032
assertNotNull(result);
10321033
assertEquals("cloned-lun-uuid", result.getLun().getUuid());
10331034
assertSame(volumeInfo, result.getVolumeInfo());
10341035
verify(sanFeignClient).createLun(eq(authHeader), eq(true), any(Lun.class));
1036+
verify(sanFeignClient).getLunByUUID(eq(authHeader), eq("cloned-lun-uuid"));
10351037
}
10361038
}
10371039

@@ -1074,6 +1076,7 @@ void testCloneCloudStackVolume_SnapshotSource_SendsSnapshotQualifiedName() {
10741076
utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password"))
10751077
.thenReturn(authHeader);
10761078
when(sanFeignClient.createLun(eq(authHeader), eq(true), any(Lun.class))).thenReturn(response);
1079+
when(sanFeignClient.getLunByUUID(eq(authHeader), eq("new-lun-uuid"))).thenReturn(createdLun);
10771080

10781081
CloudStackVolume result = unifiedSANStrategy.cloneCloudStackVolume(request);
10791082

0 commit comments

Comments
 (0)