exit jvm when detecting configuration problems 56/111656/2
authorjhh <jorge.hernandez-herrero@att.com>
Mon, 24 Aug 2020 18:09:58 +0000 (13:09 -0500)
committerjhh <jorge.hernandez-herrero@att.com>
Mon, 24 Aug 2020 18:31:56 +0000 (13:31 -0500)
It follows the same approach that in other policy
components by throwing a runtime-exception vs
System.exit(x).

Issue-ID: POLICY-2752
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Iba508fc7095b060373742849e394c8fdd2a2334f
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
policy-management/src/main/java/org/onap/policy/drools/system/Main.java
policy-management/src/main/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeException.java [new file with mode: 0644]
policy-management/src/test/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeExceptionTest.java [new file with mode: 0644]

index c53cbe9..4f0dc39 100644 (file)
@@ -26,6 +26,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.utils.resources.MessageConstants;
 import org.onap.policy.common.utils.security.CryptoUtils;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.properties.DroolsPropertyConstants;
@@ -102,7 +103,10 @@ public class Main {
         /* 4. Create and start the controllers */
         createAndStartControllers(logger, trans);
 
+        /* 5. Open the engine for dynamic configuration */
         PolicyEngineConstants.getManager().open();
+
+        logger.info(String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DROOLS_PDP));
     }
 
     private static void setSystemProperties() {
@@ -140,6 +144,8 @@ public class Main {
                         LoggerUtil.TRANSACTION_LOG_MARKER,
                         "Main: {} has been partially started",
                         PolicyEngineConstants.getManager());
+                throw new PolicyDroolsPdpRuntimeException(
+                        String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP));
             } else {
                 trans.setStatusCode(true).transaction();
             }
@@ -155,6 +161,8 @@ public class Main {
                     PolicyEngineConstants.getManager(),
                     e.getMessage(),
                     e);
+            throw new PolicyDroolsPdpRuntimeException(
+                    String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
         } catch (final Exception e) {
             trans
                 .setStatusCode(false)
@@ -167,7 +175,8 @@ public class Main {
                     PolicyEngineConstants.getManager(),
                     e.getMessage(),
                     e);
-            System.exit(1);
+            throw new PolicyDroolsPdpRuntimeException(
+                    String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
         }
         return trans;
     }
@@ -204,6 +213,8 @@ public class Main {
                         controllerName,
                         e.getMessage(),
                         e);
+                throw new PolicyDroolsPdpRuntimeException(
+                        String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
             } catch (final LinkageError e) {
                 trans
                     .setStatusCode(false)
@@ -216,7 +227,9 @@ public class Main {
                         controllerName,
                         e.getMessage(),
                         e);
+                throw new PolicyDroolsPdpRuntimeException(
+                        String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeException.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeException.java
new file mode 100644 (file)
index 0000000..719a2b8
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.system;
+
+public class PolicyDroolsPdpRuntimeException extends RuntimeException {
+    private static final long serialVersionUID = -1417471704362517416L;
+
+    /**
+     * Instantiates a new policy drools pdp runtime exception with a message.
+     *
+     * @param message the message
+     */
+    public PolicyDroolsPdpRuntimeException(final String message) {
+        super(message);
+    }
+
+    /**
+     * Instantiates a new policy drools pdp runtime exception with a message and a caused by exception.
+     *
+     * @param message the message
+     * @param exp the exception that caused this exception to be thrown
+     */
+    public PolicyDroolsPdpRuntimeException(final String message, final Throwable exp) {
+        super(message, exp);
+    }
+
+}
\ No newline at end of file
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeExceptionTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyDroolsPdpRuntimeExceptionTest.java
new file mode 100644 (file)
index 0000000..6459517
--- /dev/null
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.system;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ExceptionsTester;
+
+public class PolicyDroolsPdpRuntimeExceptionTest {
+
+    @Test
+    public void test() {
+        assertEquals(2, new ExceptionsTester().test(PolicyDroolsPdpRuntimeException.class));
+    }
+
+}