Skip to content

Commit d68200e

Browse files
committed
CSTACKEX-234: resolving comments
1 parent 67913b0 commit d68200e

5 files changed

Lines changed: 38 additions & 27 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ public interface VolumeFeignClient {
5252

5353
@RequestLine("PATCH /api/storage/volumes/{uuid}")
5454
@Headers({ "Authorization: {authHeader}"})
55-
JobResponse updateVolumeRebalancing(@Param("authHeader") String authHeader, @Param("uuid") String uuid, Volume volumeRequest);
55+
JobResponse updateVolume(@Param("authHeader") String authHeader, @Param("uuid") String uuid, Volume volumeRequest);
5656
}

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/lifecycle/OntapPrimaryDatastoreLifecycle.java‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,24 +526,32 @@ public boolean migrateToObjectStore(DataStore store) {
526526

527527
@Override
528528
public void updateStoragePool(StoragePool storagePool, Map<String, String> details) {
529+
String newCapacityStr = details.get(PrimaryDataStoreLifeCycle.CAPACITY_BYTES);
530+
if (newCapacityStr == null) {
531+
logger.debug("No capacity change requested for pool: {}, skipping FlexVolume resize", storagePool.getName());
532+
return;
533+
}
534+
529535
long currentCapacityBytes = storagePool.getCapacityBytes();
530-
long newCapacityBytes = Long.parseLong(details.get(PrimaryDataStoreLifeCycle.CAPACITY_BYTES));
536+
long newCapacityBytes = Long.parseLong(newCapacityStr);
531537
StorageStrategy storageStrategy = OntapStorageUtils.getStrategyByStoragePoolDetails(details);
532538

539+
String volumeUuid = details.get(OntapStorageConstants.VOLUME_UUID);
540+
if (volumeUuid == null || volumeUuid.isEmpty()) {
541+
logger.error("Volume UUID or name not found in details for pool: {}, cannot resize", storagePool.getName());
542+
throw new CloudRuntimeException("Volume UUID or name not found in details, cannot resize ONTAP FlexVolume");
543+
}
544+
533545
Volume volume = new Volume();
534-
volume.setUuid(details.get(OntapStorageConstants.VOLUME_UUID));
546+
volume.setUuid(volumeUuid);
535547
volume.setName(details.get(OntapStorageConstants.VOLUME_NAME));
548+
volume.setSize(newCapacityBytes);
536549
try {
537-
if (volume.getUuid() == null || volume.getUuid().isEmpty() || volume.getName() == null || volume.getName().isEmpty()) {
538-
logger.error("Volume UUID/Name not found in details for pool: {}, cannot resize", storagePool.getName());
539-
throw new CloudRuntimeException("Volume UUID/Name not found in details, cannot resize ONTAP FlexVolume");
540-
}
541-
storageStrategy.updateStorageVolume(volume, newCapacityBytes);
550+
storageStrategy.updateStorageVolume(volume);
542551
logger.info("Successfully resized ONTAP FlexVolume '{}' (UUID: {}) for pool '{}' from {} bytes to {} bytes",
543552
volume.getName(), volume.getUuid(), storagePool.getName(), currentCapacityBytes, newCapacityBytes);
544553
} catch (Exception e) {
545-
logger.error(" Exception while resizing FlexVolume for pool: {}. Error: {}",
546-
storagePool.getName(), e.getMessage(), e);
554+
logger.error("Exception while resizing FlexVolume for pool: {}. Error: {}", storagePool.getName(), e.getMessage(), e);
547555
throw new CloudRuntimeException("Failed to resize ONTAP FlexVolume for pool: " + storagePool.getName() + ". " + e.getMessage(), e);
548556
}
549557
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,28 @@ public Volume createStorageVolume(String volumeName, Long size) {
367367
* @param volume the volume to update
368368
* @return the updated Volume object
369369
*/
370-
public Volume updateStorageVolume(Volume volume, Long newSizeBytes) {
370+
public Volume updateStorageVolume(Volume volume) {
371+
logger.info("Resizing ONTAP FlexVolume '{}' (UUID: {}) to {} bytes", volume.getName(), volume.getUuid(), volume.getSize());
371372
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
372-
Volume resizeRequest = new Volume();
373-
resizeRequest.setSize(newSizeBytes);
374373
try {
375-
JobResponse jobResponse = volumeFeignClient.updateVolumeRebalancing(authHeader, volume.getUuid(), resizeRequest);
376-
Boolean jobSucceeded = jobPollForSuccess(jobResponse.getJob().getUuid(), 10, 1000);
377-
if (!jobSucceeded) {
378-
logger.error("resize job failed for FlexVolume: " + volume.getName());
379-
throw new CloudRuntimeException("resize job failed for FlexVolume: " + volume.getName());
380-
}
381-
logger.info("Volume is resized successfully for : " + volume.getName());
374+
Volume resizeRequest = new Volume();
375+
resizeRequest.setSize(volume.getSize());
376+
JobResponse jobResponse = volumeFeignClient.updateVolume(authHeader, volume.getUuid(), resizeRequest);
377+
pollJobIfPresent(jobResponse, "resize FlexVolume [" + volume.getUuid() + "]", 10, 1000);
378+
logger.info("FlexVolume '{}' (UUID: {}) resized successfully to {} bytes", volume.getName(), volume.getUuid(), volume.getSize());
382379
} catch (FeignException e) {
383-
logger.error("Exception while resizing FlexVolume: " + volume.getName(), e);
380+
if (OntapStorageUtils.isOntapObjectNotFoundError(e)) {
381+
String msg = String.format("Cannot resize FlexVolume '%s' (UUID: %s): volume not found on ONTAP (404). ", volume.getName(), volume.getUuid());
382+
logger.error(msg);
383+
throw new CloudRuntimeException(msg, e);
384+
}
385+
logger.error("Exception while resizing FlexVolume '{}' (UUID: {}): {}", volume.getName(), volume.getUuid(), e.getMessage(), e);
384386
throw new CloudRuntimeException("Failed to resize ONTAP FlexVolume: " + e.getMessage(), e);
385387
}
386388
return volume;
387389
}
388-
/**
390+
391+
/**
389392
* Delete ONTAP Flex-Volume
390393
* Eligible only for Unified ONTAP storage
391394
* throw exception in case of disaggregated ONTAP storage

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private void assignExportPolicyToVolume(String volumeUuid, String policyName) {
391391
volumeUpdate.setNas(nas);
392392

393393
try {
394-
JobResponse jobResponse = volumeFeignClient.updateVolumeRebalancing(authHeader, volumeUuid, volumeUpdate);
394+
JobResponse jobResponse = volumeFeignClient.updateVolume(authHeader, volumeUuid, volumeUpdate);
395395
if (jobResponse == null || jobResponse.getJob() == null) {
396396
throw new CloudRuntimeException("Failed to attach policy " + policyName + "to volume " + volumeUuid);
397397
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public void testCreateAccessGroup_Success() throws Exception {
296296
when(accessGroup.getHostsToConnect()).thenReturn(hosts);
297297
doNothing().when(nasFeignClient).createExportPolicy(anyString(), any(ExportPolicy.class));
298298
when(nasFeignClient.getExportPolicyResponse(anyString(), anyMap())).thenReturn(policyResponse);
299-
when(volumeFeignClient.updateVolumeRebalancing(anyString(), anyString(), any())).thenReturn(jobResponse);
299+
when(volumeFeignClient.updateVolume(anyString(), anyString(), any())).thenReturn(jobResponse);
300300
when(jobFeignClient.getJobByUUID(anyString(), anyString())).thenReturn(job);
301301
doNothing().when(storagePoolDetailsDao).addDetail(anyLong(), anyString(), anyString(), eq(true));
302302

@@ -307,7 +307,7 @@ public void testCreateAccessGroup_Success() throws Exception {
307307
assertNotNull(result);
308308
verify(nasFeignClient).createExportPolicy(anyString(), any(ExportPolicy.class));
309309
verify(nasFeignClient).getExportPolicyResponse(anyString(), anyMap());
310-
verify(volumeFeignClient).updateVolumeRebalancing(anyString(), eq("vol-uuid-123"), any());
310+
verify(volumeFeignClient).updateVolume(anyString(), eq("vol-uuid-123"), any());
311311
verify(storagePoolDetailsDao, times(2)).addDetail(anyLong(), anyString(), anyString(), eq(true));
312312
}
313313

@@ -402,7 +402,7 @@ public void testCreateAccessGroup_JobFailure() throws Exception {
402402
when(accessGroup.getHostsToConnect()).thenReturn(hosts);
403403
doNothing().when(nasFeignClient).createExportPolicy(anyString(), any(ExportPolicy.class));
404404
when(nasFeignClient.getExportPolicyResponse(anyString(), anyMap())).thenReturn(policyResponse);
405-
when(volumeFeignClient.updateVolumeRebalancing(anyString(), anyString(), any())).thenReturn(jobResponse);
405+
when(volumeFeignClient.updateVolume(anyString(), anyString(), any())).thenReturn(jobResponse);
406406
when(jobFeignClient.getJobByUUID(anyString(), anyString())).thenReturn(job);
407407

408408
assertThrows(CloudRuntimeException.class, () -> {
@@ -446,7 +446,7 @@ public void testCreateAccessGroup_HostWithPrivateIP() throws Exception {
446446
when(accessGroup.getHostsToConnect()).thenReturn(hosts);
447447
doNothing().when(nasFeignClient).createExportPolicy(anyString(), any(ExportPolicy.class));
448448
when(nasFeignClient.getExportPolicyResponse(anyString(), anyMap())).thenReturn(policyResponse);
449-
when(volumeFeignClient.updateVolumeRebalancing(anyString(), anyString(), any())).thenReturn(jobResponse);
449+
when(volumeFeignClient.updateVolume(anyString(), anyString(), any())).thenReturn(jobResponse);
450450
when(jobFeignClient.getJobByUUID(anyString(), anyString())).thenReturn(job);
451451
doNothing().when(storagePoolDetailsDao).addDetail(anyLong(), anyString(), anyString(), eq(true));
452452

0 commit comments

Comments
 (0)