diff options
Diffstat (limited to 'main/src/main/java/org/onap')
13 files changed, 6 insertions, 884 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java index 98859f10..58a484ff 100644 --- a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java +++ b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2022-2023 Bell Canada. All rights reserved. * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,6 @@ public final class PapConstants { // Registry keys public static final String REG_PAP_ACTIVATOR = "object:activator/pap"; - public static final String REG_STATISTICS_MANAGER = "object:manager/statistics"; public static final String REG_PDP_MODIFY_LOCK = "lock:pdp"; public static final String REG_PDP_MODIFY_MAP = "object:pdp/modify/map"; public static final String REG_METER_REGISTRY = "object:meter/registry"; diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java index dc4a030b..696a6942 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java @@ -38,7 +38,6 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroupFilter; -import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; @@ -48,7 +47,6 @@ import org.onap.policy.pap.main.PolicyPapException; import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.onap.policy.pap.main.parameters.PdpParameters; import org.onap.policy.pap.main.service.PdpGroupService; -import org.onap.policy.pap.main.service.PdpStatisticsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -66,12 +64,8 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { private final PdpParameters params; - private final boolean savePdpStatistics; - private final PdpGroupService pdpGroupService; - private final PdpStatisticsService pdpStatisticsService; - /** * List to store policies present in db. */ @@ -92,15 +86,11 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { * * @param parameterGroup the parameterGroup * @param pdpGroupService the pdpGroupService - * @param pdpStatisticsService the pdpStatisticsService */ - public PdpStatusMessageHandler(PapParameterGroup parameterGroup, PdpGroupService pdpGroupService, - PdpStatisticsService pdpStatisticsService) { + public PdpStatusMessageHandler(PapParameterGroup parameterGroup, PdpGroupService pdpGroupService) { super(true); this.params = parameterGroup.getPdpParameters(); - this.savePdpStatistics = parameterGroup.isSavePdpStatisticsInDb(); this.pdpGroupService = pdpGroupService; - this.pdpStatisticsService = pdpStatisticsService; } /** @@ -294,12 +284,6 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } else if (validatePdpDetails(message, pdpGroup, pdpSubGroup, pdpInstance)) { LOGGER.debug("PdpInstance details are correct. Saving current state in DB - {}", pdpInstance); updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup); - - if (savePdpStatistics) { - processPdpStatistics(message, pdpSubGroup, pdpInstance, pdpGroup); - } else { - LOGGER.debug("Not processing PdpStatistics - {}", message.getStatistics()); - } } else { LOGGER.debug("PdpInstance details are not correct. Sending PdpUpdate message - {}", pdpInstance); LOGGER.debug("Policy list in DB - {}. Policy list in heartbeat - {}", pdpSubGroup.getPolicies(), @@ -309,17 +293,6 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } } - private void processPdpStatistics(final PdpStatus message, final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, - final PdpGroup pdpGroup) { - if (validatePdpStatisticsDetails(message, pdpInstance, pdpGroup, pdpSubGroup)) { - LOGGER.debug("PdpStatistics details are correct. Saving current statistics in DB - {}", - message.getStatistics()); - createPdpStatistics(message.getStatistics()); - } else { - LOGGER.debug("PdpStatistics details are not correct - {}", message.getStatistics()); - } - } - private void processPdpTermination(final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, final PdpGroup pdpGroup) { pdpSubGroup.getPdpInstances().remove(pdpInstance); pdpSubGroup.setCurrentInstanceCount(pdpSubGroup.getCurrentInstanceCount() - 1); @@ -343,28 +316,6 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { .append(subGroup.getPolicies().containsAll(message.getPolicies()), true).build(); } - private boolean validatePdpStatisticsDetails(final PdpStatus message, final Pdp pdpInstanceDetails, - final PdpGroup pdpGroup, final PdpSubGroup pdpSubGroup) { - if (message.getStatistics() != null) { - return new EqualsBuilder() - .append(message.getStatistics().getPdpInstanceId(), pdpInstanceDetails.getInstanceId()) - .append(message.getStatistics().getPdpGroupName(), pdpGroup.getName()) - .append(message.getStatistics().getPdpSubGroupName(), pdpSubGroup.getPdpType()) - .append(message.getStatistics().getPolicyDeployCount() < 0, false) - .append(message.getStatistics().getPolicyDeployFailCount() < 0, false) - .append(message.getStatistics().getPolicyDeploySuccessCount() < 0, false) - .append(message.getStatistics().getPolicyUndeployCount() < 0, false) - .append(message.getStatistics().getPolicyUndeployFailCount() < 0, false) - .append(message.getStatistics().getPolicyUndeploySuccessCount() < 0, false) - .append(message.getStatistics().getPolicyExecutedCount() < 0, false) - .append(message.getStatistics().getPolicyExecutedFailCount() < 0, false) - .append(message.getStatistics().getPolicyExecutedSuccessCount() < 0, false).build(); - } else { - LOGGER.debug("PdpStatistics is null"); - return false; - } - } - private void updatePdpHealthStatus(final PdpStatus message, final PdpSubGroup pdpSubgroup, final Pdp pdpInstance, final PdpGroup pdpGroup) { pdpInstance.setHealthy(message.getHealthy()); @@ -375,11 +326,6 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { LOGGER.debug("Updated Pdp in DB - {}", pdpInstance); } - private void createPdpStatistics(final PdpStatistics pdpStatistics) { - pdpStatisticsService.createPdpStatistics(Arrays.asList(pdpStatistics)); - LOGGER.debug("Created PdpStatistics in DB - {}", pdpStatistics); - } - private void sendPdpMessage(final String pdpGroupName, final PdpSubGroup subGroup, final String pdpInstanceId, final PdpState pdpState) { final List<ToscaPolicy> polsToBeDeployed = new LinkedList<>(policiesToBeDeployed.values()); diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java index 6165d422..8bee9786 100644 --- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java +++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2023 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. @@ -50,7 +50,6 @@ public class PapParameterGroup extends ParameterGroupImpl { @Valid @ParameterGroupConstraint private PdpParameters pdpParameters; - private boolean savePdpStatisticsInDb; @Valid @ParameterGroupConstraint private TopicParameterGroup topicParameterGroup; diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java index bca00e87..026ec0fb 100644 --- a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java +++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2023 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. @@ -43,7 +43,6 @@ public class PdpModifyRequestMapParams { private PdpParameters params; private TimerManager updateTimers; private TimerManager stateChangeTimers; - private boolean savePdpStatistics; /** * Validates the parameters. diff --git a/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java b/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java deleted file mode 100644 index f2dfeebd..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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.repository; - -import java.util.Date; -import java.util.List; -import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PdpStatisticsRepository extends JpaRepository<JpaPdpStatistics, Long> { - - List<JpaPdpStatistics> findByTimeStampBetween(Date startTime, Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByTimeStampGreaterThanEqual(Date startTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByTimeStampLessThanEqual(Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupName(String pdpGroup, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndTimeStampBetween(String pdpGroup, Date startTime, Date endTime, - Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndTimeStampGreaterThanEqual(String pdpGroup, Date startTime, - Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndTimeStampLessThanEqual(String pdpGroup, Date endTime, - Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupName(String pdpGroup, String pdpSubGroup, - Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndTimeStampBetween(String pdpGroup, String pdpSubGroup, - Date startTime, Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndTimeStampGreaterThanEqual(String pdpGroup, - String pdpSubGroup, Date startTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndTimeStampLessThanEqual(String pdpGroup, - String pdpSubGroup, Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndName(String pdpGroup, String pdpSubGroup, - String pdp, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampGreaterThanEqual(String pdpGroup, - String pdpSubGroup, String pdp, Date startTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampLessThanEqual(String pdpGroup, - String pdpSubGroup, String pdp, Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampBetween(String pdpGroup, - String pdpSubGroup, String pdp, Date startTime, Date endTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByName(String pdp, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByNameAndTimeStampGreaterThanEqual(String pdp, Date startTime, - Pageable topRecordsSize); - - List<JpaPdpStatistics> findByNameAndTimeStampLessThanEqual(String pdp, Date startTime, Pageable topRecordsSize); - - List<JpaPdpStatistics> findByNameAndTimeStampBetween(String pdp, Date startTime, Date endTime, - Pageable topRecordsSize); - -} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java deleted file mode 100644 index daa1a9c4..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 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. - * 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.concurrent.atomic.AtomicLong; - -/** - * Class to hold statistical data for pap component. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -public class PapStatisticsManager { - - private final AtomicLong totalPdpCount = new AtomicLong(0); - private final AtomicLong totalPdpGroupCount = new AtomicLong(0); - private final AtomicLong totalPolicyDeployCount = new AtomicLong(0); - private final AtomicLong policyDeploySuccessCount = new AtomicLong(0); - private final AtomicLong policyDeployFailureCount = new AtomicLong(0); - private final AtomicLong totalPolicyDownloadCount = new AtomicLong(0); - private final AtomicLong policyDownloadSuccessCount = new AtomicLong(0); - private final AtomicLong policyDownloadFailureCount = new AtomicLong(0); - - /** - * Constructs the object. - */ - public PapStatisticsManager() { - super(); - } - - /** - * Method to update the total pdp count. - * - * @return the updated value of totalPdpCount - */ - public long updateTotalPdpCount() { - return totalPdpCount.incrementAndGet(); - } - - /** - * Method to update the total pdp group count. - * - * @return the updated value of totalPdpGroupCount - */ - public long updateTotalPdpGroupCount() { - return totalPdpGroupCount.incrementAndGet(); - } - - /** - * Method to update the total policy deploy count. - * - * @return the updated value of totalPolicyDeployCount - */ - public long updateTotalPolicyDeployCount() { - return totalPolicyDeployCount.incrementAndGet(); - } - - /** - * Method to update the policy deploy success count. - * - * @return the updated value of policyDeploySuccessCount - */ - public long updatePolicyDeploySuccessCount() { - return policyDeploySuccessCount.incrementAndGet(); - } - - /** - * Method to update the policy deploy failure count. - * - * @return the updated value of policyDeployFailureCount - */ - public long updatePolicyDeployFailureCount() { - return policyDeployFailureCount.incrementAndGet(); - } - - /** - * Method to update the total policy download count. - * - * @return the updated value of totalPolicyDownloadCount - */ - public long updateTotalPolicyDownloadCount() { - return totalPolicyDownloadCount.incrementAndGet(); - } - - /** - * Method to update the policy download success count. - * - * @return the updated value of policyDownloadSuccessCount - */ - public long updatePolicyDownloadSuccessCount() { - return policyDownloadSuccessCount.incrementAndGet(); - } - - /** - * Method to update the policy download failure count. - * - * @return the updated value of policyDownloadFailureCount - */ - public long updatePolicyDownloadFailureCount() { - return policyDownloadFailureCount.incrementAndGet(); - } - - /** - * Reset all the statistics counts to 0. - */ - public void resetAllStatistics() { - totalPdpCount.set(0L); - totalPdpGroupCount.set(0L); - totalPolicyDeployCount.set(0L); - policyDeploySuccessCount.set(0L); - policyDeployFailureCount.set(0L); - totalPolicyDownloadCount.set(0L); - policyDownloadSuccessCount.set(0L); - policyDownloadFailureCount.set(0L); - } - - public long getTotalPdpCount() { - return totalPdpCount.get(); - } - - public long getTotalPdpGroupCount() { - return totalPdpGroupCount.get(); - } - - public long getTotalPolicyDeployCount() { - return totalPolicyDeployCount.get(); - } - - public long getPolicyDeploySuccessCount() { - return policyDeploySuccessCount.get(); - } - - public long getPolicyDeployFailureCount() { - return policyDeployFailureCount.get(); - } - - public long getTotalPolicyDownloadCount() { - return totalPolicyDownloadCount.get(); - } - - public long getPolicyDownloadSuccessCount() { - return policyDownloadSuccessCount.get(); - } - - public long getPolicyDownloadFailureCount() { - return policyDownloadFailureCount.get(); - } -} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java index 2963fe62..7a3e3395 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019, 2022 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020-2021 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021, 2023 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. @@ -56,7 +56,6 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.pap.main.PapConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -429,8 +428,6 @@ public class PdpGroupDeployProvider extends ProviderBase { ToscaConceptIdentifier desiredIdent = policy.getIdentifier(); ToscaConceptIdentifier desiredType = policy.getTypeIdentifier(); - PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class); - mgr.updateTotalPolicyDeployCount(); return (group, subgroup) -> { diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsReport.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsReport.java deleted file mode 100644 index e84d9684..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsReport.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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 lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent statistics report of pap component. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -@Getter -@Setter -@ToString -public class StatisticsReport { - - private int code; - private long totalPdpCount; - private long totalPdpGroupCount; - private long totalPolicyDeployCount; - private long policyDeploySuccessCount; - private long policyDeployFailureCount; - private long totalPolicyDownloadCount; - private long policyDownloadSuccessCount; - private long policyDownloadFailureCount; -} 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 deleted file mode 100644 index 2af6e731..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2023 Nordix Foundation. - * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021-2022 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.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import lombok.RequiredArgsConstructor; -import org.onap.policy.models.pdp.concepts.PdpStatistics; -import org.onap.policy.pap.main.service.PdpStatisticsService; -import org.springframework.context.annotation.Profile; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -/** - * Class to provide REST endpoints for PAP component statistics. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -@RestController -@RequiredArgsConstructor -@Profile("default") -public class StatisticsRestControllerV1 extends PapRestControllerV1 - implements StatisticsRestControllerV1Api { - - private final PdpStatisticsService pdpStatisticsService; - - /** - * get statistics of PAP. - * - * - * @return a response - */ - @Override - public ResponseEntity<StatisticsReport> statistics(UUID requestId) { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchCurrentStatistics()); - } - - /** - * get all statistics of PDP groups. - * - * @return a response - */ - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics( - UUID requestId, - Integer recordCount, - Long startTime, - Long endTime) { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(pdpStatisticsService - .fetchDatabaseStatistics(recordCount.intValue(), convertEpochtoInstant(startTime), - convertEpochtoInstant(endTime))); - } - - - /** - * get all statistics of a PDP group. - * - * @param groupName name of the PDP group - * @return a response - */ - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics( - String groupName, - UUID requestId, - Integer recordCount, - Long startTime, - Long endTime) { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount.intValue(), - convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); - } - - /** - * get all statistics of sub PDP group. - * - * @param groupName name of the PDP group - * @param subType type of the sub PDP group - * @return a response - */ - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics( - String groupName, - String subType, - UUID requestId, - Integer recordCount, - Long startTime, - Long endTime) { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount.intValue(), - convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); - } - - /** - * get all statistics of one PDP. - * - * @param groupName name of the PDP group - * @param subType type of the sub PDP group - * @param pdpName the name of the PDP - * @param recordCount the count of the query response, optional, default return all statistics stored - * @return a response - */ - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics( - String groupName, - String subType, - String pdpName, - UUID requestId, - Integer recordCount, - Long startTime, - Long endTime) { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount.intValue(), - convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); - } - - private Instant convertEpochtoInstant(Long epochSecond) { - return (epochSecond == null ? null : Instant.ofEpochSecond(epochSecond)); - } - -} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java deleted file mode 100644 index 663f1acc..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. - * ================================================================================ - * 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.stub; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import javax.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.onap.policy.models.pdp.concepts.PdpStatistics; -import org.onap.policy.pap.main.rest.PapRestControllerV1; -import org.onap.policy.pap.main.rest.StatisticsReport; -import org.onap.policy.pap.main.rest.StatisticsRestControllerV1Api; -import org.springframework.context.annotation.Profile; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@Profile("stub") -public class StatisticsRestControllerV1Stub extends PapRestControllerV1 - implements StatisticsRestControllerV1Api { - - private final StubUtils stubUtils; - - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics( - String group, - UUID requestId, - @Valid Integer recordCount, - @Valid Long startTime, - @Valid Long endTime) { - return stubUtils.getStubbedResponseStatistics(); - } - - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics( - String group, - String type, - String pdp, - UUID requestId, - @Valid Integer recordCount, - @Valid Long startTime, - @Valid Long endTime) { - return stubUtils.getStubbedResponseStatistics(); - } - - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics( - UUID requestId, @Valid Integer recordCount, @Valid Long startTime, @Valid Long endTime) { - return stubUtils.getStubbedResponseStatistics(); - } - - @Override - public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics( - String group, - String type, - UUID requestId, - @Valid Integer recordCount, - @Valid Long startTime, - @Valid Long endTime) { - return stubUtils.getStubbedResponseStatistics(); - } - - @Override - public ResponseEntity<StatisticsReport> statistics(UUID requestId) { - return stubUtils.getStubbedResponse(StatisticsReport.class); - } - -} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java index 1f4f10f3..8eb4aba3 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; -import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.pap.main.rest.PapRestControllerV1; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,13 +103,4 @@ class StubUtils { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } - ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> getStubbedResponseStatistics() { - var accept = request.getHeader(ACCEPT); - if (accept != null && accept.contains(APPLICATION_JSON)) { - Map<String, Map<String, List<PdpStatistics>>> map = new HashMap<>(); - return new ResponseEntity<>(map, HttpStatus.OK); - } - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - } diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java b/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java deleted file mode 100644 index eba34f30..00000000 --- a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java +++ /dev/null @@ -1,275 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. - * ================================================================================ - * 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.service; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.utils.services.Registry; -import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.pdp.concepts.PdpStatistics; -import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics; -import org.onap.policy.pap.main.PapConstants; -import org.onap.policy.pap.main.repository.PdpStatisticsRepository; -import org.onap.policy.pap.main.rest.PapStatisticsManager; -import org.onap.policy.pap.main.rest.StatisticsReport; -import org.onap.policy.pap.main.startstop.PapActivator; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class PdpStatisticsService { - - private static final String TIMESTAMP = "timeStamp"; - private static final int DEFAULT_RECORD_COUNT = 10; - private static final int MAX_RECORD_COUNT = 100; - - private final PdpStatisticsRepository pdpStatisticsRepository; - - /** - * Returns the current statistics of pap component. - * - * @return Report containing statistics of pap component - */ - public StatisticsReport fetchCurrentStatistics() { - final var report = new StatisticsReport(); - report.setCode(Registry.get(PapConstants.REG_PAP_ACTIVATOR, PapActivator.class).isAlive() ? 200 : 500); - - PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class); - report.setTotalPdpCount(mgr.getTotalPdpCount()); - report.setTotalPdpGroupCount(mgr.getTotalPdpGroupCount()); - report.setTotalPolicyDownloadCount(mgr.getTotalPolicyDownloadCount()); - report.setPolicyDownloadSuccessCount(mgr.getPolicyDownloadSuccessCount()); - report.setPolicyDownloadFailureCount(mgr.getPolicyDownloadFailureCount()); - report.setTotalPolicyDeployCount(mgr.getTotalPolicyDeployCount()); - report.setPolicyDeploySuccessCount(mgr.getPolicyDeploySuccessCount()); - report.setPolicyDeployFailureCount(mgr.getPolicyDeployFailureCount()); - - return report; - } - - /** - * Creates PDP statistics. - * - * @param pdpStatisticsList a specification of the PDP statistics to create - * @return the PDP statistics created - */ - public List<PdpStatistics> createPdpStatistics(@NonNull final List<PdpStatistics> pdpStatisticsList) { - for (PdpStatistics pdpStatistics : pdpStatisticsList) { - var jpaPdpStatistics = new JpaPdpStatistics(); - jpaPdpStatistics.fromAuthorative(pdpStatistics); - BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics"); - if (!validationResult.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); - } - pdpStatisticsRepository.saveAndFlush(jpaPdpStatistics); - pdpStatistics.setGeneratedId(jpaPdpStatistics.getGeneratedId()); - } - - // Return the created PDP statistics - List<PdpStatistics> pdpStatistics = new ArrayList<>(pdpStatisticsList.size()); - - for (PdpStatistics pdpStatisticsItem : pdpStatisticsList) { - @SuppressWarnings("deprecation") - var jpaPdpStatistics = pdpStatisticsRepository.getById(pdpStatisticsItem.getGeneratedId()); - pdpStatistics.add(jpaPdpStatistics.toAuthorative()); - } - return pdpStatistics; - } - - /** - * Fetch PdpStatistics from db. - * - * @param pdpGroup the name of the group - * @param pdpSubGroup the name of the subgroup - * @param pdp the pdp instance id - * @param recordCount the number of records to return - * @param startTime start time of the records to be returned - * @param endTime end time of the records to be returned - * @return pdpStatistics grouped by pdpGroup - */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, - @NonNull String pdpSubGroup, @NonNull String pdp, int recordCount, Instant startTime, Instant endTime) { - - Pageable recordSize = getRecordSize(recordCount); - if (startTime != null && endTime != null) { - return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository - .findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampBetween(pdpGroup, pdpSubGroup, pdp, - convertInstantToDate(startTime), convertInstantToDate(endTime), recordSize))); - } else if (startTime == null && endTime == null) { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndName(pdpGroup, - pdpSubGroup, pdp, recordSize))); - } else if (startTime != null) { - return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampGreaterThanEqual( - pdpGroup, pdpSubGroup, pdp, convertInstantToDate(startTime), recordSize))); - } else { - return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampLessThanEqual( - pdpGroup, pdpSubGroup, pdp, convertInstantToDate(endTime), recordSize))); - } - } - - /** - * Fetch PdpStatistics from db. - * - * @param pdpGroup the name of the group - * @param pdpSubGroup the name of the subgroup - * @param recordCount the number of records to return - * @param startTime start time of the records to be returned - * @param endTime end time of the records to be returned - * @return pdpStatistics grouped by pdpGroup - */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, - @NonNull String pdpSubGroup, int recordCount, Instant startTime, Instant endTime) { - - Pageable recordSize = getRecordSize(recordCount); - if (startTime != null && endTime != null) { - return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndTimeStampBetween(pdpGroup, pdpSubGroup, - convertInstantToDate(startTime), convertInstantToDate(endTime), recordSize))); - } else if (startTime == null && endTime == null) { - return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository - .findByPdpGroupNameAndPdpSubGroupName(pdpGroup, pdpSubGroup, recordSize))); - } else if (startTime != null) { - return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndTimeStampGreaterThanEqual(pdpGroup, - pdpSubGroup, convertInstantToDate(startTime), recordSize))); - } else { - return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndTimeStampLessThanEqual(pdpGroup, - pdpSubGroup, convertInstantToDate(endTime), recordSize))); - } - } - - /** - * Fetch PdpStatistics from db. - * - * @param pdpGroup the name of the group - * @param recordCount the number of records to return - * @param startTime start time of the records to be returned - * @param endTime end time of the records to be returned - * @return pdpStatistics grouped by pdpGroup - */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, - int recordCount, Instant startTime, Instant endTime) { - - Pageable recordSize = getRecordSize(recordCount); - if (startTime != null && endTime != null) { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndTimeStampBetween(pdpGroup, - convertInstantToDate(startTime), convertInstantToDate(endTime), recordSize))); - } else if (startTime == null && endTime == null) { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupName(pdpGroup, recordSize))); - } else if (startTime != null) { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndTimeStampGreaterThanEqual(pdpGroup, - convertInstantToDate(startTime), recordSize))); - } else { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndTimeStampLessThanEqual(pdpGroup, - convertInstantToDate(endTime), recordSize))); - } - } - - /** - * Fetch PdpStatistics from db. - * - * @param recordCount the number of records to return - * @param startTime start time of the records to be returned - * @param endTime end time of the records to be returned - * @return pdpStatistics grouped by pdpGroup - */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(int recordCount, Instant startTime, - Instant endTime) { - - Pageable recordSize = getRecordSize(recordCount); - if (startTime != null && endTime != null) { - return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository.findByTimeStampBetween( - convertInstantToDate(startTime), convertInstantToDate(endTime), recordSize))); - } else if (startTime == null && endTime == null) { - return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findAll(recordSize).toList())); - } else if (startTime != null) { - return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository - .findByTimeStampGreaterThanEqual(convertInstantToDate(startTime), recordSize))); - } else { - return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository - .findByTimeStampLessThanEqual(convertInstantToDate(endTime), recordSize))); - } - } - - private Pageable getRecordSize(int recordCount) { - if (recordCount < 1) { - recordCount = DEFAULT_RECORD_COUNT; - } else if (recordCount > MAX_RECORD_COUNT) { - recordCount = MAX_RECORD_COUNT; - } - return PageRequest.of(0, recordCount, Sort.by(TIMESTAMP).descending()); - } - - /** - * generate the statistics of pap component by group/subgroup. - * - */ - private Map<String, Map<String, List<PdpStatistics>>> generatePdpStatistics(List<PdpStatistics> pdpStatisticsList) { - Map<String, Map<String, List<PdpStatistics>>> groupMap = new HashMap<>(); - if (pdpStatisticsList != null) { - pdpStatisticsList.stream().forEach(s -> { - String curGroup = s.getPdpGroupName(); - String curSubGroup = s.getPdpSubGroupName(); - groupMap.computeIfAbsent(curGroup, curGroupMap -> new HashMap<>()) - .computeIfAbsent(curSubGroup, curSubGroupList -> new ArrayList<>()).add(s); - }); - } - return groupMap; - } - - /** - * Convert JPA PDP statistics list to an PDP statistics list. - * - * @param jpaPdpStatisticsList the list to convert - * @return the PDP statistics list - */ - private List<PdpStatistics> asPdpStatisticsList(List<JpaPdpStatistics> jpaPdpStatisticsList) { - return jpaPdpStatisticsList.stream().map(JpaPdpStatistics::toAuthorative).collect(Collectors.toList()); - } - - private Date convertInstantToDate(Instant instant) { - return (instant == null ? null : Date.from(instant)); - } -} diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java index 825208a4..4d90d7e1 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2023 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. @@ -50,7 +50,6 @@ import org.onap.policy.pap.main.comm.TimerManager; import org.onap.policy.pap.main.notification.PolicyNotifier; import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams; -import org.onap.policy.pap.main.rest.PapStatisticsManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; @@ -172,10 +171,6 @@ public class PapActivator extends ServiceManagerContainer { TopicEndpointManager.getManager()::start, TopicEndpointManager.getManager()::shutdown); - addAction("PAP statistics", - () -> Registry.register(PapConstants.REG_STATISTICS_MANAGER, new PapStatisticsManager()), - () -> Registry.unregister(PapConstants.REG_STATISTICS_MANAGER)); - addAction("PAP Activator", () -> Registry.register(PapConstants.REG_PAP_ACTIVATOR, this), () -> Registry.unregister(PapConstants.REG_PAP_ACTIVATOR)); @@ -224,7 +219,6 @@ public class PapActivator extends ServiceManagerContainer { .responseDispatcher(responseReqIdDispatcher) .stateChangeTimers(pdpStChgTimers.get()) .updateTimers(pdpUpdTimers.get()) - .savePdpStatistics(papParameterGroup.isSavePdpStatisticsInDb()) .build()); requestMap.set(pdpModifyRequestMap); Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get()); |