Changes to make policy-distribution container crash with non zero exitCode 34/111534/1
authora.sreekumar <ajith.sreekumar@bell.ca>
Fri, 21 Aug 2020 12:01:47 +0000 (13:01 +0100)
committera.sreekumar <ajith.sreekumar@bell.ca>
Fri, 21 Aug 2020 12:02:41 +0000 (13:02 +0100)
Change-Id: Ic637253513b349ccb3f17b7c3fce1414bd5ec022
Issue-ID: POLICY-2756
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java

index 2fc86c2..6acef4d 100644 (file)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2020 AT&T Inc.
+ *  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.
@@ -23,7 +24,9 @@
 package org.onap.policy.distribution.main.startstop;
 
 import java.util.Arrays;
+import org.onap.policy.common.utils.resources.MessageConstants;
 import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
 import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
 import org.onap.policy.distribution.main.parameters.DistributionParameterHandler;
 import org.slf4j.Logger;
@@ -64,35 +67,24 @@ public class Main {
 
             // Validate that the arguments are sane
             arguments.validate();
-        } catch (final PolicyDistributionException e) {
-            LOGGER.error("start of policy distribution service failed", e);
-            return;
-        }
 
-        // Read the parameters
-        try {
+            // Read the parameters
             parameterGroup = new DistributionParameterHandler().getParameters(arguments);
-        } catch (final Exception e) {
-            LOGGER.error("start of policy distribution service failed", e);
-            return;
-        }
 
-        // Now, create the activator for the policy distribution service
-        activator = new DistributionActivator(parameterGroup);
+            // Now, create the activator for the policy distribution service
+            activator = new DistributionActivator(parameterGroup);
 
-        // Start the activator
-        try {
+            // Start the activator
             activator.initialize();
         } catch (final PolicyDistributionException e) {
-            LOGGER.error("start of policy distribution service failed, used parameters are {}",
-                    Arrays.toString(args),
-                    e);
-            return;
+            throw new PolicyDistributionRuntimeException(
+                String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION), e);
         }
 
         // Add a shutdown hook to shut everything down in an orderly manner
         Runtime.getRuntime().addShutdownHook(new PolicyDistributionShutdownHookClass());
-        LOGGER.info("Started policy distribution service");
+        String successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DISTRIBUTION);
+        LOGGER.info(successMsg);
     }
 
     /**
index d8bdd98..4094bd5 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2020 AT&T Inc.
+ *  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.distribution.main.startstop;
 
 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.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import org.junit.Test;
+import org.onap.policy.common.utils.resources.MessageConstants;
 import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
 import org.onap.policy.distribution.main.parameters.CommonTestData;
 
 /**
@@ -50,18 +53,18 @@ public class TestMain {
 
     @Test
     public void testMain_NoArguments() {
-        final String[] distributionConfigParameters =
-        {};
-        final Main main = new Main(distributionConfigParameters);
-        assertNull(main.getParameters());
+        final String[] distributionConfigParameters = {};
+        assertThatThrownBy(() -> new Main(distributionConfigParameters))
+            .isInstanceOf(PolicyDistributionRuntimeException.class)
+            .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
     }
 
     @Test
     public void testMain_InvalidArguments() {
-        final String[] distributionConfigParameters =
-        { "parameters/DistributionConfigParameters.json" };
-        final Main main = new Main(distributionConfigParameters);
-        assertNull(main.getParameters());
+        final String[] distributionConfigParameters = {"parameters/DistributionConfigParameters.json"};
+        assertThatThrownBy(() -> new Main(distributionConfigParameters))
+            .isInstanceOf(PolicyDistributionRuntimeException.class)
+            .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
     }
 
     @Test
@@ -76,8 +79,9 @@ public class TestMain {
     @Test
     public void testMain_InvalidParameters() {
         final String[] distributionConfigParameters =
-        { "-c", "parameters/DistributionConfigParameters_InvalidName.json" };
-        final Main main = new Main(distributionConfigParameters);
-        assertNull(main.getParameters());
+            {"-c", "parameters/DistributionConfigParameters_InvalidName.json"};
+        assertThatThrownBy(() -> new Main(distributionConfigParameters))
+            .isInstanceOf(PolicyDistributionRuntimeException.class)
+            .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
     }
 }