Skip to content

Commit 9107b0c

Browse files
Locharla, SandeepLocharla, Sandeep
authored andcommitted
CSTACKEX-25: additional logic for Primary storage pool creation
1 parent 11693f3 commit 9107b0c

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.cloud.storage.Storage;
3030
import com.cloud.storage.StorageManager;
3131
import com.cloud.storage.StoragePool;
32+
import com.cloud.utils.exception.CloudRuntimeException;
3233
import com.google.common.base.Preconditions;
3334
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
3435
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@@ -89,33 +90,27 @@ public DataStore initialize(Map<String, Object> dsInfos) {
8990
if (zoneId != null) {
9091
s_logger.info("Both Pod Id and Cluster Id are null, Primary storage pool will be associated with a Zone");
9192
} else {
92-
s_logger.error("Pod Id, Cluster Id and Zone Id are all null, cannot create primary storage");
93-
return null;
93+
throw new CloudRuntimeException("Pod Id, Cluster Id and Zone Id are all null, cannot create primary storage");
9494
}
9595
}
9696

9797
PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
9898
if (clusterId != null) {
9999
ClusterVO clusterVO = _clusterDao.findById(clusterId);
100100
Preconditions.checkNotNull(clusterVO, "Unable to locate the specified cluster");
101+
if (clusterVO.getHypervisorType() != Hypervisor.HypervisorType.KVM) {
102+
throw new CloudRuntimeException("ONTAP primary storage is not supported for KVM hypervisor");
103+
}
101104
parameters.setHypervisorType(clusterVO.getHypervisorType());
102105
}
103-
else {
104-
parameters.setHypervisorType(Hypervisor.HypervisorType.Any); //TODO: Make sure the hypervisor is KVM, if not throw exception
105-
}
106-
107106
// Validate the ONTAP details
108107
StorageProviderManager storageProviderManager = new StorageProviderManager(details, scheme);
109108
boolean isValid = storageProviderManager.connect(details);
110-
//TODO: Use the return value to decide if we should proceed with pool creation
111-
112109
if (isValid) {
113110
// String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
114111
storageProviderManager.createVolume(storagePoolName, Integer.parseInt((details.get("size")))); // TODO: size should be in bytes, so see if conversion is needed
115-
// TODO: The volume name should be stored against the StoragePool name/id in the DB
116112
} else {
117-
s_logger.error("ONTAP details validation failed, cannot create primary storage");
118-
return null; // TODO: Figure out a better exception handling mechanism
113+
throw new CloudRuntimeException("ONTAP details validation failed, cannot create primary storage");
119114
}
120115

121116
// TODO: While testing need to check what does this actually do and if the fields corresponding to each protocol should also be set
@@ -124,8 +119,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
124119
} else if (scheme.equalsIgnoreCase("iscsi")) {
125120
parameters.setType(Storage.StoragePoolType.Iscsi);
126121
} else {
127-
s_logger.error("Unsupported protocol: " + scheme + ", cannot create primary storage");
128-
return null; // TODO: Figure out a better exception handling mechanism
122+
throw new CloudRuntimeException("Unsupported protocol: " + scheme + ", cannot create primary storage");
129123
}
130124

131125
parameters.setTags(tags);

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.cloudstack.storage.provider;
2121

2222
import com.cloud.storage.Storage;
23+
import com.cloud.utils.exception.CloudRuntimeException;
2324
import org.apache.cloudstack.storage.feign.client.VolumeFeignClient;
2425
import org.apache.cloudstack.storage.feign.model.Svm;
2526
import org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO;
@@ -59,24 +60,22 @@ public StorageProviderManager(Map<String, String> details, String protocol) {
5960
this.aggrName = details.get("aggrName");
6061
this.username = details.get("username");
6162
this.password = details.get("password");
62-
if (protocol.equalsIgnoreCase(Storage.StoragePoolType.NetworkFilesystem.name())) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
63+
if (protocol.equalsIgnoreCase(Storage.StoragePoolType.NetworkFilesystem.name())) {
6364
this.nasStrategy = new UnifiedNASStrategy(details);
6465
this.sanStrategy = null;
65-
} else if (protocol.equalsIgnoreCase(Storage.StoragePoolType.Iscsi.name())) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
66+
} else if (protocol.equalsIgnoreCase(Storage.StoragePoolType.Iscsi.name())) {
6667
this.sanStrategy = new UnifiedSANStrategy(details);
6768
this.nasStrategy = null;
6869
} else {
69-
//TODO: Figure out the appropriate exception handling mechanism
7070
this.nasStrategy = null;
7171
this.sanStrategy = null;
72-
s_logger.error("Unsupported protocol: " + protocol);
73-
return;
72+
throw new CloudRuntimeException("Unsupported protocol: " + protocol);
7473
}
7574
}
7675

7776
// Connect method to validate ONTAP cluster, credentials, protocol, and SVM
7877
public boolean connect(Map<String, String> details) {
79-
// 1. Check if ONTAP cluster is reachable
78+
// 1. Check if ONTAP cluster is reachable ==> Use GET cluster API
8079
// 2. Validate credentials
8180
// 3. Check protocol support
8281
// 4. Check if SVM with given name exists
@@ -91,7 +90,6 @@ public void createVolume(String volumeName, int size) {
9190
// TODO: Call the ontap feign client for creating volume here
9291
// Get the AuthHeader
9392
String authHeader = utils.generateAuthHeader(username, password);
94-
// Call Create Volume API
9593

9694
// Generate the Create Volume Request
9795
VolumeRequestDTO volumeRequest = new VolumeRequestDTO();
@@ -102,11 +100,17 @@ public void createVolume(String volumeName, int size) {
102100

103101
volumeRequest.setName(volumeName);
104102
volumeRequest.setSvm(svm);
105-
volumeRequest.setAggregates((List<VolumeRequestDTO.AggregateDTO>) aggr); //TODO: Should we accept comma separated list of aggregates in the UI?
103+
volumeRequest.setAggregates((List<VolumeRequestDTO.AggregateDTO>) aggr);
106104
volumeRequest.setSize(size);
107105
// Make the POST API call to create the volume
108-
JobResponseDTO response = volumeFeignClient.createVolumeWithJob(authHeader, volumeRequest);
109-
106+
try {
107+
JobResponseDTO response = volumeFeignClient.createVolumeWithJob(authHeader, volumeRequest);
108+
//TODO: Add code to poll the job status until it is completed/ a timeout of 3 mins
110109

110+
} catch (Exception e) {
111+
s_logger.error("Exception while creating volume: ", e);
112+
throw new CloudRuntimeException("Failed to create volume: " + e.getMessage());
113+
}
114+
s_logger.info("Volume created successfully: " + volumeName);
111115
}
112116
}

0 commit comments

Comments
 (0)