From a48252db26e2ccd031ddb2046d87737d47c248a6 Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Tue, 2 Nov 2021 05:35:12 +0000 Subject: Remove code smells in controlloop runtime Remove code-smells reported by sonar cloud https://sonarcloud.io/project/issues?id=onap_policy-clamp&resolved=false Issue-ID: POLICY-3540 Signed-off-by: Sirisha_Manchikanti Change-Id: I8ed1c4599e7eeebbc3a31e74cea4148eb0435847 --- .../kubernetes/handler/ControlLoopElementHandler.java | 14 ++++++++++---- .../participant/kubernetes/helm/HelmClient.java | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'participant/participant-impl/participant-impl-kubernetes/src/main') diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java index e1e9195eb..3f2113d98 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java @@ -20,9 +20,9 @@ package org.onap.policy.clamp.controlloop.participant.kubernetes.handler; - import java.io.IOException; import java.lang.invoke.MethodHandles; +import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; @@ -51,7 +52,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - /** * This class handles implementation of controlLoopElement updates. */ @@ -170,10 +170,16 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * Overridden method. * * @param controlLoopElementId controlLoopElement id - * @throws PfModelException incase of error + * @throws PfModelException in case of error */ @Override public synchronized void handleStatistics(UUID controlLoopElementId) throws PfModelException { - // TODO Implement statistics functionality + var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId); + if (clElement != null) { + var clElementStatistics = new ClElementStatistics(); + clElementStatistics.setControlLoopState(clElement.getState()); + clElementStatistics.setTimeStamp(Instant.now()); + intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics); + } } } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java index 1c405539b..31fa62f1f 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java @@ -47,6 +47,7 @@ public class HelmClient { private ChartStore chartStore; private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final String PATH_DELIMITER = "/"; /** * Install a chart. @@ -100,7 +101,7 @@ public class HelmClient { } var localHelmChartDir = chartStore.getAppPath(chart.getChartId()).toString(); logger.info("Chart not found in helm repositories, verifying local repo {} ", localHelmChartDir); - if (verifyLocalHelmRepo(new File(localHelmChartDir + "/" + chart.getChartId().getName()))) { + if (verifyLocalHelmRepo(new File(localHelmChartDir + PATH_DELIMITER + chart.getChartId().getName()))) { repository = localHelmChartDir; } return repository; -- cgit 1.2.3-korg