Skip to content

Commit 0049858

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
commit for nfs storage pool creation
1 parent b83ce23 commit 0049858

25 files changed

+655
-448
lines changed

plugins/storage/volume/ontap/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
<artifactId>feign-httpclient</artifactId>
7777
<version>${openfeign.version}</version>
7878
</dependency>
79+
<!-- <dependency>-->
80+
<!-- <groupId>io.github.openfeign</groupId>-->
81+
<!-- <artifactId>feign-slf4j</artifactId>-->
82+
<!-- <version>${openfeign.version}</version>-->
83+
<!-- </dependency>-->
84+
<dependency>
85+
<groupId>io.github.openfeign</groupId>
86+
<artifactId>feign-jackson</artifactId>
87+
<version>${openfeign.version}</version>
88+
</dependency>
7989
<dependency>
8090
<groupId>org.apache.cloudstack</groupId>
8191
<artifactId>cloud-engine-storage-volume</artifactId>

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
3838
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
3939
import org.apache.cloudstack.storage.command.CommandResult;
40-
import org.apache.logging.log4j.LogManager;
4140
import org.apache.logging.log4j.Logger;
41+
import org.apache.logging.log4j.LogManager;
42+
4243

4344
import java.util.HashMap;
4445
import java.util.Map;
4546

4647
public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
4748

