Skip to content

Commit f283879

Browse files
- Removed occurences of string.format usage
- extracted the ONTAP plugin name to interface nane to use it from one place. - Corrected indentation gaps.
1 parent b383d35 commit f283879

12 files changed

Lines changed: 38 additions & 29 deletions

File tree

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public interface DataStoreProvider {
2929
String SAMPLE_IMAGE = "Sample";
3030
String SMB = "NFS";
3131
String DEFAULT_PRIMARY = "DefaultPrimary";
32+
/**
33+
* Primary storage provider name for NetApp ONTAP ({@code OntapPrimaryDatastoreProvider#getName}).
34+
* Single canonical value; use this instead of duplicating the string across modules.
35+
*/
36+
String ONTAP_PLUGIN_NAME = "NetApp ONTAP";
3237

3338
enum DataStoreProviderType {
3439
PRIMARY, IMAGE, ImageCache, OBJECT

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/KvmFileBasedStorageVmSnapshotStrategy.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.cloud.vm.snapshot.VMSnapshotVO;
5252
import org.apache.cloudstack.backup.BackupOfferingVO;
5353
import org.apache.cloudstack.backup.dao.BackupOfferingDao;
54+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
5455
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
5556
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
5657
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
@@ -77,8 +78,6 @@ public class KvmFileBasedStorageVmSnapshotStrategy extends StorageVMSnapshotStra
7778

7879
private static final List<Storage.StoragePoolType> supportedStoragePoolTypes = List.of(Storage.StoragePoolType.Filesystem, Storage.StoragePoolType.NetworkFilesystem, Storage.StoragePoolType.SharedMountPoint);
7980

80-
private static final String ONTAP_PROVIDER_NAME = "NetApp ONTAP";
81-
8281
@Inject
8382
protected SnapshotDataStoreDao snapshotDataStoreDao;
8483

@@ -327,8 +326,8 @@ public StrategyPriority canHandle(Long vmId, Long rootPoolId, boolean snapshotMe
327326
List<VolumeVO> volumes = volumeDao.findByInstance(vmId);
328327
for (VolumeVO volume : volumes) {
329328
StoragePoolVO storagePoolVO = storagePool.findById(volume.getPoolId());
330-
if (storagePoolVO.isManaged() && ONTAP_PROVIDER_NAME.equals(storagePoolVO.getStorageProviderName())) {
331-
logger.debug(" {} as the VM has a volume on ONTAP managed storage pool [{}]. " +
329+
if (storagePoolVO.isManaged() && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(storagePoolVO.getStorageProviderName())) {
330+
logger.debug("{} as the VM has a volume on ONTAP managed storage pool [{}]. " +
332331
"ONTAP managed storage has its own dedicated VM snapshot strategy.", cantHandleLog, storagePoolVO.getName());
333332
return StrategyPriority.CANT_HANDLE;
334333
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.io.File;
2526
import java.nio.file.Files;
2627
import java.nio.file.Paths;
2728

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,6 +30,7 @@ public class VolumeConcise {
3030
private String uuid;
3131

3232
@JsonProperty("name")
33+
3334
private String name;
3435

3536
public String getUuid() {
@@ -45,6 +46,5 @@ public String getName() {
4546
}
4647

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

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
import com.cloud.utils.exception.CloudRuntimeException;
3535
import com.google.common.base.Preconditions;
3636
import org.apache.cloudstack.api.ApiConstants;
37+
import org.apache.cloudstack.engine.subsystem.api.storage.AbstractScope;
3738
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
3839
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3940
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
4041
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
4142
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
4243
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters;
43-
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
4444
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
4545
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4646
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
@@ -232,7 +232,7 @@ private long validateInitializeInputs(Long capacityBytes, Long podId, Long clust
232232
throw new CloudRuntimeException("Storage pool name is null or empty, cannot create primary storage");
233233
}
234234

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

@@ -273,9 +273,9 @@ private long validateInitializeInputs(Long capacityBytes, Long podId, Long clust
273273
}
274274

275275
// Detect missing required keys
276-
HashSet<String> providedKeys = new HashSet<>(details.keySet());
276+
Set<String> providedKeys = new HashSet<>(details.keySet());
277277
if (!providedKeys.containsAll(requiredKeys)) {
278-
HashSet<String> missing = new HashSet<>(requiredKeys);
278+
Set<String> missing = new HashSet<>(requiredKeys);
279279
missing.removeAll(providedKeys);
280280
throw new CloudRuntimeException("ONTAP primary storage creation failed, missing detail(s): " + missing);
281281
}
@@ -287,10 +287,10 @@ private long validateInitializeInputs(Long capacityBytes, Long podId, Long clust
287287
public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
288288
logger.debug("In attachCluster for ONTAP primary storage");
289289
if (dataStore == null) {
290-
throw new InvalidParameterValueException("dataStore should not be null");
290+
throw new InvalidParameterValueException("DataStore should not be null");
291291
}
292292
if (scope == null) {
293-
throw new InvalidParameterValueException("scope should not be null");
293+
throw new InvalidParameterValueException("Scope should not be null");
294294
}
295295
List<String> hostsIdentifier = new ArrayList<>();
296296
StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId());
@@ -378,6 +378,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
378378
_dataStoreHelper.attachZone(dataStore);
379379
return true;
380380
}
381+
381382
private boolean validateProtocolSupportAndFetchHostsIdentifier(List<HostVO> hosts, ProtocolType protocolType, List<String> hostIdentifiers) {
382383
switch (protocolType) {
383384
case ISCSI:

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/provider/OntapPrimaryDatastoreProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222

2323
import com.cloud.utils.component.ComponentContext;
24+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
2425
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
2526
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
2627
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
2728
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
2829
import org.apache.cloudstack.storage.driver.OntapPrimaryDatastoreDriver;
2930
import org.apache.cloudstack.storage.lifecycle.OntapPrimaryDatastoreLifecycle;
3031
import org.apache.cloudstack.storage.listener.OntapHostListener;
31-
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
3232
import org.apache.logging.log4j.LogManager;
3333
import org.apache.logging.log4j.Logger;
3434
import org.springframework.stereotype.Component;
@@ -66,7 +66,7 @@ public HypervisorHostListener getHostListener() {
6666
@Override
6767
public String getName() {
6868
logger.trace("OntapPrimaryDatastoreProvider: getName: Called");
69-
return OntapStorageConstants.ONTAP_PLUGIN_NAME;
69+
return DataStoreProvider.ONTAP_PLUGIN_NAME;
7070
}
7171

7272
@Override

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,23 @@ public class CloudStackVolume {
3636
* a. snapshot workflows will get source LUN details from it.
3737
*/
3838
private Lun lun;
39+
3940
private String datastoreId;
41+
4042
/**
4143
* FlexVolume UUID on which this cloudstack volume is created.
4244
* a. Field is eligible for unified storage only.
4345
* b. It will be null for the disaggregated storage.
4446
*/
4547
private String flexVolumeUuid;
48+
4649
/**
4750
* Field serves for snapshot workflows
4851
*/
4952
private String destinationPath;
53+
5054
private DataObject volumeInfo; // This is needed as we need DataObject to be passed to agent to create volume
55+
5156
public FileInfo getFile() {
5257
return file;
5358
}
@@ -79,6 +84,7 @@ public DataObject getVolumeInfo() {
7984
public void setVolumeInfo(DataObject volumeInfo) {
8085
this.volumeInfo = volumeInfo;
8186
}
87+
8288
public String getFlexVolumeUuid() {
8389
return flexVolumeUuid;
8490
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

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

22+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
2223

2324
public class OntapStorageConstants {
2425

25-
public static final String ONTAP_PLUGIN_NAME = "NetApp ONTAP";
26+
/** Same as {@link DataStoreProvider#ONTAP_PLUGIN_NAME}; retained for existing ONTAP plugin call sites. */
27+
public static final String ONTAP_PLUGIN_NAME = DataStoreProvider.ONTAP_PLUGIN_NAME;
2628
public static final int NFS3_PORT = 2049;
2729
public static final int ISCSI_PORT = 3260;
2830

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/vmsnapshot/OntapVMSnapshotStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
3031
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
3132
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions;
3233
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
@@ -233,7 +234,7 @@ boolean allVolumesOnOntapManagedStorage(long vmId) {
233234
volume.getId(), pool.getName());
234235
return false;
235236
}
236-
if (!OntapStorageConstants.ONTAP_PLUGIN_NAME.equals(pool.getStorageProviderName())) {
237+
if (!DataStoreProvider.ONTAP_PLUGIN_NAME.equals(pool.getStorageProviderName())) {
237238
logger.debug("allVolumesOnOntapManagedStorage: Volume [{}] is on managed pool [{}] with provider [{}], not ONTAP",
238239
volume.getId(), pool.getName(), pool.getStorageProviderName());
239240
return false;

plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/provider/OntapPrimaryDatastoreProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
package org.apache.cloudstack.storage.provider;
2020

2121
import com.cloud.utils.component.ComponentContext;
22+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
2223
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
2324
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
2425
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType;
2526
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
2627
import org.apache.cloudstack.storage.driver.OntapPrimaryDatastoreDriver;
2728
import org.apache.cloudstack.storage.lifecycle.OntapPrimaryDatastoreLifecycle;
2829
import org.apache.cloudstack.storage.listener.OntapHostListener;
29-
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
3030
import org.junit.jupiter.api.BeforeEach;
3131
import org.junit.jupiter.api.Test;
3232
import org.junit.jupiter.api.extension.ExtendWith;
@@ -60,7 +60,7 @@ void setUp() {
6060
@Test
6161
public void testGetName() {
6262
String name = provider.getName();
63-
assertEquals(OntapStorageConstants.ONTAP_PLUGIN_NAME, name);
63+
assertEquals(DataStoreProvider.ONTAP_PLUGIN_NAME, name);
6464
}
6565

6666
@Test

0 commit comments

Comments
 (0)