Skip to content

Commit ce0dfda

Browse files
Gupta, SuryaGupta, Surya
authored andcommitted
CSTACKEX-37 FeignConfiguration
1 parent 538379d commit ce0dfda

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

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

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,30 @@ public DataStore initialize(Map<String, Object> dsInfos) {
7070
if (dsInfos == null) {
7171
throw new CloudRuntimeException("Datastore info map is null, cannot create primary storage");
7272
}
73-
String url = dsInfos.get("url").toString(); // TODO: Decide on whether should the customer enter just the Management LIF IP or https://ManagementLIF
74-
Long zoneId = dsInfos.get("zoneId").toString().trim().isEmpty() ? null : (Long)dsInfos.get("zoneId");
75-
Long podId = dsInfos.get("podId").toString().trim().isEmpty() ? null : (Long)dsInfos.get("zoneId");
76-
Long clusterId = dsInfos.get("clusterId").toString().trim().isEmpty() ? null : (Long)dsInfos.get("clusterId");
77-
String storagePoolName = dsInfos.get("name").toString().trim();
78-
String providerName = dsInfos.get("providerName").toString().trim();
79-
String tags = dsInfos.get("tags").toString().trim();
73+
String url = (String)dsInfos.get("url");
74+
Long zoneId = (Long)dsInfos.get("zoneId");
75+
Long podId = (Long)dsInfos.get("podId");
76+
Long clusterId = (Long)dsInfos.get("clusterId");
77+
String storagePoolName = (String)dsInfos.get("name");
78+
String providerName = (String)dsInfos.get("providerName");
79+
Long capacityBytes = (Long)dsInfos.get("capacityBytes");
80+
String tags = (String)dsInfos.get("tags");
8081
Boolean isTagARule = (Boolean) dsInfos.get("isTagARule");
81-
String scheme = dsInfos.get("scheme").toString();
82+
// String scheme = dsInfos.get("scheme").toString();
8283

84+
// s_logger.info("Creating ONTAP primary storage pool with name: " + storagePoolName + ", provider: " + providerName +
85+
// ", zoneId: " + zoneId + ", podId: " + podId + ", clusterId: " + clusterId + ", protocol: " + scheme);
8386
s_logger.info("Creating ONTAP primary storage pool with name: " + storagePoolName + ", provider: " + providerName +
84-
", zoneId: " + zoneId + ", podId: " + podId + ", clusterId: " + clusterId + ", protocol: " + scheme);
87+
", zoneId: " + zoneId + ", podId: " + podId + ", clusterId: " + clusterId);
8588

8689
// Additional details requested for ONTAP primary storage pool creation
8790
@SuppressWarnings("unchecked")
8891
Map<String, String> details = (Map<String, String>)dsInfos.get("details");
8992
// Validations
93+
if (capacityBytes == null || capacityBytes <= 0) {
94+
throw new IllegalArgumentException("'capacityBytes' must be present and greater than 0.");
95+
}
96+
9097
if (podId == null ^ clusterId == null) {
9198
throw new CloudRuntimeException("Cluster Id or Pod Id is null, cannot create primary storage");
9299
}
@@ -117,21 +124,51 @@ public DataStore initialize(Map<String, Object> dsInfos) {
117124
parameters.setHypervisorType(clusterVO.getHypervisorType());
118125
}
119126

