4949import org .apache .logging .log4j .Logger ;
5050
5151import java .util .HashMap ;
52+ import java .util .ArrayList ;
5253import java .util .List ;
5354import java .util .Map ;
5455import java .util .Objects ;
@@ -135,31 +136,42 @@ public boolean connect() {
135136 logger .error ("No aggregates are assigned to SVM " + svmName );
136137 throw new CloudRuntimeException ("No aggregates are assigned to SVM " + svmName );
137138 }
139+ // Collect all online aggregates assigned to the SVM. Capacity-based selection is
140+ // intentionally deferred to createStorageVolume(name, size), which validates the
141+ // available space against the actual requested volume size.
142+ List <Aggregate > eligibleAggregates = new ArrayList <>();
138143 for (Aggregate aggr : aggrs ) {
139144 logger .debug ("Found aggregate: " + aggr .getName () + " with UUID: " + aggr .getUuid ());
140145 Aggregate aggrResp = aggregateFeignClient .getAggregateByUUID (authHeader , aggr .getUuid ());
141146 if (aggrResp == null ) {
142147 logger .warn ("Aggregate details response is null for aggregate " + aggr .getName () + ". Skipping." );
143- break ;
148+ continue ;
144149 }
145150 if (!Objects .equals (aggrResp .getState (), Aggregate .StateEnum .ONLINE )) {
146151 logger .warn ("Aggregate " + aggr .getName () + " is not in online state. Skipping this aggregate." );
147152 continue ;
148- } else if (aggrResp .getSpace () == null || aggrResp .getAvailableBlockStorageSpace () == null ||
149- aggrResp .getAvailableBlockStorageSpace () <= storage .getSize ().doubleValue ()) {
150- logger .warn ("Aggregate " + aggr .getName () + " does not have sufficient available space. Skipping this aggregate." );
151- continue ;
152153 }
153- logger .info ("Selected aggregate: " + aggr .getName () + " for volume operations." );
154- this .aggregates = List .of (aggr );
155- break ;
154+ logger .debug ("Aggregate " + aggr .getName () + " is online and eligible for volume operations." );
155+ eligibleAggregates .add (aggr );
156156 }
157- if (this . aggregates == null || this . aggregates .isEmpty ()) {
158- logger .error ("No suitable aggregates found on SVM " + svmName + " for volume creation ." );
159- throw new CloudRuntimeException ("No suitable aggregates found on SVM " + svmName + " for volume creation ." );
157+ if (eligibleAggregates .isEmpty ()) {
158+ logger .error ("No suitable aggregates found on SVM " + svmName + " for volume operations ." );
159+ throw new CloudRuntimeException ("No suitable aggregates found on SVM " + svmName + " for volume operations ." );
160160 }
161+ this .aggregates = eligibleAggregates ;
162+ logger .info ("Found " + eligibleAggregates .size () + " online aggregate(s) on SVM " + svmName + " for volume operations." );
161163
162164 logger .info ("Successfully connected to ONTAP cluster and validated ONTAP details provided" );
165+ } catch (FeignException .Unauthorized e ) {
166+ logger .error ("Authentication failed while connecting to ONTAP cluster at " + storage .getStorageIP () +
167+ ". Please verify the username and password." , e );
168+ throw new CloudRuntimeException ("Authentication failed: Invalid credentials for ONTAP cluster at " +
169+ storage .getStorageIP () + ". Please verify the username and password." );
170+ } catch (FeignException .Forbidden e ) {
171+ logger .error ("Authorization failed while connecting to ONTAP cluster at " + storage .getStorageIP () +
172+ ". The user does not have sufficient privileges." , e );
173+ throw new CloudRuntimeException ("Authorization failed: User does not have sufficient privileges on ONTAP cluster at " +
174+ storage .getStorageIP () + ". Please verify user permissions." );
163175 } catch (Exception e ) {
164176 logger .error ("Failed to connect to ONTAP cluster: " + e .getMessage (), e );
165177 throw new CloudRuntimeException ("Failed to connect to ONTAP cluster: " + e .getMessage (), e );
@@ -211,7 +223,7 @@ public Volume createStorageVolume(String volumeName, Long size) {
211223
212224 if (aggrResp == null ) {
213225 logger .warn ("Aggregate details response is null for aggregate " + aggr .getName () + ". Skipping." );
214- break ;
226+ continue ;
215227 }
216228
217229 if (!Objects .equals (aggrResp .getState (), Aggregate .StateEnum .ONLINE )) {
@@ -227,7 +239,7 @@ public Volume createStorageVolume(String volumeName, Long size) {
227239 final long availableBytes = aggrResp .getAvailableBlockStorageSpace ().longValue ();
228240 logger .debug ("Aggregate " + aggr .getName () + " available bytes=" + availableBytes + ", requested=" + size );
229241
230- if (availableBytes <= size ) {
242+ if (availableBytes < size ) {
231243 logger .warn ("Aggregate " + aggr .getName () + " does not have sufficient available space. Required=" +
232244 size + " bytes, available=" + availableBytes + " bytes. Skipping this aggregate." );
233245 continue ;
@@ -251,6 +263,7 @@ public Volume createStorageVolume(String volumeName, Long size) {
251263 volumeRequest .setAggregates (List .of (aggr ));
252264 volumeRequest .setSize (size );
253265 volumeRequest .setNas (nas );
266+ volumeRequest .setGuarantee (new Volume .Guarantee (Volume .Guarantee .TypeEnum .NONE ));
254267 try {
255268 JobResponse jobResponse = volumeFeignClient .createVolumeWithJob (authHeader , volumeRequest );
256269 if (jobResponse == null || jobResponse .getJob () == null ) {
0 commit comments