Skip to content

Commit 8f3794a

Browse files
Locharla, SandeepLocharla, Sandeep
authored andcommitted
Addressing review comments
1 parent 7603ce0 commit 8f3794a

File tree

8 files changed

+495
-185
lines changed

8 files changed

+495
-185
lines changed

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

Lines changed: 113 additions & 106 deletions
Large diffs are not rendered by default.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.cloudstack.storage.provider;
21+
22+
23+
import com.cloud.utils.component.ComponentContext;
24+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
25+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
26+
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
27+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
28+
import org.apache.cloudstack.storage.driver.OntapPrimaryDatastoreDriver;
29+
import org.apache.cloudstack.storage.lifecycle.OntapPrimaryDatastoreLifecycle;
30+
import org.apache.cloudstack.storage.listener.OntapHostListener;
31+
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
32+
import org.apache.logging.log4j.LogManager;
33+
import org.apache.logging.log4j.Logger;
34+
import org.springframework.stereotype.Component;
35+
36+
import java.util.HashSet;
37+
import java.util.Map;
38+
import java.util.Set;
39+
40+
@Component
41+
public class OntapPrimaryDatastoreProvider implements PrimaryDataStoreProvider {
42+
43+
private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreProvider.class);
44+
private OntapPrimaryDatastoreDriver primaryDatastoreDriver;
45+
private OntapPrimaryDatastoreLifecycle primaryDatastoreLifecycle;
46+
private HypervisorHostListener listener;
47+
48+
public OntapPrimaryDatastoreProvider() {
49+
s_logger.info("OntapPrimaryDatastoreProvider initialized");
50+
}
51+
@Override
52+
public DataStoreLifeCycle getDataStoreLifeCycle() {
53+
return primaryDatastoreLifecycle;
54+
}
55+
56+
@Override
57+
public DataStoreDriver getDataStoreDriver() {
58+
return primaryDatastoreDriver;
59+
}
60+
61+
@Override
62+
public HypervisorHostListener getHostListener() {
63+
return listener;
64+
}
65+
66+
@Override
67+
public String getName() {
68+
s_logger.trace("OntapPrimaryDatastoreProvider: getName: Called");
69+
return OntapStorageConstants.ONTAP_PLUGIN_NAME;
70+
}
71+
72+
@Override
73+
public boolean configure(Map<String, Object> params) {
74+
s_logger.trace("OntapPrimaryDatastoreProvider: configure: Called");
75+
primaryDatastoreDriver = ComponentContext.inject(OntapPrimaryDatastoreDriver.class);
76+
primaryDatastoreLifecycle = ComponentContext.inject(OntapPrimaryDatastoreLifecycle.class);
77+
listener = ComponentContext.inject(OntapHostListener.class);
78+
return true;
79+
}
80+
81+
@Override
82+
public Set<DataStoreProviderType> getTypes() {
83+
s_logger.trace("OntapPrimaryDatastoreProvider: getTypes: Called");
84+
Set<DataStoreProviderType> typeSet = new HashSet<DataStoreProviderType>();
85+
typeSet.add(DataStoreProviderType.PRIMARY);
86+
return typeSet;
87+
}
88+
}

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.cloudstack.storage.service;
20+
package org.apache.cloudstack.storage.service;
2121

2222
import com.cloud.utils.exception.CloudRuntimeException;
2323
import feign.FeignException;
@@ -41,8 +41,8 @@
4141
import org.apache.cloudstack.storage.service.model.AccessGroup;
4242
import org.apache.cloudstack.storage.service.model.CloudStackVolume;
4343
import org.apache.cloudstack.storage.service.model.ProtocolType;
44-
import org.apache.cloudstack.storage.utils.Constants;
45-
import org.apache.cloudstack.storage.utils.Utility;
44+
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
45+
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
4646
import org.apache.logging.log4j.LogManager;
4747
import org.apache.logging.log4j.Logger;
4848

