diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-03-11 14:06:42 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-03-12 09:12:22 -0400 |
commit | 2924fa7d806435a3bf9f2cb5abcdb01aa7295b00 (patch) | |
tree | 094c3b2140e492f8ffc700f0232405dcf83d2d2e /applications/common/src/main/java | |
parent | 2a65ced426b393e9a6fe34c2c64303b1cc83e1a0 (diff) |
Better error handling for decisions
Throw exceptions when requests cannot be created and return
error information back. Consolidated some code to avoid sonar
duplication issues.
Companion review to https://gerrit.onap.org/r/c/policy/models/+/103548
Issue-ID: POLICY-2242
Change-Id: Ic873af933dab82e3aeef6335f55939666be20385
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/common/src/main/java')
5 files changed, 20 insertions, 18 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java index 47ff70f6..32b950b4 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public interface ToscaPolicyTranslator { * @param request Incoming DecisionRequest * @return Xacml Request object */ - Request convertRequest(DecisionRequest request); + Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException; /** * Implement this method to convert a Xacml Response diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java index 34936b06..3ac57b7b 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java @@ -69,7 +69,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { } @Override - public Request convertRequest(DecisionRequest request) { + public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException { return null; } @@ -99,9 +99,10 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { scanAdvice(xacmlResult.getAssociatedAdvice(), decisionResponse); } else { // - // TODO we have to return an ErrorResponse object instead + // Return error information back // - decisionResponse.setStatus("A better error message"); + decisionResponse.setStatus("error"); + decisionResponse.setMessage(xacmlResult.getStatus().getStatusMessage()); } } diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java index aba5e252..d9661829 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java @@ -127,17 +127,13 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { } @Override - public Request convertRequest(DecisionRequest request) { + public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException { LOGGER.info("Converting Request {}", request); try { return RequestParser.parseRequest(StdCombinedPolicyRequest.createInstance(request)); } catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) { - LOGGER.error("Failed to convert DecisionRequest", e); + throw new ToscaPolicyConversionException("Failed to parse request", e); } - // - // TODO throw exception - // - return null; } /** diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java index d5e2a395..7ca995e0 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java @@ -100,17 +100,13 @@ public class StdMatchableTranslator extends StdBaseTranslator { } @Override - public Request convertRequest(DecisionRequest request) { + public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException { LOGGER.info("Converting Request {}", request); try { return StdMatchablePolicyRequest.createInstance(request); } catch (XacmlApplicationException e) { - LOGGER.error("Failed to convert DecisionRequest", e); + throw new ToscaPolicyConversionException("Failed to convert DecisionRequest", e); } - // - // TODO throw exception - // - return null; } /** diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java index 11271651..0fdd3a96 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java @@ -232,7 +232,16 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // // Convert to a XacmlRequest // - Request xacmlRequest = this.getTranslator().convertRequest(request); + Request xacmlRequest; + try { + xacmlRequest = this.getTranslator().convertRequest(request); + } catch (ToscaPolicyConversionException e) { + LOGGER.error("Failed to convert request", e); + DecisionResponse response = new DecisionResponse(); + response.setStatus("error"); + response.setMessage(e.getLocalizedMessage()); + return Pair.of(response, null); + } // // Now get a decision // |