Skip to content

Commit 7a032be

Browse files
David O'SullivanZPascal
David O'Sullivan
authored andcommitted
logcache client impl
1 parent 03fd4de commit 7a032be

File tree

7 files changed

+56
-43
lines changed

7 files changed

+56
-43
lines changed

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/serviceInstances/ReactorServiceInstancesV3Test.java

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.cloudfoundry.reactor.TestRequest;
6363
import org.cloudfoundry.reactor.TestResponse;
6464
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
65+
import org.cloudfoundry.reactor.client.v3.serviceinstances.ReactorServiceInstancesV3;
6566
import org.junit.jupiter.api.Test;
6667
import reactor.test.StepVerifier;
6768

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,19 @@ Mono<CloudFoundryClient> getCloudFoundryClientPublisher() {
179179
@Nullable
180180
abstract DopplerClient getDopplerClient();
181181

182-
/**
183-
* The {@link LogCacheClient} to use for operations functionality
184-
*/
185-
@Nullable
186-
abstract LogCacheClient getLogCacheClient();
187-
188182
@Value.Derived
189183
Mono<DopplerClient> getDopplerClientPublisher() {
190184
return Optional.ofNullable(getDopplerClient())
191185
.map(Mono::just)
192186
.orElse(Mono.error(new IllegalStateException("DopplerClient must be set")));
193187
}
194188

189+
/**
190+
* The {@link LogCacheClient} to use for operations functionality
191+
*/
192+
@Nullable
193+
abstract LogCacheClient getLogCacheClient();
194+
195195
@Value.Derived
196196
Mono<LogCacheClient> getLogCacheClientPublisher() {
197197
return Optional.ofNullable(getLogCacheClient())

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/Applications.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.cloudfoundry.doppler.LogMessage;
2020
import org.cloudfoundry.logcache.v1.Log;
21+
import org.cloudfoundry.logcache.v1.ReadRequest;
22+
import org.cloudfoundry.logcache.v1.ReadResponse;
2123

2224
import reactor.core.publisher.Flux;
2325
import reactor.core.publisher.Mono;
@@ -122,7 +124,7 @@ public interface Applications {
122124
* @param request the application logs request
123125
* @return the applications logs
124126
*/
125-
Flux<Log> logs(LogsRequest request);
127+
Flux<Log> logs(ReadRequest request);
126128

127129
/**
128130
* Push a specific application

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
import org.cloudfoundry.logcache.v1.Log;
160160
import org.cloudfoundry.logcache.v1.LogCacheClient;
161161
import org.cloudfoundry.logcache.v1.ReadRequest;
162+
import org.cloudfoundry.logcache.v1.ReadResponse;
162163
import org.cloudfoundry.operations.util.OperationsLogging;
163164
import org.cloudfoundry.util.DateUtils;
164165
import org.cloudfoundry.util.DelayTimeoutException;
@@ -541,13 +542,13 @@ public Flux<Task> listTasks(ListApplicationTasksRequest request) {
541542
}
542543

543544
@Override
544-
public Flux<Log> logs(LogsRequest request) {
545+
public Flux<Log> logs(ReadRequest request) {
545546
return Mono.zip(this.cloudFoundryClient, this.spaceId)
546547
.flatMap(
547548
function(
548549
(cloudFoundryClient, spaceId) ->
549550
getApplicationId(
550-
cloudFoundryClient, request.getName(), spaceId)))
551+
cloudFoundryClient, request.getSourceId(), spaceId)))
551552
.flatMapMany(
552553
applicationId ->
553554
getRecentLogs(this.logCacheClient, applicationId))
@@ -664,7 +665,6 @@ public Mono<Void> pushManifestV3(PushManifestV3Request request) {
664665
} catch (IOException e) {
665666
throw new RuntimeException("Could not serialize manifest", e);
666667
}
667-
668668
return Mono.zip(this.cloudFoundryClient, this.spaceId)
669669
.flatMap(
670670
function(
@@ -1582,30 +1582,29 @@ private static int getInstances(AbstractApplicationResource resource) {
15821582
.orElse(0);
15831583
}
15841584

1585-
/* private static Flux<Log> getLogs(
1586-
Mono<LogCacheClient> logCacheClient, String applicationId, Boolean recent) {
1585+
private static Flux<LogMessage> getLogs(
1586+
Mono<DopplerClient> dopplerClient, String applicationId, Boolean recent) {
15871587
if (Optional.ofNullable(recent).orElse(false)) {
1588-
return getRecentLogs(logCacheClient, applicationId);
1588+
return requestLogsRecent(dopplerClient, applicationId)
1589+
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1590+
.map(Envelope::getLogMessage)
1591+
.collectSortedList(LOG_MESSAGE_COMPARATOR)
1592+
.flatMapIterable(d -> d);
1593+
} else {
1594+
return requestLogsStream(dopplerClient, applicationId)
1595+
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1596+
.map(Envelope::getLogMessage)
1597+
.transformDeferred(
1598+
SortingUtils.timespan(LOG_MESSAGE_COMPARATOR, LOG_MESSAGE_TIMESPAN));
15891599
}
1590-
}*/
1600+
}
15911601

15921602
private static Flux<Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
15931603
return requestLogsRecentLogCache(logCacheClient, applicationId)
1594-
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1595-
// .collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
15961604
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
15971605
.map(org.cloudfoundry.logcache.v1.Envelope::getLog);
15981606
}
15991607

1600-
/* private static Flux<org.cloudfoundry.logcache.v1.Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1601-
return requestLogsRecentLogCache(logCacheClient, applicationId)
1602-
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1603-
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1604-
.map(org.cloudfoundry.logcache.v1.Envelope::getLog)
1605-
.collectList()
1606-
.flatMapIterable(d1 -> d1).cast(org.cloudfoundry.logcache.v1.Log.class);
1607-
} */
1608-
16091608
@SuppressWarnings("unchecked")
16101609
private static Map<String, Object> getMetadataRequest(EventEntity entity) {
16111610
Map<String, Optional<Object>> metadata =

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java

+20-9
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@
144144
import org.cloudfoundry.doppler.LogMessage;
145145
import org.cloudfoundry.doppler.RecentLogsRequest;
146146
import org.cloudfoundry.doppler.StreamRequest;
147+
import org.cloudfoundry.logcache.v1.EnvelopeBatch;
148+
import org.cloudfoundry.logcache.v1.EnvelopeType;
147149
import org.cloudfoundry.logcache.v1.Log;
148150
import org.cloudfoundry.logcache.v1.LogCacheClient;
151+
import org.cloudfoundry.logcache.v1.LogType;
149152
import org.cloudfoundry.logcache.v1.ReadRequest;
150153
import org.cloudfoundry.logcache.v1.ReadResponse;
151154
import org.cloudfoundry.operations.AbstractOperationsTest;
@@ -1318,10 +1321,10 @@ void logs() {
13181321
"test-application-name",
13191322
TEST_SPACE_ID,
13201323
"test-metadata-id");
1321-
requestLogsStream(this.dopplerClient, "test-metadata-id");
1324+
requestLogsRecentLogCache(this.logCacheClient, "test-application-name");
13221325

13231326
this.applications
1324-
.logs(LogsRequest.builder().name("test-application-name").recent(false).build())
1327+
.logs(ReadRequest.builder().sourceId("test-application-name").build())
13251328
.as(StepVerifier::create)
13261329
.expectNext(fill(Log.builder(), "log-message-").build())
13271330
.expectComplete()
@@ -1333,7 +1336,7 @@ void logsNoApp() {
13331336
requestApplicationsEmpty(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
13341337

13351338
this.applications
1336-
.logs(LogsRequest.builder().name("test-application-name").build())
1339+
.logs(ReadRequest.builder().sourceId("test-application-name").build())
13371340
.as(StepVerifier::create)
13381341
.consumeErrorWith(
13391342
t ->
@@ -1354,7 +1357,7 @@ void logsRecent() {
13541357
requestLogsRecentLogCache(this.logCacheClient, "test-metadata-id");
13551358

13561359
this.applications
1357-
.logs(LogsRequest.builder().name("test-application-name").recent(true).build())
1360+
.logs(ReadRequest.builder().sourceId("test-application-name").build())
13581361
.as(StepVerifier::create)
13591362
.expectNext(fill(Log.builder(), "log-message-").build())
13601363
.expectComplete()
@@ -1371,7 +1374,7 @@ void logsRecentNotSet() {
13711374
requestLogsStream(this.dopplerClient, "test-metadata-id");
13721375

13731376
this.applications
1374-
.logs(LogsRequest.builder().name("test-application-name").build())
1377+
.logs(ReadRequest.builder().sourceId("test-application-name").build())
13751378
.as(StepVerifier::create)
13761379
.expectNext(fill(Log.builder(), "log-message-").build())
13771380
.expectComplete()
@@ -5254,10 +5257,18 @@ private static void requestListTasksEmpty(
52545257
}
52555258

52565259
private static void requestLogsRecentLogCache(LogCacheClient logCacheClient, String applicationId) {
5257-
when(logCacheClient.recentLogs(
5258-
ReadRequest.builder().sourceId(applicationId).build()))
5259-
.thenReturn(
5260-
Mono.just(ReadResponse.builder().envelopes(fill(org.cloudfoundry.logcache.v1.EnvelopeBatch.builder()).build()).build()));
5260+
when(logCacheClient.recentLogs(
5261+
ReadRequest.builder().sourceId(applicationId).build()))
5262+
.thenReturn(
5263+
Mono.just(fill(ReadResponse.builder())
5264+
.envelopes(fill(EnvelopeBatch.builder())
5265+
.batch(fill(org.cloudfoundry.logcache.v1.Envelope.builder())
5266+
.log(fill(Log.builder())
5267+
.payload("test-payload")
5268+
.type(LogType.OUT).build())
5269+
.build())
5270+
.build())
5271+
.build()));
52615272
}
52625273

52635274
private static void requestLogsStream(DopplerClient dopplerClient, String applicationId) {

integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.cloudfoundry.client.v2.stacks.ListStacksRequest;
4747
import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest;
4848
import org.cloudfoundry.doppler.DopplerClient;
49+
import org.cloudfoundry.logcache.v1.LogCacheClient;
4950
import org.cloudfoundry.logcache.v1.TestLogCacheEndpoints;
5051
import org.cloudfoundry.networking.NetworkingClient;
5152
import org.cloudfoundry.operations.DefaultCloudFoundryOperations;
@@ -254,6 +255,7 @@ ReactorCloudFoundryClient cloudFoundryClient(
254255
DefaultCloudFoundryOperations cloudFoundryOperations(
255256
CloudFoundryClient cloudFoundryClient,
256257
DopplerClient dopplerClient,
258+
LogCacheClient logCacheClient,
257259
NetworkingClient networkingClient,
258260
RoutingClient routingClient,
259261
UaaClient uaaClient,
@@ -263,6 +265,7 @@ DefaultCloudFoundryOperations cloudFoundryOperations(
263265
.cloudFoundryClient(cloudFoundryClient)
264266
.dopplerClient(dopplerClient)
265267
.networkingClient(networkingClient)
268+
.logCacheClient(logCacheClient)
266269
.routingClient(routingClient)
267270
.uaaClient(uaaClient)
268271
.organization(organizationName)
@@ -547,7 +550,7 @@ Mono<String> stackId(CloudFoundryClient cloudFoundryClient, String stackName) {
547550

548551
@Bean
549552
String stackName() {
550-
return "cflinuxfs3";
553+
return "cflinuxfs4";
551554
}
552555

553556
@Bean(initMethod = "block")

integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.cloudfoundry.doppler.LogMessage;
3333
import org.cloudfoundry.doppler.MessageType;
3434
import org.cloudfoundry.logcache.v1.LogType;
35+
import org.cloudfoundry.logcache.v1.ReadRequest;
3536
import org.cloudfoundry.operations.applications.ApplicationDetail;
3637
import org.cloudfoundry.operations.applications.ApplicationEnvironments;
3738
import org.cloudfoundry.operations.applications.ApplicationEvent;
@@ -496,17 +497,13 @@ public void logs() throws IOException {
496497
this.cloudFoundryOperations,
497498
new ClassPathResource("test-application.zip").getFile().toPath(),
498499
applicationName,
499-
false)
500-
.thenMany(
501-
this.cloudFoundryOperations
500+
false)
501+
.thenMany(this.cloudFoundryOperations
502502
.applications()
503-
.logs(
504-
LogsRequest.builder()
505-
.name(applicationName)
506-
.recent(true)
503+
.logs(ReadRequest.builder()
504+
.sourceId(applicationName)
507505
.build()))
508506
.map(org.cloudfoundry.logcache.v1.Log::getType)
509-
.next()
510507
.as(StepVerifier::create)
511508
.expectNext(org.cloudfoundry.logcache.v1.LogType.OUT)
512509
.expectComplete()

0 commit comments

Comments
 (0)