Skip to content

Commit bdc5ce3

Browse files
David O'SullivanZPascal
authored andcommitted
logcache client impl
1 parent 65a4f28 commit bdc5ce3

7 files changed

Lines changed: 51 additions & 36 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ Mono<CloudFoundryClient> getCloudFoundryClientPublisher() {
191191
@Nullable
192192
abstract DopplerClient getDopplerClient();
193193

194-
/**
195-
* The {@link LogCacheClient} to use for operations functionality
196-
*/
197-
@Nullable
198-
abstract LogCacheClient getLogCacheClient();
199-
200194
@Value.Derived
201195
Mono<DopplerClient> getDopplerClientPublisher() {
202196
return Optional.ofNullable(getDopplerClient())
203197
.map(Mono::just)
204198
.orElse(Mono.error(new IllegalStateException("DopplerClient must be set")));
205199
}
206200

201+
/**
202+
* The {@link LogCacheClient} to use for operations functionality
203+
*/
204+
@Nullable
205+
abstract LogCacheClient getLogCacheClient();
206+
207207
@Value.Derived
208208
Mono<LogCacheClient> getLogCacheClientPublisher() {
209209
return Optional.ofNullable(getLogCacheClient())

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

Lines changed: 3 additions & 1 deletion
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
import reactor.core.publisher.Flux;
2224
import reactor.core.publisher.Mono;
2325

@@ -125,7 +127,7 @@ public interface Applications {
125127
* @deprecated Use {@link #logs(ApplicationLogsRequest)} instead.
126128
*/
127129
@Deprecated
128-
Flux<Log> logs(LogsRequest request);
130+
Flux<Log> logs(ReadRequest request);
129131

130132
/**
131133
* List the applications logs.

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

Lines changed: 17 additions & 18 deletions
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;
@@ -543,13 +544,13 @@ public Flux<Task> listTasks(ListApplicationTasksRequest request) {
543544
}
544545

545546
@Override
546-
public Flux<Log> logs(LogsRequest request) {
547+
public Flux<Log> logs(ReadRequest request) {
547548
return Mono.zip(this.cloudFoundryClient, this.spaceId)
548549
.flatMap(
549550
function(
550551
(cloudFoundryClient, spaceId) ->
551552
getApplicationId(
552-
cloudFoundryClient, request.getName(), spaceId)))
553+
cloudFoundryClient, request.getSourceId(), spaceId)))
553554
.flatMapMany(
554555
applicationId ->
555556
getRecentLogs(this.logCacheClient, applicationId))
@@ -686,7 +687,6 @@ public Mono<Void> pushManifestV3(PushManifestV3Request request) {
686687
} catch (IOException e) {
687688
throw new RuntimeException("Could not serialize manifest", e);
688689
}
689-
690690
return Mono.zip(this.cloudFoundryClient, this.spaceId)
691691
.flatMap(
692692
function(
@@ -1613,30 +1613,29 @@ private static int getInstances(AbstractApplicationResource resource) {
16131613
.orElse(0);
16141614
}
16151615

1616-
/* private static Flux<Log> getLogs(
1617-
Mono<LogCacheClient> logCacheClient, String applicationId, Boolean recent) {
1616+
private static Flux<LogMessage> getLogs(
1617+
Mono<DopplerClient> dopplerClient, String applicationId, Boolean recent) {
16181618
if (Optional.ofNullable(recent).orElse(false)) {
1619-
return getRecentLogs(logCacheClient, applicationId);
1619+
return requestLogsRecent(dopplerClient, applicationId)
1620+
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1621+
.map(Envelope::getLogMessage)
1622+
.collectSortedList(LOG_MESSAGE_COMPARATOR)
1623+
.flatMapIterable(d -> d);
1624+
} else {
1625+
return requestLogsStream(dopplerClient, applicationId)
1626+
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1627+
.map(Envelope::getLogMessage)
1628+
.transformDeferred(
1629+
SortingUtils.timespan(LOG_MESSAGE_COMPARATOR, LOG_MESSAGE_TIMESPAN));
16201630
}
1621-
}*/
1631+
}
16221632

16231633
private static Flux<Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
16241634
return requestLogsRecentLogCache(logCacheClient, applicationId)
1625-
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1626-
// .collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
16271635
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
16281636
.map(org.cloudfoundry.logcache.v1.Envelope::getLog);
16291637
}
16301638

1631-
/* private static Flux<org.cloudfoundry.logcache.v1.Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1632-
return requestLogsRecentLogCache(logCacheClient, applicationId)
1633-
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1634-
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1635-
.map(org.cloudfoundry.logcache.v1.Envelope::getLog)
1636-
.collectList()
1637-
.flatMapIterable(d1 -> d1).cast(org.cloudfoundry.logcache.v1.Log.class);
1638-
} */
1639-
16401639
@SuppressWarnings("unchecked")
16411640
private static Map<String, Object> getMetadataRequest(EventEntity entity) {
16421641
Map<String, Optional<Object>> metadata =

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

Lines changed: 20 additions & 9 deletions
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()
@@ -5323,10 +5326,18 @@ private static void requestListTasksEmpty(
53235326
}
53245327

53255328
private static void requestLogsRecentLogCache(LogCacheClient logCacheClient, String applicationId) {
5326-
when(logCacheClient.recentLogs(
5327-
ReadRequest.builder().sourceId(applicationId).build()))
5328-
.thenReturn(
5329-
Mono.just(ReadResponse.builder().envelopes(fill(org.cloudfoundry.logcache.v1.EnvelopeBatch.builder()).build()).build()));
5329+
when(logCacheClient.recentLogs(
5330+
ReadRequest.builder().sourceId(applicationId).build()))
5331+
.thenReturn(
5332+
Mono.just(fill(ReadResponse.builder())
5333+
.envelopes(fill(EnvelopeBatch.builder())
5334+
.batch(fill(org.cloudfoundry.logcache.v1.Envelope.builder())
5335+
.log(fill(Log.builder())
5336+
.payload("test-payload")
5337+
.type(LogType.OUT).build())
5338+
.build())
5339+
.build())
5340+
.build()));
53305341
}
53315342

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.cloudfoundry.client.v2.stacks.StackResource;
4949
import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest;
5050
import org.cloudfoundry.doppler.DopplerClient;
51+
import org.cloudfoundry.logcache.v1.LogCacheClient;
5152
import org.cloudfoundry.logcache.v1.TestLogCacheEndpoints;
5253
import org.cloudfoundry.networking.NetworkingClient;
5354
import org.cloudfoundry.operations.DefaultCloudFoundryOperations;
@@ -273,6 +274,7 @@ ReactorCloudFoundryClient cloudFoundryClient(
273274
DefaultCloudFoundryOperations cloudFoundryOperations(
274275
CloudFoundryClient cloudFoundryClient,
275276
DopplerClient dopplerClient,
277+
LogCacheClient logCacheClient,
276278
NetworkingClient networkingClient,
277279
RoutingClient routingClient,
278280
UaaClient uaaClient,
@@ -281,6 +283,7 @@ DefaultCloudFoundryOperations cloudFoundryOperations(
281283
return DefaultCloudFoundryOperations.builder()
282284
.cloudFoundryClient(cloudFoundryClient)
283285
.dopplerClient(dopplerClient)
286+
.logCacheClient(logCacheClient)
284287
.networkingClient(networkingClient)
285288
.routingClient(routingClient)
286289
.uaaClient(uaaClient)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ public void logs() throws IOException {
526526
.applications()
527527
.logs(
528528
ApplicationLogsRequest.builder()
529-
.name(applicationName)
530-
.recent(true)
529+
.sourceId(applicationName)
531530
.build()))
532531
.map(org.cloudfoundry.logcache.v1.Log::getType)
533532
.next()

0 commit comments

Comments
 (0)