diff options
Diffstat (limited to 'main')
14 files changed, 140 insertions, 21 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java index beef4750..f231130a 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java @@ -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); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java index 641546c1..824d1dbd 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java @@ -69,7 +69,7 @@ public class PolicyNotifier { publish(notification); - } catch (PfModelException e) { + } catch (PfModelException | RuntimeException e) { logger.warn("cannot update deployment status", e); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/DmaapGetTopicResponse.java b/main/src/main/java/org/onap/policy/pap/main/rest/DmaapGetTopicResponse.java new file mode 100644 index 00000000..82886509 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/DmaapGetTopicResponse.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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. + * 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.pap.main.rest; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to capture get topic response from dmaap. + */ +@Getter +@Setter +@ToString +public class DmaapGetTopicResponse { + + private List<String> topics; +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java index 1e1732f2..300d3c72 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java @@ -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) diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java index c28b91e4..576eb8d8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java @@ -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) diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java index 9435296d..31574ab1 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java @@ -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) diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java index b1e1f5cf..2eceb4b0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020-2021 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. @@ -195,26 +195,32 @@ public class PolicyComponentsHealthCheckProvider { HealthCheckReport clientReport; try { Response resp = httpClient.get(); - clientReport = replaceIpWithHostname(resp.readEntity(HealthCheckReport.class), httpClient.getBaseUrl()); + if (httpClient.getName().equalsIgnoreCase("dmaap")) { + clientReport = verifyDmaapClient(httpClient, resp); + } else { + clientReport = replaceIpWithHostname(resp.readEntity(HealthCheckReport.class), httpClient.getBaseUrl()); + } - // A health report is read successfully when HTTP status is not OK, it is also not healthy + // A health report is read successfully when HTTP status is not OK, it is also + // not healthy // even in the report it says healthy. if (resp.getStatus() != HttpURLConnection.HTTP_OK) { clientReport.setHealthy(false); } } catch (RuntimeException e) { LOGGER.warn("{} connection error", httpClient.getName()); - clientReport = createUnHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(), - HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage()); + clientReport = createHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(), + HttpURLConnection.HTTP_INTERNAL_ERROR, false, e.getMessage()); } return clientReport; } - private HealthCheckReport createUnHealthCheckReport(String name, String url, int code, String message) { + private HealthCheckReport createHealthCheckReport(String name, String url, int code, boolean status, + String message) { var report = new HealthCheckReport(); report.setName(name); report.setUrl(url); - report.setHealthy(false); + report.setHealthy(status); report.setCode(code); report.setMessage(message); return report; @@ -229,6 +235,17 @@ public class PolicyComponentsHealthCheckProvider { return report; } + private HealthCheckReport verifyDmaapClient(HttpClient httpClient, Response resp) { + DmaapGetTopicResponse dmaapResponse = resp.readEntity(DmaapGetTopicResponse.class); + var topicVerificationStatus = (dmaapResponse.getTopics() != null + && dmaapResponse.getTopics().contains(PapConstants.TOPIC_POLICY_PDP_PAP)); + String message = (topicVerificationStatus ? "PAP to DMaaP connection check is successfull" + : "PAP to DMaaP connection check failed"); + int code = (topicVerificationStatus ? resp.getStatus() : 503); + return createHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(), code, + topicVerificationStatus, message); + } + /** * This method clears clients {@link List} and clientHealthCheckExecutorService {@link ExecutorService}. */ diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java index bd187dcb..718ae574 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java @@ -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) diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java index 5c28e7a6..d180c934 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java @@ -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); } } diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml index c2cf972d..3e1d428d 100644 --- a/main/src/main/resources/META-INF/persistence.xml +++ b/main/src/main/resources/META-INF/persistence.xml @@ -61,7 +61,7 @@ <properties> <property name="javax.persistence.schema-generation.database.action" value="none" /> <property name="eclipselink.ddl-generation" value="none" /> - <property name="eclipselink.logging.level" value="INFO" /> + <property name="eclipselink.logging.level" value="WARNING" /> </properties> </persistence-unit> </persistence> diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java index 27c01e18..e626d28d 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java @@ -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; @@ -423,6 +424,13 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { } @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); group.setPdpSubgroups(List.of(makeSubGroup(MY_SUBGROUP, PDP1, PDP2, PDP3))); @@ -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 diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java index 3f4ecd32..f27a8d32 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Corp. - * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020-2021 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. @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import java.io.File; import java.net.HttpURLConnection; +import java.util.Arrays; import java.util.List; import java.util.Map; import javax.ws.rs.core.Response; @@ -89,11 +90,17 @@ public class TestPolicyComponentsHealthCheckProvider { private HttpClient client2; @Mock + private HttpClient client3; + + @Mock private Response response1; @Mock private Response response2; + @Mock + private Response response3; + private List<PdpGroup> groups; private PapParameterGroup savedPapParameterGroup; @@ -133,10 +140,17 @@ public class TestPolicyComponentsHealthCheckProvider { when(response2.readEntity(HealthCheckReport.class)).thenReturn(createReport(HttpURLConnection.HTTP_OK, true)); when(client2.get()).thenReturn(response2); + when(client3.getName()).thenReturn("dmaap"); + when(client3.getBaseUrl()).thenReturn("message-router"); + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_OK); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(createDmaapResponse()); + when(client3.get()).thenReturn(response3); + PapParameterGroup papParameterGroup = ParameterService.get(PAP_GROUP_PARAMS_NAME); List<RestClientParameters> params = papParameterGroup.getHealthCheckRestClientParameters(); when(clientFactory.build(params.get(0))).thenReturn(client1); when(clientFactory.build(params.get(1))).thenReturn(client2); + when(clientFactory.build(params.get(2))).thenReturn(client3); PolicyComponentsHealthCheckProvider.initializeClientHealthCheckExecutorService(papParameterGroup, clientFactory); @@ -180,6 +194,20 @@ public class TestPolicyComponentsHealthCheckProvider { assertFalse((Boolean) result2.get(HEALTHY)); HealthCheckReport report2 = (HealthCheckReport) result.get(CLIENT_1); assertFalse(report2.isHealthy()); + + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(null); + Map<String, Object> result3 = callFetchPolicyComponentsHealthStatus(); + assertFalse((Boolean) result3.get(HEALTHY)); + HealthCheckReport report3 = (HealthCheckReport) result3.get("dmaap"); + assertFalse(report3.isHealthy()); + + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_OK); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(new DmaapGetTopicResponse()); + Map<String, Object> result4 = callFetchPolicyComponentsHealthStatus(); + assertFalse((Boolean) result4.get(HEALTHY)); + HealthCheckReport report4 = (HealthCheckReport) result4.get("dmaap"); + assertFalse(report4.isHealthy()); } @SuppressWarnings("unchecked") @@ -234,4 +262,10 @@ public class TestPolicyComponentsHealthCheckProvider { throw new RuntimeException(e); } } + + private DmaapGetTopicResponse createDmaapResponse() { + DmaapGetTopicResponse response = new DmaapGetTopicResponse(); + response.setTopics(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP)); + return response; + } } diff --git a/main/src/test/resources/parameters/PapConfigParameters.json b/main/src/test/resources/parameters/PapConfigParameters.json index 09adfcec..4f59d69b 100644 --- a/main/src/test/resources/parameters/PapConfigParameters.json +++ b/main/src/test/resources/parameters/PapConfigParameters.json @@ -68,5 +68,12 @@ "password": "zb!XztG34", "useHttps": true, "basePath": "healthcheck" + }, + { + "clientName": "dmaap", + "hostname": "message-router", + "port": 3905, + "useHttps": true, + "basePath": "topics" }] } diff --git a/main/src/test/resources/parameters/PapConfigParametersStd.json b/main/src/test/resources/parameters/PapConfigParametersStd.json index 0f881430..56e891a1 100644 --- a/main/src/test/resources/parameters/PapConfigParametersStd.json +++ b/main/src/test/resources/parameters/PapConfigParametersStd.json @@ -69,5 +69,12 @@ "password": "zb!XztG34", "useHttps": true, "basePath": "healthcheck" + }, + { + "clientName": "dmaap", + "hostname": "message-router", + "port": 3905, + "useHttps": true, + "basePath": "topics" }] } |