127+
// Get ONTAP details from the URL
128+
Map<String, String> storageDetails = Map.of(
129+
Constants.USERNAME, "",
130+
Constants.PASSWORD, "",
131+
Constants.SVM_NAME, "",
132+
Constants.PROTOCOL, "",
133+
Constants.MANAGEMENT_LIF, "",
134+
Constants.SIZE, "",
135+
Constants.IS_DISAGGREGATED, ""
136+
);
137+
138+
String[] urlDetails = url.split(";");
139+
for(int m =0; m < urlDetails.length; m++) {
140+
String[] kvs = urlDetails[m].split("=");
141+
if(kvs.length == 2) {
142+
details.put(kvs[0], kvs[1]);
143+
}
144+
}
145+
146+
//managementLIF=;username=;password=;svmName=;protocol=;size=;isDisaggregated=;
147+
148+
for (String key : storageDetails.keySet()) {
149+
if (!details.containsKey(key) || details.get(key).isEmpty()) {
150+
throw new CloudRuntimeException("ONTAP primary storage creation failed, missing detail: " + key);
151+
}
152+
}
153+
154+
120155
// TODO: While testing need to check what does this actually do and if the fields corresponding to each protocol should also be set
121156
// TODO: scheme could be 'custom' in our case and we might have to ask 'protocol' separately to the user
122-
ProtocolType protocol = ProtocolType.valueOf(details.get(Constants.PROTOCOL).toLowerCase());
157+
String path = "";
158+
ProtocolType protocol = ProtocolType.valueOf(details.get(Constants.PROTOCOL));
123159
switch (protocol) {
124160
case NFS:
125161
parameters.setType(Storage.StoragePoolType.NetworkFilesystem);
162+
path = "/"+ storagePoolName;
126163
break;
127164
case ISCSI:
128165
parameters.setType(Storage.StoragePoolType.Iscsi);
129166
break;
130167
default:
131-
throw new CloudRuntimeException("Unsupported protocol: " + scheme + ", cannot create primary storage");
168+
throw new CloudRuntimeException("Unsupported protocol: " + protocol + ", cannot create primary storage");
132169
}
133170

134-
details.put(Constants.MANAGEMENT_LIF, url);
171+
// details.put(Constants.MANAGEMENT_LIF, url);
135172

136173
// Validate the ONTAP details
137174
if(details.get(Constants.IS_DISAGGREGATED) == null || details.get(Constants.IS_DISAGGREGATED).isEmpty()) {
@@ -140,16 +177,19 @@ public DataStore initialize(Map<String, Object> dsInfos) {
140177

141178
OntapStorage ontapStorage = new OntapStorage(details.get(Constants.USERNAME), details.get(Constants.PASSWORD),
142179
details.get(Constants.MANAGEMENT_LIF), details.get(Constants.SVM_NAME), protocol,
143-
Boolean.parseBoolean(details.get(Constants.IS_DISAGGREGATED)));
180+
Boolean.parseBoolean(details.get(Constants.IS_DISAGGREGATED).toLowerCase()));
144181
StorageStrategy storageStrategy = StorageProviderFactory.getStrategy(ontapStorage);
145182
boolean isValid = storageStrategy.connect();
146183
if (isValid) {
147184
// String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
148-
storageStrategy.createStorageVolume(storagePoolName, Long.parseLong((details.get("size")))); // TODO: size should be in bytes, so see if conversion is needed
185+
storageStrategy.createStorageVolume(storagePoolName, Long.parseLong((details.get(Constants.SIZE)))); // TODO: size should be in bytes, so see if conversion is needed
149186
} else {
150187
throw new CloudRuntimeException("ONTAP details validation failed, cannot create primary storage");
151188
}
152189

190+
parameters.setHost(details.get(Constants.MANAGEMENT_LIF));
191+
parameters.setPort(443);
192+
parameters.setPath(path);
153193
parameters.setTags(tags);
154194
parameters.setIsTagARule(isTagARule);
155195
parameters.setDetails(details);
@@ -160,6 +200,8 @@ public DataStore initialize(Map<String, Object> dsInfos) {
160200
parameters.setName(storagePoolName);
161201
parameters.setProviderName(providerName);
162202
parameters.setManaged(true);
203+
parameters.setCapacityBytes(capacityBytes);
204+
parameters.setUsedBytes(0);
163205

164206
return _dataStoreHelper.createPrimaryDataStore(parameters);
165207
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public boolean connect() {
8686
// Call the SVM API to check if the SVM exists
8787
Svm svm = new Svm();
8888
URI url = URI.create(Constants.HTTPS + storage.getManagementLIF() + Constants.GET_SVMs + "?name=" + svmName);
89+
s_logger.info("Fetching SVM details from URL: " + url.toString());
90+
s_logger.info("svmFeignClient value {}", svmFeignClient);
8991
OntapResponse<Svm> svms = svmFeignClient.getSvmResponse(url, authHeader);
9092
if (svms != null && svms.getRecords() != null && !svms.getRecords().isEmpty()) {
9193
svm = svms.getRecords().get(0);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ public class Constants {
5151
public static final String CREATE_VOLUME = "/api/storage/volumes";
5252
public static final String GET_JOB_BY_UUID = "/api/cluster/jobs";
5353
public static final String CREATE_LUN = "/api/storage/luns";
54+
public static final String SIZE = "size";
5455

5556
}

0 commit comments

Comments
 (0)