-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/cstackex-01: Primary Storage pool creation #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ec1707b
b855306
fd67a41
43c3684
80b24ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,24 +58,35 @@ | |
| <version>${json.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.cloud</groupId> | ||
| <artifactId>spring-cloud-commons</artifactId> | ||
| <groupId>io.github.openfeign</groupId> | ||
| <artifactId>feign-core</artifactId> | ||
| <version>${openfeign.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.cloud</groupId> | ||
| <artifactId>spring-cloud-starter-openfeign</artifactId> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.springframework.security</groupId> | ||
| <artifactId>spring-security-crypto</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| <groupId>io.github.openfeign</groupId> | ||
| <artifactId>feign-httpclient</artifactId> | ||
| <version>${openfeign.version}</version> | ||
| </dependency> | ||
| <!-- <dependency>--> | ||
| <!-- <groupId>io.github.openfeign</groupId>--> | ||
| <!-- <artifactId>feign-slf4j</artifactId>--> | ||
| <!-- <version>${openfeign.version}</version>--> | ||
| <!-- </dependency>--> | ||
| <dependency> | ||
| <groupId>io.github.openfeign</groupId> | ||
| <artifactId>feign-httpclient</artifactId> | ||
| <artifactId>feign-jackson</artifactId> | ||
| <version>${openfeign.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| <version>2.15.2</version> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this version inside property tag
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thankyou |
||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.httpcomponents</groupId> | ||
| <artifactId>httpclient</artifactId> | ||
| <version>4.5.14</version> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thankyou |
||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-engine-storage-volume</artifactId> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,8 @@ | |
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.storage.feign.model.OntapStorage; | ||
| import org.apache.cloudstack.storage.provider.StorageProviderFactory; | ||
| import org.apache.cloudstack.storage.service.StorageStrategy; | ||
| import org.apache.cloudstack.storage.service.model.CloudStackVolume; | ||
| import org.apache.cloudstack.storage.service.model.ProtocolType; | ||
|
|
@@ -60,9 +62,12 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver { | |
|
|
||
| private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreDriver.class); | ||
|
|
||
| @Inject private Utility utils; | ||
| private Utility utils; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make it 'final'
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| @Inject private StoragePoolDetailsDao storagePoolDetailsDao; | ||
| @Inject private PrimaryDataStoreDao storagePoolDao; | ||
| public OntapPrimaryDatastoreDriver() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can also create utility method as static, so we need not to instantiate utility class here
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thankyou |
||
| utils = new Utility(); | ||
| } | ||
| @Override | ||
| public Map<String, String> getCapabilities() { | ||
| s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called"); | ||
|
|
@@ -126,7 +131,7 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje | |
| throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); | ||
| } | ||
| Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId()); | ||
| StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details); | ||
| StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details); | ||
| s_logger.info("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest", details.get(Constants.SVM_NAME)); | ||
| CloudStackVolume cloudStackVolumeRequest = utils.createCloudStackVolumeRequestByProtocol(storagePool, details, dataObject); | ||
| CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest); | ||
|
|
@@ -268,4 +273,24 @@ public boolean isStorageSupportHA(Storage.StoragePoolType type) { | |
| public void detachVolumeFromAllStorageNodes(Volume volume) { | ||
|
|
||
| } | ||
|
|
||
| public StorageStrategy getStrategyByStoragePoolDetails(Map<String, String> details) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make it 'private'
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done
sandeeplocharla marked this conversation as resolved.
Outdated
|
||
| if (details == null || details.isEmpty()) { | ||
| s_logger.error("getStrategyByStoragePoolDetails: Storage pool details are null or empty"); | ||
| throw new CloudRuntimeException("getStrategyByStoragePoolDetails: Storage pool details are null or empty"); | ||
| } | ||
| String protocol = details.get(Constants.PROTOCOL); | ||
| OntapStorage ontapStorage = new OntapStorage(details.get(Constants.USERNAME), details.get(Constants.PASSWORD), | ||
| details.get(Constants.MANAGEMENT_LIF), details.get(Constants.SVM_NAME), ProtocolType.valueOf(protocol), | ||
| Boolean.parseBoolean(details.get(Constants.IS_DISAGGREGATED))); | ||
| StorageStrategy storageStrategy = StorageProviderFactory.getStrategy(ontapStorage); | ||
| boolean isValid = storageStrategy.connect(); | ||
| if (isValid) { | ||
| s_logger.info("Connection to Ontap SVM [{}] successful", details.get(Constants.SVM_NAME)); | ||
| return storageStrategy; | ||
| } else { | ||
| s_logger.error("getStrategyByStoragePoolDetails: Connection to Ontap SVM [" + details.get(Constants.SVM_NAME) + "] failed"); | ||
| throw new CloudRuntimeException("getStrategyByStoragePoolDetails: Connection to Ontap SVM [" + details.get(Constants.SVM_NAME) + "] failed"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.cloudstack.storage.feign; | ||
|
|
||
| import feign.Feign; | ||
|
|
||
| public class FeignClientFactory { | ||
|
|
||
| private final FeignConfiguration feignConfiguration; | ||
|
|
||
| public FeignClientFactory() { | ||
| this.feignConfiguration = new FeignConfiguration(); | ||
| } | ||
|
|
||
| public FeignClientFactory(FeignConfiguration feignConfiguration) { | ||
| this.feignConfiguration = feignConfiguration; | ||
| } | ||
|
|
||
| public <T> T createClient(Class<T> clientClass, String baseURL) { | ||
| return Feign.builder() | ||
| .client(feignConfiguration.createClient()) | ||
| .encoder(feignConfiguration.createEncoder()) | ||
| .decoder(feignConfiguration.createDecoder()) | ||
| // .logger(feignConfiguration.createLogger()) | ||
| .retryer(feignConfiguration.createRetryer()) | ||
| .requestInterceptor(feignConfiguration.createRequestInterceptor()) | ||
| .target(clientClass, baseURL); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,41 +19,51 @@ | |||||
|
|
||||||
| package org.apache.cloudstack.storage.feign; | ||||||
|
|
||||||
|
|
||||||
| import feign.RequestInterceptor; | ||||||
| import feign.RequestTemplate; | ||||||
| import feign.Retryer; | ||||||
| import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory; | ||||||
| import feign.Client; | ||||||
| import feign.httpclient.ApacheHttpClient; | ||||||
| import feign.codec.Decoder; | ||||||
| import feign.codec.Encoder; | ||||||
| //import feign.slf4j.Slf4jLogger; | ||||||
| import feign.Response; | ||||||
| import feign.codec.DecodeException; | ||||||
| import feign.codec.EncodeException; | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
| import org.apache.http.conn.ConnectionKeepAliveStrategy; | ||||||
| import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||||||
| import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||||||
| import org.apache.http.conn.ssl.TrustAllStrategy; | ||||||
| import org.apache.http.impl.client.CloseableHttpClient; | ||||||
| import org.apache.http.impl.client.HttpClientBuilder; | ||||||
| import org.apache.http.ssl.SSLContexts; | ||||||
| import org.apache.logging.log4j.LogManager; | ||||||
| import org.apache.logging.log4j.Logger; | ||||||
| import org.springframework.context.annotation.Bean; | ||||||
| import org.springframework.context.annotation.Configuration; | ||||||
| import feign.Client; | ||||||
| import feign.httpclient.ApacheHttpClient; | ||||||
|
|
||||||
| import javax.net.ssl.SSLContext; | ||||||
| import java.io.IOException; | ||||||
| import java.lang.reflect.Type; | ||||||
| import java.nio.charset.StandardCharsets; | ||||||
| import java.util.concurrent.TimeUnit; | ||||||
|
|
||||||
| @Configuration | ||||||
| public class FeignConfiguration { | ||||||
| private static Logger logger = LogManager.getLogger(FeignConfiguration.class); | ||||||
| private static final Logger logger = LogManager.getLogger(FeignConfiguration.class); | ||||||
|
|
||||||
| private int retryMaxAttempt = 3; | ||||||
| private final int retryMaxAttempt = 3; | ||||||
| private final int retryMaxInterval = 5; | ||||||
| private final String ontapFeignMaxConnection = "80"; | ||||||
| private final String ontapFeignMaxConnectionPerRoute = "20"; | ||||||
| private final ObjectMapper objectMapper; | ||||||
|
|
||||||
| private int retryMaxInterval = 5; | ||||||
|
|
||||||
| private String ontapFeignMaxConnection = "80"; | ||||||
|
|
||||||
| private String ontapFeignMaxConnectionPerRoute = "20"; | ||||||
|
|
||||||
| @Bean | ||||||
| public Client client(ApacheHttpClientFactory httpClientFactory) { | ||||||
| public FeignConfiguration() { | ||||||
| this.objectMapper = new ObjectMapper(); | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check out if json mapper could be used here to ignore unknown properties
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
| // Configure ObjectMapper to ignore unknown properties like _links | ||||||
| this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||||||
| } | ||||||
|
|
||||||
| public Client createClient() { | ||||||
| int maxConn; | ||||||
| int maxConnPerRoute; | ||||||
| try { | ||||||
|
|
@@ -68,10 +78,11 @@ public Client client(ApacheHttpClientFactory httpClientFactory) { | |||||
| logger.error("ontapFeignClient: encounter exception while parse the max connection per route from env. setting default value"); | ||||||
| maxConnPerRoute = 2; | ||||||
| } | ||||||
|
|
||||||
| // Disable Keep Alive for Http Connection | ||||||
| logger.debug("ontapFeignClient: Setting the feign client config values as max connection: {}, max connections per route: {}", maxConn, maxConnPerRoute); | ||||||
| ConnectionKeepAliveStrategy keepAliveStrategy = (response, context) -> 0; | ||||||
| CloseableHttpClient httpClient = httpClientFactory.createBuilder() | ||||||
| CloseableHttpClient httpClient = HttpClientBuilder.create() | ||||||
| .setMaxConnTotal(maxConn) | ||||||
| .setMaxConnPerRoute(maxConnPerRoute) | ||||||
| .setKeepAliveStrategy(keepAliveStrategy) | ||||||
|
|
@@ -91,22 +102,62 @@ private SSLConnectionSocketFactory getSSLSocketFactory() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| public RequestInterceptor createRequestInterceptor() { | ||||||
| return template -> { | ||||||
| logger.info("Feign Request URL: {}", template.url()); | ||||||
| logger.info("HTTP Method: {}", template.method()); | ||||||
| logger.info("Headers: {}", template.headers()); | ||||||
| if (template.body() != null) { | ||||||
| logger.info("Body: {}", new String(template.body())); | ||||||
| } | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| public Retryer createRetryer() { | ||||||
| return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt); | ||||||
| } | ||||||
|
|
||||||
| @Bean | ||||||
| public RequestInterceptor requestInterceptor() { | ||||||
| return new RequestInterceptor() { | ||||||
| public Encoder createEncoder() { | ||||||
| return new Encoder() { | ||||||
| @Override | ||||||
| public void apply(RequestTemplate template) { | ||||||
| logger.info("Feign Request URL: {}", template.url()); | ||||||
| logger.info("HTTP Method: {}", template.method()); | ||||||
| logger.info("Headers: {}", template.headers()); | ||||||
| logger.info("Body: {}", template.requestBody().asString()); | ||||||
| public void encode(Object object, Type bodyType, feign.RequestTemplate template) throws EncodeException { | ||||||
| if (object == null) { | ||||||
| template.body((byte[]) null, StandardCharsets.UTF_8); | ||||||
|
||||||
| template.body((byte[]) null, StandardCharsets.UTF_8); | |
| template.body(null, StandardCharsets.UTF_8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using 'var' for type inference is valid in Java 11+, but may reduce code readability. Consider explicitly declaring the type as 'InputStream bodyStream' for clarity.
| try (var bodyStream = response.body().asInputStream()) { | |
| try (InputStream bodyStream = response.body().asInputStream()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
rajiv-jain-netapp marked this conversation as resolved.
|
|
rajiv-jain-netapp marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.