aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
authorhalil.cakal <halil.cakal@est.tech>2022-10-28 14:51:46 +0100
committerhalil.cakal <halil.cakal@est.tech>2022-11-01 15:05:56 +0000
commitc08690c4904d70f867c8d5b24aac2bb76f3dfbb0 (patch)
tree68744fa3d7ecd43a2aa83242371e41b4ec994cfb /a1-policy-management/src
parent6b99dcc7dc6b8b0eb66fbefe2a7e5470cdb6c92e (diff)
sonarcloud fixes
Sonarqube fixes Issue-ID: CCSDK-3766 Change-Id: Ib03463a13194c18b00ed0d99754d7884af0d805f Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'a1-policy-management/src')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java35
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java71
2 files changed, 49 insertions, 57 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java
index 8eb8fbcb..95999a04 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java
@@ -22,37 +22,37 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
import io.micrometer.core.instrument.MeterRegistry;
import java.lang.invoke.MethodHandles;
-import java.util.concurrent.atomic.AtomicLong;
+import lombok.AccessLevel;
+import lombok.Getter;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* The aim is to collect statistical values from the A1 Policy Management Service.
- * The counters are being updated every minute.
*/
-@EnableScheduling
@Component
public class RefreshCounterTask {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ @Autowired
private final Rics rics;
+
+ @Autowired
private final PolicyTypes policyTypes;
+
+ @Autowired
private final Policies policies;
+ @Autowired
+ @Getter(AccessLevel.PUBLIC)
private final MeterRegistry meterRegistry;
- private final AtomicLong ricCount;
- private final AtomicLong policyTypeCount;
- private final AtomicLong policyCount;
-
@Autowired
public RefreshCounterTask(Rics rics, PolicyTypes policyTypes, Policies policies, MeterRegistry meterRegistry) {
this.rics = rics;
@@ -60,19 +60,10 @@ public class RefreshCounterTask {
this.policies = policies;
this.meterRegistry = meterRegistry;
- ricCount = meterRegistry.gauge("total_ric_count", new AtomicLong(0));
- policyTypeCount = meterRegistry.gauge("total_policy_type_count", new AtomicLong(0));
- policyCount = meterRegistry.gauge("total_policy_count", new AtomicLong(0));
+ logger.trace("Counters have been initialized.");
+ meterRegistry.gauge("total_ric_count", rics, Rics::size);
+ meterRegistry.gauge("total_policy_type_count", policyTypes, PolicyTypes::size);
+ meterRegistry.gauge("total_policy_count", policies, Policies::size);
}
- /**
- * Every minute, updates counters for statistical purposes.
- */
- @Scheduled(fixedRate = 1000 * 60)
- public void checkAllCounters() {
- logger.trace("Checking counters starting...");
- ricCount.set(rics.size());
- policyCount.set(policies.size());
- policyTypeCount.set(policyTypes.size());
- }
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java
index 3adfb316..bd315c26 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java
@@ -23,6 +23,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy;
+import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import java.time.Instant;
@@ -42,7 +43,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
@ExtendWith(MockitoExtension.class)
-public class RefreshCounterTaskTest {
+class RefreshCounterTaskTest {
private static final String POLICY_TYPE_1_NAME = "type1";
private static final PolicyType POLICY_TYPE_1 = PolicyType.builder().id(POLICY_TYPE_1_NAME).schema("").build();
@@ -56,16 +57,16 @@ public class RefreshCounterTaskTest {
.ric(RIC_1).type(POLICY_TYPE_1).lastModified(Instant.now()).isTransient(false)
.statusNotificationUri("statusNotificationUri").build();
- private PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
+ private final PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
private final ApplicationConfig appConfig = new ApplicationConfig();
- private PolicyTypes types;
+ private PolicyTypes policyTypes;
private Policies policies;
private Rics rics = new Rics();
@BeforeEach
void init() {
- types = new PolicyTypes(appConfig);
+ policyTypes = new PolicyTypes(appConfig);
policies = new Policies(appConfig);
rics.clear();
@@ -79,16 +80,16 @@ public class RefreshCounterTaskTest {
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
rics.put(RIC_1);
- types.put(POLICY_TYPE_1);
+ policyTypes.put(POLICY_TYPE_1);
policies.put(POLICY_1);
- RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask());
- refreshCounterTaskUnderTest.checkAllCounters();
+ RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
+ MeterRegistry meterRegistry = spy.getMeterRegistry();
- assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
- assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
}
@Test
@@ -97,30 +98,30 @@ public class RefreshCounterTaskTest {
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
rics.put(RIC_1);
- types.put(POLICY_TYPE_1);
+ policyTypes.put(POLICY_TYPE_1);
policies.put(POLICY_1);
String POLICY_2_ID = "policyId2";
- Policy POLICY_2 = Policy.builder() //
- .id(POLICY_2_ID) //
- .json("") //
- .ownerServiceId("service") //
- .ric(RIC_1) //
- .type(POLICY_TYPE_1) //
- .lastModified(Instant.now()) //
+ Policy POLICY_2 = Policy.builder()
+ .id(POLICY_2_ID)
+ .json("")
+ .ownerServiceId("service")
+ .ric(RIC_1)
+ .type(POLICY_TYPE_1)
+ .lastModified(Instant.now())
.isTransient(false) //
- .statusNotificationUri("statusNotificationUri") //
+ .statusNotificationUri("statusNotificationUri")
.build();
policies.put(POLICY_2);
- RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask());
- refreshCounterTaskUnderTest.checkAllCounters();
+ RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
+ MeterRegistry meterRegistry = spy.getMeterRegistry();
- assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
- assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(2);
+ assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(2);
}
@Test
@@ -128,29 +129,29 @@ public class RefreshCounterTaskTest {
RIC_1.setState(Ric.RicState.AVAILABLE);
String POLICY_TYPE_2_NAME = "type2";
- PolicyType POLICY_TYPE_2 = PolicyType.builder() //
- .id(POLICY_TYPE_2_NAME) //
- .schema("") //
+ PolicyType POLICY_TYPE_2 = PolicyType.builder()
+ .id(POLICY_TYPE_2_NAME)
+ .schema("")
.build();
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
RIC_1.addSupportedPolicyType(POLICY_TYPE_2);
rics.put(RIC_1);
- types.put(POLICY_TYPE_1);
- types.put(POLICY_TYPE_2);
+ policyTypes.put(POLICY_TYPE_1);
+ policyTypes.put(POLICY_TYPE_2);
policies.put(POLICY_1);
- RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask());
- refreshCounterTaskUnderTest.checkAllCounters();
+ RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
+ MeterRegistry meterRegistry = spy.getMeterRegistry();
- assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(2);
- assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(2);
+ assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
}
private RefreshCounterTask createRefreshCounterTask() {
- return new RefreshCounterTask(rics, types, policies, prometheusMeterRegistry);
+ return new RefreshCounterTask(rics, policyTypes, policies, prometheusMeterRegistry);
}
}