Skip to content

Commit c968ccc

Browse files
Gupta, SuryaGupta, Surya
authored andcommitted
CSTACKEX-35 Added Null and empty check
1 parent 0cf8d60 commit c968ccc

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
4242
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
4343
import org.apache.cloudstack.storage.command.CommandResult;
44+
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4445
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
46+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
4547
import org.apache.cloudstack.storage.feign.model.OntapStorage;
4648
import org.apache.cloudstack.storage.provider.StorageProviderFactory;
4749
import org.apache.cloudstack.storage.service.StorageStrategy;
@@ -62,6 +64,7 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
6264

6365
@Inject private Utility utils;
6466
@Inject private StoragePoolDetailsDao storagePoolDetailsDao;
67+
@Inject private PrimaryDataStoreDao storagePoolDao;
6568
@Override
6669
public Map<String, String> getCapabilities() {
6770
s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called");
@@ -119,7 +122,14 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
119122
}
120123

121124
private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObject dataObject) {
125+
StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId());
126+
if(storagePool == null) {
127+
throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId());
128+
}
122129
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
130+
if(details == null || details.isEmpty()) {
131+
throw new CloudRuntimeException("createCloudStackVolume : Storage Details not found for id: " + dataStore.getId());
132+
}
123133
String protocol = details.get(Constants.PROTOCOL);
124134
OntapStorage ontapStorage = new OntapStorage(details.get(Constants.USERNAME), details.get(Constants.PASSWORD),
125135
details.get(Constants.MANAGEMENT_LIF), details.get(Constants.SVM_NAME), ProtocolType.valueOf(protocol),
@@ -128,7 +138,7 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
128138
boolean isValid = storageStrategy.connect();
129139
if (isValid) {
130140
s_logger.info("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest", details.get(Constants.SVM_NAME));
131-
CloudStackVolume cloudStackVolumeRequest = utils.createCloudStackVolumeRequestByProtocol(dataStore.getId(), details, dataObject);
141+
CloudStackVolume cloudStackVolumeRequest = utils.createCloudStackVolumeRequestByProtocol(storagePool, details, dataObject);
132142
CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest);
133143
if (ProtocolType.ISCSI.name().equalsIgnoreCase(protocol) && cloudStackVolume.getLun() != null && cloudStackVolume.getLun().getName() != null) {
134144
return cloudStackVolume.getLun().getName();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import com.cloud.utils.exception.CloudRuntimeException;
2323
import org.apache.cloudstack.storage.feign.client.SANFeignClient;
2424
import org.apache.cloudstack.storage.feign.model.Lun;
25-
import org.apache.cloudstack.storage.feign.model.LunSpace;
2625
import org.apache.cloudstack.storage.feign.model.OntapStorage;
27-
import org.apache.cloudstack.storage.feign.model.Svm;
2826
import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
2927
import org.apache.cloudstack.storage.service.model.AccessGroup;
3028
import org.apache.cloudstack.storage.service.model.CloudStackVolume;

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
2626
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
2727
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
28-
import org.apache.cloudstack.storage.driver.OntapPrimaryDatastoreDriver;
2928
import org.apache.cloudstack.storage.feign.model.Lun;
3029
import org.apache.cloudstack.storage.feign.model.LunSpace;
3130
import org.apache.cloudstack.storage.feign.model.OntapStorage;
3231
import org.apache.cloudstack.storage.feign.model.Svm;
33-
import org.apache.cloudstack.storage.provider.StorageProviderFactory;
34-
import org.apache.cloudstack.storage.service.StorageStrategy;
3532
import org.apache.cloudstack.storage.service.model.CloudStackVolume;
3633
import org.apache.cloudstack.storage.service.model.ProtocolType;
3734
import org.apache.logging.log4j.LogManager;
@@ -71,11 +68,7 @@ public URI generateURI (String path) {
7168
return URI.create(uriString);
7269
}
7370

74-
public CloudStackVolume createCloudStackVolumeRequestByProtocol(Long storagePoolId, Map<String, String> details, DataObject dataObject) {
75-
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
76-
if(storagePool == null) {
77-
throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + storagePoolId);
78-
}
71+
public CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePoolVO storagePool, Map<String, String> details, DataObject dataObject) {
7972
CloudStackVolume cloudStackVolumeRequest = null;
8073

8174
String protocol = details.get(Constants.PROTOCOL);

0 commit comments

Comments
 (0)