From f93a6c0ab006258628fc2da69dcfe65010baf848 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Wed, 6 Apr 2022 09:53:27 +0100 Subject: Error handling when a decoder fails to parse policy - catch exception only if it was a parse error (still raises exception when no decoder found) - reducing of complexity on acm decoding for sonar - added some debug logging and exception messages for better tracking of issues Issue-ID: POLICY-4006 Change-Id: Ie09aaf541fc06244b84477ecbfe70fc837438a86 Signed-off-by: adheli.tavares --- .../reception/handling/AbstractReceptionHandler.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'reception/src/main/java/org/onap') diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java index 8ad293c3..e898b335 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2022 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -72,17 +72,28 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler { * handler. * * @param policyInput the input that has been received - * @throws PolicyDecodingException if an error occurs in decoding a policy from the received input + * @throws PolicyDecodingException if an error occurs when no decoders are available */ protected void inputReceived(final PolicyInput policyInput) throws PolicyDecodingException { final Collection policies = new ArrayList<>(); - for (final PolicyDecoder policyDecoder : getRelevantPolicyDecoders(policyInput)) { - policies.addAll(policyDecoder.decode(policyInput)); + + try { + for (final PolicyDecoder policyDecoder : getRelevantPolicyDecoders(policyInput)) { + LOGGER.debug("Policy decoder: {}", policyDecoder.getClass()); + policies.addAll(policyDecoder.decode(policyInput)); + } + } catch (PolicyDecodingException decodingException) { + if (decodingException.getMessage().contains("No decoder")) { + throw decodingException; + } else { + LOGGER.error("Couldn't decode the policy", decodingException); + } } for (final PolicyForwarder policyForwarder : pluginHandler.getPolicyForwarders()) { try { + LOGGER.debug("Trying to forward policy to {}", policyForwarder.getClass()); policyForwarder.forward(policies); } catch (final PolicyForwardingException policyForwardingException) { LOGGER.error("Error when forwarding policies to {}", policyForwarder, policyForwardingException); -- cgit 1.2.3-korg