aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestController.java10
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsProvider.java49
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsReport.java188
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java129
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestStatisticsReport.java47
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java8
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java14
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/statistics/DistributionStatisticsManager.java156
8 files changed, 600 insertions, 1 deletions
diff --git a/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestController.java b/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestController.java
index 95cfdd5c..d7e0f9f5 100644
--- a/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestController.java
+++ b/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestController.java
@@ -57,4 +57,14 @@ public class DistributionRestController {
public Response healthcheck() {
return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();
}
+
+ @GET
+ @Path("statistics")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Fetch current statistics",
+ notes = "Provides current statistics of the Policy Distribution component",
+ response = StatisticsReport.class)
+ public Response statistics() {
+ return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
+ }
}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsProvider.java b/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsProvider.java
new file mode 100644
index 00000000..7532ac61
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsProvider.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.rest;
+
+import org.onap.policy.distribution.main.startstop.DistributionActivator;
+import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
+
+/**
+ * Class to fetch statistics of distribution service.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class StatisticsProvider {
+
+ /**
+ * Returns the current statistics of distribution service.
+ *
+ * @return Report containing statistics of distribution service
+ */
+ public StatisticsReport fetchCurrentStatistics() {
+ final StatisticsReport report = new StatisticsReport();
+ report.setCode(DistributionActivator.isAlive() ? 200 : 500);
+ report.setTotalDistributionCount(DistributionStatisticsManager.getTotalDistributionCount());
+ report.setDistributionSuccessCount(DistributionStatisticsManager.getDistributionSuccessCount());
+ report.setDistributionFailureCount(DistributionStatisticsManager.getDistributionFailureCount());
+ report.setTotalDownloadCount(DistributionStatisticsManager.getTotalDownloadCount());
+ report.setDownloadSuccessCount(DistributionStatisticsManager.getDownloadSuccessCount());
+ report.setDownloadFailureCount(DistributionStatisticsManager.getDownloadFailureCount());
+ return report;
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsReport.java b/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsReport.java
new file mode 100644
index 00000000..4cbbcd70
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/rest/StatisticsReport.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.rest;
+
+/**
+ * Class to represent statistics report of distribution service.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class StatisticsReport {
+
+ private int code;
+ private long totalDistributionCount;
+ private long distributionSuccessCount;
+ private long distributionFailureCount;
+ private long totalDownloadCount;
+ private long downloadSuccessCount;
+ private long downloadFailureCount;
+
+ /**
+ * Returns the code of this {@link StatisticsReport} instance.
+ *
+ * @return the code
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * Set code in this {@link StatisticsReport} instance.
+ *
+ * @param code the code to set
+ */
+ public void setCode(final int code) {
+ this.code = code;
+ }
+
+ /**
+ * Returns the totalDistributionCount of this {@link StatisticsReport} instance.
+ *
+ * @return the totalDistributionCount
+ */
+ public long getTotalDistributionCount() {
+ return totalDistributionCount;
+ }
+
+ /**
+ * Set totalDistributionCount in this {@link StatisticsReport} instance.
+ *
+ * @param totalDistributionCount the totalDistributionCount to set
+ */
+ public void setTotalDistributionCount(final long totalDistributionCount) {
+ this.totalDistributionCount = totalDistributionCount;
+ }
+
+ /**
+ * Returns the distributionSuccessCount of this {@link StatisticsReport} instance.
+ *
+ * @return the distributionSuccessCount
+ */
+ public long getDistributionSuccessCount() {
+ return distributionSuccessCount;
+ }
+
+ /**
+ * Set distributionSuccessCount in this {@link StatisticsReport} instance.
+ *
+ * @param distributionSuccessCount the distributionSuccessCount to set
+ */
+ public void setDistributionSuccessCount(final long distributionSuccessCount) {
+ this.distributionSuccessCount = distributionSuccessCount;
+ }
+
+ /**
+ * Returns the distributionFailureCount of this {@link StatisticsReport} instance.
+ *
+ * @return the distributionFailureCount
+ */
+ public long getDistributionFailureCount() {
+ return distributionFailureCount;
+ }
+
+ /**
+ * Set distributionFailureCount in this {@link StatisticsReport} instance.
+ *
+ * @param distributionFailureCount the distributionFailureCount to set
+ */
+ public void setDistributionFailureCount(final long distributionFailureCount) {
+ this.distributionFailureCount = distributionFailureCount;
+ }
+
+ /**
+ * Returns the totalDownloadCount of this {@link StatisticsReport} instance.
+ *
+ * @return the totalDownloadCount
+ */
+ public long getTotalDownloadCount() {
+ return totalDownloadCount;
+ }
+
+ /**
+ * Set totalDownloadCount in this {@link StatisticsReport} instance.
+ *
+ * @param totalDownloadCount the totalDownloadCount to set
+ */
+ public void setTotalDownloadCount(final long totalDownloadCount) {
+ this.totalDownloadCount = totalDownloadCount;
+ }
+
+ /**
+ * Returns the downloadSuccessCount of this {@link StatisticsReport} instance.
+ *
+ * @return the downloadSuccessCount
+ */
+ public long getDownloadSuccessCount() {
+ return downloadSuccessCount;
+ }
+
+ /**
+ * Set downloadSuccessCount in this {@link StatisticsReport} instance.
+ *
+ * @param downloadSuccessCount the downloadSuccessCount to set
+ */
+ public void setDownloadSuccessCount(final long downloadSuccessCount) {
+ this.downloadSuccessCount = downloadSuccessCount;
+ }
+
+ /**
+ * Returns the downloadFailureCount of this {@link StatisticsReport} instance.
+ *
+ * @return the downloadFailureCount
+ */
+ public long getDownloadFailureCount() {
+ return downloadFailureCount;
+ }
+
+ /**
+ * Set downloadFailureCount in this {@link StatisticsReport} instance.
+ *
+ * @param downloadFailureCount the downloadFailureCount to set
+ */
+ public void setDownloadFailureCount(final long downloadFailureCount) {
+ this.downloadFailureCount = downloadFailureCount;
+ }
+
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("StatisticsReport [code=");
+ builder.append(getCode());
+ builder.append(", totalDistributionCount=");
+ builder.append(getTotalDistributionCount());
+ builder.append(", distributionSuccessCount=");
+ builder.append(getDistributionSuccessCount());
+ builder.append(", distributionFailureCount=");
+ builder.append(getDistributionFailureCount());
+ builder.append(", totalDownloadCount=");
+ builder.append(getTotalDownloadCount());
+ builder.append(", downloadSuccessCount=");
+ builder.append(getDownloadSuccessCount());
+ builder.append(", downloadFailureCount=");
+ builder.append(getDownloadFailureCount());
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
new file mode 100644
index 00000000..92ae14a8
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.parameters.CommonTestData;
+import org.onap.policy.distribution.main.parameters.RestServerParameters;
+import org.onap.policy.distribution.main.startstop.Main;
+import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
+
+/**
+ * Class to perform unit test of {@link DistributionRestController}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionStatistics {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(TestDistributionStatistics.class);
+
+
+ @Test
+ public void testDistributionStatistics_200() throws PolicyDistributionException, InterruptedException {
+ final Main main = startDistributionService();
+ StatisticsReport report = getDistributionStatistics();
+
+ validateReport(report, 0, 200);
+ updateDistributionStatistics();
+ report = getDistributionStatistics();
+ validateReport(report, 1, 200);
+ stopDistributionService(main);
+ DistributionStatisticsManager.resetAllStatistics();
+ }
+
+ @Test
+ public void testDistributionStatistics_500() throws InterruptedException {
+ final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
+ restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
+
+ final DistributionRestServer restServer = new DistributionRestServer(restServerParams);
+ restServer.start();
+ final StatisticsReport report = getDistributionStatistics();
+
+ validateReport(report, 0, 500);
+ restServer.shutdown();
+ DistributionStatisticsManager.resetAllStatistics();
+ }
+
+
+ private Main startDistributionService() {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters.json" };
+ return new Main(distributionConfigParameters);
+ }
+
+ private void stopDistributionService(final Main main) throws PolicyDistributionException {
+ main.shutdown();
+ }
+
+ private StatisticsReport getDistributionStatistics() throws InterruptedException {
+ StatisticsReport response = null;
+ final ClientConfig clientConfig = new ClientConfig();
+
+ final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
+ clientConfig.register(feature);
+
+ final Client client = ClientBuilder.newClient(clientConfig);
+ final WebTarget webTarget = client.target("http://localhost:6969/statistics");
+
+ final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
+ while (response == null) {
+ try {
+ response = invocationBuilder.get(StatisticsReport.class);
+ } catch (final Exception exp) {
+ LOGGER.info("the server is not started yet. We will retry again");
+ }
+ }
+ return response;
+ }
+
+ private void updateDistributionStatistics() {
+ DistributionStatisticsManager.updateTotalDistributionCount();
+ DistributionStatisticsManager.updateDistributionSuccessCount();
+ DistributionStatisticsManager.updateDistributionFailureCount();
+ DistributionStatisticsManager.updateTotalDownloadCount();
+ DistributionStatisticsManager.updateDownloadSuccessCount();
+ DistributionStatisticsManager.updateDownloadFailureCount();
+ }
+
+ private void validateReport(final StatisticsReport report, final int count, final int code) {
+ assertEquals(code, report.getCode());
+ assertEquals(count, report.getTotalDistributionCount());
+ assertEquals(count, report.getDistributionSuccessCount());
+ assertEquals(count, report.getDistributionFailureCount());
+ assertEquals(count, report.getTotalDownloadCount());
+ assertEquals(count, report.getDownloadSuccessCount());
+ assertEquals(count, report.getDownloadFailureCount());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestStatisticsReport.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestStatisticsReport.java
new file mode 100644
index 00000000..64d2e5c5
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestStatisticsReport.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.rest;
+
+import com.openpojo.reflection.filters.FilterClassName;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.validation.ToStringTester;
+
+/**
+ * Class to perform unit testing of {@link StatisticsReport}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestStatisticsReport {
+
+ @Test
+ public void testStatisticsReport() {
+ final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
+ validator.validate(StatisticsReport.class.getPackage().getName(),
+ new FilterClassName(StatisticsReport.class.getName()));
+ }
+}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
index 14b0f1ec..443235b7 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
@@ -35,6 +35,7 @@ import org.onap.policy.distribution.reception.decoding.PluginTerminationExceptio
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
import org.onap.policy.distribution.reception.handling.sdc.exceptions.ArtifactDownloadException;
+import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
import org.onap.sdc.api.consumer.IDistributionStatusMessage;
@@ -180,7 +181,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
*/
public void processCsarServiceArtifacts(final INotificationData notificationData) {
boolean artifactsProcessedSuccessfully = true;
-
+ DistributionStatisticsManager.updateTotalDistributionCount();
for (final IArtifactInfo artifact : notificationData.getServiceArtifacts()) {
try {
final IDistributionClientDownloadResult resultArtifact =
@@ -200,9 +201,11 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
}
}
if (artifactsProcessedSuccessfully) {
+ DistributionStatisticsManager.updateDistributionSuccessCount();
sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_OK,
null);
} else {
+ DistributionStatisticsManager.updateDistributionFailureCount();
sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_ERROR,
"Failed to process the artifact");
}
@@ -218,8 +221,10 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
private IDistributionClientDownloadResult downloadTheArtifact(final IArtifactInfo artifact,
final INotificationData notificationData) throws ArtifactDownloadException {
+ DistributionStatisticsManager.updateTotalDownloadCount();
final IDistributionClientDownloadResult downloadResult = distributionClient.download(artifact);
if (!downloadResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ DistributionStatisticsManager.updateDownloadFailureCount();
final String message = "Failed to download artifact with name: " + artifact.getArtifactName() + " due to: "
+ downloadResult.getDistributionMessageResult();
LOGGER.error(message);
@@ -227,6 +232,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, message);
throw new ArtifactDownloadException(message);
}
+ DistributionStatisticsManager.updateDownloadSuccessCount();
sendDistributionStatus(DistributionStatusType.DOWNLOAD, artifact.getArtifactURL(),
notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_OK, null);
return downloadResult;
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
index 231c50ff..bf42476f 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
@@ -57,6 +57,7 @@ import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
import org.onap.policy.distribution.reception.handling.PluginHandler;
import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
+import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
@@ -99,6 +100,7 @@ public class TestSdcReceptionHandler {
*/
@Before
public final void init() throws IOException {
+ DistributionStatisticsManager.resetAllStatistics();
final Gson gson = new GsonBuilder().create();
pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
SdcReceptionHandlerConfigurationParameterGroup.class);
@@ -237,6 +239,12 @@ public class TestSdcReceptionHandler {
assertTrue(policyDecoder.getDecodedPolicy().getPolicyName().contains(DUMMY_SERVICE_CSAR));
assertEquals(1, policyForwarder.getNumberOfPoliciesReceived());
assertTrue(policyForwarder.receivedPolicyWithGivenType(DummyDecoder.DUMMY_POLICY));
+ assertEquals(1, DistributionStatisticsManager.getTotalDistributionCount());
+ assertEquals(1, DistributionStatisticsManager.getDistributionSuccessCount());
+ assertEquals(0, DistributionStatisticsManager.getDistributionFailureCount());
+ assertEquals(1, DistributionStatisticsManager.getTotalDownloadCount());
+ assertEquals(1, DistributionStatisticsManager.getDownloadSuccessCount());
+ assertEquals(0, DistributionStatisticsManager.getDownloadFailureCount());
}
@Test
@@ -260,6 +268,12 @@ public class TestSdcReceptionHandler {
assertEquals(null, policyDecoder.getDecodedPolicy());
assertEquals(0, policyForwarder.getNumberOfPoliciesReceived());
+ assertEquals(1, DistributionStatisticsManager.getTotalDistributionCount());
+ assertEquals(0, DistributionStatisticsManager.getDistributionSuccessCount());
+ assertEquals(1, DistributionStatisticsManager.getDistributionFailureCount());
+ assertEquals(1, DistributionStatisticsManager.getTotalDownloadCount());
+ assertEquals(0, DistributionStatisticsManager.getDownloadSuccessCount());
+ assertEquals(1, DistributionStatisticsManager.getDownloadFailureCount());
}
@Test
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/statistics/DistributionStatisticsManager.java b/reception/src/main/java/org/onap/policy/distribution/reception/statistics/DistributionStatisticsManager.java
new file mode 100644
index 00000000..cd78d254
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/statistics/DistributionStatisticsManager.java
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.statistics;
+
+/**
+ * Class to hold statistical data for distribution component.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DistributionStatisticsManager {
+
+ private static long totalDistributionCount;
+ private static long distributionSuccessCount;
+ private static long distributionFailureCount;
+ private static long totalDownloadCount;
+ private static long downloadSuccessCount;
+ private static long downloadFailureCount;
+
+ /**
+ * Method to update the total distribution count.
+ *
+ * @return the updated value of totalDistributionCount
+ */
+ public static long updateTotalDistributionCount() {
+ return ++totalDistributionCount;
+ }
+
+ /**
+ * Method to update the distribution success count.
+ *
+ * @return the updated value of distributionSuccessCount
+ */
+ public static long updateDistributionSuccessCount() {
+ return ++distributionSuccessCount;
+ }
+
+ /**
+ * Method to update the distribution failure count.
+ *
+ * @return the updated value of distributionFailureCount
+ */
+ public static long updateDistributionFailureCount() {
+ return ++distributionFailureCount;
+ }
+
+ /**
+ * Method to update the total download count.
+ *
+ * @return the updated value of totalDownloadCount
+ */
+ public static long updateTotalDownloadCount() {
+ return ++totalDownloadCount;
+ }
+
+ /**
+ * Method to update the download success count.
+ *
+ * @return the updated value of downloadSuccessCount
+ */
+ public static long updateDownloadSuccessCount() {
+ return ++downloadSuccessCount;
+ }
+
+ /**
+ * Method to update the download failure count.
+ *
+ * @return the updated value of downloadFailureCount
+ */
+ public static long updateDownloadFailureCount() {
+ return ++downloadFailureCount;
+ }
+
+ /**
+ * Returns the current value of totalDistributionCount.
+ *
+ * @return the totalDistributionCount
+ */
+ public static long getTotalDistributionCount() {
+ return totalDistributionCount;
+ }
+
+ /**
+ * Returns the current value of distributionSuccessCount.
+ *
+ * @return the distributionSuccessCount
+ */
+ public static long getDistributionSuccessCount() {
+ return distributionSuccessCount;
+ }
+
+ /**
+ * Returns the current value of distributionFailureCount.
+ *
+ * @return the distributionFailureCount
+ */
+ public static long getDistributionFailureCount() {
+ return distributionFailureCount;
+ }
+
+ /**
+ * Returns the current value of totalDownloadCount.
+ *
+ * @return the totalDownloadCount
+ */
+ public static long getTotalDownloadCount() {
+ return totalDownloadCount;
+ }
+
+ /**
+ * Returns the current value of downloadSuccessCount.
+ *
+ * @return the downloadSuccessCount
+ */
+ public static long getDownloadSuccessCount() {
+ return downloadSuccessCount;
+ }
+
+ /**
+ * Returns the current value of downloadFailureCount.
+ *
+ * @return the downloadFailureCount
+ */
+ public static long getDownloadFailureCount() {
+ return downloadFailureCount;
+ }
+
+ /**
+ * Reset all the statistics counts to 0.
+ */
+ public static void resetAllStatistics() {
+ totalDistributionCount = 0L;
+ distributionSuccessCount = 0L;
+ distributionFailureCount = 0L;
+ totalDownloadCount = 0L;
+ downloadSuccessCount = 0L;
+ downloadFailureCount = 0L;
+ }
+}