summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-16 15:34:32 -0400
committerJim Hahn <jrh3@att.com>2021-07-21 11:23:29 -0400
commit014db93590258af9d04d317a391f0f43ac71526c (patch)
tree863fb44daaa9c601ee8f580aa2fb82621f35d3eb /main/src
parent6c5332aef8f348c362a2aa4b91f47078fc68dcfc (diff)
Use singleton for api statistics
Reimplemented the statistics manager to use a singleton instead of static fields. Also changed some fields to "private". Issue-ID: POLICY-3392 Change-Id: Ic708f7fa29cba795c47d387764267016163f679f Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java89
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiStatisticsManager.java177
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/StatisticsReport.java30
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java17
-rw-r--r--main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java29
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java50
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiStatisticsManager.java51
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java8
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java14
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java6
10 files changed, 180 insertions, 291 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
index 5e845089..eb60c5e5 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
@@ -1093,7 +1093,8 @@ public class ApiRestController extends CommonRestController {
private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
- ApiStatisticsManager.updateTotalApiCallCount();
+ var mgr = ApiStatisticsManager.getInstance();
+ mgr.updateTotalApiCallCount();
switch (target) {
case POLICY:
@@ -1103,98 +1104,102 @@ public class ApiRestController extends CommonRestController {
updatePolicyTypeStats(result, http);
break;
default:
- ApiStatisticsManager.updateApiCallSuccessCount();
+ mgr.updateApiCallSuccessCount();
break;
}
}
private void updatePolicyStats(Result result, HttpMethod http) {
+ var mgr = ApiStatisticsManager.getInstance();
+
if (result == Result.SUCCESS) {
switch (http) {
case GET:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyGetCount();
- ApiStatisticsManager.updatePolicyGetSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyGetCount();
+ mgr.updatePolicyGetSuccessCount();
break;
case POST:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyPostCount();
- ApiStatisticsManager.updatePolicyPostSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyPostCount();
+ mgr.updatePolicyPostSuccessCount();
break;
case DELETE:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyDeleteCount();
- ApiStatisticsManager.updatePolicyDeleteSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyDeleteCount();
+ mgr.updatePolicyDeleteSuccessCount();
break;
default:
- ApiStatisticsManager.updateApiCallSuccessCount();
+ mgr.updateApiCallSuccessCount();
break;
}
} else {
switch (http) {
case GET:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyGetCount();
- ApiStatisticsManager.updatePolicyGetFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyGetCount();
+ mgr.updatePolicyGetFailureCount();
break;
case POST:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyPostCount();
- ApiStatisticsManager.updatePolicyPostFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyPostCount();
+ mgr.updatePolicyPostFailureCount();
break;
case DELETE:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyDeleteCount();
- ApiStatisticsManager.updatePolicyDeleteFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyDeleteCount();
+ mgr.updatePolicyDeleteFailureCount();
break;
default:
- ApiStatisticsManager.updateApiCallFailureCount();
+ mgr.updateApiCallFailureCount();
break;
}
}
}
private void updatePolicyTypeStats(Result result, HttpMethod http) {
+ var mgr = ApiStatisticsManager.getInstance();
+
if (result == Result.SUCCESS) {
switch (http) {
case GET:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyTypeGetCount();
- ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyTypeGetCount();
+ mgr.updatePolicyTypeGetSuccessCount();
break;
case POST:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyTypePostCount();
- ApiStatisticsManager.updatePolicyTypePostSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyTypePostCount();
+ mgr.updatePolicyTypePostSuccessCount();
break;
case DELETE:
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateTotalPolicyTypeDeleteCount();
- ApiStatisticsManager.updatePolicyTypeDeleteSuccessCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateTotalPolicyTypeDeleteCount();
+ mgr.updatePolicyTypeDeleteSuccessCount();
break;
default:
- ApiStatisticsManager.updateApiCallSuccessCount();
+ mgr.updateApiCallSuccessCount();
break;
}
} else {
switch (http) {
case GET:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyTypeGetCount();
- ApiStatisticsManager.updatePolicyTypeGetFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyTypeGetCount();
+ mgr.updatePolicyTypeGetFailureCount();
break;
case POST:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyTypePostCount();
- ApiStatisticsManager.updatePolicyTypePostFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyTypePostCount();
+ mgr.updatePolicyTypePostFailureCount();
break;
case DELETE:
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyTypeDeleteCount();
- ApiStatisticsManager.updatePolicyTypeDeleteFailureCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyTypeDeleteCount();
+ mgr.updatePolicyTypeDeleteFailureCount();
break;
default:
- ApiStatisticsManager.updateApiCallFailureCount();
+ mgr.updateApiCallFailureCount();
break;
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiStatisticsManager.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiStatisticsManager.java
index 5be9cf1a..2a4a46ae 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/ApiStatisticsManager.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiStatisticsManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2021 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@
package org.onap.policy.api.main.rest;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -32,79 +31,27 @@ import lombok.NoArgsConstructor;
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ApiStatisticsManager {
-
- @Getter
- private static long totalApiCallCount;
-
- @Getter
- private static long apiCallSuccessCount;
-
- @Getter
- private static long apiCallFailureCount;
-
- @Getter
- private static long totalPolicyGetCount;
-
- @Getter
- private static long totalPolicyPostCount;
-
- @Getter
- private static long totalPolicyDeleteCount;
-
- @Getter
- private static long totalPolicyTypeGetCount;
-
- @Getter
- private static long totalPolicyTypePostCount;
-
- @Getter
- private static long totalPolicyTypeDeleteCount;
-
- @Getter
- private static long policyGetSuccessCount;
-
+@Getter
+@NoArgsConstructor
+public class ApiStatisticsManager {
@Getter
- private static long policyGetFailureCount;
+ private static ApiStatisticsManager instance = new ApiStatisticsManager();
- @Getter
- private static long policyPostSuccessCount;
-
- @Getter
- private static long policyPostFailureCount;
-
- @Getter
- private static long policyDeleteSuccessCount;
-
- @Getter
- private static long policyDeleteFailureCount;
-
- @Getter
- private static long policyTypeGetSuccessCount;
-
- @Getter
- private static long policyTypeGetFailureCount;
-
- @Getter
- private static long policyTypePostSuccessCount;
-
- @Getter
- private static long policyTypePostFailureCount;
-
- @Getter
- private static long policyTypeDeleteSuccessCount;
-
- @Getter
- private static long policyTypeDeleteFailureCount;
+ private StatisticsReport report = new StatisticsReport();
+ private long totalPolicyDeleteCount;
+ private long totalPolicyTypeDeleteCount;
+ private long policyDeleteSuccessCount;
+ private long policyDeleteFailureCount;
+ private long policyTypeDeleteSuccessCount;
+ private long policyTypeDeleteFailureCount;
/**
* Method to update the total api call count.
*
* @return the updated value of totalApiCallCount
*/
- public static long updateTotalApiCallCount() {
- return ++totalApiCallCount;
+ public long updateTotalApiCallCount() {
+ return ++report.totalApiCallCount;
}
/**
@@ -112,8 +59,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of apiCallSuccessCount
*/
- public static long updateApiCallSuccessCount() {
- return ++apiCallSuccessCount;
+ public long updateApiCallSuccessCount() {
+ return ++report.apiCallSuccessCount;
}
/**
@@ -121,8 +68,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of apiCallFailureCount
*/
- public static long updateApiCallFailureCount() {
- return ++apiCallFailureCount;
+ public long updateApiCallFailureCount() {
+ return ++report.apiCallFailureCount;
}
/**
@@ -130,8 +77,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyGetCount
*/
- public static long updateTotalPolicyGetCount() {
- return ++totalPolicyGetCount;
+ public long updateTotalPolicyGetCount() {
+ return ++report.totalPolicyGetCount;
}
/**
@@ -139,8 +86,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyPostCount
*/
- public static long updateTotalPolicyPostCount() {
- return ++totalPolicyPostCount;
+ public long updateTotalPolicyPostCount() {
+ return ++report.totalPolicyPostCount;
}
/**
@@ -148,7 +95,7 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyDeleteCount
*/
- public static long updateTotalPolicyDeleteCount() {
+ public long updateTotalPolicyDeleteCount() {
return ++totalPolicyDeleteCount;
}
@@ -157,8 +104,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyTypeGetCount
*/
- public static long updateTotalPolicyTypeGetCount() {
- return ++totalPolicyTypeGetCount;
+ public long updateTotalPolicyTypeGetCount() {
+ return ++report.totalPolicyTypeGetCount;
}
/**
@@ -166,8 +113,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyTypePostCount
*/
- public static long updateTotalPolicyTypePostCount() {
- return ++totalPolicyTypePostCount;
+ public long updateTotalPolicyTypePostCount() {
+ return ++report.totalPolicyTypePostCount;
}
/**
@@ -175,7 +122,7 @@ public final class ApiStatisticsManager {
*
* @return the updated value of totalPolicyTypeDeleteCount
*/
- public static long updateTotalPolicyTypeDeleteCount() {
+ public long updateTotalPolicyTypeDeleteCount() {
return ++totalPolicyTypeDeleteCount;
}
@@ -184,8 +131,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyGetSuccessCount
*/
- public static long updatePolicyGetSuccessCount() {
- return ++policyGetSuccessCount;
+ public long updatePolicyGetSuccessCount() {
+ return ++report.policyGetSuccessCount;
}
/**
@@ -193,8 +140,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyGetFailureCount
*/
- public static long updatePolicyGetFailureCount() {
- return ++policyGetFailureCount;
+ public long updatePolicyGetFailureCount() {
+ return ++report.policyGetFailureCount;
}
/**
@@ -202,8 +149,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyPostSuccessCount
*/
- public static long updatePolicyPostSuccessCount() {
- return ++policyPostSuccessCount;
+ public long updatePolicyPostSuccessCount() {
+ return ++report.policyPostSuccessCount;
}
/**
@@ -211,8 +158,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyPostFailureCount
*/
- public static long updatePolicyPostFailureCount() {
- return ++policyPostFailureCount;
+ public long updatePolicyPostFailureCount() {
+ return ++report.policyPostFailureCount;
}
/**
@@ -220,7 +167,7 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyDeleteSuccessCount
*/
- public static long updatePolicyDeleteSuccessCount() {
+ public long updatePolicyDeleteSuccessCount() {
return ++policyDeleteSuccessCount;
}
@@ -229,7 +176,7 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyDeleteFailureCount
*/
- public static long updatePolicyDeleteFailureCount() {
+ public long updatePolicyDeleteFailureCount() {
return ++policyDeleteFailureCount;
}
@@ -238,8 +185,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypeGetSuccessCount
*/
- public static long updatePolicyTypeGetSuccessCount() {
- return ++policyTypeGetSuccessCount;
+ public long updatePolicyTypeGetSuccessCount() {
+ return ++report.policyTypeGetSuccessCount;
}
/**
@@ -247,8 +194,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypeGetFailureCount
*/
- public static long updatePolicyTypeGetFailureCount() {
- return ++policyTypeGetFailureCount;
+ public long updatePolicyTypeGetFailureCount() {
+ return ++report.policyTypeGetFailureCount;
}
/**
@@ -256,8 +203,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypePostSuccessCount
*/
- public static long updatePolicyTypePostSuccessCount() {
- return ++policyTypePostSuccessCount;
+ public long updatePolicyTypePostSuccessCount() {
+ return ++report.policyTypePostSuccessCount;
}
/**
@@ -265,8 +212,8 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypePostFailureCount
*/
- public static long updatePolicyTypePostFailureCount() {
- return ++policyTypePostFailureCount;
+ public long updatePolicyTypePostFailureCount() {
+ return ++report.policyTypePostFailureCount;
}
/**
@@ -274,7 +221,7 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypeDeleteSuccessCount
*/
- public static long updatePolicyTypeDeleteSuccessCount() {
+ public long updatePolicyTypeDeleteSuccessCount() {
return ++policyTypeDeleteSuccessCount;
}
@@ -283,36 +230,14 @@ public final class ApiStatisticsManager {
*
* @return the updated value of policyTypePostFailureCount
*/
- public static long updatePolicyTypeDeleteFailureCount() {
+ public long updatePolicyTypeDeleteFailureCount() {
return ++policyTypeDeleteFailureCount;
}
/**
- * Reset all the statistics counts to 0.
+ * Resets the statistics.
*/
- public static void resetAllStatistics() {
- totalApiCallCount = 0L;
- apiCallSuccessCount = 0L;
- apiCallFailureCount = 0L;
- totalPolicyGetCount = 0L;
- totalPolicyPostCount = 0L;
- totalPolicyDeleteCount = 0L;
- totalPolicyTypeGetCount = 0L;
- totalPolicyTypePostCount = 0L;
- totalPolicyTypeDeleteCount = 0L;
- policyGetSuccessCount = 0L;
- policyGetFailureCount = 0L;
- policyPostSuccessCount = 0L;
- policyPostFailureCount = 0L;
- policyDeleteSuccessCount = 0L;
- policyDeleteFailureCount = 0L;
- policyTypeGetSuccessCount = 0L;
- policyTypeGetFailureCount = 0L;
- policyTypePostSuccessCount = 0L;
- policyTypePostFailureCount = 0L;
- policyTypeDeleteSuccessCount = 0L;
- policyTypeDeleteFailureCount = 0L;
-
+ protected static void resetAllStatistics() {
+ instance = new ApiStatisticsManager();
}
-
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/StatisticsReport.java b/main/src/main/java/org/onap/policy/api/main/rest/StatisticsReport.java
index e434f04a..bf12c7f5 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/StatisticsReport.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/StatisticsReport.java
@@ -37,19 +37,19 @@ import lombok.ToString;
@Setter
public class StatisticsReport {
private int code;
- private long totalApiCallCount;
- private long apiCallSuccessCount;
- private long apiCallFailureCount;
- private long totalPolicyGetCount;
- private long totalPolicyPostCount;
- private long totalPolicyTypeGetCount;
- private long totalPolicyTypePostCount;
- private long policyGetSuccessCount;
- private long policyGetFailureCount;
- private long policyPostSuccessCount;
- private long policyPostFailureCount;
- private long policyTypeGetSuccessCount;
- private long policyTypeGetFailureCount;
- private long policyTypePostSuccessCount;
- private long policyTypePostFailureCount;
+ protected long totalApiCallCount;
+ protected long apiCallSuccessCount;
+ protected long apiCallFailureCount;
+ protected long totalPolicyGetCount;
+ protected long totalPolicyPostCount;
+ protected long totalPolicyTypeGetCount;
+ protected long totalPolicyTypePostCount;
+ protected long policyGetSuccessCount;
+ protected long policyGetFailureCount;
+ protected long policyPostSuccessCount;
+ protected long policyPostFailureCount;
+ protected long policyTypeGetSuccessCount;
+ protected long policyTypeGetFailureCount;
+ protected long policyTypePostSuccessCount;
+ protected long policyTypePostFailureCount;
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java
index dadc630e..9df00470 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java
@@ -40,23 +40,8 @@ public class StatisticsProvider {
* @return Report containing API statistics
*/
public StatisticsReport fetchCurrentStatistics() {
- final var report = new StatisticsReport();
+ final var report = ApiStatisticsManager.getInstance().getReport();
report.setCode(ApiActivator.isAlive() ? 200 : 500);
- report.setTotalApiCallCount(ApiStatisticsManager.getTotalApiCallCount());
- report.setApiCallSuccessCount(ApiStatisticsManager.getApiCallSuccessCount());
- report.setApiCallFailureCount(ApiStatisticsManager.getApiCallFailureCount());
- report.setTotalPolicyGetCount(ApiStatisticsManager.getTotalPolicyGetCount());
- report.setTotalPolicyPostCount(ApiStatisticsManager.getTotalPolicyPostCount());
- report.setTotalPolicyTypeGetCount(ApiStatisticsManager.getTotalPolicyTypeGetCount());
- report.setTotalPolicyTypePostCount(ApiStatisticsManager.getTotalPolicyTypePostCount());
- report.setPolicyGetSuccessCount(ApiStatisticsManager.getPolicyGetSuccessCount());
- report.setPolicyGetFailureCount(ApiStatisticsManager.getPolicyGetFailureCount());
- report.setPolicyPostSuccessCount(ApiStatisticsManager.getPolicyPostSuccessCount());
- report.setPolicyPostFailureCount(ApiStatisticsManager.getPolicyPostFailureCount());
- report.setPolicyTypeGetSuccessCount(ApiStatisticsManager.getPolicyTypeGetSuccessCount());
- report.setPolicyTypeGetFailureCount(ApiStatisticsManager.getPolicyTypeGetFailureCount());
- report.setPolicyTypePostSuccessCount(ApiStatisticsManager.getPolicyTypePostSuccessCount());
- report.setPolicyTypePostFailureCount(ApiStatisticsManager.getPolicyTypePostFailureCount());
return report;
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
index a630ea9b..156837d5 100644
--- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
+++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,7 @@
package org.onap.policy.api.main.startstop;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.onap.policy.api.main.exception.PolicyApiException;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
@@ -39,27 +40,19 @@ import org.slf4j.LoggerFactory;
* This class wraps a distributor so that it can be activated as a complete service together with all its api and
* forwarding handlers.
*/
+@RequiredArgsConstructor
public class ApiActivator {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiActivator.class);
@Getter
- private final ApiParameterGroup apiParameterGroup;
-
- @Getter
@Setter
private static boolean alive = false;
- private RestServer restServer;
+ @Getter
+ private final ApiParameterGroup parameterGroup;
- /**
- * Instantiate the activator for policy api as a complete service.
- *
- * @param apiParameterGroup the parameters for the api service
- */
- public ApiActivator(final ApiParameterGroup apiParameterGroup) {
- this.apiParameterGroup = apiParameterGroup;
- }
+ private RestServer restServer;
/**
* Initialize api as a complete service.
@@ -69,7 +62,7 @@ public class ApiActivator {
public void initialize() throws PolicyApiException {
LOGGER.debug("Policy api starting as a service . . .");
startApiRestServer();
- registerToParameterService(apiParameterGroup);
+ registerToParameterService(parameterGroup);
ApiActivator.setAlive(true);
LOGGER.debug("Policy api started as a service");
}
@@ -80,8 +73,8 @@ public class ApiActivator {
* @throws PolicyApiException if server start fails
*/
private void startApiRestServer() throws PolicyApiException {
- apiParameterGroup.getRestServerParameters().setName(apiParameterGroup.getName());
- restServer = new RestServer(apiParameterGroup.getRestServerParameters(), AafApiFilter.class,
+ parameterGroup.getRestServerParameters().setName(parameterGroup.getName());
+ restServer = new RestServer(parameterGroup.getRestServerParameters(), AafApiFilter.class,
ApiRestController.class);
if (!restServer.start()) {
throw new PolicyApiException("Failed to start api rest server. Check log for more details...");
@@ -95,7 +88,7 @@ public class ApiActivator {
*/
public void terminate() throws PolicyApiException {
try {
- deregisterToParameterService(apiParameterGroup);
+ deregisterToParameterService(parameterGroup);
if (ApiActivator.isAlive()) {
ApiActivator.setAlive(false);
@@ -129,4 +122,4 @@ public class ApiActivator {
ParameterService.deregister(apiParameterGroup.getName());
}
}
-} \ No newline at end of file
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index aac37f19..ba3ad895 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -28,12 +28,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.List;
@@ -226,20 +223,6 @@ public class TestApiRestServer {
}
@Test
- public void testApiStatisticsConstructorIsPrivate() {
-
- try {
- final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
-
- } catch (final Exception exp) {
- assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
- }
- }
-
- @Test
public void testCreatePolicyTypes() throws Exception {
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES, resrcName);
@@ -815,22 +798,23 @@ public class TestApiRestServer {
}
private void updateApiStatistics() {
-
- ApiStatisticsManager.updateTotalApiCallCount();
- ApiStatisticsManager.updateApiCallSuccessCount();
- ApiStatisticsManager.updateApiCallFailureCount();
- ApiStatisticsManager.updateTotalPolicyGetCount();
- ApiStatisticsManager.updateTotalPolicyPostCount();
- ApiStatisticsManager.updateTotalPolicyTypeGetCount();
- ApiStatisticsManager.updateTotalPolicyTypePostCount();
- ApiStatisticsManager.updatePolicyGetSuccessCount();
- ApiStatisticsManager.updatePolicyGetFailureCount();
- ApiStatisticsManager.updatePolicyPostSuccessCount();
- ApiStatisticsManager.updatePolicyPostFailureCount();
- ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
- ApiStatisticsManager.updatePolicyTypeGetFailureCount();
- ApiStatisticsManager.updatePolicyTypePostSuccessCount();
- ApiStatisticsManager.updatePolicyTypePostFailureCount();
+ var mgr = ApiStatisticsManager.getInstance();
+
+ mgr.updateTotalApiCallCount();
+ mgr.updateApiCallSuccessCount();
+ mgr.updateApiCallFailureCount();
+ mgr.updateTotalPolicyGetCount();
+ mgr.updateTotalPolicyPostCount();
+ mgr.updateTotalPolicyTypeGetCount();
+ mgr.updateTotalPolicyTypePostCount();
+ mgr.updatePolicyGetSuccessCount();
+ mgr.updatePolicyGetFailureCount();
+ mgr.updatePolicyPostSuccessCount();
+ mgr.updatePolicyPostFailureCount();
+ mgr.updatePolicyTypeGetSuccessCount();
+ mgr.updatePolicyTypeGetFailureCount();
+ mgr.updatePolicyTypePostSuccessCount();
+ mgr.updatePolicyTypePostFailureCount();
}
private void validateStatisticsReport(final StatisticsReport report, final int code) {
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiStatisticsManager.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiStatisticsManager.java
index 148ec1b8..5f5c586d 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiStatisticsManager.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiStatisticsManager.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019 IBM.
* Modifications Copyright (C) 2020 Bell Canada.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.
@@ -25,38 +26,34 @@ package org.onap.policy.api.main.rest;
import static org.junit.Assert.assertEquals;
-import org.junit.Before;
import org.junit.Test;
public class TestApiStatisticsManager {
- @Before
- public void setUp() {
- ApiStatisticsManager.resetAllStatistics();
- }
-
@Test
public void testUpdateMethods() {
- assertEquals(1, ApiStatisticsManager.updateTotalApiCallCount());
- assertEquals(1, ApiStatisticsManager.updateApiCallSuccessCount());
- assertEquals(1, ApiStatisticsManager.updateApiCallFailureCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyGetCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyPostCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyDeleteCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyTypeGetCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyTypePostCount());
- assertEquals(1, ApiStatisticsManager.updateTotalPolicyTypeDeleteCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyGetSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyGetFailureCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyPostSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyPostFailureCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyDeleteSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyDeleteFailureCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypeGetSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypeGetFailureCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypePostSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypePostFailureCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypeDeleteSuccessCount());
- assertEquals(1, ApiStatisticsManager.updatePolicyTypeDeleteFailureCount());
+ var mgr = new ApiStatisticsManager();
+
+ assertEquals(1, mgr.updateTotalApiCallCount());
+ assertEquals(1, mgr.updateApiCallSuccessCount());
+ assertEquals(1, mgr.updateApiCallFailureCount());
+ assertEquals(1, mgr.updateTotalPolicyGetCount());
+ assertEquals(1, mgr.updateTotalPolicyPostCount());
+ assertEquals(1, mgr.updateTotalPolicyDeleteCount());
+ assertEquals(1, mgr.updateTotalPolicyTypeGetCount());
+ assertEquals(1, mgr.updateTotalPolicyTypePostCount());
+ assertEquals(1, mgr.updateTotalPolicyTypeDeleteCount());
+ assertEquals(1, mgr.updatePolicyGetSuccessCount());
+ assertEquals(1, mgr.updatePolicyGetFailureCount());
+ assertEquals(1, mgr.updatePolicyPostSuccessCount());
+ assertEquals(1, mgr.updatePolicyPostFailureCount());
+ assertEquals(1, mgr.updatePolicyDeleteSuccessCount());
+ assertEquals(1, mgr.updatePolicyDeleteFailureCount());
+ assertEquals(1, mgr.updatePolicyTypeGetSuccessCount());
+ assertEquals(1, mgr.updatePolicyTypeGetFailureCount());
+ assertEquals(1, mgr.updatePolicyTypePostSuccessCount());
+ assertEquals(1, mgr.updatePolicyTypePostFailureCount());
+ assertEquals(1, mgr.updatePolicyTypeDeleteSuccessCount());
+ assertEquals(1, mgr.updatePolicyTypeDeleteFailureCount());
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
index 7541c50c..e47a4ce6 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada.
* ================================================================================
@@ -81,12 +81,12 @@ public class TestPolicyProvider {
"policies/vCPE.policy.different.policy.fields.json";
private static final String MULTIPLE_POLICIES_RESOURCE = "policies/vCPE.policies.optimization.input.tosca.json";
- public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON =
+ private static final String POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON =
"policytypes/onap.policies.controlloop.operational.Common.yaml";
- public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS =
+ private static final String POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS =
"policytypes/onap.policies.controlloop.operational.common.Drools.yaml";
private static final String POLICY_RESOURCE_OPERATIONAL = "policies/vCPE.policy.operational.input.tosca.json";
- public static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
+ private static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
/**
* Initializes parameters.
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
index 95f93865..355f3d45 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
@@ -64,15 +64,15 @@ public class TestPolicyTypeProvider {
"policytypes/onap.policies.optimization.Resource.no.version.yaml";
private static final String POLICY_TYPE_NAME_MONITORING = "onap.policies.monitoring.tcagen2";
- public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON =
+ private static final String POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON =
"policytypes/onap.policies.controlloop.operational.Common.yaml";
- public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS =
+ private static final String POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS =
"policytypes/onap.policies.controlloop.operational.common.Drools.yaml";
- public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_APEX =
+ private static final String POLICY_TYPE_RESOURCE_OPERATIONAL_APEX =
"policytypes/onap.policies.controlloop.operational.common.Apex.yaml";
- public static final String POLICY_TYPE_OPERATIONAL_COMMON = "onap.policies.controlloop.operational.Common";
- public static final String POLICY_TYPE_OPERATIONAL_APEX = "onap.policies.controlloop.operational.common.Apex";
- public static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
+ private static final String POLICY_TYPE_OPERATIONAL_COMMON = "onap.policies.controlloop.operational.Common";
+ private static final String POLICY_TYPE_OPERATIONAL_APEX = "onap.policies.controlloop.operational.common.Apex";
+ private static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
/**
* Initializes parameters.
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
index b899e014..ccd0f14d 100644
--- a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,8 +47,8 @@ public class TestApiActivator {
final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(arguments);
final ApiActivator activator = new ApiActivator(parGroup);
activator.initialize();
- assertTrue(activator.getApiParameterGroup().isValid());
- assertEquals(CommonTestData.API_GROUP_NAME, activator.getApiParameterGroup().getName());
+ assertTrue(activator.getParameterGroup().isValid());
+ assertEquals(CommonTestData.API_GROUP_NAME, activator.getParameterGroup().getName());
activator.terminate();
}
}