Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 48 additions & 0 deletions plugins/storage/volume/ontap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
<version>4.22.0.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<properties>
<spring-cloud.version>2021.0.7</spring-cloud.version>
<openfeign.version>11.0</openfeign.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
Expand All @@ -38,14 +53,47 @@
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</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>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>${openfeign.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-volume</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.apache.cloudstack.storage.feign;


import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.Retryer;
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
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.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.util.concurrent.TimeUnit;

@Configuration
public class FeignConfiguration {
private static Logger logger = LogManager.getLogger(FeignConfiguration.class);

private int retryMaxAttempt = 3;

private int retryMaxInterval = 5;

private String ontapFeignMaxConnection = "80";

private String ontapFeignMaxConnectionPerRoute = "20";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep these in property file


@Bean
public Client client(ApacheHttpClientFactory httpClientFactory) {

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");
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");
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()
.setMaxConnTotal(maxConn)
.setMaxConnPerRoute(maxConnPerRoute)
.setKeepAliveStrategy(keepAliveStrategy)
.setSSLSocketFactory(getSSLSocketFactory())
.setConnectionTimeToLive(60, TimeUnit.SECONDS)
.build();
return new ApacheHttpClient(httpClient);
}

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);
}
}


@Bean
public RequestInterceptor requestInterceptor() {
return new RequestInterceptor() {
@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());
}
};
}

@Bean
public Retryer feignRetryer() {
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.apache.cloudstack.storage.feign.client;


import org.apache.cloudstack.storage.feign.FeignConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;


@FeignClient(name = "VolumeClient", url = "https://{clusterIP}/api/storage/volumes", configuration = FeignConfiguration.class)
public interface VolumeFeignClient {

@DeleteMapping("/storage/volumes/{id}")
void deleteVolume(@RequestHeader("Authorization") String authHeader,
@PathVariable("id") String volumeId);

@PostMapping("/api/storage/volumes")
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO createVolumeWithJob(
@RequestHeader("Authorization") String authHeader,
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
);

@GetMapping("/api/storage/volumes/{uuid}")
org.apache.cloudstack.storage.feign.model.response.VolumeDetailsResponseDTO getVolumeDetails(
@RequestHeader("Authorization") String authHeader,
@PathVariable("uuid") String uuid
);

@PatchMapping("/api/storage/volumes/{uuid}")
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO updateVolumeRebalancing(
@RequestHeader("accept") String acceptHeader,
@PathVariable("uuid") String uuid,
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.annotations.SerializedName;

import java.util.Objects;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Aggregate {

@SerializedName("name")
private String name = null;

@SerializedName("uuid")
private String uuid = null;

public Aggregate name(String name) {
this.name = name;
return this;
}

/**
* Get name
*
* @return name
**/
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Aggregate uuid(String uuid) {
this.uuid = uuid;
return this;
}

/**
* Get uuid
*
* @return uuid
**/
public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}


@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Aggregate diskAggregates = (Aggregate) o;
return Objects.equals(this.name, diskAggregates.name) &&
Objects.equals(this.uuid, diskAggregates.uuid);
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

@Override
public String toString() {
return "DiskAggregates [name=" + name + ", uuid=" + uuid + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// AntiRansomware.java
package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class AntiRansomware {
@JsonProperty("state")
private String state;

// Getters and setters
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ExportPolicy.java
package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ExportPolicy {
private String name;
private long id;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public long getId() { return id; }
public void setId(long id) { this.id = id; }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Nas.java
package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Nas {
@JsonProperty("path")
private String path;

@JsonProperty("export_policy")
private ExportPolicy exportPolicy;

// Getters and setters
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Policy {
private int minThroughputIops;
private int minThroughputMbps;
private int maxThroughputIops;
private int maxThroughputMbps;
private String uuid;
private String name;
public int getMinThroughputIops() { return minThroughputIops; }
public void setMinThroughputIops(int minThroughputIops) { this.minThroughputIops = minThroughputIops; }
public int getMinThroughputMbps() { return minThroughputMbps; }
public void setMinThroughputMbps(int minThroughputMbps) { this.minThroughputMbps = minThroughputMbps; }
public int getMaxThroughputIops() { return maxThroughputIops; }
public void setMaxThroughputIops(int maxThroughputIops) { this.maxThroughputIops = maxThroughputIops; }
public int getMaxThroughputMbps() { return maxThroughputMbps; }
public void setMaxThroughputMbps(int maxThroughputMbps) { this.maxThroughputMbps = maxThroughputMbps; }
public String getUuid() { return uuid; }
public void setUuid(String uuid) { this.uuid = uuid; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Qos.java
package org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Qos {
@JsonProperty("policy")
private Policy policy;

// Getters and setters
}
Loading
Loading