aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-http/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-05-22 10:53:27 +0100
committerLiam Fallon <liam.fallon@est.tech>2023-05-23 15:25:11 +0000
commit290d7273d4df9f956c5e48284d09d306e31c706f (patch)
tree844b4a7d3cb1436ef6e1b2f3ae58eab06586ff69 /participant/participant-impl/participant-impl-http/src/main
parent4539ab951ef81839d38641fa09f2cbd490d71a63 (diff)
Refactor failure handling in http-participant
In the case, a http-participant fails to deploy an element, it should responds with UNDEPLOYED on a DEPLOY order. Issue-ID: POLICY-4694 Change-Id: I97d2660c7b91e4407ff3fa2cc51557b6c96a3a9e Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-http/src/main')
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java33
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java6
2 files changed, 25 insertions, 14 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index f294d47ff..f5fb03054 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -39,6 +39,7 @@ import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.common.utils.coder.Coder;
@@ -91,31 +92,37 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Override
public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
throws PfModelException {
- var configRequest = getConfigRequest(properties);
- var restResponseMap = invokeHttpClient(configRequest);
- var failedResponseStatus = restResponseMap.values().stream()
- .filter(response -> !HttpStatus.valueOf(response.getKey()).is2xxSuccessful())
- .collect(Collectors.toList());
- if (failedResponseStatus.isEmpty()) {
+ try {
+ var configRequest = getConfigRequest(properties);
+ var restResponseMap = invokeHttpClient(configRequest);
+ var failedResponseStatus = restResponseMap.values().stream()
+ .filter(response -> !HttpStatus.valueOf(response.getKey()).is2xxSuccessful())
+ .collect(Collectors.toList());
+ if (failedResponseStatus.isEmpty()) {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.DEPLOYED, null, "Deployed");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, "Error on Invoking the http request: " + failedResponseStatus);
+ }
+ } catch (AutomationCompositionException e) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
- } else {
- throw new PfModelException(Status.BAD_REQUEST, "Error on Invoking the http request: {}",
- failedResponseStatus);
+ DeployState.UNDEPLOYED, null, e.getMessage());
}
}
- private ConfigRequest getConfigRequest(Map<String, Object> properties) throws PfModelException {
+ private ConfigRequest getConfigRequest(Map<String, Object> properties) throws AutomationCompositionException {
try {
var configRequest = CODER.convert(properties, ConfigRequest.class);
var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest);
if (!violations.isEmpty()) {
LOGGER.error("Violations found in the config request parameters: {}", violations);
- throw new PfModelException(Status.BAD_REQUEST, "Constraint violations in the config request");
+ throw new AutomationCompositionException(Status.BAD_REQUEST,
+ "Constraint violations in the config request");
}
return configRequest;
} catch (CoderException e) {
- throw new PfModelException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e);
+ throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e);
}
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
index c71d73f22..a88f93aa5 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
@@ -38,6 +38,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
@@ -88,9 +89,12 @@ public class AcHttpClient {
new ImmutablePair<>(request.getExpectedResponse(), response));
} catch (HttpWebClientException ex) {
- LOGGER.error("Error occurred on the HTTP request ", ex);
+ LOGGER.error("Error occurred on the HTTP response ", ex);
responseMap.put(request.getRestRequestId(),
new ImmutablePair<>(ex.getStatusCode().value(), ex.getResponseBodyAsString()));
+ } catch (WebClientRequestException ex) {
+ LOGGER.error("Error occurred on the HTTP request ", ex);
+ responseMap.put(request.getRestRequestId(), new ImmutablePair<>(404, ex.getMessage()));
}
}
}