Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions plugins/storage/volume/ontap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<spring-cloud.version>2021.0.7</spring-cloud.version>
<openfeign.version>11.0</openfeign.version>
<json.version>20230227</json.version>
<jackson-databind.version>2.15.2</jackson-databind.version>
<httpclient.version>4.5.14</httpclient.version>
<swagger-annotations.version>1.6.2</swagger-annotations.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
Expand Down Expand Up @@ -58,24 +60,30 @@
<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-httpclient</artifactId>
<artifactId>feign-jackson</artifactId>
<version>${openfeign.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-volume</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,7 +62,6 @@ 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;
@Override
Expand Down Expand Up @@ -126,9 +127,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();
Expand Down Expand Up @@ -268,4 +269,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)
Expand All @@ -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(null, StandardCharsets.UTF_8);
return;
}
try {
byte[] jsonBytes = jsonMapper.writeValueAsBytes(object);
template.body(jsonBytes, StandardCharsets.UTF_8);
template.header("Content-Type", "application/json");
} catch (JsonProcessingException e) {
throw new EncodeException("Error encoding object to JSON", e);
}
}
};
}

@Bean
public Retryer feignRetryer() {
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
public Decoder createDecoder() {
return new Decoder() {
@Override
public Object decode(Response response, Type type) throws IOException, DecodeException {
if (response.body() == null) {
return null;
}
String json = null;
try (InputStream bodyStream = response.body().asInputStream()) {
json = new String(bodyStream.readAllBytes(), StandardCharsets.UTF_8);
logger.debug("Decoding JSON response: {}", json);
return jsonMapper.readValue(json, jsonMapper.getTypeFactory().constructType(type));
} catch (IOException e) {
logger.error("Error decoding JSON response. Status: {}, Raw body: {}", response.status(), json, e);
throw new DecodeException(response.status(), "Error decoding JSON response", response.request(), e);
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@
package org.apache.cloudstack.storage.feign.client;

import org.apache.cloudstack.storage.feign.model.Aggregate;
import org.apache.cloudstack.storage.feign.FeignConfiguration;
import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import feign.Headers;
import feign.Param;
import feign.RequestLine;

import java.net.URI;

@Lazy
@FeignClient(name="AggregateClient", url="https://{clusterIP}/api/storage/aggregates", configuration = FeignConfiguration.class)
public interface AggregateFeignClient {

//this method to get all aggregates and also filtered aggregates based on query params as a part of URL
@RequestMapping(method=RequestMethod.GET)
OntapResponse<Aggregate> getAggregateResponse(URI baseURL, @RequestHeader("Authorization") String header);

@RequestMapping(method=RequestMethod.GET, value="/{uuid}")
Aggregate getAggregateByUUID(URI baseURL,@RequestHeader("Authorization") String header, @PathVariable(name = "uuid", required = true) String uuid);
@RequestLine("GET /api/storage/aggregates")
@Headers({"Authorization: {authHeader}"})
OntapResponse<Aggregate> getAggregateResponse(@Param("authHeader") String authHeader);

@RequestLine("GET /api/storage/aggregates/{uuid}")
@Headers({"Authorization: {authHeader}"})
Aggregate getAggregateByUUID(@Param("authHeader") String authHeader, @Param("uuid") String uuid);
}
Loading
Loading