Skip to content

Commit e3c44ae

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
accessgroup create recode
1 parent c88483a commit e3c44ae

File tree

8 files changed

+177
-78
lines changed

8 files changed

+177
-78
lines changed

plugins/storage/volume/ontap/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
<spring-cloud.version>2021.0.7</spring-cloud.version>
3232
<openfeign.version>11.0</openfeign.version>
3333
<json.version>20230227</json.version>
34-
<jackson-databind.version>2.15.2</jackson-databind.version>
3534
<httpclient.version>4.5.14</httpclient.version>
3635
<swagger-annotations.version>1.6.2</swagger-annotations.version>
3736
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
@@ -77,7 +76,7 @@
7776
<dependency>
7877
<groupId>com.fasterxml.jackson.core</groupId>
7978
<artifactId>jackson-databind</artifactId>
80-
<version>${jackson-databind.version}</version>
79+
<version>2.13.4</version>
8180
</dependency>
8281
<dependency>
8382
<groupId>org.apache.httpcomponents</groupId>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
179179

180180
@Override
181181
public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) {
182-
183182
}
184183

185184
@Override

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import feign.codec.EncodeException;
3131
import com.fasterxml.jackson.core.JsonProcessingException;
3232
import com.fasterxml.jackson.databind.DeserializationFeature;
33-
import com.fasterxml.jackson.databind.json.JsonMapper;
33+
import com.fasterxml.jackson.databind.ObjectMapper;
3434
import org.apache.http.conn.ConnectionKeepAliveStrategy;
3535
import org.apache.http.conn.ssl.NoopHostnameVerifier;
3636
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -55,13 +55,11 @@ public class FeignConfiguration {
5555
private final int retryMaxInterval = 5;
5656
private final String ontapFeignMaxConnection = "80";
5757
private final String ontapFeignMaxConnectionPerRoute = "20";
58-
private final JsonMapper jsonMapper;
58+
private final ObjectMapper jsonMapper;
5959

6060
public FeignConfiguration() {
61-
this.jsonMapper = JsonMapper.builder()
62-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
63-
.findAndAddModules()
64-
.build();
61+
this.jsonMapper = new ObjectMapper();
62+
this.jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
6563
}
6664

6765
public Client createClient() {
@@ -139,16 +137,43 @@ public Decoder createDecoder() {
139137
@Override
140138
public Object decode(Response response, Type type) throws IOException, DecodeException {
141139
if (response.body() == null) {
140+
logger.debug("Response body is null, returning null");
142141
return null;
143142
}
144143
String json = null;
145144
try (InputStream bodyStream = response.body().asInputStream()) {
146145
json = new String(bodyStream.readAllBytes(), StandardCharsets.UTF_8);
147146
logger.debug("Decoding JSON response: {}", json);
148-
return jsonMapper.readValue(json, jsonMapper.getTypeFactory().constructType(type));
147+
logger.debug("Target type: {}", type);
148+
logger.debug("About to call jsonMapper.readValue()...");
149+
150+
Object result = null;
151+
try {
152+
logger.debug("Calling jsonMapper.constructType()...");
153+
var javaType = jsonMapper.getTypeFactory().constructType(type);
154+
logger.debug("constructType() returned: {}", javaType);
155+
156+
logger.debug("Calling jsonMapper.readValue() with json and javaType...");
157+
result = jsonMapper.readValue(json, javaType);
158+
logger.debug("jsonMapper.readValue() completed successfully");
159+
} catch (Throwable ex) {
160+
logger.error("EXCEPTION in jsonMapper.readValue()! Type: {}, Message: {}", ex.getClass().getName(), ex.getMessage(), ex);
161+
throw ex;
162+
}
163+
164+
if (result == null) {
165+
logger.warn("Decoded result is null!");
166+
} else {
167+
logger.debug("Successfully decoded to object of type: {}", result.getClass().getName());
168+
}
169+
logger.debug("Returning result from decoder");
170+
return result;
149171
} catch (IOException e) {
150-
logger.error("Error decoding JSON response. Status: {}, Raw body: {}", response.status(), json, e);
172+
logger.error("IOException during decoding. Status: {}, Raw body: {}", response.status(), json, e);
151173
throw new DecodeException(response.status(), "Error decoding JSON response", response.request(), e);
174+
} catch (Exception e) {
175+
logger.error("Unexpected error during decoding. Status: {}, Type: {}, Raw body: {}", response.status(), type, json, e);
176+
throw new DecodeException(response.status(), "Unexpected error during decoding", response.request(), e);
152177
}
153178
}
154179
};

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

100644100755
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
3939
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters;
4040
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
41+
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
4142
import org.apache.cloudstack.storage.datastore.lifecycle.BasePrimaryDataStoreLifeCycleImpl;
43+
import org.apache.cloudstack.storage.feign.model.ExportPolicy;
4244
import org.apache.cloudstack.storage.feign.model.OntapStorage;
45+
import org.apache.cloudstack.storage.feign.model.Svm;
4346
import org.apache.cloudstack.storage.feign.model.Volume;
4447
import org.apache.cloudstack.storage.provider.StorageProviderFactory;
4548
import org.apache.cloudstack.storage.service.StorageStrategy;
@@ -62,6 +65,7 @@ public class OntapPrimaryDatastoreLifecycle extends BasePrimaryDataStoreLifeCycl
6265
@Inject private StorageManager _storageMgr;
6366
@Inject private ResourceManager _resourceMgr;
6467
@Inject private PrimaryDataStoreHelper _dataStoreHelper;
68+
@Inject private StoragePoolDetailsDao storagePoolDetailsDao;
6569
private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreLifecycle.class);
6670

6771
// ONTAP minimum volume size is 1.56 GB (1677721600 bytes)
@@ -216,9 +220,21 @@ public DataStore initialize(Map<String, Object> dsInfos) {
216220
long volumeSize = Long.parseLong(details.get(Constants.SIZE));
217221
s_logger.info("Creating ONTAP volume '" + storagePoolName + "' with size: " + volumeSize + " bytes (" +
218222
(volumeSize / (1024 * 1024 * 1024)) + " GB)");
219-
Volume volume = storageStrategy.createStorageVolume(storagePoolName, volumeSize);
220-
details.put(Constants.VOLUME_UUID, volume.getUuid());
221-
details.put(Constants.VOLUME_NAME, volume.getName());
223+
try {
224+
Volume volume = storageStrategy.createStorageVolume(storagePoolName, volumeSize);
225+
if (volume == null) {
226+
s_logger.error("createStorageVolume returned null for volume: " + storagePoolName);
227+
throw new CloudRuntimeException("Failed to create ONTAP volume: " + storagePoolName);
228+
}
229+
230+
s_logger.info("Volume object retrieved successfully. UUID: " + volume.getUuid() + ", Name: " + volume.getName());
231+
232+
details.putIfAbsent(Constants.VOLUME_UUID, volume.getUuid());
233+
details.putIfAbsent(Constants.VOLUME_NAME, volume.getName());
234+
} catch (Exception e) {
235+
s_logger.error("Exception occurred while creating ONTAP volume: " + storagePoolName, e);
236+
throw new CloudRuntimeException("Failed to create ONTAP volume: " + storagePoolName + ". Error: " + e.getMessage(), e);
237+
}
222238
} else {
223239
throw new CloudRuntimeException("ONTAP details validation failed, cannot create primary storage");
224240
}
@@ -249,14 +265,21 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
249265
PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)dataStore;
250266
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInClusterForStorageConnection(primaryStore);
251267

