@@ -412,13 +412,14 @@ private String resizeVolume(DataObject data, String path, VolumeObject vol) {
412412 if (err == null && needResize ) {
413413 err = notifyQemuForTheNewSize (data , err , vol , payload );
414414 }
415-
416415 if (err != null ) {
417416 // try restoring volume to its initial size
418417 SpApiResponse response = StorPoolUtil .volumeUpdate (name , oldSize , true , oldMaxIops , conn );
419418 if (response .getError () != null ) {
420419 logger .debug (String .format ("Could not resize StorPool volume %s back to its original size. Error: %s" , name , response .getError ()));
421420 }
421+ } else {
422+ updateVolumeWithTheNewSize (vol , payload );
422423 }
423424 } catch (Exception e ) {
424425 logger .debug ("sending resize command failed" , e );
@@ -427,6 +428,18 @@ private String resizeVolume(DataObject data, String path, VolumeObject vol) {
427428 return err ;
428429 }
429430
431+ private void updateVolumeWithTheNewSize (VolumeObject vol , ResizeVolumePayload payload ) {
432+
433+ vol .setSize (payload .newSize );
434+ vol .update ();
435+ if (payload .newMaxIops != null ) {
436+ VolumeVO volume = volumeDao .findById (vol .getId ());
437+ volume .setMaxIops (payload .newMaxIops );
438+ volumeDao .update (volume .getId (), volume );
439+ }
440+ updateStoragePool (vol .getPoolId (), payload .newSize - vol .getSize ());
441+ }
442+
430443 private String notifyQemuForTheNewSize (DataObject data , String err , VolumeObject vol , ResizeVolumePayload payload )
431444 throws StorageUnavailableException {
432445 StoragePool pool = (StoragePool )data .getDataStore ();
@@ -455,37 +468,43 @@ private String updateStorPoolVolume(VolumeObject vol, ResizeVolumePayload payloa
455468 }
456469 SpApiResponse resp = new SpApiResponse ();
457470 if (tier != null || template != null ) {
458- Map <String , String > tags = StorPoolHelper .addStorPoolTags (null , null , null , null , tier );
459- StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , tags , null , null , template , null , null ,
460- payload .shrinkOk );
461- resp = StorPoolUtil .volumeUpdate (spVolume , conn );
471+ resp = updateVolumeByStorPoolQoS (payload , conn , name , tier , template );
462472 } else {
463- long maxIops = payload .newMaxIops == null ? Long .valueOf (0 ) : payload .newMaxIops ;
464-
465- StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , null , null , maxIops , null , null , null ,
466- payload .shrinkOk );
467- StorPoolUtil .spLog (
468- "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s" ,
469- name , vol .getUuid (), vol .getSize (), payload .newSize , payload .shrinkOk , maxIops );
470-
471- resp = StorPoolUtil .volumeUpdate (spVolume , conn );
473+ resp = updateVolumeByOffering (vol , payload , conn , name );
472474 }
473475 if (resp .getError () != null ) {
474476 err = String .format ("Could not resize StorPool volume %s. Error: %s" , name , resp .getError ());
475- } else {
476- vol .setSize (payload .newSize );
477- vol .update ();
478- if (payload .newMaxIops != null ) {
479- VolumeVO volume = volumeDao .findById (vol .getId ());
480- volume .setMaxIops (payload .newMaxIops );
481- volumeDao .update (volume .getId (), volume );
482- }
483-
484- updateStoragePool (vol .getPoolId (), payload .newSize - vol .getSize ());
485477 }
486478 return err ;
487479 }
488480
481+ @ NotNull
482+ private static SpApiResponse updateVolumeByStorPoolQoS (ResizeVolumePayload payload , SpConnectionDesc conn , String name , String tier , String template ) {
483+
484+ SpApiResponse resp ;
485+ Map <String , String > tags = StorPoolHelper .addStorPoolTags (null , null , null , null , tier );
486+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , tags , null , null , template , null , null ,
487+ payload .shrinkOk );
488+ resp = StorPoolUtil .volumeUpdate (spVolume , conn );
489+ return resp ;
490+ }
491+
492+ @ NotNull
493+ private static SpApiResponse updateVolumeByOffering (VolumeObject vol , ResizeVolumePayload payload , SpConnectionDesc conn , String name ) {
494+
495+ SpApiResponse resp ;
496+ long maxIops = payload .newMaxIops == null ? Long .valueOf (0 ) : payload .newMaxIops ;
497+
498+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , null , null , maxIops , null , null , null ,
499+ payload .shrinkOk );
500+ StorPoolUtil .spLog (
501+ "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s" ,
502+ name , vol .getUuid (), vol .getSize (), payload .newSize , payload .shrinkOk , maxIops );
503+
504+ resp = StorPoolUtil .volumeUpdate (spVolume , conn );
505+ return resp ;
506+ }
507+
489508 @ Override
490509 public void deleteAsync (DataStore dataStore , DataObject data , AsyncCompletionCallback <CommandResult > callback ) {
491510 String err = null ;
0 commit comments