Fix PAP PDP expiration timer 13/123813/1
authorJim Hahn <jrh3@att.com>
Thu, 2 Sep 2021 13:39:37 +0000 (09:39 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 2 Sep 2021 13:52:26 +0000 (09:52 -0400)
Added runtime exceptions to the "catch" clause so that the thread
associated with the PDP expiration timer will not terminate.
Also added to a few other "catch" clauses, particularly those in the
REST controllers.

Issue-ID: POLICY-3625
Change-Id: I9206121d3e9b91da593ae771e7586752b13949be
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java
main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java
main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java
main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java

index beef475..f231130 100644 (file)
@@ -295,7 +295,7 @@ public class PdpModifyRequestMap {
                     policyNotifier.publish(notification);
                 }
 
-            } catch (PfModelException e) {
+            } catch (PfModelException | RuntimeException e) {
                 logger.warn("failed to remove expired PDPs", e);
             }
         }
index 641546c..824d1db 100644 (file)
@@ -69,7 +69,7 @@ public class PolicyNotifier {
 
             publish(notification);
 
-        } catch (PfModelException e) {
+        } catch (PfModelException | RuntimeException e) {
             logger.warn("cannot update deployment status", e);
         }
     }
index 1e1732f..300d3c7 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019,2021 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 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.
@@ -36,6 +37,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.Pdps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -95,7 +97,7 @@ public class PdpGroupHealthCheckControllerV1 extends PapRestControllerV1 {
             final Pair<Status, Pdps> pair = provider.fetchPdpGroupHealthStatus();
             return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
                     .entity(pair.getRight()).build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info("pdpGroup health check failed", exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
index c28b91e..576eb8d 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019,2021 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -96,7 +97,7 @@ public class PdpGroupQueryControllerV1 extends PapRestControllerV1 {
             final Pair<Status, PdpGroups> pair = provider.fetchPdpGroupDetails();
             return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
                     .entity(pair.getRight()).build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info("group query failed", exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
index 9435296..31574ab 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2021 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.slf4j.Logger;
@@ -102,7 +103,7 @@ public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 {
             final Pair<Status, PdpGroupStateChangeResponse> pair = provider.changeGroupState(groupName, state);
             return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
                     .entity(pair.getRight()).build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info("group state-change failed", exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
index bd187dc..718ae57 100644 (file)
@@ -39,6 +39,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -124,7 +125,7 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
                                     .endTime(convertEpochtoInstant(endTime))
                                     .build()))
                     .build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
@@ -182,7 +183,7 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
                                     .endTime(convertEpochtoInstant(endTime))
                                     .build()))
                     .build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
@@ -243,7 +244,7 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
                                     .endTime(convertEpochtoInstant(endTime))
                                     .build()))
                     .build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
@@ -310,7 +311,7 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
                                     .endTime(convertEpochtoInstant(endTime))
                                     .build()))
                     .build();
-        } catch (final PfModelException exp) {
+        } catch (final PfModelException | PfModelRuntimeException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
             return addLoggingHeaders(
                     addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
index 5c28e7a..d180c93 100644 (file)
@@ -82,7 +82,7 @@ public class PapDatabaseInitializer {
                 LOGGER.info("Initial pdpGroup already exists in DB, skipping create - {} from {}",
                         pdpGroupsFromDb, groupsJson);
             }
-        } catch (final PfModelException | CoderException exp) {
+        } catch (final PfModelException | CoderException | RuntimeException exp) {
             throw new PolicyPapException(exp);
         }
     }
index 27c01e1..e626d28 100644 (file)
@@ -56,6 +56,7 @@ import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpMessage;
@@ -422,6 +423,13 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
         assertThatCode(map::removeExpiredPdps).doesNotThrowAnyException();
     }
 
+    @Test
+    public void testRemoveExpiredPdps_DaoRtEx() throws Exception {
+        when(dao.getFilteredPdpGroups(any())).thenThrow(makeRuntimeException());
+
+        assertThatCode(map::removeExpiredPdps).doesNotThrowAnyException();
+    }
+
     @Test
     public void testRemoveFromSubgroup() throws Exception {
         PdpGroup group = makeGroup(MY_GROUP);
@@ -454,6 +462,10 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
         return new PfModelException(Status.BAD_REQUEST, "expected exception");
     }
 
+    protected PfModelRuntimeException makeRuntimeException() {
+        return new PfModelRuntimeException(Status.BAD_REQUEST, "expected exception");
+    }
+
     @Test
     public void testMakePdpRequests() {
         // this should invoke the real method without throwing an exception