2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2022 Nordix Foundation. 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.
18 * ========================LICENSE_END===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
23 import io.micrometer.core.instrument.MeterRegistry;
24 import java.lang.invoke.MethodHandles;
25 import java.util.concurrent.atomic.AtomicLong;
26 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
27 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
28 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.scheduling.annotation.EnableScheduling;
33 import org.springframework.scheduling.annotation.Scheduled;
34 import org.springframework.stereotype.Component;
37 * The aim is to collect statistical values from the A1 Policy Management Service.
38 * The counters are being updated every minute.
42 public class RefreshCounterTask {
44 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
46 private final Rics rics;
47 private final PolicyTypes policyTypes;
48 private final Policies policies;
50 private final MeterRegistry meterRegistry;
52 private final AtomicLong ricCount;
53 private final AtomicLong policyTypeCount;
54 private final AtomicLong policyCount;
57 public RefreshCounterTask(Rics rics, PolicyTypes policyTypes, Policies policies, MeterRegistry meterRegistry) {
59 this.policyTypes = policyTypes;
60 this.policies = policies;
61 this.meterRegistry = meterRegistry;
63 ricCount = meterRegistry.gauge("total_ric_count", new AtomicLong(0));
64 policyTypeCount = meterRegistry.gauge("total_policy_type_count", new AtomicLong(0));
65 policyCount = meterRegistry.gauge("total_policy_count", new AtomicLong(0));
69 * Every minute, updates counters for statistical purposes.
71 @Scheduled(fixedRate = 1000 * 60)
72 public void checkAllCounters() {
73 logger.trace("Checking counters starting...");
74 ricCount.set(rics.size());
75 policyCount.set(policies.size());
76 policyTypeCount.set(policyTypes.size());