diff options
Diffstat (limited to 'services')
3 files changed, 48 insertions, 45 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java index 04de6b1bc..076c50b40 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -199,14 +200,14 @@ public class ApexFileEventConsumer implements ApexEventConsumer, Runnable { } } while (!textBlock.isEndOfText()); } catch (final Exception e) { - LOGGER.warn("\"" + consumerName + "\" failed to read event from file: \"" - + fileCarrierTechnologyParameters.getFileName() + "\"", e); + LOGGER.warn("\"{}\" failed to read event from file: \"{}\"", consumerName, + fileCarrierTechnologyParameters.getFileName(), e); } finally { try { eventInputStream.close(); } catch (final IOException e) { - LOGGER.warn(APEX_FILE_CONSUMER_PREAMBLE + consumerName + "\" failed to close file: \"" - + fileCarrierTechnologyParameters.getFileName() + "\"", e); + LOGGER.warn("{}{}\" failed to close file: \"{}\"", APEX_FILE_CONSUMER_PREAMBLE, consumerName, + fileCarrierTechnologyParameters.getFileName(), e); } } @@ -220,8 +221,8 @@ public class ApexFileEventConsumer implements ApexEventConsumer, Runnable { try { eventInputStream.close(); } catch (final IOException e) { - LOGGER.warn(APEX_FILE_CONSUMER_PREAMBLE + consumerName + "\" failed to close file for reading: \"" - + fileCarrierTechnologyParameters.getFileName() + "\"", e); + LOGGER.warn("{}{}\" failed to close file for reading: \"{}\"", + APEX_FILE_CONSUMER_PREAMBLE, consumerName, fileCarrierTechnologyParameters.getFileName(), e); } if (consumerThread.isAlive() && !consumerThread.isInterrupted()) { diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java index 4a5fb360e..7daa22846 100644 --- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java +++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Bell Canada. 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. @@ -24,8 +25,10 @@ package org.onap.policy.apex.services.onappf; import java.util.Arrays; import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager; import org.onap.policy.apex.services.onappf.exception.ApexStarterException; +import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException; import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup; import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler; +import org.onap.policy.common.utils.resources.MessageConstants; import org.onap.policy.common.utils.services.Registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,8 +40,6 @@ import org.slf4j.LoggerFactory; */ public class ApexStarterMain { - private static final String APEX_STARTER_FAIL_MSG = "start of services-onappf failed"; - private static final Logger LOGGER = LoggerFactory.getLogger(ApexStarterMain.class); private ApexStarterActivator activator; @@ -50,7 +51,8 @@ public class ApexStarterMain { * @param args the command line arguments */ public ApexStarterMain(final String[] args) { - LOGGER.info("In ApexStarter with parameters " + Arrays.toString(args)); + final String params = Arrays.toString(args); + LOGGER.info("In ApexStarter with parameters {}", params); // Check the arguments final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments(); @@ -63,36 +65,30 @@ public class ApexStarterMain { } // Validate that the arguments are sane arguments.validate(); - } catch (final ApexStarterException e) { - LOGGER.error(APEX_STARTER_FAIL_MSG, e); - return; - } - // Read the parameters - try { + // Read the parameters parameterGroup = new ApexStarterParameterHandler().getParameters(arguments); - } catch (final Exception e) { - LOGGER.error(APEX_STARTER_FAIL_MSG, e); - return; - } - // create the activator - activator = new ApexStarterActivator(parameterGroup); - Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator); - Registry.register(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER, new ApexPolicyStatisticsManager()); - // Start the activator - try { + // create the activator + activator = new ApexStarterActivator(parameterGroup); + Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator); + Registry.register(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER, + new ApexPolicyStatisticsManager()); + + // Start the activator activator.initialize(); } catch (final ApexStarterException e) { - LOGGER.error("start of ApexStarter failed, used parameters are {}", Arrays.toString(args), e); - Registry.unregister(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR); - return; + if (null != activator) { + Registry.unregister(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR); + } + throw new ApexStarterRunTimeException( + String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_APEX_PDP), e); } // Add a shutdown hook to shut everything down in an orderly manner Runtime.getRuntime().addShutdownHook(new ApexStarterShutdownHookClass()); - - LOGGER.info("Started ApexStarter service"); + String successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_APEX_PDP); + LOGGER.info(successMsg); } /** diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java index adcec020b..f24329c29 100644 --- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java +++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020 Bell Canada. 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. @@ -22,9 +23,9 @@ package org.onap.policy.apex.services.onappf; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.After; @@ -32,7 +33,9 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager; import org.onap.policy.apex.services.onappf.exception.ApexStarterException; +import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException; import org.onap.policy.apex.services.onappf.parameters.CommonTestData; +import org.onap.policy.common.utils.resources.MessageConstants; import org.onap.policy.common.utils.services.Registry; /** @@ -59,8 +62,8 @@ public class TestApexStarterMain { @After public void tearDown() throws Exception { // shut down activator - final ApexStarterActivator activator = Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, - ApexStarterActivator.class, null); + final ApexStarterActivator activator = + Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class, null); if (activator != null && activator.isAlive()) { activator.terminate(); } @@ -68,43 +71,46 @@ public class TestApexStarterMain { @Test public void testApexStarter() throws ApexStarterException { - final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParametersNoop.json"}; + final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"}; apexStarter = new ApexStarterMain(apexStarterConfigParameters); assertTrue(apexStarter.getParameters().isValid()); assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName()); // ensure items were added to the registry assertNotNull(Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class)); - assertNotNull(Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER, - ApexPolicyStatisticsManager.class)); + assertNotNull( + Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER, ApexPolicyStatisticsManager.class)); apexStarter.shutdown(); } @Test public void testApexStarter_NoArguments() { final String[] apexStarterConfigParameters = {}; - apexStarter = new ApexStarterMain(apexStarterConfigParameters); - assertNull(apexStarter.getParameters()); + assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters)) + .isInstanceOf(ApexStarterRunTimeException.class) + .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_APEX_PDP)); } @Test public void testApexStarter_InvalidArguments() { - final String[] apexStarterConfigParameters = { "src/test/resources/ApexStarterConfigParameters.json" }; - apexStarter = new ApexStarterMain(apexStarterConfigParameters); - assertNull(apexStarter.getParameters()); + final String[] apexStarterConfigParameters = {"src/test/resources/ApexStarterConfigParameters.json"}; + assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters)) + .isInstanceOf(ApexStarterRunTimeException.class) + .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_APEX_PDP)); } @Test public void testApexStarter_Help() { - final String[] apexStarterConfigParameters = { "-h" }; + final String[] apexStarterConfigParameters = {"-h"}; assertThatCode(() -> ApexStarterMain.main(apexStarterConfigParameters)).doesNotThrowAnyException(); } @Test public void testApexStarter_InvalidParameters() { final String[] apexStarterConfigParameters = - { "-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json" }; - apexStarter = new ApexStarterMain(apexStarterConfigParameters); - assertNull(apexStarter.getParameters()); + {"-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json"}; + assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters)) + .isInstanceOf(ApexStarterRunTimeException.class) + .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_APEX_PDP)); } } |