48-
private static final Logger s_logger = (Logger)LogManager.getLogger(OntapPrimaryDatastoreDriver.class);
49+
private static final Logger s_logger = LogManager.getLogger(OntapPrimaryDatastoreDriver.class);
4950
@Override
5051
public Map<String, String> getCapabilities() {
5152
s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
import feign.Feign;
23+
24+
public class FeignClientFactory {
25+
26+
private final FeignConfiguration feignConfiguration;
27+
28+
public FeignClientFactory() {
29+
this.feignConfiguration = new FeignConfiguration();
30+
}
31+
32+
public FeignClientFactory(FeignConfiguration feignConfiguration) {
33+
this.feignConfiguration = feignConfiguration;
34+
}
35+
36+
public <T> T createClient(Class<T> clientClass) {
37+
return Feign.builder()
38+
.client(feignConfiguration.createClient())
39+
.encoder(feignConfiguration.createEncoder())
40+
.decoder(feignConfiguration.createDecoder())
41+
// .logger(feignConfiguration.createLogger())
42+
.retryer(feignConfiguration.createRetryer())
43+
.requestInterceptor(feignConfiguration.createRequestInterceptor())
44+
.target(clientClass, "https://10.196.38.171/");
45+
}
46+
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/FeignConfiguration.java

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,43 @@
1919

2020
package org.apache.cloudstack.storage.feign;
2121

22-
2322
import feign.RequestInterceptor;
24-
import feign.RequestTemplate;
2523
import feign.Retryer;
26-
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
24+
import feign.Client;
25+
import feign.httpclient.ApacheHttpClient;
26+
import feign.codec.Decoder;
27+
import feign.codec.Encoder;
28+
import feign.Response;
29+
import feign.codec.DecodeException;
30+
import feign.codec.EncodeException;
31+
import com.fasterxml.jackson.databind.ObjectMapper;
32+
import com.fasterxml.jackson.core.JsonProcessingException;
2733
import org.apache.http.conn.ConnectionKeepAliveStrategy;
2834
import org.apache.http.conn.ssl.NoopHostnameVerifier;
2935
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
3036
import org.apache.http.conn.ssl.TrustAllStrategy;
3137
import org.apache.http.impl.client.CloseableHttpClient;
38+
import org.apache.http.impl.client.HttpClientBuilder;
3239
import org.apache.http.ssl.SSLContexts;
3340
import org.apache.logging.log4j.LogManager;
3441
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;
42+
3943
import javax.net.ssl.SSLContext;
44+
import java.io.IOException;
45+
import java.lang.reflect.Type;
46+
import java.nio.charset.StandardCharsets;
4047
import java.util.concurrent.TimeUnit;
4148

42-
@Configuration
4349
public class FeignConfiguration {
44-
private static Logger logger = LogManager.getLogger(FeignConfiguration.class);
50+
private static final Logger logger = LogManager.getLogger(FeignConfiguration.class);
4551

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) {
52+
private final int retryMaxAttempt = 3;
53+
private final int retryMaxInterval = 5;
54+
private final String ontapFeignMaxConnection = "80";
55+
private final String ontapFeignMaxConnectionPerRoute = "20";
56+
private final ObjectMapper objectMapper = new ObjectMapper();
5657

58+
public Client createClient() {
5759
int maxConn;
5860
int maxConnPerRoute;
5961
try {
@@ -68,10 +70,11 @@ public Client client(ApacheHttpClientFactory httpClientFactory) {
6870
logger.error("ontapFeignClient: encounter exception while parse the max connection per route from env. setting default value");
6971
maxConnPerRoute = 2;
7072
}
73+
7174
// Disable Keep Alive for Http Connection
7275
logger.debug("ontapFeignClient: Setting the feign client config values as max connection: {}, max connections per route: {}", maxConn, maxConnPerRoute);
7376
ConnectionKeepAliveStrategy keepAliveStrategy = (response, context) -> 0;
74-
CloseableHttpClient httpClient = httpClientFactory.createBuilder()
77+
CloseableHttpClient httpClient = HttpClientBuilder.create()
7578
.setMaxConnTotal(maxConn)
7679
.setMaxConnPerRoute(maxConnPerRoute)
7780
.setKeepAliveStrategy(keepAliveStrategy)
@@ -91,22 +94,55 @@ private SSLConnectionSocketFactory getSSLSocketFactory() {
9194
}
9295
}
9396

97+
public RequestInterceptor createRequestInterceptor() {
98+
return template -> {
99+
logger.info("Feign Request URL: {}", template.url());
100+
logger.info("HTTP Method: {}", template.method());
101+
logger.info("Headers: {}", template.headers());
102+
if (template.body() != null) {
103+
logger.info("Body: {}", new String(template.body()));
104+
}
105+
};
106+
}
107+
108+
public Retryer createRetryer() {
109+
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
110+
}
94111

95-
@Bean
96-
public RequestInterceptor requestInterceptor() {
97-
return new RequestInterceptor() {
112+
public Encoder createEncoder() {
113+
return new Encoder() {
98114
@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());
115+
public void encode(Object object, Type bodyType, feign.RequestTemplate template) throws EncodeException {
116+
try {
117+
String json = objectMapper.writeValueAsString(object);
118+
logger.debug("Encoding object to JSON: {}", json);
119+
120+
// Use the String version - it handles charset conversion internally
121+
template.body(json);
122+
123+
template.header("Content-Type", "application/json");
124+
} catch (JsonProcessingException e) {
125+
throw new EncodeException("Error encoding object to JSON", e);
126+
}
104127
}
105128
};
106129
}
107130

108-
@Bean
109-
public Retryer feignRetryer() {
110-
return new Retryer.Default(1000L, retryMaxInterval * 1000L, retryMaxAttempt);
131+
public Decoder createDecoder() {
132+
return new Decoder() {
133+
@Override
134+
public Object decode(Response response, Type type) throws IOException, DecodeException {
135+
if (response.body() == null) {
136+
return null;
137+
}
138+
try {
139+
String json = new String(response.body().asInputStream().readAllBytes(), StandardCharsets.UTF_8);
140+
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(type));
141+
} catch (IOException e) {
142+
throw new DecodeException(response.status(), "Error decoding JSON response", response.request(), e);
143+
}
144+
}
145+
};
111146
}
112-
}
147+
148+
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/AggregateFeignClient.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,19 @@
2020
package org.apache.cloudstack.storage.feign.client;
2121

2222
import org.apache.cloudstack.storage.feign.model.Aggregate;
23-
import org.apache.cloudstack.storage.feign.FeignConfiguration;
2423
import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
25-
import org.springframework.cloud.openfeign.FeignClient;
26-
import org.springframework.context.annotation.Lazy;
27-
import org.springframework.web.bind.annotation.PathVariable;
28-
import org.springframework.web.bind.annotation.RequestHeader;
29-
import org.springframework.web.bind.annotation.RequestMapping;
30-
import org.springframework.web.bind.annotation.RequestMethod;
31-
24+
import feign.Headers;
25+
import feign.Param;
26+
import feign.RequestLine;
3227
import java.net.URI;
3328

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

38-
//this method to get all aggregates and also filtered aggregates based on query params as a part of URL
39-
@RequestMapping(method=RequestMethod.GET)
40-
OntapResponse<Aggregate> getAggregateResponse(URI baseURL, @RequestHeader("Authorization") String header);
41-
42-
@RequestMapping(method=RequestMethod.GET, value="/{uuid}")
43-
Aggregate getAggregateByUUID(URI baseURL,@RequestHeader("Authorization") String header, @PathVariable(name = "uuid", required = true) String uuid);
31+
@RequestLine("GET /")
32+
@Headers("Authorization: {authHeader}")
33+
OntapResponse<Aggregate> getAggregateResponse(@Param("baseURL") URI baseURL, @Param("authHeader") String authHeader);
4434

35+
@RequestLine("GET /{uuid}")
36+
@Headers("Authorization: {authHeader}")
37+
Aggregate getAggregateByUUID(@Param("baseURL") URI baseURL, @Param("authHeader") String authHeader, @Param("uuid") String uuid);
4538
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/ClusterFeignClient.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@
1919

2020
package org.apache.cloudstack.storage.feign.client;
2121

22-
import org.apache.cloudstack.storage.feign.FeignConfiguration;
2322
import org.apache.cloudstack.storage.feign.model.Cluster;
24-
import org.springframework.cloud.openfeign.FeignClient;
25-
import org.springframework.web.bind.annotation.RequestHeader;
26-
import org.springframework.web.bind.annotation.RequestMapping;
27-
import org.springframework.web.bind.annotation.RequestMethod;
28-
23+
import feign.Headers;
24+
import feign.Param;
25+
import feign.RequestLine;
2926
import java.net.URI;
3027

31-
@FeignClient(name="ClusterClient", url="https://{clusterIP}/api/cluster", configuration = FeignConfiguration.class)
3228
public interface ClusterFeignClient {
3329

34-
@RequestMapping(method= RequestMethod.GET)
35-
Cluster getCluster(URI baseURL, @RequestHeader("Authorization") String header, @RequestHeader("return_records") boolean value);
36-
30+
@RequestLine("GET /")
31+
@Headers({"Authorization: {authHeader}", "return_records: {returnRecords}"})
32+
Cluster getCluster(@Param("baseURL") URI baseURL, @Param("authHeader") String authHeader, @Param("returnRecords") boolean returnRecords);
3733
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/JobFeignClient.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,15 @@
1818
*/
1919
package org.apache.cloudstack.storage.feign.client;
2020

21-
import org.apache.cloudstack.storage.feign.FeignConfiguration;
2221
import org.apache.cloudstack.storage.feign.model.Job;
23-
import org.springframework.cloud.openfeign.FeignClient;
24-
import org.springframework.context.annotation.Lazy;
25-
import org.springframework.web.bind.annotation.PathVariable;
26-
import org.springframework.web.bind.annotation.RequestHeader;
27-
import org.springframework.web.bind.annotation.RequestMapping;
28-
import org.springframework.web.bind.annotation.RequestMethod;
22+
import feign.Headers;
23+
import feign.Param;
24+
import feign.RequestLine;
2925
import java.net.URI;
3026

31-
/**
32-
* @author Administrator
33-
*
34-
*/
35-
@Lazy
36-
@FeignClient(name = "JobClient", url = "https://{clusterIP}/api/cluster/jobs" , configuration = FeignConfiguration.class)
3727
public interface JobFeignClient {
3828

39-
@RequestMapping(method = RequestMethod.GET, value="/{uuid}")
40-
Job getJobByUUID(URI baseURL, @RequestHeader("Authorization") String header, @PathVariable(name = "uuid", required = true) String uuid);
41-
29+
@RequestLine("GET /{uuid}")
30+
@Headers("Authorization: {authHeader}")
31+
Job getJobByUUID(URI baseURL, @Param("authHeader") String authHeader, @Param("uuid") String uuid);
4232
}

0 commit comments

Comments
 (0)