Added checkstyle
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -30,6 +30,7 @@ import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider;
|
||||
import org.cloudfoundry.reactor.uaa.ReactorUaaClient;
|
||||
import org.cloudfoundry.routing.RoutingClient;
|
||||
import org.cloudfoundry.uaa.UaaClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -46,9 +47,12 @@ import org.springframework.context.annotation.Lazy;
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.cloudfoundry", name = {"username", "password"})
|
||||
@ConditionalOnClass(name = {"reactor.core.publisher.Flux", "org.cloudfoundry.operations.DefaultCloudFoundryOperations",
|
||||
"org.cloudfoundry.reactor.client.ReactorCloudFoundryClient", "org.reactivestreams.Publisher"})
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.cloudfoundry", name = { "username",
|
||||
"password" })
|
||||
@ConditionalOnClass(name = { "reactor.core.publisher.Flux",
|
||||
"org.cloudfoundry.operations.DefaultCloudFoundryOperations",
|
||||
"org.cloudfoundry.reactor.client.ReactorCloudFoundryClient",
|
||||
"org.reactivestreams.Publisher" })
|
||||
@EnableConfigurationProperties(CloudFoundryProperties.class)
|
||||
public class CloudFoundryClientAutoConfiguration {
|
||||
|
||||
@@ -61,67 +65,59 @@ public class CloudFoundryClientAutoConfiguration {
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public CloudFoundryService cloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
|
||||
public CloudFoundryService cloudFoundryService(
|
||||
CloudFoundryOperations cloudFoundryOperations) {
|
||||
return new CloudFoundryService(cloudFoundryOperations);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public DefaultCloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient,
|
||||
DopplerClient dopplerClient,
|
||||
RoutingClient routingClient,
|
||||
UaaClient uaaClient) {
|
||||
public DefaultCloudFoundryOperations cloudFoundryOperations(
|
||||
CloudFoundryClient cloudFoundryClient, DopplerClient dopplerClient,
|
||||
RoutingClient routingClient, UaaClient uaaClient) {
|
||||
String organization = this.cloudFoundryProperties.getOrg();
|
||||
String space = this.cloudFoundryProperties.getSpace();
|
||||
return DefaultCloudFoundryOperations
|
||||
.builder()
|
||||
.cloudFoundryClient(cloudFoundryClient)
|
||||
.dopplerClient(dopplerClient)
|
||||
.routingClient(routingClient)
|
||||
.uaaClient(uaaClient)
|
||||
.organization(organization)
|
||||
.space(space)
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
|
||||
return ReactorCloudFoundryClient.builder()
|
||||
.connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider)
|
||||
.build();
|
||||
return DefaultCloudFoundryOperations.builder()
|
||||
.cloudFoundryClient(cloudFoundryClient).dopplerClient(dopplerClient)
|
||||
.routingClient(routingClient).uaaClient(uaaClient)
|
||||
.organization(organization).space(space).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public DopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
|
||||
return ReactorDopplerClient.builder()
|
||||
.connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider)
|
||||
.build();
|
||||
public ReactorCloudFoundryClient cloudFoundryClient(
|
||||
ConnectionContext connectionContext, TokenProvider tokenProvider) {
|
||||
return ReactorCloudFoundryClient.builder().connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public RoutingClient routingClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
|
||||
return ReactorRoutingClient.builder()
|
||||
.connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider)
|
||||
.build();
|
||||
public DopplerClient dopplerClient(ConnectionContext connectionContext,
|
||||
TokenProvider tokenProvider) {
|
||||
return ReactorDopplerClient.builder().connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
|
||||
return ReactorUaaClient.builder()
|
||||
.connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider)
|
||||
.build();
|
||||
public RoutingClient routingClient(ConnectionContext connectionContext,
|
||||
TokenProvider tokenProvider) {
|
||||
return ReactorRoutingClient.builder().connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnMissingBean
|
||||
public ReactorUaaClient uaaClient(ConnectionContext connectionContext,
|
||||
TokenProvider tokenProvider) {
|
||||
return ReactorUaaClient.builder().connectionContext(connectionContext)
|
||||
.tokenProvider(tokenProvider).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -131,10 +127,8 @@ public class CloudFoundryClientAutoConfiguration {
|
||||
String apiHost = this.cloudFoundryProperties.getUrl();
|
||||
Boolean skipSslValidation = this.cloudFoundryProperties.isSkipSslValidation();
|
||||
|
||||
return DefaultConnectionContext.builder()
|
||||
.apiHost(apiHost)
|
||||
.skipSslValidation(skipSslValidation)
|
||||
.build();
|
||||
return DefaultConnectionContext.builder().apiHost(apiHost)
|
||||
.skipSslValidation(skipSslValidation).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -143,11 +137,8 @@ public class CloudFoundryClientAutoConfiguration {
|
||||
public PasswordGrantTokenProvider tokenProvider() {
|
||||
String username = this.cloudFoundryProperties.getUsername();
|
||||
String password = this.cloudFoundryProperties.getPassword();
|
||||
return PasswordGrantTokenProvider.builder()
|
||||
.password(password)
|
||||
.username(username)
|
||||
return PasswordGrantTokenProvider.builder().password(password).username(username)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package org.springframework.cloud.cloudfoundry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Configuration properties for a connection to a Cloud Foundry platform.
|
||||
*
|
||||
@@ -69,6 +69,10 @@ public class CloudFoundryProperties implements InitializingBean {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String cloudControllerUrl) {
|
||||
this.url = cloudControllerUrl;
|
||||
}
|
||||
|
||||
private String safeUrl(String t) {
|
||||
String input = t.trim().toLowerCase();
|
||||
Pattern p = Pattern.compile("(http(s)?://)(.*)");
|
||||
@@ -82,10 +86,6 @@ public class CloudFoundryProperties implements InitializingBean {
|
||||
return t;
|
||||
}
|
||||
|
||||
public void setUrl(String cloudControllerUrl) {
|
||||
this.url = cloudControllerUrl;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class CloudFoundryProperties implements InitializingBean {
|
||||
}
|
||||
|
||||
public boolean isSkipSslValidation() {
|
||||
return skipSslValidation;
|
||||
return this.skipSslValidation;
|
||||
}
|
||||
|
||||
public boolean getSkipSslValidation() {
|
||||
@@ -146,6 +146,8 @@ public class CloudFoundryProperties implements InitializingBean {
|
||||
vals.put("url", getUrl());
|
||||
vals.put("username", getUsername());
|
||||
vals.put("password", getPassword());
|
||||
vals.forEach((key, value) -> Assert.hasText(value, String.format("'%s' must be provided", key)));
|
||||
vals.forEach((key, value) -> Assert.hasText(value,
|
||||
String.format("'%s' must be provided", key)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.cloudfoundry;
|
||||
|
||||
|
||||
import org.cloudfoundry.operations.CloudFoundryOperations;
|
||||
import org.cloudfoundry.operations.applications.ApplicationDetail;
|
||||
import org.cloudfoundry.operations.applications.GetApplicationRequest;
|
||||
@@ -38,15 +37,17 @@ public class CloudFoundryService {
|
||||
this.cloudFoundryOperations = cloudFoundryOperations;
|
||||
}
|
||||
|
||||
public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
|
||||
GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
|
||||
return this.cloudFoundryOperations
|
||||
.applications()
|
||||
.get(applicationRequest)
|
||||
public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(
|
||||
String serviceId) {
|
||||
GetApplicationRequest applicationRequest = GetApplicationRequest.builder()
|
||||
.name(serviceId).build();
|
||||
return this.cloudFoundryOperations.applications().get(applicationRequest)
|
||||
.flatMapMany(applicationDetail -> {
|
||||
Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
|
||||
Flux<InstanceDetail> ids = Flux
|
||||
.fromStream(applicationDetail.getInstanceDetails().stream())
|
||||
.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
|
||||
Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
|
||||
Flux<ApplicationDetail> generate = Flux
|
||||
.generate(sink -> sink.next(applicationDetail));
|
||||
return generate.zipWith(ids);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.cloudfoundry.CloudFoundryClientAutoConfiguration
|
||||
org.springframework.cloud.cloudfoundry.CloudFoundryClientAutoConfiguration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -27,6 +27,7 @@ import org.cloudfoundry.reactor.uaa.ReactorUaaClient;
|
||||
import org.cloudfoundry.routing.RoutingClient;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
@@ -35,13 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CloudFoundryClientAutoConfigurationTest {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CloudFoundryClientAutoConfiguration.class));
|
||||
private final static String[] SPRING_CLOUD_PROPERTIES = {
|
||||
"spring.cloud.cloudfoundry.username", "spring.cloud.cloudfoundry.password", };
|
||||
|
||||
private final static String SPRING_CLOUD_PROPERTIES[] = {
|
||||
"spring.cloud.cloudfoundry.username",
|
||||
"spring.cloud.cloudfoundry.password",
|
||||
};
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(CloudFoundryClientAutoConfiguration.class));
|
||||
|
||||
private static boolean requiredPropertiesSet() {
|
||||
for (String k : SPRING_CLOUD_PROPERTIES) {
|
||||
@@ -53,23 +53,19 @@ public class CloudFoundryClientAutoConfigurationTest {
|
||||
}
|
||||
|
||||
private static String envVarFromProperty(String propertyName) {
|
||||
return propertyName
|
||||
.replaceAll("\\.", "_")
|
||||
.toUpperCase();
|
||||
return propertyName.replaceAll("\\.", "_").toUpperCase();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoConfiguresBeansWithAllProperties() {
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.cloud.cloudfoundry.username=user",
|
||||
"spring.cloud.cloudfoundry.password=secret",
|
||||
"spring.cloud.cloudfoundry.org=myorg",
|
||||
"spring.cloud.cloudfoundry.space=myspace")
|
||||
.run((context) -> {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.username=user",
|
||||
"spring.cloud.cloudfoundry.password=secret",
|
||||
"spring.cloud.cloudfoundry.org=myorg",
|
||||
"spring.cloud.cloudfoundry.space=myspace").run((context) -> {
|
||||
assertCloudFoundryClientBeansPresent(context);
|
||||
|
||||
DefaultCloudFoundryOperations operations = context.getBean(DefaultCloudFoundryOperations.class);
|
||||
DefaultCloudFoundryOperations operations = context
|
||||
.getBean(DefaultCloudFoundryOperations.class);
|
||||
assertThat(operations.getOrganization()).isEqualTo("myorg");
|
||||
assertThat(operations.getSpace()).isEqualTo("myspace");
|
||||
});
|
||||
@@ -77,14 +73,12 @@ public class CloudFoundryClientAutoConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void autoConfiguresBeansWithMinimalProperties() {
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.cloud.cloudfoundry.username=user",
|
||||
"spring.cloud.cloudfoundry.password=secret")
|
||||
.run((context) -> {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.username=user",
|
||||
"spring.cloud.cloudfoundry.password=secret").run((context) -> {
|
||||
assertCloudFoundryClientBeansPresent(context);
|
||||
|
||||
DefaultCloudFoundryOperations operations = context.getBean(DefaultCloudFoundryOperations.class);
|
||||
DefaultCloudFoundryOperations operations = context
|
||||
.getBean(DefaultCloudFoundryOperations.class);
|
||||
assertThat(operations.getOrganization()).isNullOrEmpty();
|
||||
assertThat(operations.getSpace()).isNullOrEmpty();
|
||||
});
|
||||
@@ -94,23 +88,21 @@ public class CloudFoundryClientAutoConfigurationTest {
|
||||
public void organizationsRetrievedWithUserProvidedProperties() {
|
||||
Assume.assumeTrue(requiredPropertiesSet());
|
||||
|
||||
this.contextRunner
|
||||
.run((context) -> {
|
||||
assertCloudFoundryClientBeansPresent(context);
|
||||
CloudFoundryOperations operations = context.getBean(CloudFoundryOperations.class);
|
||||
this.contextRunner.run((context) -> {
|
||||
assertCloudFoundryClientBeansPresent(context);
|
||||
CloudFoundryOperations operations = context
|
||||
.getBean(CloudFoundryOperations.class);
|
||||
|
||||
OrganizationSummary summary = operations
|
||||
.organizations()
|
||||
.list()
|
||||
.blockFirst();
|
||||
OrganizationSummary summary = operations.organizations().list().blockFirst();
|
||||
|
||||
assertThat(summary).isNotNull();
|
||||
assertThat(summary.getId()).isNotEmpty();
|
||||
assertThat(summary.getName()).isNotEmpty();
|
||||
});
|
||||
assertThat(summary).isNotNull();
|
||||
assertThat(summary.getId()).isNotEmpty();
|
||||
assertThat(summary.getName()).isNotEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private void assertCloudFoundryClientBeansPresent(AssertableApplicationContext context) {
|
||||
private void assertCloudFoundryClientBeansPresent(
|
||||
AssertableApplicationContext context) {
|
||||
assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
|
||||
assertThat(context).hasSingleBean(DefaultCloudFoundryOperations.class);
|
||||
assertThat(context).hasSingleBean(DefaultConnectionContext.class);
|
||||
@@ -119,4 +111,5 @@ public class CloudFoundryClientAutoConfigurationTest {
|
||||
assertThat(context).hasSingleBean(PasswordGrantTokenProvider.class);
|
||||
assertThat(context).hasSingleBean(ReactorUaaClient.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user