From 5f396d3da0ce68b91af4cbcbc13ac11a130f9c62 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 17 Jan 2020 18:29:47 -0500 Subject: [PATCH] Removes ribbon support --- ...CloudFoundryRibbonClientConfiguration.java | 62 --------- .../discovery/CloudFoundryServer.java | 58 --------- .../discovery/CloudFoundryServerList.java | 95 -------------- .../RibbonCloudFoundryAutoConfiguration.java | 45 ------- .../main/resources/META-INF/spring.factories | 3 +- .../discovery/AdhocTestSuite.java | 2 +- .../discovery/CloudFoundryServerListTest.java | 123 ------------------ 7 files changed, 2 insertions(+), 386 deletions(-) delete mode 100644 spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryRibbonClientConfiguration.java delete mode 100644 spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServer.java delete mode 100644 spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerList.java delete mode 100644 spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/RibbonCloudFoundryAutoConfiguration.java delete mode 100644 spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerListTest.java diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryRibbonClientConfiguration.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryRibbonClientConfiguration.java deleted file mode 100644 index 0f84271..0000000 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryRibbonClientConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2019 the original author or 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 - * - * https://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.springframework.cloud.cloudfoundry.discovery; - -import javax.annotation.PostConstruct; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.cloudfoundry.CloudFoundryService; -import org.springframework.cloud.netflix.ribbon.RibbonClientName; -import org.springframework.cloud.netflix.ribbon.RibbonUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Josh Long - */ -@Configuration(proxyBeanMethods = false) -public class CloudFoundryRibbonClientConfiguration { - - @RibbonClientName - private String serviceId; - - public CloudFoundryRibbonClientConfiguration() { - } - - public CloudFoundryRibbonClientConfiguration(String svcId) { - this.serviceId = svcId; - } - - @Bean - @ConditionalOnMissingBean - public ServerList ribbonServerList(CloudFoundryService svc, IClientConfig config, - CloudFoundryDiscoveryProperties properties) { - CloudFoundryServerList cloudFoundryServerList = new CloudFoundryServerList(svc, - properties); - cloudFoundryServerList.initWithNiwsConfig(config); - return cloudFoundryServerList; - } - - @PostConstruct - public void postConstruct() { - RibbonUtils.initializeRibbonDefaults(this.serviceId); - } - -} diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServer.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServer.java deleted file mode 100644 index d516f82..0000000 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2013-2019 the original author or 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 - * - * https://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.springframework.cloud.cloudfoundry.discovery; - -import com.netflix.loadbalancer.Server; - -/** - * @author Josh Long - */ -public class CloudFoundryServer extends Server { - - private final MetaInfo metaInfo; - - public CloudFoundryServer(String appName, String uri, int port) { - super(uri, port); - this.metaInfo = new MetaInfo() { - @Override - public String getAppName() { - return appName; - } - - @Override - public String getServerGroup() { - return null; - } - - @Override - public String getServiceIdForDiscovery() { - return appName; - } - - @Override - public String getInstanceId() { - return appName; - } - }; - } - - @Override - public MetaInfo getMetaInfo() { - return this.metaInfo; - } - -} diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerList.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerList.java deleted file mode 100644 index 2f307a1..0000000 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerList.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2013-2019 the original author or 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 - * - * https://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.springframework.cloud.cloudfoundry.discovery; - -import java.util.ArrayList; -import java.util.List; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractServerList; - -import org.springframework.cloud.cloudfoundry.CloudFoundryService; -import org.springframework.cloud.netflix.ribbon.RibbonProperties; -import org.springframework.util.Assert; - -/** - * @author Josh Long - */ -public class CloudFoundryServerList extends AbstractServerList { - - private final CloudFoundryService cloudFoundryService; - - private final CloudFoundryDiscoveryProperties properties; - - private IClientConfig clientConfig; - - private String serviceId; - - CloudFoundryServerList(CloudFoundryService svc, - CloudFoundryDiscoveryProperties properties) { - this.cloudFoundryService = svc; - this.properties = properties; - } - - @Override - public void initWithNiwsConfig(IClientConfig clientConfig) { - this.clientConfig = clientConfig; - this.serviceId = clientConfig.getClientName(); - } - - @Override - public List getInitialListOfServers() { - return cloudFoundryServers(); - } - - @Override - public List getUpdatedListOfServers() { - return cloudFoundryServers(); - } - - private List cloudFoundryServers() { - Assert.notNull(this.clientConfig, "clientConfig may not be null"); - - RibbonProperties ribbon = RibbonProperties.from(this.clientConfig); - - Boolean secure = ribbon.getSecure(); - Integer securePort = ribbon.getSecurePort(); - Integer nonSecurePort = ribbon.getPort(); - - final int port; - if (secure != null && secure && securePort != null) { - port = securePort; - } - else if (nonSecurePort != null) { - port = nonSecurePort; - } - else { - port = this.properties.getDefaultServerPort(); - } - - return this.cloudFoundryService.getApplicationInstances(this.serviceId) - .map(tpl -> new CloudFoundryServer(tpl.getT1().getName(), - tpl.getT1().getUrls().get(0), port)) - .collectList().blockOptional().orElse(new ArrayList<>()); - } - - // for testing - String getServiceId() { - return this.serviceId; - } - -} diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/RibbonCloudFoundryAutoConfiguration.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/RibbonCloudFoundryAutoConfiguration.java deleted file mode 100644 index 671b79f..0000000 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/RibbonCloudFoundryAutoConfiguration.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2013-2019 the original author or 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 - * - * https://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.springframework.cloud.cloudfoundry.discovery; - -import com.netflix.client.IClient; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; -import org.springframework.cloud.netflix.ribbon.RibbonClients; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.context.annotation.Configuration; - -/** - * Auto configuration for Ribbon. - * - * @author Josh Long - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnClass(IClient.class) -@ConditionalOnBean(SpringClientFactory.class) -@ConditionalOnProperty(value = "ribbon.cloudfoundry.enabled", matchIfMissing = true) -@AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = CloudFoundryRibbonClientConfiguration.class) -public class RibbonCloudFoundryAutoConfiguration { - -} diff --git a/spring-cloud-cloudfoundry-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-cloudfoundry-discovery/src/main/resources/META-INF/spring.factories index 5cebac6..29579f6 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-cloudfoundry-discovery/src/main/resources/META-INF/spring.factories @@ -1,5 +1,4 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.cloudfoundry.discovery.RibbonCloudFoundryAutoConfiguration +#org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ # Discovery Client Configuration org.springframework.cloud.client.discovery.EnableDiscoveryClient=\ org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClientConfiguration, \ diff --git a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/AdhocTestSuite.java b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/AdhocTestSuite.java index 5d309d5..c3c080b 100644 --- a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/AdhocTestSuite.java +++ b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/AdhocTestSuite.java @@ -27,7 +27,7 @@ import org.junit.runners.Suite.SuiteClasses; * @author Dave Syer */ @RunWith(Suite.class) -@SuiteClasses({ CloudFoundryServerListTest.class }) +@SuiteClasses({}) @Ignore public class AdhocTestSuite { diff --git a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerListTest.java b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerListTest.java deleted file mode 100644 index 2ccfc5f..0000000 --- a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryServerListTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2013-2019 the original author or 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 - * - * https://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.springframework.cloud.cloudfoundry.discovery; - -import java.util.List; - -import com.netflix.client.config.CommonClientConfigKey; -import com.netflix.client.config.IClientConfig; -import org.cloudfoundry.operations.applications.ApplicationDetail; -import org.cloudfoundry.operations.applications.InstanceDetail; -import org.junit.Before; -import org.junit.Test; -import reactor.core.publisher.Flux; -import reactor.util.function.Tuple2; -import reactor.util.function.Tuples; - -import org.springframework.cloud.cloudfoundry.CloudFoundryService; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author Josh Long - */ -public class CloudFoundryServerListTest { - - private CloudFoundryServerList cloudFoundryServerList; - - private String serviceId = "foo-service"; - - @Before - public void setUp() { - IClientConfig iClientConfig = IClientConfig.Builder.newBuilder(this.serviceId) - .withSecure(true).build(); - iClientConfig.set(CommonClientConfigKey.SecurePort, 443); - - Tuple2 tuple2 = getInstanceDetail(); - - CloudFoundryService cfs = mock(CloudFoundryService.class); - when(cfs.getApplicationInstances(this.serviceId)).thenReturn(Flux.just(tuple2)); - - this.cloudFoundryServerList = new CloudFoundryServerList(cfs, - new CloudFoundryDiscoveryProperties()); - this.cloudFoundryServerList.initWithNiwsConfig(iClientConfig); - } - - private Tuple2 getInstanceDetail() { - // @formatter:off - ApplicationDetail applicationDetail = ApplicationDetail - .builder() - .instances(2) - .name("my-app") - .stack("stack") - .memoryLimit(1024) - .id("id") - .requestedState("requestedState") - .runningInstances(2) - .url("https://my-app.cfapps.io") - .diskQuota(20) - .build(); - - InstanceDetail instanceDetail = InstanceDetail - .builder() - .index("0") - .build(); - // @formatter:on - - return Tuples.of(applicationDetail, instanceDetail); - } - - @Test - public void testListOfServers() { - List initialListOfServers = this.cloudFoundryServerList - .getInitialListOfServers(); - List updatedListOfServers = this.cloudFoundryServerList - .getUpdatedListOfServers(); - assertThat(initialListOfServers) - .containsExactly(updatedListOfServers.toArray(new CloudFoundryServer[0])) - .hasSize(1); - - CloudFoundryServer server = initialListOfServers.get(0); - assertThat(server.getPort()).isEqualTo(443); - } - - @Test - public void testDefaultServerPort() { - IClientConfig iClientConfig = mock(IClientConfig.class); - when(iClientConfig.getClientName()).thenReturn(this.serviceId); - - Tuple2 tuple2 = getInstanceDetail(); - - CloudFoundryService cfs = mock(CloudFoundryService.class); - when(cfs.getApplicationInstances(this.serviceId)).thenReturn(Flux.just(tuple2)); - - CloudFoundryServerList serverList = new CloudFoundryServerList(cfs, - new CloudFoundryDiscoveryProperties()); - serverList.initWithNiwsConfig(iClientConfig); - - CloudFoundryServer server = serverList.getInitialListOfServers().get(0); - assertThat(server.getPort()).isEqualTo(80); - } - - @Test - public void testInit() { - assertThat(this.cloudFoundryServerList.getServiceId()).isEqualTo(this.serviceId); - } - -}