Skip to content

Commit 5f71168

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
NFS Cloudstack volume and export policy utils
1 parent 1b0c7f7 commit 5f71168

File tree

17 files changed

+430
-69
lines changed

17 files changed

+430
-69
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
129129
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
130130
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);
131131
s_logger.info("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest", details.get(Constants.SVM_NAME));
132-
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, dataObject);
132+
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject);
133133
CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest);
134134
if (ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL)) && cloudStackVolume.getLun() != null && cloudStackVolume.getLun().getName() != null) {
135135
return cloudStackVolume.getLun().getName();
136+
} else if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
137+
return cloudStackVolume.getFile().getName();
136138
} else {
137139
String errMsg = "createCloudStackVolumeForTypeVolume: Volume creation failed. Lun or Lun Path is null for dataObject: " + dataObject;
138140
s_logger.error(errMsg);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/NASFeignClient.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@
2626
import feign.Param;
2727
import feign.RequestLine;
2828

29-
//TODO: Proper URLs should be added in the RequestLine annotations below
3029
public interface NASFeignClient {
3130

3231
// File Operations
3332
@RequestLine("GET /{volumeUuid}/files/{path}")
3433
@Headers({"Authorization: {authHeader}"})
3534
OntapResponse<FileInfo> getFileResponse(@Param("authHeader") String authHeader,
36-
@Param("volumeUuid") String volumeUUID,
37-
@Param("path") String filePath);
35+
@Param("volumeUuid") String volumeUUID,
36+
@Param("path") String filePath);
3837

3938
@RequestLine("DELETE /{volumeUuid}/files/{path}")
4039
@Headers({"Authorization: {authHeader}"})
4140
void deleteFile(@Param("authHeader") String authHeader,
42-
@Param("volumeUuid") String volumeUUID,
43-
@Param("path") String filePath);
41+
@Param("volumeUuid") String volumeUUID,
42+
@Param("path") String filePath);
4443

4544
@RequestLine("PATCH /{volumeUuid}/files/{path}")
4645
@Headers({"Authorization: {authHeader}"})
4746
void updateFile(@Param("authHeader") String authHeader,
48-
@Param("volumeUuid") String volumeUUID,
49-
@Param("path") String filePath, FileInfo fileInfo);
47+
@Param("volumeUuid") String volumeUUID,
48+
@Param("path") String filePath,
49+
FileInfo fileInfo);
5050

5151
@RequestLine("POST /{volumeUuid}/files/{path}")
5252
@Headers({"Authorization: {authHeader}"})
5353
void createFile(@Param("authHeader") String authHeader,
54-
@Param("volumeUuid") String volumeUUID,
55-
@Param("path") String filePath, FileInfo file);
54+
@Param("volumeUuid") String volumeUUID,
55+
@Param("path") String filePath,
56+
FileInfo file);
5657

5758
// Export Policy Operations
5859
@RequestLine("POST /")
59-
@Headers({"Authorization: {authHeader}", "return_records: {returnRecords}"})
60+
@Headers({"Authorization: {authHeader}"})
6061
ExportPolicy createExportPolicy(@Param("authHeader") String authHeader,
61-
@Param("returnRecords") boolean returnRecords,
6262
ExportPolicy exportPolicy);
6363

6464
@RequestLine("GET /")
@@ -68,16 +68,16 @@ ExportPolicy createExportPolicy(@Param("authHeader") String authHeader,
6868
@RequestLine("GET /{id}")
6969
@Headers({"Authorization: {authHeader}"})
7070
OntapResponse<ExportPolicy> getExportPolicyById(@Param("authHeader") String authHeader,
71-
@Param("id") String id);
71+
@Param("id") String id);
7272

7373
@RequestLine("DELETE /{id}")
7474
@Headers({"Authorization: {authHeader}"})
7575
void deleteExportPolicyById(@Param("authHeader") String authHeader,
76-
@Param("id") String id);
76+
@Param("id") String id);
7777

7878
@RequestLine("PATCH /{id}")
7979
@Headers({"Authorization: {authHeader}"})
8080
OntapResponse<ExportPolicy> updateExportPolicy(@Param("authHeader") String authHeader,
81-
@Param("id") String id,
82-
ExportPolicy request);
81+
@Param("id") String id,
82+
ExportPolicy request);
8383
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/VolumeFeignClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
*/
1919
package org.apache.cloudstack.storage.feign.client;
2020

