Skip to content

Commit eb15b06

Browse files
committed
make compatibilityChecker robust if v2 api is disabled
1 parent feadaec commit eb15b06

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/CloudFoundryClientCompatibilityChecker.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ final class CloudFoundryClientCompatibilityChecker {
3939
void check() {
4040
this.info
4141
.get(GetInfoRequest.builder().build())
42-
.map(response -> Version.valueOf(response.getApiVersion()))
42+
.map(
43+
response -> {
44+
String version = response.getApiVersion();
45+
if (version == null || version.isEmpty()) {
46+
if ("CF API v2 is disabled".equals(response.getSupport())) {
47+
this.logger.warn(
48+
"calling v2 info endpoint but CF API v2 is disabled",
49+
response);
50+
}
51+
return Version.of(0, 0, 0);
52+
}
53+
return Version.valueOf(version);
54+
})
4355
.zipWith(Mono.just(Version.valueOf(CloudFoundryClient.SUPPORTED_API_VERSION)))
4456
.subscribe(
4557
consumer(

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,20 @@ Version serverVersion(@Qualifier("admin") CloudFoundryClient cloudFoundryClient)
468468
return cloudFoundryClient
469469
.info()
470470
.get(GetInfoRequest.builder().build())
471-
.map(response -> Version.valueOf(response.getApiVersion()))
471+
.map(
472+
response -> {
473+
String version = response.getApiVersion();
474+
if (version == null || version.isEmpty()) {
475+
this.logger.warn(
476+
"calling v2 info endpoint but CF API v2 is disabled");
477+
return new Version.Builder()
478+
.setMajorVersion(0)
479+
.setMinorVersion(0)
480+
.setPatchVersion(0)
481+
.build();
482+
}
483+
return Version.valueOf(version);
484+
})
472485
.doOnSubscribe(s -> this.logger.debug(">> CLOUD FOUNDRY VERSION <<"))
473486
.doOnSuccess(r -> this.logger.debug("<< CLOUD FOUNDRY VERSION >>"))
474487
.block();

integration-test/src/test/java/org/cloudfoundry/client/v2/InfoTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public void info() {
4141
.consumeNextWith(
4242
response -> {
4343
Version expected = Version.valueOf(SUPPORTED_API_VERSION);
44-
Version actual = Version.valueOf(response.getApiVersion());
44+
Version actual;
45+
String version = response.getApiVersion();
46+
if (version == null || version.isEmpty()) {
47+
actual = Version.of(0, 0, 0);
48+
} else {
49+
actual = Version.valueOf(version);
50+
}
4551

4652
assertThat(actual).isLessThanOrEqualTo(expected);
4753
})

0 commit comments

Comments
 (0)