2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2023 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.rest;
25 import java.time.Instant;
26 import java.util.List;
28 import java.util.UUID;
29 import lombok.RequiredArgsConstructor;
30 import org.onap.policy.models.pdp.concepts.PdpStatistics;
31 import org.onap.policy.pap.main.service.PdpStatisticsService;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.RestController;
36 * Class to provide REST endpoints for PAP component statistics.
38 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41 @RequiredArgsConstructor
42 public class StatisticsRestControllerV1 extends PapRestControllerV1
43 implements StatisticsRestControllerV1Api {
45 private final PdpStatisticsService pdpStatisticsService;
48 * get statistics of PAP.
54 public ResponseEntity<StatisticsReport> statistics(UUID requestId) {
55 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
56 .body(pdpStatisticsService.fetchCurrentStatistics());
60 * get all statistics of PDP groups.
65 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics(
70 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(pdpStatisticsService
71 .fetchDatabaseStatistics(recordCount.intValue(), convertEpochtoInstant(startTime),
72 convertEpochtoInstant(endTime)));
77 * get all statistics of a PDP group.
79 * @param groupName name of the PDP group
83 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics(
89 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
90 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount.intValue(),
91 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
95 * get all statistics of sub PDP group.
97 * @param groupName name of the PDP group
98 * @param subType type of the sub PDP group
102 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics(
109 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
110 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount.intValue(),
111 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
115 * get all statistics of one PDP.
117 * @param groupName name of the PDP group
118 * @param subType type of the sub PDP group
119 * @param pdpName the name of the PDP
120 * @param recordCount the count of the query response, optional, default return all statistics stored
124 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics(
132 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
133 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount.intValue(),
134 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
137 private Instant convertEpochtoInstant(Long epochSecond) {
138 return (epochSecond == null ? null : Instant.ofEpochSecond(epochSecond));