diff options
Diffstat (limited to 'reception')
2 files changed, 22 insertions, 12 deletions
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<ToscaEntity> policies = new ArrayList<>(); - for (final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder : getRelevantPolicyDecoders(policyInput)) { - policies.addAll(policyDecoder.decode(policyInput)); + + try { + for (final PolicyDecoder<PolicyInput, ToscaEntity> 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); diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java index 2f2d42c3..1dc4bfe0 100644 --- a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java +++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,10 +119,10 @@ public class AbstractReceptionHandlerTest { handler.inputReceived(new DummyPolicyInput()); } - class DummyPolicyInput implements PolicyInput { + static class DummyPolicyInput implements PolicyInput { } - class DummyPolicy1 extends ToscaEntity { + static class DummyPolicy1 extends ToscaEntity { @Override public String getName() { @@ -129,7 +130,7 @@ public class AbstractReceptionHandlerTest { } } - class DummyPolicy2 extends ToscaEntity { + static class DummyPolicy2 extends ToscaEntity { @Override public String getName() { @@ -161,7 +162,7 @@ public class AbstractReceptionHandlerTest { } private Map<String, PolicyDecoderParameters> getPolicyDecoders() { - final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<String, PolicyDecoderParameters>(); + final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>(); final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME, DECODER_CONFIGURATION_PARAMETERS); policyDecoders.put(DECODER_KEY, pDParameters); @@ -170,7 +171,7 @@ public class AbstractReceptionHandlerTest { private Map<String, PolicyForwarderParameters> getPolicyForwarders() { final Map<String, PolicyForwarderParameters> policyForwarders = - new HashMap<String, PolicyForwarderParameters>(); + new HashMap<>(); final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS); policyForwarders.put(FORWARDER_KEY, pFParameters); @@ -180,9 +181,7 @@ public class AbstractReceptionHandlerTest { private PluginHandlerParameters getPluginHandlerParameters() { final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders(); final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders(); - final PluginHandlerParameters pluginHandlerParameters = - new PluginHandlerParameters(policyDecoders, policyForwarders); - return pluginHandlerParameters; + return new PluginHandlerParameters(policyDecoders, policyForwarders); } } |