From 91510edb313c32cecd63931446d3fd852f2db761 Mon Sep 17 00:00:00 2001 From: JUSTIN BRAATHEN Date: Fri, 18 Aug 2017 18:56:02 -0500 Subject: [PATCH] Handle 170001 StagingError from CC when fetching application instance information #798 https://github.com/cloudfoundry/cf-java-client/issues/798 The current implementation of getApplicationInstances handles errors like CF_BUILDPACK_COMPILED_FAILED and CF_INSTANCES_ERROR that can be returned from CC if the staging previously failed. However, the general StagingError (error code 170001) is not handled and will throw an exception when fetching application instances. I was able to confirm and verify that this resolves deployment issues ( _CF-StagerError(170011)_ ) when making the following API call. **API Request** ``` GET /v2/apps//instances HTTP/1.1 host: api.pdc.np.sys.paas.lmig.com authorization: bearer user-agent: CloudFoundryJavaClient/unknown (Java; Oracle Corporation/1.8.0_131) ReactorNetty/unknown (Netty/unknown) accept: application/json content-length: 0 ``` **API Response** ``` HTTP/1.1 400 Bad Request Content-Length: 133 Content-Type: application/json;charset=utf-8 Date: Tue, 15 Aug 2017 21:29:40 GMT Server: nginx X-Content-Type-Options: nosniff X-Vcap-Request-Id: X-Vcap-Request-Id: Connection: Keep-alive { "description": "Staging error: cannot get instances since staging failed", "error_code": "CF-StagingError", "code": 170001 } ``` There is a related issue with the Bamboo Cloud Foundry Plugin (https://gaptap.atlassian.net/browse/CFBAMBOO-236) that is dependent on this change. The cf-java-client:2.17.0 doesn't have a target release date, would it be possible to cut a patch-level release of cf-java-client:2.16.1? --- .../operations/applications/DefaultApplications.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index 4d5b1b031ab..2b376ae26aa 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -138,6 +138,8 @@ public final class DefaultApplications implements Applications { private static final int CF_STAGING_NOT_FINISHED = 170002; private static final int CF_STAGING_TIME_EXPIRED = 170007; + + private static final int CF_STAGING_ERROR = 170001; private static final Comparator LOG_MESSAGE_COMPARATOR = Comparator.comparing(LogMessage::getTimestamp); @@ -724,7 +726,7 @@ private static Mono getApplicationIdWhere(CloudFoundryClient cloudFoundr private static Mono getApplicationInstances(CloudFoundryClient cloudFoundryClient, String applicationId) { return requestApplicationInstances(cloudFoundryClient, applicationId) - .onErrorResume(ExceptionUtils.statusCode(CF_BUILDPACK_COMPILED_FAILED, CF_INSTANCES_ERROR, CF_STAGING_NOT_FINISHED, CF_STAGING_TIME_EXPIRED), + .onErrorResume(ExceptionUtils.statusCode(CF_BUILDPACK_COMPILED_FAILED, CF_INSTANCES_ERROR, CF_STAGING_NOT_FINISHED, CF_STAGING_TIME_EXPIRED, CF_STAGING_ERROR), t -> Mono.just(ApplicationInstancesResponse.builder().build())); }