Allow xacml-pdp to use kafka
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / startstop / Main.java
index 62b811d..a096d1f 100644 (file)
@@ -1,7 +1,8 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 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.
 package org.onap.policy.pdpx.main.startstop;
 
 import java.util.Arrays;
-import java.util.Properties;
 import lombok.Getter;
-import org.onap.policy.common.endpoints.utils.ParameterUtils;
+import org.onap.policy.common.utils.resources.MessageConstants;
 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
+import org.onap.policy.pdpx.main.PolicyXacmlPdpRuntimeException;
 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
 import org.slf4j.Logger;
@@ -43,7 +44,7 @@ public class Main {
     private XacmlPdpActivator activator;
 
     @Getter
-    private String argumentMessage = null;
+    private String argumentMessage;
 
     /**
      * Instantiates the policy xacml pdp service.
@@ -52,11 +53,11 @@ public class Main {
      * @throws PolicyXacmlPdpException if an error occurs
      */
     public Main(final String[] args) throws PolicyXacmlPdpException {
-        final String argumentString = Arrays.toString(args);
+        final var argumentString = Arrays.toString(args);
         LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
 
         // Check the arguments
-        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
+        final var arguments = new XacmlPdpCommandLineArguments();
 
         // The arguments return a string if there is a message to print and we should exit
         argumentMessage = arguments.parse(args);
@@ -71,11 +72,8 @@ public class Main {
         // Read the parameters
         XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
 
-        // Read the properties
-        Properties props = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
-
         // Now, create the activator for the policy xacml pdp service
-        activator = new XacmlPdpActivator(parameterGroup, props);
+        activator = new XacmlPdpActivator(parameterGroup);
         XacmlPdpActivator.setCurrent(activator);
 
         // Start the activator
@@ -83,13 +81,13 @@ public class Main {
 
         // Add a shutdown hook to shut everything down in an orderly manner
         Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
-        LOGGER.info("Started policy xacml pdp service");
+        var successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_XACML_PDP);
+        LOGGER.info(successMsg);
     }
 
     /**
      * Shut down Execution.
      *
-     * @throws PolicyXacmlPdpException on shutdown errors
      */
     public synchronized void shutdown() {
         // clear the xacml pdp activator
@@ -100,15 +98,18 @@ public class Main {
     }
 
     /**
-     * The main method.
+     * The main method. The NOSONAR is for security hotspot for checking
+     * command line arguments. Since we use XacmlPdpCommandLineArguments
+     * and validate the arguments the NOSONAR is ok to clear it.
      *
      * @param args the arguments
      */
-    public static void main(final String[] args) {
+    public static void main(final String[] args) { //NOSONAR
         try {
             new Main(args);
         } catch (RuntimeException | PolicyXacmlPdpException e) {
-            LOGGER.error("start of policy xacml pdp service failed", e);
+            throw new PolicyXacmlPdpRuntimeException(
+                String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_XACML_PDP), e);
         }
     }
 }