-
Notifications
You must be signed in to change notification settings - Fork 0
Feignconfiguration and volume feignClient along with desired POJOs with cstack 28 #4
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
Changes from all commits
2e0efe8
a96eb9e
0f09c5f
2cc4b0c
033c23d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,25 @@ | |
| <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> | ||
| <json.version>20230227</json.version> | ||
| <swagger-annotations.version>1.6.2</swagger-annotations.version> | ||
| <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> | ||
| <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.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> | ||
|
|
@@ -36,18 +55,52 @@ | |
| <dependency> | ||
| <groupId>org.json</groupId> | ||
| <artifactId>json</artifactId> | ||
| <version>20230227</version> | ||
| <version>${json.version}</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> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now yes, we can remove it later if required. |
||
| <groupId>io.swagger</groupId> | ||
| <artifactId>swagger-annotations</artifactId> | ||
| <version>${swagger-annotations.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>${maven-compiler-plugin.version}</version> | ||
| <configuration> | ||
| <source>11</source> | ||
| <target>11</target> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>${maven-surefire-plugin.version}</version> | ||
| <configuration> | ||
| <skipTests>true</skipTests> | ||
| </configuration> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| 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 { | ||
rajiv-jain-netapp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| 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,107 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| 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") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see in some model we are using JsonProperty and SerializedName which serves same purpose but are from 2 different libraries. What's your thought on using Jackson or gson any one of the above across our models. |
||
| private String name = null; | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(getName(), getUuid()); | ||
| } | ||
|
|
||
| @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,34 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.cloudstack.storage.feign.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| public class AntiRansomware { | ||
| @JsonProperty("state") | ||
| private String state; | ||
|
|
||
| public String getState() { | ||
| return state; | ||
| } | ||
|
|
||
| public void setState(String state) { | ||
| this.state = state; | ||
| } | ||
| } |
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.
Need to include both spring-web and spring-boot-starter(v2.7.10), if we intend to use @FeignClient annotation in VolumeFeignClient.java
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.
As mentioned earlier, I don't see any compilation issues with the newly added code. If additional dependencies are required as we proceed, we can incorporate them accordingly. For now, I'd prefer not to include all potential dependencies until the corresponding code is in place.