Fix formatting with spring-javaformat plugin.

This commit is contained in:
Olga Maciaszek-Sharma
2019-05-10 16:11:54 +02:00
parent e41b177129
commit ac247d985a
6 changed files with 35 additions and 20 deletions

View File

@@ -33,7 +33,6 @@ import org.springframework.cloud.cloudfoundry.CloudFoundryService;
* Discovery.
*
* @author Toshiaki Maki
*
* @see <a href="https://github.com/cloudfoundry/cf-app-sd-release">CF App Service
* Discovery Release</a>
* @see <a href=
@@ -45,7 +44,8 @@ public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscovery
private static final String INTERNAL_DOMAIN = "apps.internal";
CloudFoundryAppServiceDiscoveryClient(CloudFoundryOperations cloudFoundryOperations,
CloudFoundryService svc, CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
CloudFoundryService svc,
CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
super(cloudFoundryOperations, svc, cloudFoundryDiscoveryProperties);
}
@@ -57,9 +57,8 @@ public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscovery
@Override
public List<ServiceInstance> getInstances(String serviceId) {
return getCloudFoundryService()
.getApplicationInstances(serviceId)
.filter(tuple -> tuple.getT1().getUrls().stream()
.anyMatch(this::isInternalDomain))
.getApplicationInstances(serviceId).filter(tuple -> tuple.getT1()
.getUrls().stream().anyMatch(this::isInternalDomain))
.map(tuple -> {
ApplicationDetail applicationDetail = tuple.getT1();
InstanceDetail instanceDetail = tuple.getT2();
@@ -67,21 +66,18 @@ public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscovery
String applicationIndex = instanceDetail.getIndex();
String name = applicationDetail.getName();
String url = applicationDetail.getUrls().stream()
.filter(this::isInternalDomain)
.findFirst()
.map(x -> instanceDetail.getIndex() + "." + x)
.get();
.filter(this::isInternalDomain).findFirst()
.map(x -> instanceDetail.getIndex() + "." + x).get();
HashMap<String, String> metadata = new HashMap<>();
metadata.put("applicationId", applicationId);
metadata.put("instanceId", applicationIndex);
return (ServiceInstance) new DefaultServiceInstance(name, url, 8080,
false, metadata);
})
.collectList()
.block();
}).collectList().block();
}
private boolean isInternalDomain(String url) {
return url != null && url.endsWith(INTERNAL_DOMAIN);
}
}

View File

@@ -101,4 +101,5 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
CloudFoundryService getCloudFoundryService() {
return this.cloudFoundryService;
}
}

View File

@@ -35,7 +35,8 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
@ConditionalOnClass(CloudFoundryOperations.class)
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.enabled", matchIfMissing = true)
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.enabled",
matchIfMissing = true)
@EnableConfigurationProperties(CloudFoundryDiscoveryProperties.class)
public class CloudFoundryDiscoveryClientConfiguration {
@@ -47,24 +48,30 @@ public class CloudFoundryDiscoveryClientConfiguration {
}
@Configuration
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "false", matchIfMissing = true)
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns",
havingValue = "false", matchIfMissing = true)
public static class CloudFoundryDiscoveryClientConfig {
@Bean
@ConditionalOnMissingBean(DiscoveryClient.class)
public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
CloudFoundryService svc,
public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(
CloudFoundryOperations cf, CloudFoundryService svc,
CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
return new CloudFoundryDiscoveryClient(cf, svc,
cloudFoundryDiscoveryProperties);
}
}
@Configuration
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "true")
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns",
havingValue = "true")
public static class DnsBasedCloudFoundryDiscoveryClientConfig {
@Bean
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true")
@ConditionalOnProperty(
value = "spring.cloud.cloudfoundry.discovery.use-container-ip",
havingValue = "true")
@ConditionalOnMissingBean(DiscoveryClient.class)
public SimpleDnsBasedDiscoveryClient discoveryClient(
ObjectProvider<ServiceIdToHostnameConverter> provider,
@@ -75,7 +82,9 @@ public class CloudFoundryDiscoveryClientConfiguration {
}
@Bean
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false", matchIfMissing = true)
@ConditionalOnProperty(
value = "spring.cloud.cloudfoundry.discovery.use-container-ip",
havingValue = "false", matchIfMissing = true)
@ConditionalOnMissingBean(DiscoveryClient.class)
public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(
CloudFoundryOperations cf, CloudFoundryService svc,

View File

@@ -42,7 +42,8 @@ public class CloudFoundryHeartbeatSender implements ApplicationEventPublisherAwa
this.client = client;
}
@Scheduled(fixedDelayString = "${spring.cloud.cloudfoundry.discovery.heartbeatFrequency:5000}")
@Scheduled(
fixedDelayString = "${spring.cloud.cloudfoundry.discovery.heartbeatFrequency:5000}")
public void poll() {
if (this.publisher != null) {
List<String> services = this.client.getServices();

View File

@@ -39,8 +39,11 @@ import static org.mockito.Mockito.mock;
* @author Toshiaki Maki
*/
public class CloudFoundryAppServiceDiscoveryClientTest {
private CloudFoundryAppServiceDiscoveryClient discoveryClient;
private CloudFoundryOperations cloudFoundryOperations;
private CloudFoundryService cloudFoundryService;
@Before
@@ -129,4 +132,5 @@ public class CloudFoundryAppServiceDiscoveryClientTest {
assertThat(instances).isEmpty();
}
}

View File

@@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CloudFoundryDiscoveryClientConfiguration}.
*
* @author Toshiaki Maki
*/
public class CloudFoundryDiscoveryClientConfigurationTest {
@@ -102,6 +103,7 @@ public class CloudFoundryDiscoveryClientConfigurationTest {
@Configuration
public static class CloudFoundryConfig {
@Bean
public CloudFoundryOperations cloudFoundryOperations() {
return Mockito.mock(CloudFoundryOperations.class);
@@ -111,5 +113,7 @@ public class CloudFoundryDiscoveryClientConfigurationTest {
public CloudFoundryService cloudFoundryService() {
return Mockito.mock(CloudFoundryService.class);
}
}
}