Skip to content

Commit 28faca1

Browse files
Feignconfiguration and volume feignClient along with desired POJOs
1 parent ebc3f00 commit 28faca1

File tree

18 files changed

+665
-0
lines changed

18 files changed

+665
-0
lines changed

plugins/storage/volume/ontap/pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<version>4.22.0.0-SNAPSHOT</version>
2828
<relativePath>../../../pom.xml</relativePath>
2929
</parent>
30+
<properties>
31+
<spring-cloud.version>2021.0.7</spring-cloud.version>
32+
<openfeign.version>11.0</openfeign.version>
33+
</properties>
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-dependencies</artifactId>
39+
<version>${spring-cloud.version}</version>
40+
<type>pom</type>
41+
<scope>import</scope>
42+
</dependency>
43+
</dependencies>
44+
</dependencyManagement>
3045
<dependencies>
3146
<dependency>
3247
<groupId>org.apache.cloudstack</groupId>
@@ -38,14 +53,47 @@
3853
<artifactId>json</artifactId>
3954
<version>20230227</version>
4055
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.cloud</groupId>
58+
<artifactId>spring-cloud-commons</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.cloud</groupId>
62+
<artifactId>spring-cloud-starter-openfeign</artifactId>
63+
<exclusions>
64+
<exclusion>
65+
<groupId>org.springframework.security</groupId>
66+
<artifactId>spring-security-crypto</artifactId>
67+
</exclusion>
68+
</exclusions>
69+
</dependency>
70+
<dependency>
71+
<groupId>io.github.openfeign</groupId>
72+
<artifactId>feign-httpclient</artifactId>
73+
<version>${openfeign.version}</version>
74+
</dependency>
4175
<dependency>
4276
<groupId>org.apache.cloudstack</groupId>
4377
<artifactId>cloud-engine-storage-volume</artifactId>
4478
<version>${project.version}</version>
4579
</dependency>
80+
<dependency>
81+
<groupId>io.swagger</groupId>
82+
<artifactId>swagger-annotations</artifactId>
83+
<version>1.6.2</version>
84+
</dependency>
4685
</dependencies>
4786
<build>
4887
<plugins>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-compiler-plugin</artifactId>
91+
<version>3.8.1</version>
92+
<configuration>
93+
<source>11</source>
94+
<target>11</target>
95+
</configuration>
96+
</plugin>
4997
<plugin>
5098
<artifactId>maven-surefire-plugin</artifactId>
5199
<configuration>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.apache.cloudstack.storage.feign;
2+
3+
4+
import feign.RequestInterceptor;
5+
import feign.RequestTemplate;
6+
import feign.Retryer;
7+
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
8+
import org.apache.http.conn.ConnectionKeepAliveStrategy;
9+
import org.apache.http.conn.ssl.NoopHostnameVerifier;
10+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
11+
import org.apache.http.conn.ssl.TrustAllStrategy;
12+
import org.apache.http.impl.client.CloseableHttpClient;
13+
import org.apache.http.ssl.SSLContexts;
14+
import org.apache.logging.log4j.LogManager;
15+
import org.apache.logging.log4j.Logger;
16+
import org.springframework.context.annotation.Bean;
17+
import org.springframework.context.annotation.Configuration;
18+
import feign.Client;
19+
import feign.httpclient.ApacheHttpClient;
20+
import javax.net.ssl.SSLContext;
21+
import java.util.concurrent.TimeUnit;
22+
23+
@Configuration
24+
public class FeignConfiguration {
25+
private static Logger logger = LogManager.getLogger(FeignConfiguration.class);
26+
27+
private int retryMaxAttempt = 3;
28+
29+
private int retryMaxInterval = 5;
30+
31+
private String ontapFeignMaxConnection = "80";
32+
33+
private String ontapFeignMaxConnectionPerRoute = "20";
34+
35+
@Bean
36+
public Client client(ApacheHttpClientFactory httpClientFactory) {
37+
38+
int maxConn;
39+
int maxConnPerRoute;
40+
try {
41+
maxConn = Integer.parseInt(this.ontapFeignMaxConnection);
42+
} catch (Exception e) {
43+
logger.error("ontapFeignClient: encounter exception while parse the max connection from env. setting default value");
44+
maxConn = 20;
45+
}
46+
try {
47+
maxConnPerRoute = Integer.parseInt(this.ontapFeignMaxConnectionPerRoute);
48+
} catch (Exception e) {
49+
logger.error("ontapFeignClient: encounter exception while parse the max connection per route from env. setting default value");
50+
maxConnPerRoute = 2;
51+
}
52+
// Disable Keep Alive for Http Connection
53+
logger.debug("ontapFeignClient: Setting the feign client config values as max connection: {}, max connections per route: {}", maxConn, maxConnPerRoute);
54+
ConnectionKeepAliveStrategy keepAliveStrategy = (response, context) -> 0;
55+
CloseableHttpClient httpClient = httpClientFactory.createBuilder()
56+
.setMaxConnTotal(maxConn)
57+
.setMaxConnPerRoute(maxConnPerRoute)
58+
.setKeepAliveStrategy(keepAliveStrategy)
59+
.setSSLSocketFactory(getSSLSocketFactory())
60+
.setConnectionTimeToLive(60, TimeUnit.SECONDS)
61+
.build();
62+
return new ApacheHttpClient(httpClient);
63+
}
64+
65+
private SSLConnectionSocketFactory getSSLSocketFactory() {
66+
try {
67+
// The TrustAllStrategy is a strategy used in SSL context configuration that accepts any certificate
68+
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build();
69+
return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
70+
} catch (Exception ex) {
71+
throw new RuntimeException(ex);
72+
}
73+
}
74+
75+
76+
@Bean
77+
public RequestInterceptor requestInterceptor() {
78+
return new RequestInterceptor() {
79+
@Override
80+
public void apply(RequestTemplate template) {
81+
logger.info("Feign Request URL: {}", template.url());
82+
logger.info("HTTP Method: {}", template.method());
83+
logger.info("Headers: {}", template.headers());
84+
logger.info("Body: {}", template.requestBody().asString());
85+
}
86+
};
87+
}
88+
89+
@Bean
90+
public Retryer feignRetryer() {
91+
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
92+
}
93+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.apache.cloudstack.storage.feign.client;
2+
3+
4+
import org.apache.cloudstack.storage.feign.FeignConfiguration;
5+
import org.springframework.cloud.openfeign.FeignClient;
6+
import org.springframework.web.bind.annotation.DeleteMapping;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.PatchMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestHeader;
13+
14+
15+
@FeignClient(name = "VolumeClient", url = "https://{clusterIP}/api/storage/volumes", configuration = FeignConfiguration.class)
16+
public interface VolumeFeignClient {
17+
18+
@DeleteMapping("/storage/volumes/{id}")
19+
void deleteVolume(@RequestHeader("Authorization") String authHeader,
20+
@PathVariable("id") String volumeId);
21+
22+
@PostMapping("/api/storage/volumes")
23+
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO createVolumeWithJob(
24+
@RequestHeader("Authorization") String authHeader,
25+
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
26+
);
27+
28+
@GetMapping("/api/storage/volumes/{uuid}")
29+
org.apache.cloudstack.storage.feign.model.response.VolumeDetailsResponseDTO getVolumeDetails(
30+
@RequestHeader("Authorization") String authHeader,
31+
@PathVariable("uuid") String uuid
32+
);
33+
34+
@PatchMapping("/api/storage/volumes/{uuid}")
35+
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO updateVolumeRebalancing(
36+
@RequestHeader("accept") String acceptHeader,
37+
@PathVariable("uuid") String uuid,
38+
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
39+
);
40+
41+
42+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.apache.cloudstack.storage.feign.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.Objects;
7+
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
public class Aggregate {
10+
11+
@SerializedName("name")
12+
private String name = null;
13+
14+
@SerializedName("uuid")
15+
private String uuid = null;
16+
17+
public Aggregate name(String name) {
18+
this.name = name;
19+
return this;
20+
}
21+
22+
/**
23+
* Get name
24+
*
25+
* @return name
26+
**/
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
35+
public Aggregate uuid(String uuid) {
36+
this.uuid = uuid;
37+
return this;
38+
}
39+
40+
/**
41+
* Get uuid
42+
*
43+
* @return uuid
44+
**/
45+
public String getUuid() {
46+
return uuid;
47+
}
48+
49+
public void setUuid(String uuid) {
50+
this.uuid = uuid;
51+
}
52+
53+
54+
@Override
55+
public boolean equals(java.lang.Object o) {
56+
if (this == o) {
57+
return true;
58+
}
59+
if (o == null || getClass() != o.getClass()) {
60+
return false;
61+
}
62+
Aggregate diskAggregates = (Aggregate) o;
63+
return Objects.equals(this.name, diskAggregates.name) &&
64+
Objects.equals(this.uuid, diskAggregates.uuid);
65+
}
66+
67+
/**
68+
* Convert the given object to string with each line indented by 4 spaces
69+
* (except the first line).
70+
*/
71+
private String toIndentedString(java.lang.Object o) {
72+
if (o == null) {
73+
return "null";
74+
}
75+
return o.toString().replace("\n", "\n ");
76+
}
77+
78+
@Override
79+
public String toString() {
80+
return "DiskAggregates [name=" + name + ", uuid=" + uuid + "]";
81+
}
82+
83+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// AntiRansomware.java
2+
package org.apache.cloudstack.storage.feign.model;
3+
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
public class AntiRansomware {
7+
@JsonProperty("state")
8+
private String state;
9+
10+
// Getters and setters
11+
}
12+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ExportPolicy.java
2+
package org.apache.cloudstack.storage.feign.model;
3+
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
6+
@JsonInclude(JsonInclude.Include.NON_NULL)
7+
public class ExportPolicy {
8+
private String name;
9+
private long id;
10+
public String getName() { return name; }
11+
public void setName(String name) { this.name = name; }
12+
public long getId() { return id; }
13+
public void setId(long id) { this.id = id; }
14+
}
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Nas.java
2+
package org.apache.cloudstack.storage.feign.model;
3+
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class Nas {
9+
@JsonProperty("path")
10+
private String path;
11+
12+
@JsonProperty("export_policy")
13+
private ExportPolicy exportPolicy;
14+
15+
// Getters and setters
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
package org.apache.cloudstack.storage.feign.model;
3+
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
6+
@JsonInclude(JsonInclude.Include.NON_NULL)
7+
public class Policy {
8+
private int minThroughputIops;
9+
private int minThroughputMbps;
10+
private int maxThroughputIops;
11+
private int maxThroughputMbps;
12+
private String uuid;
13+
private String name;
14+
public int getMinThroughputIops() { return minThroughputIops; }
15+
public void setMinThroughputIops(int minThroughputIops) { this.minThroughputIops = minThroughputIops; }
16+
public int getMinThroughputMbps() { return minThroughputMbps; }
17+
public void setMinThroughputMbps(int minThroughputMbps) { this.minThroughputMbps = minThroughputMbps; }
18+
public int getMaxThroughputIops() { return maxThroughputIops; }
19+
public void setMaxThroughputIops(int maxThroughputIops) { this.maxThroughputIops = maxThroughputIops; }
20+
public int getMaxThroughputMbps() { return maxThroughputMbps; }
21+
public void setMaxThroughputMbps(int maxThroughputMbps) { this.maxThroughputMbps = maxThroughputMbps; }
22+
public String getUuid() { return uuid; }
23+
public void setUuid(String uuid) { this.uuid = uuid; }
24+
public String getName() { return name; }
25+
public void setName(String name) { this.name = name; }
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Qos.java
2+
package org.apache.cloudstack.storage.feign.model;
3+
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class Qos {
9+
@JsonProperty("policy")
10+
private Policy policy;
11+
12+
// Getters and setters
13+
}

0 commit comments

Comments
 (0)