Skip to content

Commit

Permalink
Update CloudFoundry deployers to include ApplicationLogAccessor (spri…
Browse files Browse the repository at this point in the history
…ng-cloud#5536)

* Update CloudFoundry deployers to include ApplicationLogAccessor

This commit picks up the changes in Spring Cloud Deployer spring-cloud/spring-cloud-deployer@a36ee24

* Fixing tests requiring LogCacheClient
  • Loading branch information
onobc authored Nov 4, 2023
1 parent e6a413c commit 0ca477f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 35 deletions.
22 changes: 8 additions & 14 deletions .settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,27 @@
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
<username>${env.ARTIFACTORY_USERNAME}</username>
<password>${env.ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>spring-snapshots</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
<username>${env.ARTIFACTORY_USERNAME}</username>
<password>${env.ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>spring-milestones</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
<username>${env.ARTIFACTORY_USERNAME}</username>
<password>${env.ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>spring-staging</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
<username>${env.ARTIFACTORY_USERNAME}</username>
<password>${env.ARTIFACTORY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should point their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation>
<activeByDefault>true</activeByDefault>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import java.util.Map;

import org.cloudfoundry.client.CloudFoundryClient;
import org.cloudfoundry.logcache.v1.LogCacheClient;
import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient;
import org.cloudfoundry.reactor.logcache.v1.ReactorLogCacheClient;

/**
* @author David Turanski
**/
* @author Chris Bono
*/
public class CloudFoundryPlatformClientProvider {

private final CloudFoundryPlatformProperties platformProperties;
Expand All @@ -35,6 +38,8 @@ public class CloudFoundryPlatformClientProvider {

private final Map<String, CloudFoundryClient> cloudFoundryClients = new HashMap<>();

private final Map<String, LogCacheClient> cloudFoundryLogClients = new HashMap<>();

CloudFoundryPlatformClientProvider(
CloudFoundryPlatformProperties platformProperties,
CloudFoundryPlatformConnectionContextProvider connectionContextProvider,
Expand All @@ -45,10 +50,16 @@ public class CloudFoundryPlatformClientProvider {
}

public CloudFoundryClient cloudFoundryClient(String account){
cloudFoundryClients.putIfAbsent(account, ReactorCloudFoundryClient.builder()
return cloudFoundryClients.computeIfAbsent(account, (__) -> ReactorCloudFoundryClient.builder()
.connectionContext(connectionContextProvider.connectionContext(account))
.tokenProvider(platformTokenProvider.tokenProvider(account))
.build());
}

public LogCacheClient logCacheClient(String account) {
return cloudFoundryLogClients.computeIfAbsent(account, (__) -> ReactorLogCacheClient.builder()
.connectionContext(connectionContextProvider.connectionContext(account))
.tokenProvider(platformTokenProvider.tokenProvider(account))
.build());
return cloudFoundryClients.get(account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.cloud.dataflow.core.AbstractTaskPlatformFactory;
import org.springframework.cloud.dataflow.core.Launcher;
import org.springframework.cloud.deployer.spi.app.AppDeployer;
import org.springframework.cloud.deployer.spi.cloudfoundry.ApplicationLogAccessor;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployer;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeploymentProperties;
Expand Down Expand Up @@ -85,7 +86,8 @@ public Launcher createLauncher(String account) {
cloudFoundryClient,
deploymentProperties(account),
cloudFoundryOperations,
runtimeEnvironmentInfo(cloudFoundryClient, account));
runtimeEnvironmentInfo(cloudFoundryClient, account),
new ApplicationLogAccessor(this.cloudFoundryClientProvider.logCacheClient(account)));
Launcher launcher = new Launcher(account, CLOUDFOUNDRY_PLATFORM_TYPE, taskLauncher,
scheduler(account, taskLauncher, cloudFoundryOperations));
CloudFoundryConnectionProperties connectionProperties = connectionProperties(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.cloudfoundry.client.v2.spaces.ListSpacesResponse;
import org.cloudfoundry.client.v2.spaces.SpaceResource;
import org.cloudfoundry.client.v2.spaces.Spaces;
import org.cloudfoundry.logcache.v1.LogCacheClient;
import org.cloudfoundry.reactor.TokenProvider;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -61,13 +62,13 @@ public class CloudFoundryTaskPlatformFactoryTests {

private CloudFoundryPlatformConnectionContextProvider connectionContextProvider;

private CloudFoundryPlatformClientProvider cloudFoundryClientProvider = mock(
CloudFoundryPlatformClientProvider.class);
private CloudFoundryPlatformClientProvider cloudFoundryClientProvider;

private CloudFoundrySchedulerClientProvider cloudFoundrySchedulerClientProvider = mock(
CloudFoundrySchedulerClientProvider.class);
private CloudFoundrySchedulerClientProvider cloudFoundrySchedulerClientProvider;

private CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class);
private CloudFoundryClient cloudFoundryClient;

private LogCacheClient logCacheClient;

private CloudFoundryPlatformProperties cloudFoundryPlatformProperties;

Expand All @@ -79,13 +80,20 @@ public class CloudFoundryTaskPlatformFactoryTests {

@Before
public void setUp() throws Exception {
cloudFoundryClientProvider = mock(CloudFoundryPlatformClientProvider.class);
cloudFoundrySchedulerClientProvider = mock(CloudFoundrySchedulerClientProvider.class);
cloudFoundryClient = mock(CloudFoundryClient.class);
logCacheClient = mock(LogCacheClient.class);

when(this.cloudFoundryClient.info())
.thenReturn(getInfoRequest -> Mono.just(GetInfoResponse.builder().apiVersion("0.0.0").build()));
when(this.cloudFoundryClient.organizations()).thenReturn(mock(Organizations.class));
when(this.cloudFoundryClient.spaces()).thenReturn(mock(Spaces.class));
when(this.cloudFoundryClient.organizations().list(any())).thenReturn(listOrganizationsResponse());
when(this.cloudFoundryClient.spaces().list(any())).thenReturn(listSpacesResponse());
when(this.cloudFoundryClientProvider.cloudFoundryClient(anyString())).thenReturn(this.cloudFoundryClient);
when(this.cloudFoundryClientProvider.logCacheClient(anyString())).thenReturn(this.logCacheClient);

this.cloudFoundryPlatformProperties = new CloudFoundryPlatformProperties();

this.defaultConnectionProperties = new CloudFoundryConnectionProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.cloudfoundry.client.v2.spaces.ListSpacesResponse;
import org.cloudfoundry.client.v2.spaces.SpaceResource;
import org.cloudfoundry.client.v2.spaces.Spaces;
import org.cloudfoundry.logcache.v1.LogCacheClient;
import org.cloudfoundry.reactor.TokenProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -97,6 +98,8 @@ public void schedulerServiceCreated() {
static class TestConfig {
private CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class);

private LogCacheClient logCacheClient = mock(LogCacheClient.class);

private TokenProvider tokenProvider = mock(TokenProvider.class);

@Bean
Expand All @@ -110,10 +113,8 @@ public CloudFoundryPlatformClientProvider mockCloudFoundryClientProvider() {
when(cloudFoundryClient.spaces().list(any())).thenReturn(listSpacesResponse());
CloudFoundryPlatformClientProvider cloudFoundryClientProvider = mock(
CloudFoundryPlatformClientProvider.class);
when(cloudFoundryClientProvider.cloudFoundryClient(anyString())).thenAnswer(invocation -> {
System.out.println("Returning " + cloudFoundryClient);
return cloudFoundryClient;
});
when(cloudFoundryClientProvider.cloudFoundryClient(anyString())).thenAnswer((__) -> this.cloudFoundryClient);
when(cloudFoundryClientProvider.logCacheClient(anyString())).thenAnswer((__) -> this.logCacheClient);
return cloudFoundryClientProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cloudfoundry.client.v2.spaces.ListSpacesResponse;
import org.cloudfoundry.client.v2.spaces.SpaceResource;
import org.cloudfoundry.client.v2.spaces.Spaces;
import org.cloudfoundry.logcache.v1.LogCacheClient;
import org.cloudfoundry.reactor.TokenProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -120,6 +121,8 @@ public void kubernetesTaskPlatform() {
static class TestConfig {
private CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class);

private LogCacheClient logCacheClient = mock(LogCacheClient.class);

private TokenProvider tokenProvider = mock(TokenProvider.class);

@Bean
Expand All @@ -133,10 +136,8 @@ public CloudFoundryPlatformClientProvider mockCloudFoundryClientProvider() {
when(cloudFoundryClient.spaces().list(any())).thenReturn(listSpacesResponse());
CloudFoundryPlatformClientProvider cloudFoundryClientProvider = mock(
CloudFoundryPlatformClientProvider.class);
when(cloudFoundryClientProvider.cloudFoundryClient(anyString())).thenAnswer(invocation -> {
System.out.println("Returning " + cloudFoundryClient);
return cloudFoundryClient;
});
when(cloudFoundryClientProvider.cloudFoundryClient(anyString())).thenAnswer((__) -> this.cloudFoundryClient);
when(cloudFoundryClientProvider.logCacheClient(anyString())).thenAnswer((__) -> this.logCacheClient);
return cloudFoundryClientProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import com.github.zafarkhaja.semver.Version;
import org.cloudfoundry.client.CloudFoundryClient;
import org.cloudfoundry.client.v2.info.GetInfoRequest;
import org.cloudfoundry.logcache.v1.LogCacheClient;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.DefaultCloudFoundryOperations;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.DefaultConnectionContext;
import org.cloudfoundry.reactor.TokenProvider;
import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient;
import org.cloudfoundry.reactor.doppler.ReactorDopplerClient;
import org.cloudfoundry.reactor.logcache.v1.ReactorLogCacheClient;
import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider;
import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider.Builder;
import org.slf4j.Logger;
Expand All @@ -39,6 +41,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.deployer.spi.app.ActuatorOperations;
import org.springframework.cloud.deployer.spi.app.AppDeployer;
import org.springframework.cloud.deployer.spi.cloudfoundry.ApplicationLogAccessor;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryActuatorTemplate;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployer;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppNameGenerator;
Expand Down Expand Up @@ -124,8 +127,13 @@ private Deployer createAndSaveCFAppDeployer(
TokenProvider tokenProvider = tokenProviderBuilder.build();

CloudFoundryClient cloudFoundryClient = ReactorCloudFoundryClient.builder()
.connectionContext(connectionContext).tokenProvider(tokenProvider)
.build();
.connectionContext(connectionContext)
.tokenProvider(tokenProvider)
.build();
LogCacheClient logCacheClient = ReactorLogCacheClient.builder()
.connectionContext(connectionContext)
.tokenProvider(tokenProvider)
.build();
Version version = cloudFoundryClient.info()
.get(GetInfoRequest.builder().build())
.map(response -> Version.valueOf(response.getApiVersion()))
Expand Down Expand Up @@ -163,8 +171,7 @@ private Deployer createAndSaveCFAppDeployer(
deploymentProperties,
cloudFoundryOperations,
runtimeEnvironmentInfo,
applicationContext
);
new ApplicationLogAccessor(logCacheClient));
ActuatorOperations actuatorOperations = new CloudFoundryActuatorTemplate(
restTemplate, cfAppDeployer, cloudFoundryProperties
.getDeployment().getAppAdmin());
Expand Down

0 comments on commit 0ca477f

Please sign in to comment.