X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Fstartstop%2FMain.java;h=21bd5c48857c031cd3fe532d20d999e7cf0a1e28;hb=2d4db3c6375ca761b25700226addea6060432b0d;hp=23dcd269df37cb1620bcd7618953f1ac9fcdad04;hpb=304afadb59bdc83c25df315dbf16bd217b0ba5de;p=policy%2Fapi.git diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/Main.java b/main/src/main/java/org/onap/policy/api/main/startstop/Main.java index 23dcd269..21bd5c48 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/Main.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/Main.java @@ -3,7 +3,9 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +26,13 @@ package org.onap.policy.api.main.startstop; import java.util.Arrays; +import lombok.Getter; import org.onap.policy.api.main.exception.PolicyApiException; +import org.onap.policy.api.main.exception.PolicyApiRuntimeException; import org.onap.policy.api.main.parameters.ApiParameterGroup; import org.onap.policy.api.main.parameters.ApiParameterHandler; +import org.onap.policy.common.utils.cmd.CommandLineException; +import org.onap.policy.common.utils.resources.MessageConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +48,7 @@ public class Main { private ApiActivator activator; // The parameters read in from JSON + @Getter private ApiParameterGroup parameterGroup; /** @@ -50,11 +57,11 @@ public class Main { * @param args the command line arguments */ public Main(final String[] args) { - final String argumentString = Arrays.toString(args); + final var argumentString = Arrays.toString(args); LOGGER.info("Starting policy api service with arguments - {}", argumentString); // Check the arguments - final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); + final var arguments = new ApiCommandLineArguments(); try { // The arguments return a string if there is a message to print and we should exit final String argumentMessage = arguments.parse(args); @@ -65,50 +72,26 @@ public class Main { // Validate that the arguments are sane arguments.validate(); - } catch (final PolicyApiException e) { - LOGGER.error("start of policy api service failed", e); - return; - } - // Read the parameters - try { + // Read the parameters parameterGroup = new ApiParameterHandler().getParameters(arguments); - } catch (final Exception e) { - LOGGER.error("start of policy api service failed", e); - return; - } - - // Initialize database - try { + // Initialize database new ApiDatabaseInitializer().initializeApiDatabase(parameterGroup); - } catch (final PolicyApiException e) { - LOGGER.error("Preloading policy types into DB failed", e); - return; - } - // Now, create the activator for the policy api service - activator = new ApiActivator(parameterGroup); + // Now, create the activator for the policy api service + activator = new ApiActivator(parameterGroup); - // Start the activator - try { + // Start the activator activator.initialize(); - } catch (final PolicyApiException e) { - LOGGER.error("start of policy api service failed, used parameters are {} ", argumentString, e); - return; + } catch (final PolicyApiException | CommandLineException e) { + throw new PolicyApiRuntimeException( + String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_API), e); } // Add a shutdown hook to shut everything down in an orderly manner Runtime.getRuntime().addShutdownHook(new PolicyApiShutdownHookClass()); - LOGGER.info("Started policy api service"); - } - - /** - * Get the parameters specified in JSON. - * - * @return the parameters - */ - public ApiParameterGroup getParameters() { - return parameterGroup; + var successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_API); + LOGGER.info(successMsg); } /**