268+
logger.debug(" datastore object received is {} ",primaryStore );
269+
252270
logger.debug(String.format("Attaching the pool to each of the hosts %s in the cluster: %s", hostsToConnect, primaryStore.getClusterId()));
253271

254-
Map<String, String> details = primaryStore.getDetails(); // TODO check while testing , if it is populated we can remove below db call
272+
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(primaryStore.getId());
255273
StorageStrategy strategy = Utility.getStrategyByStoragePoolDetails(details);
274+
Svm svm = new Svm();
275+
svm.setName(details.get(Constants.SVM_NAME));
276+
ExportPolicy exportPolicy = new ExportPolicy();
277+
exportPolicy.setSvm(svm);
256278
AccessGroup accessGroupRequest = new AccessGroup();
257279
accessGroupRequest.setHostsToConnect(hostsToConnect);
258280
accessGroupRequest.setScope(scope);
259281
accessGroupRequest.setPrimaryDataStoreInfo(primaryStore);
282+
accessGroupRequest.setPolicy(exportPolicy);
260283
strategy.createAccessGroup(accessGroupRequest);
261284

262285
logger.debug("attachCluster: Attaching the pool to each of the host in the cluster: {}", primaryStore.getClusterId());

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

100644100755
Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,41 @@
1818
*/
1919

