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.context.annotation.Profile;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.web.bind.annotation.RestController;
37 * Class to provide REST endpoints for PAP component statistics.
39 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
42 @RequiredArgsConstructor
44 public class StatisticsRestControllerV1 extends PapRestControllerV1
45 implements StatisticsRestControllerV1Api {
47 private final PdpStatisticsService pdpStatisticsService;
50 * get statistics of PAP.
56 public ResponseEntity<StatisticsReport> statistics(UUID requestId) {
57 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
58 .body(pdpStatisticsService.fetchCurrentStatistics());
62 * get all statistics of PDP groups.
67 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics(
72 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(pdpStatisticsService
73 .fetchDatabaseStatistics(recordCount.intValue(), convertEpochtoInstant(startTime),
74 convertEpochtoInstant(endTime)));
79 * get all statistics of a PDP group.
81 * @param groupName name of the PDP group
85 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics(
91 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
92 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount.intValue(),
93 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
97 * get all statistics of sub PDP group.
99 * @param groupName name of the PDP group
100 * @param subType type of the sub PDP group
104 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics(
111 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
112 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount.intValue(),
113 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
117 * get all statistics of one PDP.
119 * @param groupName name of the PDP group
120 * @param subType type of the sub PDP group
121 * @param pdpName the name of the PDP
122 * @param recordCount the count of the query response, optional, default return all statistics stored
126 public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics(
134 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
135 .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount.intValue(),
136 convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));
139 private Instant convertEpochtoInstant(Long epochSecond) {
140 return (epochSecond == null ? null : Instant.ofEpochSecond(epochSecond));