Skip to content

Commit 0407d2b

Browse files
CSTACKEX-191: logical access methods can have return type as primitive
1 parent 8ae97bf commit 0407d2b

7 files changed

Lines changed: 31 additions & 37 deletions

File tree

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/VolumeConcise.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class VolumeConcise {
3030
private String uuid;
3131

3232
@JsonProperty("name")
33-
3433
private String name;
3534

3635
public String getUuid() {
@@ -46,5 +45,6 @@ public String getName() {
4645
}
4746

4847
public void setName(String name) {
49-
this.name = name; }
48+
this.name = name;
49+
}
5050
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private long validateInitializeInputs(Long capacityBytes, Long podId, Long clust
231231
throw new CloudRuntimeException("Storage pool name is null or empty, cannot create primary storage");
232232
}
233233

234-
if (StringUtils.isBlank(providerName )) {
234+
if (StringUtils.isBlank(providerName)) {
235235
throw new CloudRuntimeException("Provider name is null or empty, cannot create primary storage");
236236
}
237237

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ public abstract JobResponse revertSnapshotForCloudStackVolume(String snapshotNam
595595
* @param values map including SVM name, LUN name, and igroup name (for SAN) or equivalent for NAS
596596
* @return map containing logical unit number for the new/existing mapping (SAN) or relevant info for NAS
597597
*/
598-
abstract public Map<String,String> enableLogicalAccess(Map<String,String> values);
598+
abstract public String enableLogicalAccess(Map<String,String> values);
599599

600600
/**
601601
* Method encapsulates the behavior based on the opted protocol in subclasses
@@ -610,7 +610,7 @@ public abstract JobResponse revertSnapshotForCloudStackVolume(String snapshotNam
610610
* @param values map with SVM name, LUN name, and igroup name (for SAN) or equivalent for NAS
611611
* @return map containing logical unit number if mapping exists; otherwise null
612612
*/
613-
abstract public Map<String, String> getLogicalAccess(Map<String, String> values);
613+
abstract public String getLogicalAccess(Map<String, String> values);
614614

615615
// ── FlexVolume Snapshot accessors ────────────────────────────────────────
616616

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public AccessGroup getAccessGroup(Map<String, String> values) {
202202
}
203203

204204
@Override
205-
public Map <String, String> enableLogicalAccess(Map<String, String> values) {
205+
public String enableLogicalAccess(Map<String, String> values) {
206206
return null;
207207
}
208208

@@ -211,8 +211,8 @@ public void disableLogicalAccess(Map<String, String> values) {
211211
}
212212

213213
@Override
214-
public Map<String, String> getLogicalAccess(Map<String, String> values) {
215-
return Map.of();
214+
public String getLogicalAccess(Map<String, String> values) {
215+
return null;
216216
}
217217

218218
private ExportPolicy createExportPolicy(String svmName, ExportPolicy policy) {

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ public AccessGroup getAccessGroup(Map<String, String> values) {
383383
}
384384
}
385385

386-
public Map<String, String> enableLogicalAccess(Map<String, String> values) {
386+
public String enableLogicalAccess(Map<String, String> values) {
387387
logger.info("enableLogicalAccess : Create LunMap");
388388
logger.debug("enableLogicalAccess : Creating LunMap with values {} ", values);
389-
Map<String, String> response = null;
389+
String lunNumber = null;
390390
if (values == null) {
391391
logger.error("enableLogicalAccess: LunMap creation failed. Invalid request values: null");
392392
throw new CloudRuntimeException("Failed to create LunMap, invalid request");
@@ -435,9 +435,7 @@ public Map<String, String> enableLogicalAccess(Map<String, String> values) {
435435
OntapStorageConstants.IGROUP_DOT_NAME, igroupName,
436436
OntapStorageConstants.FIELDS, OntapStorageConstants.LOGICAL_UNIT_NUMBER
437437
));
438-
response = Map.of(
439-
OntapStorageConstants.LOGICAL_UNIT_NUMBER, lunMapResponse.getRecords().get(0).getLogicalUnitNumber().toString()
440-
);
438+
lunNumber = lunMapResponse.getRecords().get(0).getLogicalUnitNumber().toString();
441439
} catch (Exception e) {
442440
logger.error("enableLogicalAccess: Failed to fetch LunMap details for Lun: {} and igroup: {}, Exception: {}", lunName, igroupName, e);
443441
throw new CloudRuntimeException("Failed to fetch LunMap details for Lun: " + lunName + " and igroup: " + igroupName);
@@ -448,7 +446,7 @@ public Map<String, String> enableLogicalAccess(Map<String, String> values) {
448446
logger.error("Exception occurred while creating LunMap", e);
449447
throw new CloudRuntimeException("Failed to create LunMap: " + e.getMessage());
450448
}
451-
return response;
449+
return lunNumber;
452450
}
453451

454452
public void disableLogicalAccess(Map<String, String> values) {
@@ -482,8 +480,9 @@ public void disableLogicalAccess(Map<String, String> values) {
482480
}
483481

484482
// GET-only helper: fetch LUN-map and return logical unit number if it exists; otherwise return null
485-
public Map<String, String> getLogicalAccess(Map<String, String> values) {
483+
public String getLogicalAccess(Map<String, String> values) {
486484
logger.info("getLogicalAccess : Fetch LunMap");
485+
String lunNumber = null;
487486
logger.debug("getLogicalAccess : Fetching LunMap with values {} ", values);
488487
if (values == null) {
489488
logger.error("getLogicalAccess: Invalid request values: null");
@@ -507,13 +506,12 @@ public Map<String, String> getLogicalAccess(Map<String, String> values) {
507506
));
508507
if (lunMapResponse != null && lunMapResponse.getRecords() != null && !lunMapResponse.getRecords().isEmpty()) {
509508
Integer lunLogicalUnitNum = lunMapResponse.getRecords().get(0).getLogicalUnitNumber();
510-
String lunNumber = lunLogicalUnitNum != null ? lunLogicalUnitNum.toString() : null;
511-
return lunNumber != null ? Map.of(OntapStorageConstants.LOGICAL_UNIT_NUMBER, lunNumber) : null;
509+
lunNumber = lunLogicalUnitNum != null ? lunLogicalUnitNum.toString() : null;
512510
}
513511
} catch (Exception e) {
514512
logger.warn("getLogicalAccess: LunMap not found for Lun: {} and igroup: {} ({}).", lunName, igroupName, e.getMessage());
515513
}
516-
return null;
514+
return lunNumber;
517515
}
518516

519517
@Override
@@ -526,9 +524,8 @@ public String ensureLunMapped(String svmName, String lunName, String accessGroup
526524
OntapStorageConstants.SVM_DOT_NAME, svmName,
527525
OntapStorageConstants.IGROUP_DOT_NAME, accessGroupName
528526
);
529-
Map<String, String> mapResp = getLogicalAccess(getMap);
530-
if (mapResp != null && mapResp.containsKey(OntapStorageConstants.LOGICAL_UNIT_NUMBER)) {
531-
String lunNumber = mapResp.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER);
527+
String lunNumber = getLogicalAccess(getMap);
528+
if (lunNumber != null) {
532529
logger.info("ensureLunMapped: Existing LunMap found for LUN [{}] in igroup [{}] with LUN number [{}]", lunName, accessGroupName, lunNumber);
533530
return lunNumber;
534531
}
@@ -539,12 +536,12 @@ public String ensureLunMapped(String svmName, String lunName, String accessGroup
539536
OntapStorageConstants.SVM_DOT_NAME, svmName,
540537
OntapStorageConstants.IGROUP_DOT_NAME, accessGroupName
541538
);
542-
Map<String, String> response = enableLogicalAccess(enableMap);
543-
if (response == null || !response.containsKey(OntapStorageConstants.LOGICAL_UNIT_NUMBER)) {
539+
String response = enableLogicalAccess(enableMap);
540+
if (response == null ) {
544541
throw new CloudRuntimeException("Failed to map LUN [" + lunName + "] to iGroup [" + accessGroupName + "]");
545542
}
546-
logger.info("ensureLunMapped: Successfully mapped LUN [{}] to igroup [{}] with LUN number [{}]", lunName, accessGroupName, response.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER));
547-
return response.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER);
543+
logger.info("ensureLunMapped: Successfully mapped LUN [{}] to igroup [{}] with LUN number [{}]", lunName, accessGroupName, response);
544+
return response;
548545
}
549546
/**
550547
* Reverts a LUN to a snapshot using the ONTAP CLI-based snapshot file restore API.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public AccessGroup getAccessGroup(Map<String, String> values) {
169169
}
170170

171171
@Override
172-
public Map<String, String> enableLogicalAccess(Map<String, String> values) {
172+
public String enableLogicalAccess(Map<String, String> values) {
173173
return null;
174174
}
175175

@@ -178,7 +178,7 @@ public void disableLogicalAccess(Map<String, String> values) {
178178
}
179179

180180
@Override
181-
public Map<String, String> getLogicalAccess(Map<String, String> values) {
181+
public String getLogicalAccess(Map<String, String> values) {
182182
return null;
183183
}
184184
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,10 @@ void testEnableLogicalAccess_Success() {
516516
when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response);
517517

518518
// Execute
519-
Map<String, String> result = unifiedSANStrategy.enableLogicalAccess(values);
519+
String result = unifiedSANStrategy.enableLogicalAccess(values);
520520

521521
// Verify
522522
assertNotNull(result);
523-
assertTrue(result.containsKey(OntapStorageConstants.LOGICAL_UNIT_NUMBER));
524-
assertEquals("0", result.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER));
525523

526524
verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class));
527525
}
@@ -550,11 +548,10 @@ void testEnableLogicalAccess_AlreadyMapped_ReturnsLunNumber() {
550548
when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response);
551549

552550
// Execute
553-
Map<String, String> result = unifiedSANStrategy.enableLogicalAccess(values);
551+
String result = unifiedSANStrategy.enableLogicalAccess(values);
554552

555553
// Verify
556554
assertNotNull(result);
557-
assertEquals("5", result.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER));
558555
}
559556
}
560557

@@ -621,11 +618,11 @@ void testGetLogicalAccess_Success() {
621618
when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response);
622619

623620
// Execute
624-
Map<String, String> result = unifiedSANStrategy.getLogicalAccess(values);
621+
String result = unifiedSANStrategy.getLogicalAccess(values);
625622

626623
// Verify
627624
assertNotNull(result);
628-
assertEquals("3", result.get(OntapStorageConstants.LOGICAL_UNIT_NUMBER));
625+
assertEquals("3", result);
629626
}
630627
}
631628

@@ -645,7 +642,7 @@ void testGetLogicalAccess_NotFound_ReturnsNull() {
645642
.thenThrow(new RuntimeException("Not found"));
646643

647644
// Execute
648-
Map<String, String> result = unifiedSANStrategy.getLogicalAccess(values);
645+
String result = unifiedSANStrategy.getLogicalAccess(values);
649646

650647
// Verify
651648
assertNull(result);
@@ -1671,7 +1668,7 @@ void testGetLogicalAccess_EmptyResponse_ReturnsNull() {
16711668

16721669
when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse);
16731670

1674-
Map<String, String> result = unifiedSANStrategy.getLogicalAccess(values);
1671+
String result = unifiedSANStrategy.getLogicalAccess(values);
16751672

16761673
assertNull(result);
16771674
}
@@ -1691,7 +1688,7 @@ void testGetLogicalAccess_ExceptionThrown_ReturnsNull() {
16911688
when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap()))
16921689
.thenThrow(new RuntimeException("Connection failed"));
16931690

1694-
Map<String, String> result = unifiedSANStrategy.getLogicalAccess(values);
1691+
String result = unifiedSANStrategy.getLogicalAccess(values);
16951692

16961693
assertNull(result);
16971694
}

0 commit comments

Comments
 (0)