diff --git a/pom.xml b/pom.xml index 678c7f66..1551ab60 100644 --- a/pom.xml +++ b/pom.xml @@ -79,11 +79,13 @@ 1.3.74 1.16.8 + 2.5 1.3.3.RELEASE 1.0.4.RELEASE 1.0.4.RELEASE 1.0.0.RC1 1.0.6.RELEASE + 4.2.5.RELEASE 0.14.2 @@ -97,6 +99,8 @@ spring-cloud-starter-kubernetes spring-cloud-kubernetes-ribbon spring-cloud-kubernetes-zipkin + spring-cloud-kubernetes-compat + spring-cloud-kubernetes-hystrix @@ -114,12 +118,24 @@ ${project.version} + + io.fabric8 + spring-cloud-kubernetes-hystrix + ${project.version} + + io.fabric8 spring-cloud-kubernetes-ribbon ${project.version} + + io.fabric8 + spring-cloud-kubernetes-zipkin + ${project.version} + + io.fabric8 kubernetes-client @@ -164,6 +180,18 @@ spring-cloud-context ${spring-cloud.version} + + org.springframework + spring-web + ${spring.version} + + + + javax.servlet + servlet-api + ${servlet-api.version} + + org.projectlombok lombok diff --git a/spring-cloud-kubernetes-compat/pom.xml b/spring-cloud-kubernetes-compat/pom.xml new file mode 100644 index 00000000..a7389ae8 --- /dev/null +++ b/spring-cloud-kubernetes-compat/pom.xml @@ -0,0 +1,45 @@ + + + + + + spring-cloud-kubernetes-project + io.fabric8 + 0.0.3-SNAPSHOT + + 4.0.0 + + io.fabric8 + spring-cloud-kubernetes-compat + Fabric8 :: Spring Cloud Kubernetes :: Compatibility + + Compatibility module to cover for the lack of InetUtils in older version of Spring Cloud Commons. + + + + + org.projectlombok + lombok + 1.16.8 + compile + true + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-compat/src/main/java/org/springframework/cloud/commons/util/InetUtils.java b/spring-cloud-kubernetes-compat/src/main/java/org/springframework/cloud/commons/util/InetUtils.java new file mode 100644 index 00000000..cb85bccc --- /dev/null +++ b/spring-cloud-kubernetes-compat/src/main/java/org/springframework/cloud/commons/util/InetUtils.java @@ -0,0 +1,45 @@ +package org.springframework.cloud.commons.util; + +import lombok.Data; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; + +/** + * Copied from spring-cloud-commons as a workaround for version incompatibilities + */ +public class InetUtils { + + public static int getIpAddressAsInt(String host) { + return new HostInfo(host).getIpAddressAsInt(); + } + + @Data + public static final class HostInfo { + public boolean override; + private String ipAddress; + private String hostname; + + HostInfo(String hostname) { + this.hostname = hostname; + } + + HostInfo() { + } + + public int getIpAddressAsInt() { + InetAddress inetAddress = null; + String host = this.ipAddress; + if (host == null) { + host = this.hostname; + } + try { + inetAddress = InetAddress.getByName(host); + } catch (final UnknownHostException e) { + throw new IllegalArgumentException(e); + } + return ByteBuffer.wrap(inetAddress.getAddress()).getInt(); + } + } +} \ No newline at end of file diff --git a/spring-cloud-kubernetes-hystrix/pom.xml b/spring-cloud-kubernetes-hystrix/pom.xml new file mode 100644 index 00000000..c09ad838 --- /dev/null +++ b/spring-cloud-kubernetes-hystrix/pom.xml @@ -0,0 +1,74 @@ + + + + + + spring-cloud-kubernetes-project + io.fabric8 + 0.0.3-SNAPSHOT + + 4.0.0 + + io.fabric8 + spring-cloud-kubernetes-hystrix + Fabric8 :: Spring Cloud Kubernetes :: Hystrix + + + + javax.servlet + servlet-api + true + + + com.netflix.hystrix + hystrix-core + true + + + com.netflix.hystrix + hystrix-javanica + true + + + org.springframework.boot + spring-boot-autoconfigure + true + + + + org.springframework.cloud + spring-cloud-commons + true + + + + org.springframework.cloud + spring-cloud-context + true + + + + org.springframework + spring-web + true + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixFilterAutoConfiguration.java b/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixFilterAutoConfiguration.java new file mode 100644 index 00000000..f2183f4b --- /dev/null +++ b/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixFilterAutoConfiguration.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 to the original authors. + * + * Licensed 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 io.fabric8.spring.cloud.kubernetes.hystrix; + +import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnProperty(value = "spring.sleuth.hystrix.strategy.enabled", matchIfMissing = true) +@ConditionalOnClass(HystrixCommand.class) +public class HystrixFilterAutoConfiguration { + + @Bean + HystrixRequestContextServletFilter hystrixRequestContextServletFilter() { + return new HystrixRequestContextServletFilter(); + } +} diff --git a/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixRequestContextServletFilter.java b/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixRequestContextServletFilter.java new file mode 100644 index 00000000..a8f6bb8b --- /dev/null +++ b/spring-cloud-kubernetes-hystrix/src/main/java/io/fabric8/spring/cloud/kubernetes/hystrix/HystrixRequestContextServletFilter.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016 to the original authors. + * + * Licensed 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 io.fabric8.spring.cloud.kubernetes.hystrix; + +import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class HystrixRequestContextServletFilter extends OncePerRequestFilter { + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { + HystrixRequestContext context = HystrixRequestContext.initializeContext(); + try { + chain.doFilter(request, response); + } finally { + context.shutdown(); + } + } + +} \ No newline at end of file diff --git a/spring-cloud-kubernetes-hystrix/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-hystrix/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..21ca389f --- /dev/null +++ b/spring-cloud-kubernetes-hystrix/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +io.fabric8.spring.cloud.kubernetes.hystrix.HystrixFilterAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-starter-kubernetes/pom.xml b/spring-cloud-starter-kubernetes/pom.xml index 928b79de..527e9d32 100644 --- a/spring-cloud-starter-kubernetes/pom.xml +++ b/spring-cloud-starter-kubernetes/pom.xml @@ -40,10 +40,20 @@ spring-cloud-kubernetes-discovery + + io.fabric8 + spring-cloud-kubernetes-hystrix + + io.fabric8 spring-cloud-kubernetes-ribbon + + + io.fabric8 + spring-cloud-kubernetes-zipkin + \ No newline at end of file