forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Feignconfiguration and volume feignClient along with desired POJOs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...ge/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/FeignConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
|
|
||
| @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); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
...ume/ontap/src/main/java/org/apache/cloudstack/storage/feign/client/VolumeFeignClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ); | ||
|
|
||
|
|
||
| } |
83 changes: 83 additions & 0 deletions
83
...orage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/Aggregate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 + "]"; | ||
| } | ||
|
|
||
| } |
12 changes: 12 additions & 0 deletions
12
.../volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/AntiRansomware.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
|
15 changes: 15 additions & 0 deletions
15
...ge/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/ExportPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
|
|
16 changes: 16 additions & 0 deletions
16
...ins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/Nas.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
26 changes: 26 additions & 0 deletions
26
.../storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/Policy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...ins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/Qos.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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