Skip to content

Commit 24335b4

Browse files
Addressed review comments
1 parent e2bb488 commit 24335b4

6 files changed

Lines changed: 27 additions & 14 deletions

File tree

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ protected Void managedCopyBaseImageCallback(AsyncCallbackDispatcher<VolumeServic
766766

767767
if (templateObjectTo.getFormat() != null) {
768768
PrimaryDataStore primaryDataStore = context.getPrimaryDataStore();
769-
boolean isOntap = primaryDataStore != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(primaryDataStore.getStorageProviderName());
770-
if (!isOntap || volume.getFormat() == null) {
769+
boolean isOntapDataStore = primaryDataStore != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(primaryDataStore.getStorageProviderName());
770+
if (!isOntapDataStore || volume.getFormat() == null) {
771771
volume.setFormat(templateObjectTo.getFormat());
772772
}
773773
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/listener/OntapHostListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.cloudstack.storage.service.model.ProtocolType;
3434
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
3535
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
36+
import org.apache.commons.collections.MapUtils;
3637
import org.apache.commons.lang3.StringUtils;
3738
import org.apache.logging.log4j.LogManager;
3839
import org.apache.logging.log4j.Logger;
@@ -91,7 +92,7 @@ public boolean hostConnect(long hostId, long poolId) {
9192
try {
9293
// Load storage pool details from database to pass mount options and other config to agent
9394
Map<String, String> detailsMap = _storagePoolDetailsDao.listDetailsKeyPairs(poolId);
94-
if (detailsMap == null || detailsMap.isEmpty()) {
95+
if (MapUtils.isEmpty(detailsMap)) {
9596
logger.error("hostConnect: Failed to load storage pool details for pool id: {}", poolId);
9697
return false;
9798
}
@@ -247,7 +248,7 @@ public boolean hostRemoved(long hostId, long clusterId) {
247248
private void removeHostFromOntapPoolIfNeeded(StoragePoolVO pool, Host host) {
248249
try {
249250
Map<String, String> detailsMap = _storagePoolDetailsDao.listDetailsKeyPairs(pool.getId());
250-
if (detailsMap == null || detailsMap.isEmpty()) {
251+
if (MapUtils.isEmpty(detailsMap)) {
251252
logger.debug("hostAboutToBeRemoved: removeHostFromOntapPoolIfNeeded: No pool details found for pool id: {}", pool.getId());
252253
return;
253254
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.cloudstack.storage.service;
2121

22+
import java.util.ArrayList;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
@@ -190,6 +191,7 @@ private void validateAndSelectAggregatesForVolumeCreation(String authHeader, Str
190191
logger.error("No aggregates are assigned to SVM " + svmName);
191192
throw new CloudRuntimeException("No aggregates are assigned to SVM " + svmName);
192193
}
194+
List<Aggregate> eligibleAggregates = new ArrayList<>();
193195
for (Aggregate aggr : aggrs) {
194196
logger.debug("Found aggregate: " + aggr.getName() + " with UUID: " + aggr.getUuid());
195197
Aggregate aggrResp = aggregateFeignClient.getAggregateByUUID(authHeader, aggr.getUuid(),
@@ -209,12 +211,13 @@ private void validateAndSelectAggregatesForVolumeCreation(String authHeader, Str
209211
continue;
210212
}
211213
logger.info("Selected aggregate: " + aggr.getName() + " for volume operations.");
212-
this.aggregates = List.of(aggr);
214+
eligibleAggregates.add(aggrResp);
213215
}
214-
if (this.aggregates == null || this.aggregates.isEmpty()) {
216+
if (eligibleAggregates.isEmpty()) {
215217
logger.error("No suitable aggregates found on SVM " + svmName + " for volume creation.");
216218
throw new CloudRuntimeException("No suitable aggregates found on SVM " + svmName + " for volume creation.");
217219
}
220+
this.aggregates = eligibleAggregates;
218221
}
219222

220223
// Common methods like create/delete etc., should be here
@@ -528,7 +531,10 @@ public Pair<String, String> getNetworkInterface() {
528531
IpInterface fallbackInterface = null;
529532

530533
for (IpInterface iface : response.getRecords()) {
531-
if (!Boolean.TRUE.equals(iface.getEnabled()) || !OntapStorageConstants.LIF_STATE_UP.equals(iface.getState())) {
534+
if (iface == null || !Boolean.TRUE.equals(iface.getEnabled()) || !OntapStorageConstants.LIF_STATE_UP.equals(iface.getState())) {
535+
continue;
536+
}
537+
if (iface.getIp() == null || iface.getIp().getAddress() == null) {
532538
continue;
533539
}
534540
if (!isIPv4Address(iface.getIp().getAddress())) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
5050
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
5151
import org.apache.cloudstack.storage.volume.VolumeObject;
52+
import org.apache.commons.collections.MapUtils;
53+
import org.apache.commons.lang3.StringUtils;
5254
import org.apache.logging.log4j.LogManager;
5355
import org.apache.logging.log4j.Logger;
5456

@@ -213,11 +215,11 @@ public AccessGroup updateAccessGroup(AccessGroup accessGroup) {
213215
}
214216

215217
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(accessGroup.getStoragePoolId());
216-
if (details == null || details.isEmpty()) {
218+
if (MapUtils.isEmpty(details)) {
217219
throw new CloudRuntimeException("No storage pool details found for storagePoolId: " + accessGroup.getStoragePoolId());
218220
}
219221
String exportPolicyId = details.get(OntapStorageConstants.EXPORT_POLICY_ID);
220-
if (exportPolicyId == null || exportPolicyId.isEmpty()) {
222+
if (StringUtils.isBlank(exportPolicyId)) {
221223
throw new CloudRuntimeException("No export policy found for storagePoolId: " + accessGroup.getStoragePoolId());
222224
}
223225

@@ -446,6 +448,10 @@ private ExportPolicy createExportPolicyRequest(AccessGroup accessGroup,String sv
446448
String ip = (hostStorageIp != null && !hostStorageIp.isEmpty())
447449
? hostStorageIp
448450
: (host.getPrivateIpAddress() != null ? host.getPrivateIpAddress().trim() : null);
451+
if (StringUtils.isBlank(ip)) {
452+
logger.warn("Skipping host {} while creating export policy because it has no storage or private IP address", host.getId());
453+
continue;
454+
}
449455
String ipToUse = ip + "/32";
450456
ExportRule.ExportClient exportClient = new ExportRule.ExportClient();
451457
exportClient.setMatch(ipToUse);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,5 @@ public void testUpdateAccessGroup_TrimsWhitespaceFromPrivateIp() {
953953
List<ExportRule.ExportClient> clients = existingPolicy.getRules().get(0).getClients();
954954
assertEquals(1, clients.size());
955955
assertEquals("192.168.1.10/32", clients.get(0).getMatch());
956-
}}
956+
}
957+
}

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,6 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
16381638
boolean isKvmAndFileBasedStorage = isHypervisorKvmAndFileBasedStorage(volume, storagePool);
16391639
boolean backupSnapToSecondary = isBackupSnapshotToSecondaryForZone(volume.getDataCenterId());
16401640

1641-
16421641
StoragePoolType poolType = volume.getStoragePoolType();
16431642

16441643
updateSnapshotPayload(volume.getPoolId(), payload, isKvmAndFileBasedStorage, poolType, clusterId);
@@ -1647,7 +1646,7 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
16471646
// They must not use secondary archive bookkeeping (postSnapshotDirectlyToSecondary) or a physical
16481647
// secondary copy — delete is handled via StorageSystemSnapshotStrategy → driver deleteAsync.
16491648
boolean archiveSnapshotToSecondary = backupSnapToSecondary
1650-
&& !isManagedPrimaryLocationSnapshot(storagePool, payload);
1649+
&& !isOntapManagedPrimaryLocationSnapshot(storagePool, payload);
16511650

16521651
if (isKvmAndFileBasedStorage && archiveSnapshotToSecondary) {
16531652
DataStore imageStore = snapshotSrv.findSnapshotImageStore(snapshot);
@@ -1681,7 +1680,7 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
16811680
postSnapshotDirectlyToSecondary(snapshot, snapshotOnPrimary, snapshotId);
16821681
}
16831682
} else {
1684-
if (backupSnapToSecondary && isManagedPrimaryLocationSnapshot(storagePool, payload)) {
1683+
if (backupSnapToSecondary && isOntapManagedPrimaryLocationSnapshot(storagePool, payload)) {
16851684
logger.info("takeSnapshot: snapshot [{}] on NetApp ONTAP managed primary pool [{}] with locationType=PRIMARY — "
16861685
+ "keeping snapshot on primary/array storage only; not archiving to secondary "
16871686
+ "(backup.snapshot.after.take is ignored for this snapshot class)",
@@ -1787,7 +1786,7 @@ private void postSnapshotDirectlyToSecondary(SnapshotInfo snapshot, SnapshotInfo
17871786
*
17881787
* <p>Other managed storage providers are not affected by this check.</p>
17891788
*/
1790-
private boolean isManagedPrimaryLocationSnapshot(StoragePool storagePool, CreateSnapshotPayload payload) {
1789+
private boolean isOntapManagedPrimaryLocationSnapshot(StoragePool storagePool, CreateSnapshotPayload payload) {
17911790
return storagePool != null && storagePool.isManaged()
17921791
&& DataStoreProvider.ONTAP_PLUGIN_NAME.equals(storagePool.getStorageProviderName())
17931792
&& Snapshot.LocationType.PRIMARY.equals(payload.getLocationType());

0 commit comments

Comments
 (0)