@@ -68,7 +68,7 @@ public abstract class StorageStrategy {
6868

6969
public StorageStrategy(OntapStorage ontapStorage) {
7070
storage = ontapStorage;
71-
String baseURL = Constants.HTTPS + storage.getManagementLIF();
71+
String baseURL = OntapStorageConstants.HTTPS + storage.getManagementLIF();
7272
s_logger.info("Initializing StorageStrategy with base URL: " + baseURL);
7373
this.feignClientFactory = new FeignClientFactory();
7474
this.aggregateFeignClient = feignClientFactory.createClient(AggregateFeignClient.class, baseURL);
@@ -82,13 +82,13 @@ public StorageStrategy(OntapStorage ontapStorage) {
8282
public boolean connect() {
8383
s_logger.info("Attempting to connect to ONTAP cluster at " + storage.getManagementLIF() + " and validate SVM " +
8484
storage.getSvmName() + ", protocol " + storage.getProtocol());
85-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
85+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
8686
String svmName = storage.getSvmName();
8787
try {
8888
Svm svm = new Svm();
8989
s_logger.info("Fetching the SVM details...");
90-
Map<String, Object> queryParams = Map.of(Constants.NAME, svmName, Constants.FIELDS, Constants.AGGREGATES +
91-
Constants.COMMA + Constants.STATE);
90+
Map<String, Object> queryParams = Map.of(OntapStorageConstants.NAME, svmName, OntapStorageConstants.FIELDS, OntapStorageConstants.AGGREGATES +
91+
OntapStorageConstants.COMMA + OntapStorageConstants.STATE);
9292
OntapResponse<Svm> svms = svmFeignClient.getSvmResponse(queryParams, authHeader);
9393
if (svms != null && svms.getRecords() != null && !svms.getRecords().isEmpty()) {
9494
svm = svms.getRecords().get(0);
@@ -98,14 +98,14 @@ public boolean connect() {
9898
}
9999

100100
s_logger.info("Validating SVM state and protocol settings...");
101-
if (!Objects.equals(svm.getState(), Constants.RUNNING)) {
101+
if (!Objects.equals(svm.getState(), OntapStorageConstants.RUNNING)) {
102102
s_logger.error("SVM " + svmName + " is not in running state.");
103103
return false;
104104
}
105-
if (Objects.equals(storage.getProtocol(), Constants.NFS) && !svm.getNfsEnabled()) {
105+
if (Objects.equals(storage.getProtocol(), OntapStorageConstants.NFS) && !svm.getNfsEnabled()) {
106106
s_logger.error("NFS protocol is not enabled on SVM " + svmName);
107107
return false;
108-
} else if (Objects.equals(storage.getProtocol(), Constants.ISCSI) && !svm.getIscsiEnabled()) {
108+
} else if (Objects.equals(storage.getProtocol(), OntapStorageConstants.ISCSI) && !svm.getIscsiEnabled()) {
109109
s_logger.error("iSCSI protocol is not enabled on SVM " + svmName);
110110
return false;
111111
}
@@ -155,13 +155,13 @@ public Volume createStorageVolume(String volumeName, Long size) {
155155
throw new CloudRuntimeException("Invalid volume size provided: " + size);
156156
}
157157

158-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
158+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
159159

160160
Volume volumeRequest = new Volume();
161161
Svm svm = new Svm();
162162
svm.setName(svmName);
163163
Nas nas = new Nas();
164-
nas.setPath(Constants.SLASH + volumeName);
164+
nas.setPath(OntapStorageConstants.SLASH + volumeName);
165165

166166
volumeRequest.setName(volumeName);
167167
volumeRequest.setSvm(svm);
@@ -231,7 +231,7 @@ public Volume createStorageVolume(String volumeName, Long size) {
231231
s_logger.error("Exception while creating volume: ", e);
232232
throw new CloudRuntimeException("Failed to create volume: " + e.getMessage());
233233
}
234-
OntapResponse<Volume> volumesResponse = volumeFeignClient.getAllVolumes(authHeader, Map.of(Constants.NAME, volumeName));
234+
OntapResponse<Volume> volumesResponse = volumeFeignClient.getAllVolumes(authHeader, Map.of(OntapStorageConstants.NAME, volumeName));
235235
if (volumesResponse == null || volumesResponse.getRecords() == null || volumesResponse.getRecords().isEmpty()) {
236236
s_logger.error("Volume " + volumeName + " not found after creation.");
237237
throw new CloudRuntimeException("Volume " + volumeName + " not found after creation.");
@@ -246,7 +246,7 @@ public Volume createStorageVolume(String volumeName, Long size) {
246246
}
247247
s_logger.info("Volume created successfully: " + volumeName);
248248
try {
249-
Map<String, Object> queryParams = Map.of(Constants.NAME, volumeName);
249+
Map<String, Object> queryParams = Map.of(OntapStorageConstants.NAME, volumeName);
250250
s_logger.debug("Fetching volume details for: " + volumeName);
251251

252252
OntapResponse<Volume> ontapVolume = volumeFeignClient.getVolume(authHeader, queryParams);
@@ -284,7 +284,7 @@ public Volume updateStorageVolume(Volume volume) {
284284

285285
public void deleteStorageVolume(Volume volume) {
286286
s_logger.info("Deleting ONTAP volume by name: " + volume.getName() + " and uuid: " + volume.getUuid());
287-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
287+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
288288
try {
289289
JobResponse jobResponse = volumeFeignClient.deleteVolume(authHeader, volume.getUuid());
290290
Boolean jobSucceeded = jobPollForSuccess(jobResponse.getJob().getUuid());
@@ -305,14 +305,14 @@ public Volume getStorageVolume(Volume volume) {
305305
}
306306

307307
public String getStoragePath() {
308-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
308+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
309309
String targetIqn = null;
310310
try {
311311
if (storage.getProtocol() == ProtocolType.ISCSI) {
312312
s_logger.info("Fetching iSCSI target IQN for SVM: {}", storage.getSvmName());
313313

314314
Map<String, Object> queryParams = new HashMap<>();
315-
queryParams.put(Constants.SVM_DOT_NAME, storage.getSvmName());
315+
queryParams.put(OntapStorageConstants.SVM_DOT_NAME, storage.getSvmName());
316316
queryParams.put("fields", "enabled,target");
317317
queryParams.put("max_records", "1");
318318

@@ -345,25 +345,25 @@ public String getStoragePath() {
345345
}
346346

347347
public String getNetworkInterface() {
348-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
348+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
349349
try {
350350
Map<String, Object> queryParams = new HashMap<>();
351-
queryParams.put(Constants.SVM_DOT_NAME, storage.getSvmName());
351+
queryParams.put(OntapStorageConstants.SVM_DOT_NAME, storage.getSvmName());
352352
if (storage.getProtocol() != null) {
353353
switch (storage.getProtocol()) {
354354
case NFS3:
355-
queryParams.put(Constants.SERVICES, Constants.DATA_NFS);
355+
queryParams.put(OntapStorageConstants.SERVICES, OntapStorageConstants.DATA_NFS);
356356
break;
357357
case ISCSI:
358-
queryParams.put(Constants.SERVICES, Constants.DATA_ISCSI);
358+
queryParams.put(OntapStorageConstants.SERVICES, OntapStorageConstants.DATA_ISCSI);
359359
break;
360360
default:
361361
s_logger.error("Unsupported protocol: " + storage.getProtocol());
362362
throw new CloudRuntimeException("Unsupported protocol: " + storage.getProtocol());
363363
}
364364
}
365-
queryParams.put(Constants.FIELDS, Constants.IP_ADDRESS);
366-
queryParams.put(Constants.RETURN_RECORDS, Constants.TRUE);
365+
queryParams.put(OntapStorageConstants.FIELDS, OntapStorageConstants.IP_ADDRESS);
366+
queryParams.put(OntapStorageConstants.RETURN_RECORDS, OntapStorageConstants.TRUE);
367367
OntapResponse<IpInterface> response =
368368
networkFeignClient.getNetworkIpInterfaces(authHeader, queryParams);
369369
if (response != null && response.getRecords() != null && !response.getRecords().isEmpty()) {
@@ -419,9 +419,9 @@ private Boolean jobPollForSuccess(String jobUUID) {
419419
int jobRetryCount = 0;
420420
Job jobResp = null;
421421
try {
422-
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
423-
while (jobResp == null || !jobResp.getState().equals(Constants.JOB_SUCCESS)) {
424-
if (jobRetryCount >= Constants.JOB_MAX_RETRIES) {
422+
String authHeader = OntapStorageUtils.generateAuthHeader(storage.getUsername(), storage.getPassword());
423+
while (jobResp == null || !jobResp.getState().equals(OntapStorageConstants.JOB_SUCCESS)) {
424+
if (jobRetryCount >= OntapStorageConstants.JOB_MAX_RETRIES) {
425425
s_logger.error("Job did not complete within expected time.");
426426
throw new CloudRuntimeException("Job did not complete within expected time.");
427427
}
@@ -430,17 +430,17 @@ private Boolean jobPollForSuccess(String jobUUID) {
430430
jobResp = jobFeignClient.getJobByUUID(authHeader, jobUUID);
431431
if (jobResp == null) {
432432
s_logger.warn("Job with UUID " + jobUUID + " not found. Retrying...");
433-
} else if (jobResp.getState().equals(Constants.JOB_FAILURE)) {
433+
} else if (jobResp.getState().equals(OntapStorageConstants.JOB_FAILURE)) {
434434
throw new CloudRuntimeException("Job failed with error: " + jobResp.getMessage());
435435
}
436436
} catch (FeignException.FeignClientException e) {
437437
throw new CloudRuntimeException("Failed to fetch job status: " + e.getMessage());
438438
}
439439

440440
jobRetryCount++;
441-
Thread.sleep(Constants.CREATE_VOLUME_CHECK_SLEEP_TIME);
441+
Thread.sleep(OntapStorageConstants.CREATE_VOLUME_CHECK_SLEEP_TIME);
442442
}
443-
if (jobResp == null || !jobResp.getState().equals(Constants.JOB_SUCCESS)) {
443+
if (jobResp == null || !jobResp.getState().equals(OntapStorageConstants.JOB_SUCCESS)) {
444444
return false;
445445
}
446446
} catch (FeignException.FeignClientException e) {

0 commit comments

Comments
 (0)