Skip to content

Commit 2822946

Browse files
Merge pull request #4 from NetApp/feature/CSTACKEX-28
Feignconfiguration and volume feignClient along with desired POJOs with cstack 28
2 parents a03a2c4 + 033c23d commit 2822946

File tree

18 files changed

+1227
-1
lines changed

18 files changed

+1227
-1
lines changed

plugins/storage/volume/ontap/pom.xml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
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+
<json.version>20230227</json.version>
34+
<swagger-annotations.version>1.6.2</swagger-annotations.version>
35+
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
36+
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
37+
</properties>
38+
<dependencyManagement>
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.cloud</groupId>
42+
<artifactId>spring-cloud-dependencies</artifactId>
43+
<version>${spring-cloud.version}</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
3049
<dependencies>
3150
<dependency>
3251
<groupId>org.apache.cloudstack</groupId>
@@ -36,18 +55,52 @@
3655
<dependency>
3756
<groupId>org.json</groupId>
3857
<artifactId>json</artifactId>
39-
<version>20230227</version>
58+
<version>${json.version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.cloud</groupId>
62+
<artifactId>spring-cloud-commons</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.springframework.cloud</groupId>
66+
<artifactId>spring-cloud-starter-openfeign</artifactId>
67+
<exclusions>
68+
<exclusion>
69+
<groupId>org.springframework.security</groupId>
70+
<artifactId>spring-security-crypto</artifactId>
71+
</exclusion>
72+
</exclusions>
73+
</dependency>
74+
<dependency>
75+
<groupId>io.github.openfeign</groupId>
76+
<artifactId>feign-httpclient</artifactId>
77+
<version>${openfeign.version}</version>
4078
</dependency>
4179
<dependency>
4280
<groupId>org.apache.cloudstack</groupId>
4381
<artifactId>cloud-engine-storage-volume</artifactId>
4482
<version>${project.version}</version>
4583
</dependency>
84+
<dependency>
85+
<groupId>io.swagger</groupId>
86+
<artifactId>swagger-annotations</artifactId>
87+
<version>${swagger-annotations.version}</version>
88+
</dependency>
4689
</dependencies>
4790
<build>
4891
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<version>${maven-compiler-plugin.version}</version>
96+
<configuration>
97+
<source>11</source>
98+
<target>11</target>
99+
</configuration>
100+
</plugin>
49101
<plugin>
50102
<artifactId>maven-surefire-plugin</artifactId>
103+
<version>${maven-surefire-plugin.version}</version>
51104
<configuration>
52105
<skipTests>true</skipTests>
53106
</configuration>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.cloudstack.storage.feign;
21+
22+
23+
import feign.RequestInterceptor;
24+
import feign.RequestTemplate;
25+
import feign.Retryer;
26+
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
27+
import org.apache.http.conn.ConnectionKeepAliveStrategy;
28+
import org.apache.http.conn.ssl.NoopHostnameVerifier;
29+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
30+
import org.apache.http.conn.ssl.TrustAllStrategy;
31+
import org.apache.http.impl.client.CloseableHttpClient;
32+
import org.apache.http.ssl.SSLContexts;
33+
import org.apache.logging.log4j.LogManager;
34+
import org.apache.logging.log4j.Logger;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Configuration;
37+
import feign.Client;
38+
import feign.httpclient.ApacheHttpClient;
39+
import javax.net.ssl.SSLContext;
40+
import java.util.concurrent.TimeUnit;
41+
42+
@Configuration
43+
public class FeignConfiguration {
44+
private static Logger logger = LogManager.getLogger(FeignConfiguration.class);
45+
46+
private int retryMaxAttempt = 3;
47+
48+
private int retryMaxInterval = 5;
49+
50+
private String ontapFeignMaxConnection = "80";
51+
52+
private String ontapFeignMaxConnectionPerRoute = "20";
53+
54+
@Bean
55+
public Client client(ApacheHttpClientFactory httpClientFactory) {
56+
57+
int maxConn;
58+
int maxConnPerRoute;
59+
try {
60+
maxConn = Integer.parseInt(this.ontapFeignMaxConnection);
61+
} catch (Exception e) {
62+
logger.error("ontapFeignClient: encounter exception while parse the max connection from env. setting default value");
63+
maxConn = 20;
64+
}
65+
try {
66+
maxConnPerRoute = Integer.parseInt(this.ontapFeignMaxConnectionPerRoute);
67+
} catch (Exception e) {
68+
logger.error("ontapFeignClient: encounter exception while parse the max connection per route from env. setting default value");
69+
maxConnPerRoute = 2;
70+
}
71+
// Disable Keep Alive for Http Connection
72+
logger.debug("ontapFeignClient: Setting the feign client config values as max connection: {}, max connections per route: {}", maxConn, maxConnPerRoute);
73+
ConnectionKeepAliveStrategy keepAliveStrategy = (response, context) -> 0;
74+
CloseableHttpClient httpClient = httpClientFactory.createBuilder()
75+
.setMaxConnTotal(maxConn)
76+
.setMaxConnPerRoute(maxConnPerRoute)
77+
.setKeepAliveStrategy(keepAliveStrategy)
78+
.setSSLSocketFactory(getSSLSocketFactory())
79+
.setConnectionTimeToLive(60, TimeUnit.SECONDS)
80+
.build();
81+
return new ApacheHttpClient(httpClient);
82+
}
83+
84+
private SSLConnectionSocketFactory getSSLSocketFactory() {
85+
try {
86+
// The TrustAllStrategy is a strategy used in SSL context configuration that accepts any certificate
87+
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build();
88+
return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
89+
} catch (Exception ex) {
90+
throw new RuntimeException(ex);
91+
}
92+
}
93+
94+
95+
@Bean
96+
public RequestInterceptor requestInterceptor() {
97+
return new RequestInterceptor() {
98+
@Override
99+
public void apply(RequestTemplate template) {
100+
logger.info("Feign Request URL: {}", template.url());
101+
logger.info("HTTP Method: {}", template.method());
102+
logger.info("Headers: {}", template.headers());
103+
logger.info("Body: {}", template.requestBody().asString());
104+
}
105+
};
106+
}
107+
108+
@Bean
109+
public Retryer feignRetryer() {
110+
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
111+
}
112+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.feign.client;
20+
21+
22+
import org.apache.cloudstack.storage.feign.FeignConfiguration;
23+
import org.springframework.cloud.openfeign.FeignClient;
24+
import org.springframework.web.bind.annotation.DeleteMapping;
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.PatchMapping;
27+
import org.springframework.web.bind.annotation.PathVariable;
28+
import org.springframework.web.bind.annotation.PostMapping;
29+
import org.springframework.web.bind.annotation.RequestBody;
30+
import org.springframework.web.bind.annotation.RequestHeader;
31+
32+
33+
@FeignClient(name = "VolumeClient", url = "https://{clusterIP}/api/storage/volumes", configuration = FeignConfiguration.class)
34+
public interface VolumeFeignClient {
35+
36+
@DeleteMapping("/storage/volumes/{id}")
37+
void deleteVolume(@RequestHeader("Authorization") String authHeader,
38+
@PathVariable("id") String volumeId);
39+
40+
@PostMapping("/api/storage/volumes")
41+
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO createVolumeWithJob(
42+
@RequestHeader("Authorization") String authHeader,
43+
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
44+
);
45+
46+
@GetMapping("/api/storage/volumes/{uuid}")
47+
org.apache.cloudstack.storage.feign.model.response.VolumeDetailsResponseDTO getVolumeDetails(
48+
@RequestHeader("Authorization") String authHeader,
49+
@PathVariable("uuid") String uuid
50+
);
51+
52+
@PatchMapping("/api/storage/volumes/{uuid}")
53+
org.apache.cloudstack.storage.feign.model.response.JobResponseDTO updateVolumeRebalancing(
54+
@RequestHeader("accept") String acceptHeader,
55+
@PathVariable("uuid") String uuid,
56+
@RequestBody org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO request
57+
);
58+
59+
60+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.cloudstack.storage.feign.model;
21+
22+
import com.fasterxml.jackson.annotation.JsonInclude;
23+
import com.google.gson.annotations.SerializedName;
24+
25+
import java.util.Objects;
26+
27+
@JsonInclude(JsonInclude.Include.NON_NULL)
28+
public class Aggregate {
29+
30+
@SerializedName("name")
31+
private String name = null;
32+
33+
@Override
34+
public int hashCode() {
35+
return Objects.hash(getName(), getUuid());
36+
}
37+
38+
@SerializedName("uuid")
39+
private String uuid = null;
40+
41+
public Aggregate name(String name) {
42+
this.name = name;
43+
return this;
44+
}
45+
46+
/**
47+
* Get name
48+
*
49+
* @return name
50+
**/
51+
public String getName() {
52+
return name;
53+
}
54+
55+
public void setName(String name) {
56+
this.name = name;
57+
}
58+
59+
public Aggregate uuid(String uuid) {
60+
this.uuid = uuid;
61+
return this;
62+
}
63+
64+
/**
65+
* Get uuid
66+
*
67+
* @return uuid
68+
**/
69+
public String getUuid() {
70+
return uuid;
71+
}
72+
73+
public void setUuid(String uuid) {
74+
this.uuid = uuid;
75+
}
76+
77+
78+
@Override
79+
public boolean equals(java.lang.Object o) {
80+
if (this == o) {
81+
return true;
82+
}
83+
if (o == null || getClass() != o.getClass()) {
84+
return false;
85+
}
86+
Aggregate diskAggregates = (Aggregate) o;
87+
return Objects.equals(this.name, diskAggregates.name) &&
88+
Objects.equals(this.uuid, diskAggregates.uuid);
89+
}
90+
91+
/**
92+
* Convert the given object to string with each line indented by 4 spaces
93+
* (except the first line).
94+
*/
95+
private String toIndentedString(java.lang.Object o) {
96+
if (o == null) {
97+
return "null";
98+
}
99+
return o.toString().replace("\n", "\n ");
100+
}
101+
102+
@Override
103+
public String toString() {
104+
return "DiskAggregates [name=" + name + ", uuid=" + uuid + "]";
105+
}
106+
107+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.feign.model;
20+
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
23+
public class AntiRansomware {
24+
@JsonProperty("state")
25+
private String state;
26+
27+
public String getState() {
28+
return state;
29+
}
30+
31+
public void setState(String state) {
32+
this.state = state;
33+
}
34+
}

0 commit comments

Comments
 (0)