21+
import feign.QueryMap;
2122
import org.apache.cloudstack.storage.feign.model.Volume;
2223
import org.apache.cloudstack.storage.feign.model.response.JobResponse;
2324
import feign.Headers;
2425
import feign.Param;
2526
import feign.RequestLine;
27+
import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
28+
29+
import java.util.Map;
2630

2731
public interface VolumeFeignClient {
2832

@@ -38,8 +42,12 @@ public interface VolumeFeignClient {
3842
@Headers({"Authorization: {authHeader}"})
3943
Volume getVolumeByUUID(@Param("authHeader") String authHeader, @Param("uuid") String uuid);
4044

45+
@RequestLine("GET /api/storage/volumes")
46+
@Headers({"Authorization: {authHeader}"})
47+
OntapResponse<Volume> getVolume(@Param("authHeader") String authHeader, @QueryMap Map<String, Object> queryMap);
48+
4149
@RequestLine("PATCH /api/storage/volumes/{uuid}")
42-
@Headers({"Accept: {acceptHeader}", "Authorization: {authHeader}"})
43-
JobResponse updateVolumeRebalancing(@Param("acceptHeader") String acceptHeader, @Param("uuid") String uuid, Volume volumeRequest);
50+
@Headers({ "Authorization: {authHeader}"})
51+
JobResponse updateVolumeRebalancing(@Param("authHeader") String authHeader, @Param("uuid") String uuid, Volume volumeRequest);
4452
}
4553

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

100644100755
File mode changed.

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

100644100755
File mode changed.

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

100644100755
File mode changed.

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
4141
import org.apache.cloudstack.storage.datastore.lifecycle.BasePrimaryDataStoreLifeCycleImpl;
4242
import org.apache.cloudstack.storage.feign.model.OntapStorage;
43+
import org.apache.cloudstack.storage.feign.model.Volume;
4344
import org.apache.cloudstack.storage.provider.StorageProviderFactory;
4445
import org.apache.cloudstack.storage.service.StorageStrategy;
46+
import org.apache.cloudstack.storage.service.model.AccessGroup;
4547
import org.apache.cloudstack.storage.service.model.ProtocolType;
4648
import org.apache.cloudstack.storage.utils.Constants;
49+
import org.apache.cloudstack.storage.utils.Utility;
4750
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
4851
import org.apache.logging.log4j.LogManager;
4952
import org.apache.logging.log4j.Logger;
@@ -184,7 +187,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
184187
String path;
185188
ProtocolType protocol = ProtocolType.valueOf(details.get(Constants.PROTOCOL));
186189
switch (protocol) {
187-
case NFS3:
190+
case NFS:
188191
parameters.setType(Storage.StoragePoolType.NetworkFilesystem);
189192
path = details.get(Constants.MANAGEMENT_LIF) + ":/" + storagePoolName;
190193
s_logger.info("Setting NFS path for storage pool: " + path);
@@ -213,7 +216,9 @@ public DataStore initialize(Map<String, Object> dsInfos) {
213216
long volumeSize = Long.parseLong(details.get(Constants.SIZE));
214217
s_logger.info("Creating ONTAP volume '" + storagePoolName + "' with size: " + volumeSize + " bytes (" +
215218
(volumeSize / (1024 * 1024 * 1024)) + " GB)");
216-
storageStrategy.createStorageVolume(storagePoolName, volumeSize);
219+
Volume volume = storageStrategy.createStorageVolume(storagePoolName, volumeSize);
220+
details.put(Constants.VOLUME_UUID, volume.getUuid());
221+
details.put(Constants.VOLUME_NAME, volume.getName());
217222
} else {
218223
throw new CloudRuntimeException("ONTAP details validation failed, cannot create primary storage");
219224
}
@@ -241,10 +246,20 @@ public DataStore initialize(Map<String, Object> dsInfos) {
241246
@Override
242247
public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
243248
logger.debug("In attachCluster for ONTAP primary storage");
244-
PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo)dataStore;
245-
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInClusterForStorageConnection(primarystore);
249+
PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)dataStore;
250+
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInClusterForStorageConnection(primaryStore);
246251

247-
logger.debug(String.format("Attaching the pool to each of the hosts %s in the cluster: %s", hostsToConnect, primarystore.getClusterId()));
252+
logger.debug(String.format("Attaching the pool to each of the hosts %s in the cluster: %s", hostsToConnect, primaryStore.getClusterId()));
253+
254+
Map<String, String> details = primaryStore.getDetails(); // TODO check while testing , if it is populated we can remove below db call
255+
StorageStrategy strategy = Utility.getStrategyByStoragePoolDetails(details);
256+
AccessGroup accessGroupRequest = new AccessGroup();
257+
accessGroupRequest.setHostsToConnect(hostsToConnect);
258+
accessGroupRequest.setScope(scope);
259+
accessGroupRequest.setPrimaryDataStoreInfo(primaryStore);
260+
strategy.createAccessGroup(accessGroupRequest);
261+
262+
logger.debug("attachCluster: Attaching the pool to each of the host in the cluster: {}", primaryStore.getClusterId());
248263
for (HostVO host : hostsToConnect) {
249264
// TODO: Fetch the host IQN and add to the initiator group on ONTAP cluster
250265
try {
@@ -265,9 +280,18 @@ public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo exis
265280
@Override
266281
public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.HypervisorType hypervisorType) {
267282
logger.debug("In attachZone for ONTAP primary storage");
268-
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInZoneForStorageConnection(dataStore, scope.getScopeId(), Hypervisor.HypervisorType.KVM);
269283

284+
PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)dataStore;
285+
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInZoneForStorageConnection(dataStore, scope.getScopeId(), Hypervisor.HypervisorType.KVM);
270286
logger.debug(String.format("In createPool. Attaching the pool to each of the hosts in %s.", hostsToConnect));
287+
288+
Map<String, String> details = primaryStore.getDetails(); // TODO check while testing , if it is populated we can remove below db call
289+
StorageStrategy strategy = Utility.getStrategyByStoragePoolDetails(details);
290+
AccessGroup accessGroupRequest = new AccessGroup();
291+
accessGroupRequest.setHostsToConnect(hostsToConnect);
292+
accessGroupRequest.setScope(scope);
293+
accessGroupRequest.setPrimaryDataStoreInfo(primaryStore);
294+
strategy.createAccessGroup(accessGroupRequest);
271295
for (HostVO host : hostsToConnect) {
272296
// TODO: Fetch the host IQN and add to the initiator group on ONTAP cluster
273297
try {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.apache.cloudstack.storage.provider;
2+
3+
import com.cloud.exception.StorageConflictException;
4+
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
5+
6+
class OntapHostListener implements HypervisorHostListener {
7+
8+
@Override
9+
public boolean hostAdded(long hostId) {
10+
return false;
11+
}
12+
13+
@Override
14+
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
15+
return false;
16+
}
17+
18+
@Override
19+
public boolean hostDisconnected(long hostId, long poolId) {
20+
return false;
21+
}
22+
23+
@Override
24+
public boolean hostAboutToBeRemoved(long hostId) {
25+
return false;
26+
}
27+
28+
@Override
29+
public boolean hostRemoved(long hostId, long clusterId) {
30+
return false;
31+
}
32+
33+
@Override
34+
public boolean hostEnabled(long hostId) {
35+
return false;
36+
}
37+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class OntapPrimaryDatastoreProvider implements PrimaryDataStoreProvider {
4141
private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreProvider.class);
4242
private OntapPrimaryDatastoreDriver primaryDatastoreDriver;
4343
private OntapPrimaryDatastoreLifecycle primaryDatastoreLifecycle;
44+
private OntapHostListener ontapHostListener;
4445

4546
public OntapPrimaryDatastoreProvider() {
4647
s_logger.info("OntapPrimaryDatastoreProvider initialized");
@@ -57,7 +58,7 @@ public DataStoreDriver getDataStoreDriver() {
5758

5859
@Override
5960
public HypervisorHostListener getHostListener() {
60-
return null;
61+
return ontapHostListener;
6162
}
6263

6364
@Override
@@ -71,6 +72,8 @@ public boolean configure(Map<String, Object> params) {
7172
s_logger.trace("OntapPrimaryDatastoreProvider: configure: Called");
7273
primaryDatastoreDriver = ComponentContext.inject(OntapPrimaryDatastoreDriver.class);
7374
primaryDatastoreLifecycle = ComponentContext.inject(OntapPrimaryDatastoreLifecycle.class);
75+
ontapHostListener = ComponentContext.inject(OntapHostListener.class);
76+
7477
return true;
7578
}
7679

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static StorageStrategy getStrategy(OntapStorage ontapStorage) {
3636
ProtocolType protocol = ontapStorage.getProtocol();
3737
s_logger.info("Initializing StorageProviderFactory with protocol: " + protocol);
3838
switch (protocol) {
39-
case NFS3:
39+
case NFS:
4040
if (!ontapStorage.getIsDisaggregated()) {
4141
UnifiedNASStrategy unifiedNASStrategy = new UnifiedNASStrategy(ontapStorage);
4242
unifiedNASStrategy.setOntapStorage(ontapStorage);

0 commit comments

Comments
 (0)