diff options
author | liamfallon <liam.fallon@est.tech> | 2019-10-14 14:25:58 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-10-14 16:36:47 +0100 |
commit | e940ccf7d38373c145b5d5f4a95603edaa089796 (patch) | |
tree | b762cf9aeb4fcee6f79cfe8fbb81a70722d51378 /models-interactions/model-impl/vfc | |
parent | ccebb3497292cfa831ad7cdc7ee7739a0d94a70c (diff) |
Clean up minor things in policy-models
Cleam up of some minor eclipse, checkstyle, and Sonar issues in
policy-models
Issue-ID: POLICY-2165
Change-Id: Id5682fd60e1a6cebbf716d9c258453aa53ca2482
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-interactions/model-impl/vfc')
-rw-r--r-- | models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java index 406e35d33..14382f0e9 100644 --- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java @@ -125,45 +125,7 @@ public final class VfcManager implements Runnable { } try { - VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class); - NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second); - String body = Serialization.gsonPretty.toJson(response); - logger.debug("Response to VFC Heal post:"); - logger.debug(body); - - String jobId = response.getJobId(); - int attemptsLeft = 20; - - String urlGet = vfcUrlBase + "/jobs/" + jobId; - VfcResponse responseGet = null; - - while (attemptsLeft-- > 0) { - NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet); - Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); - responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class); - NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second); - responseGet.setRequestId(vfcRequest.getRequestId().toString()); - body = Serialization.gsonPretty.toJson(responseGet); - logger.debug("Response to VFC Heal get:"); - logger.debug(body); - - String responseStatus = responseGet.getResponseDescriptor().getStatus(); - if (httpDetailsGet.first == 200 - && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { - logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); - this.callback.onResponse(responseGet); - break; - } - Thread.sleep(20000); - } - boolean isTimeout = (attemptsLeft <= 0) && (responseGet != null) - && (responseGet.getResponseDescriptor() != null); - isTimeout = isTimeout && (responseGet.getResponseDescriptor().getStatus() != null) - && (!responseGet.getResponseDescriptor().getStatus().isEmpty()); - if (isTimeout) { - logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); - this.callback.onResponse(responseGet); - } + handleVfcResponse(headers, httpDetails, vfcUrl); } catch (JsonSyntaxException e) { logger.error("Failed to deserialize into VfcResponse {}", e.getLocalizedMessage(), e); } catch (InterruptedException e) { @@ -175,6 +137,57 @@ public final class VfcManager implements Runnable { } /** + * Handle a VFC response message. + * + * @param headers the headers in the response + * @param httpDetails the HTTP details in the response + * @param vfcUrl the response URL + * @throws InterruptedException on errors in the response + */ + private void handleVfcResponse(Map<String, String> headers, Pair<Integer, String> httpDetails, String vfcUrl) + throws InterruptedException { + VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second); + String body = Serialization.gsonPretty.toJson(response); + logger.debug("Response to VFC Heal post:"); + logger.debug(body); + + String jobId = response.getJobId(); + int attemptsLeft = 20; + + String urlGet = vfcUrlBase + "/jobs/" + jobId; + VfcResponse responseGet = null; + + while (attemptsLeft-- > 0) { + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet); + Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); + responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second); + responseGet.setRequestId(vfcRequest.getRequestId().toString()); + body = Serialization.gsonPretty.toJson(responseGet); + logger.debug("Response to VFC Heal get:"); + logger.debug(body); + + String responseStatus = responseGet.getResponseDescriptor().getStatus(); + if (httpDetailsGet.first == 200 + && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { + logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); + this.callback.onResponse(responseGet); + return; + } + Thread.sleep(20000); + } + boolean isTimeout = (attemptsLeft <= 0) && (responseGet != null) + && (responseGet.getResponseDescriptor() != null); + isTimeout = isTimeout && (responseGet.getResponseDescriptor().getStatus() != null) + && (!responseGet.getResponseDescriptor().getStatus().isEmpty()); + if (isTimeout) { + logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); + this.callback.onResponse(responseGet); + } + } + + /** * Protected setter for rest manager to allow mocked rest manager to be used for testing. * * @param restManager the test REST manager |