diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java index a632ecf78fb8..844c99d80cf0 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java @@ -306,22 +306,40 @@ public void resizeCloudStackVolume(CloudStackVolume cloudstackVolume, long sizeI if (sizeInBytes <= 0) { throw new CloudRuntimeException("Failed to resize Lun, invalid size " + sizeInBytes); } + String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword()); + LunSpace lunSpace = new LunSpace(); + lunSpace.setSize(sizeInBytes); + Lun patch = new Lun(); + patch.setSpace(lunSpace); + + int maxRetries = OntapStorageConstants.ONTAP_LUN_RESIZE_MAX_RETRIES; + int pollIntervalMs = OntapStorageConstants.ONTAP_LUN_RESIZE_RETRY_INTERVAL_MS; String lunUuid = cloudstackVolume.getLun().getUuid(); - logger.trace("resizeCloudStackVolume: Resizing Lun {} to {} bytes", lunUuid, sizeInBytes); - try { - String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword()); - LunSpace lunSpace = new LunSpace(); - lunSpace.setSize(sizeInBytes); - Lun patch = new Lun(); - patch.setSpace(lunSpace); - JobResponse response = sanFeignClient.updateLun(authHeader, lunUuid, patch); - pollJobIfPresent(response, "resize Lun [" + lunUuid + "]"); - logger.debug("resizeCloudStackVolume: Lun {} resized to {} bytes", lunUuid, sizeInBytes); - } catch (FeignException e) { - throw new CloudRuntimeException("Failed to resize Lun: " + e.getMessage(), e); - } catch (Exception e) { - logger.error("Exception occurred while resizing LUN: {}, Exception: {}", lunUuid, e.getMessage()); - throw new CloudRuntimeException("Failed to resize Lun: " + e.getMessage()); + for (int attempt = 1; ; attempt++) { + logger.trace("resizeCloudStackVolume: Resizing Lun {} to {} bytes", lunUuid, sizeInBytes); + try { + JobResponse response = sanFeignClient.updateLun(authHeader, lunUuid, patch); + pollJobIfPresent(response, "resize Lun [" + lunUuid + "]"); + logger.debug("resizeCloudStackVolume: Lun {} resized to {} bytes", lunUuid, sizeInBytes); + return; + } catch (FeignException e) { + if (e.status() != 404 || attempt >= maxRetries) { + logger.error("FeignException occurred while resizing LUN: {}, Status: {}, Exception: {}", + lunUuid, e.status(), e.getMessage()); + throw new CloudRuntimeException("Failed to resize Lun: " + e.getMessage(), e); + } + logger.debug("resizeCloudStackVolume: PATCH for Lun {} returned 404, retry {}/{}", + lunUuid, attempt, maxRetries); + } catch (Exception e) { + logger.error("Exception occurred while resizing LUN: {}, Exception: {}", lunUuid, e.getMessage()); + throw new CloudRuntimeException("Failed to resize Lun: " + e.getMessage(), e); + } + try { + Thread.sleep(pollIntervalMs); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw new CloudRuntimeException("Interrupted while waiting for Lun to accept resize", ie); + } } } diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java index 9cf9b7356b15..b824d7e363e7 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java @@ -147,6 +147,9 @@ public class OntapStorageConstants { public static final int ONTAP_CG_JOB_POLL_INTERVAL_MS = 2000; public static final int ONTAP_CG_SNAPSHOT_RESOLVE_MAX_RETRIES = 30; public static final int ONTAP_CG_SNAPSHOT_RESOLVE_POLL_INTERVAL_MS = 1000; + /** Retry settings for a newly cloned LUN that is not yet visible to the resize API. */ + public static final int ONTAP_LUN_RESIZE_MAX_RETRIES = 30; + public static final int ONTAP_LUN_RESIZE_RETRY_INTERVAL_MS = 1000; public static final int ONTAP_SFSR_JOB_MAX_RETRIES = 60; public static final int ONTAP_SFSR_JOB_POLL_INTERVAL_MS = 2000; public static final int ONTAP_SNAPSHOT_DELETE_JOB_MAX_RETRIES = 30;