-
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 4 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,9 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver { | |
|
|
||
| private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreDriver.class); | ||
|
|
||
| @Inject private Utility utils; | ||
| @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. Why do we need this constructor?
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. Not needed. Removed |
||
| @Override | ||
| public Map<String, String> getCapabilities() { | ||
| s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called"); | ||
|
|
@@ -126,9 +128,9 @@ 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 cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, dataObject); | ||
| CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest); | ||
| if (ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL)) && cloudStackVolume.getLun() != null && cloudStackVolume.getLun().getName() != null) { | ||
| return cloudStackVolume.getLun().getName(); | ||
|
|
@@ -268,4 +270,24 @@ public boolean isStorageSupportHA(Storage.StoragePoolType type) { | |
| public void detachVolumeFromAllStorageNodes(Volume volume) { | ||
|
|
||
| } | ||
|
|
||
| private StorageStrategy getStrategyByStoragePoolDetails(Map<String, String> details) { | ||
| 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,45 @@ | ||
| /* | ||
| * 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()) | ||
| .retryer(feignConfiguration.createRetryer()) | ||
| .requestInterceptor(feignConfiguration.createRequestInterceptor()) | ||
| .target(clientClass, baseURL); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,77 +1,68 @@ | ||||||
| /* | ||||||
| * 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.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.Response; | ||||||
| import feign.codec.DecodeException; | ||||||
| import feign.codec.EncodeException; | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||||||
| import com.fasterxml.jackson.databind.json.JsonMapper; | ||||||
| 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.io.InputStream; | ||||||
| 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 int retryMaxAttempt = 3; | ||||||
|
|
||||||
| private int retryMaxInterval = 5; | ||||||
| private static final Logger logger = LogManager.getLogger(FeignConfiguration.class); | ||||||
|
|
||||||
| private String ontapFeignMaxConnection = "80"; | ||||||
| private final int retryMaxAttempt = 3; | ||||||
| private final int retryMaxInterval = 5; | ||||||
| private final String ontapFeignMaxConnection = "80"; | ||||||
| private final String ontapFeignMaxConnectionPerRoute = "20"; | ||||||
| private final JsonMapper jsonMapper; | ||||||
|
|
||||||
| private String ontapFeignMaxConnectionPerRoute = "20"; | ||||||
|
|
||||||
| @Bean | ||||||
| public Client client(ApacheHttpClientFactory httpClientFactory) { | ||||||
| public FeignConfiguration() { | ||||||
| this.jsonMapper = JsonMapper.builder() | ||||||
| .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||||||
| .findAndAddModules() | ||||||
| .build(); | ||||||
| } | ||||||
|
|
||||||
| public Client createClient() { | ||||||
| int maxConn; | ||||||
| int maxConnPerRoute; | ||||||
| try { | ||||||
| maxConn = Integer.parseInt(this.ontapFeignMaxConnection); | ||||||
| } catch (Exception e) { | ||||||
| logger.error("ontapFeignClient: encounter exception while parse the max connection from env. setting default value"); | ||||||
| logger.error("ontapFeignClient: parse max connection failed, using default"); | ||||||
| maxConn = 20; | ||||||
| } | ||||||
| try { | ||||||
| maxConnPerRoute = Integer.parseInt(this.ontapFeignMaxConnectionPerRoute); | ||||||
| } catch (Exception e) { | ||||||
| logger.error("ontapFeignClient: encounter exception while parse the max connection per route from env. setting default value"); | ||||||
| logger.error("ontapFeignClient: parse max connection per route failed, using default"); | ||||||
| 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); | ||||||
| logger.debug("ontapFeignClient: maxConn={}, maxConnPerRoute={}", maxConn, maxConnPerRoute); | ||||||
| ConnectionKeepAliveStrategy keepAliveStrategy = (response, context) -> 0; | ||||||
| CloseableHttpClient httpClient = httpClientFactory.createBuilder() | ||||||
| CloseableHttpClient httpClient = HttpClientBuilder.create() | ||||||
| .setMaxConnTotal(maxConn) | ||||||
| .setMaxConnPerRoute(maxConnPerRoute) | ||||||
| .setKeepAliveStrategy(keepAliveStrategy) | ||||||
|
|
@@ -83,30 +74,64 @@ public Client client(ApacheHttpClientFactory httpClientFactory) { | |||||
|
|
||||||
| private SSLConnectionSocketFactory getSSLSocketFactory() { | ||||||
| try { | ||||||
| // The TrustAllStrategy is a strategy used in SSL context configuration that accepts any certificate | ||||||
| SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build(); | ||||||
| return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); | ||||||
| } catch (Exception ex) { | ||||||
| throw new RuntimeException(ex); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| 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(), StandardCharsets.UTF_8)); | ||||||
| } | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| @Bean | ||||||
| public RequestInterceptor requestInterceptor() { | ||||||
| return new RequestInterceptor() { | ||||||
| public Retryer createRetryer() { | ||||||
| return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt); | ||||||
| } | ||||||
|
|
||||||
| 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
|
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.