2020
package org.apache.cloudstack.storage.provider;
21-
22-
import com.cloud.exception.StorageConflictException;
23-
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
24-
25-
class OntapHostListener implements HypervisorHostListener {
26-
27-
@Override
28-
public boolean hostAdded(long hostId) {
29-
return false;
30-
}
31-
32-
@Override
33-
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
34-
return false;
35-
}
36-
37-
@Override
38-
public boolean hostDisconnected(long hostId, long poolId) {
39-
return false;
40-
}
41-
42-
@Override
43-
public boolean hostAboutToBeRemoved(long hostId) {
44-
return false;
45-
}
46-
47-
@Override
48-
public boolean hostRemoved(long hostId, long clusterId) {
49-
return false;
50-
}
51-
52-
@Override
53-
public boolean hostEnabled(long hostId) {
54-
return false;
55-
}
56-
}
21+
//
22+
//import com.cloud.exception.StorageConflictException;
23+
//import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
24+
//
25+
//public class OntapHostListener implements HypervisorHostListener {
26+
//
27+
// public OntapHostListener(){}
28+
//
29+
// @Override
30+
// public boolean hostAdded(long hostId) {
31+
// return false;
32+
// }
33+
//
34+
// @Override
35+
// public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
36+
// return false;
37+
// }
38+
//
39+
// @Override
40+
// public boolean hostDisconnected(long hostId, long poolId) {
41+
// return false;
42+
// }
43+
//
44+
// @Override
45+
// public boolean hostAboutToBeRemoved(long hostId) {
46+
// return false;
47+
// }
48+
//
49+
// @Override
50+
// public boolean hostRemoved(long hostId, long clusterId) {
51+
// return false;
52+
// }
53+
//
54+
// @Override
55+
// public boolean hostEnabled(long hostId) {
56+
// return false;
57+
// }
58+
//}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +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;
44+
// private HypervisorHostListener listener;
4545

4646
public OntapPrimaryDatastoreProvider() {
4747
s_logger.info("OntapPrimaryDatastoreProvider initialized");
@@ -58,7 +58,7 @@ public DataStoreDriver getDataStoreDriver() {
5858

5959
@Override
6060
public HypervisorHostListener getHostListener() {
61-
return ontapHostListener;
61+
return null;
6262
}
6363

6464
@Override
@@ -72,7 +72,7 @@ public boolean configure(Map<String, Object> params) {
7272
s_logger.trace("OntapPrimaryDatastoreProvider: configure: Called");
7373
primaryDatastoreDriver = ComponentContext.inject(OntapPrimaryDatastoreDriver.class);
7474
primaryDatastoreLifecycle = ComponentContext.inject(OntapPrimaryDatastoreLifecycle.class);
75-
ontapHostListener = ComponentContext.inject(OntapHostListener.class);
75+
// listener = ComponentContext.inject(OntapHostListener.class);
7676

7777
return true;
7878
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,37 @@ public Volume createStorageVolume(String volumeName, Long size) {
196196
}
197197
s_logger.info("Volume created successfully: " + volumeName);
198198
// Below code is to update volume uuid to storage pool mapping once and used for all other workflow saving get volume call
199-
OntapResponse<Volume> ontapVolume = new OntapResponse<>();
200199
try {
201200
Map<String, Object> queryParams = Map.of(Constants.NAME, volumeName);
202-
ontapVolume = volumeFeignClient.getVolume(authHeader, queryParams);
203-
if ((ontapVolume == null || ontapVolume.getRecords().isEmpty())) {
204-
s_logger.error("Exception while getting volume volume not found:");
205-
throw new CloudRuntimeException("Failed to fetch volume " + volumeName);
201+
s_logger.debug("Fetching volume details for: " + volumeName);
202+
203+
OntapResponse<Volume> ontapVolume = volumeFeignClient.getVolume(authHeader, queryParams);
204+
s_logger.debug("Feign call completed. Processing response...");
205+
206+
if (ontapVolume == null) {
207+
s_logger.error("OntapResponse is null for volume: " + volumeName);
208+
throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": Response is null");
209+
}
210+
s_logger.debug("OntapResponse is not null. Checking records field...");
211+
212+
if (ontapVolume.getRecords() == null) {
213+
s_logger.error("OntapResponse.records is null for volume: " + volumeName);
214+
throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": Records list is null");
206215
}
207-
}catch (Exception e) {
208-
s_logger.error("Exception while getting volume: " + e.getMessage());
209-
throw new CloudRuntimeException("Failed to fetch volume: " + e.getMessage());
216+
s_logger.debug("Records field is not null. Size: " + ontapVolume.getRecords().size());
217+
218+
if (ontapVolume.getRecords().isEmpty()) {
219+
s_logger.error("OntapResponse.records is empty for volume: " + volumeName);
220+
throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": No records found");
221+
}
222+
223+
Volume volume = ontapVolume.getRecords().get(0);
224+
s_logger.info("Volume retrieved successfully: " + volumeName + ", UUID: " + volume.getUuid());
225+
return volume;
226+
} catch (Exception e) {
227+
s_logger.error("Exception while retrieving volume details for: " + volumeName, e);
228+
throw new CloudRuntimeException("Failed to fetch volume: " + volumeName + ". Error: " + e.getMessage(), e);
210229
}
211-
return ontapVolume.getRecords().get(0);
212230
}
213231

214232
/**

0 commit comments

Comments
 (0)