From bf06e83f40cdbfcfc1428040bf8fa58a518cdea4 Mon Sep 17 00:00:00 2001 From: Taka Cho Date: Tue, 17 Aug 2021 14:23:26 -0400 Subject: sonar fix for clamp - bug: added InterruptedException for sleep - vulns: two false positve - removed some unused import - changed to use var for local variable Issue-ID: POLICY-3452 Change-Id: I8b4be1378a2aad8f68562b63f70853832673ce97 Signed-off-by: Taka Cho --- .../participant/dcae/httpclient/ClampHttpClient.java | 4 +++- .../dcae/main/handler/ControlLoopElementHandler.java | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'participant/participant-impl/participant-impl-dcae/src/main') diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java index 74c1ee5c1..5cf1b0df9 100644 --- a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java +++ b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java @@ -2,6 +2,8 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. * ================================================================================ + * 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. * You may obtain a copy of the License at @@ -115,7 +117,7 @@ public class ClampHttpClient extends AbstractHttpClient { if (loop == null || loop.getComponents() == null || loop.getComponents().isEmpty()) { return STATUS_NOT_FOUND; } - ExternalComponent externalComponent = loop.getComponents().get("DCAE"); + var externalComponent = loop.getComponents().get("DCAE"); if (externalComponent == null || externalComponent.getComponentState() == null) { return STATUS_NOT_FOUND; } diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java index 08ebd194a..b80fbfb5b 100644 --- a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java @@ -2,6 +2,8 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. * ================================================================================ + * 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. * You may obtain a copy of the License at @@ -93,7 +95,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { ControlLoopOrderedState newState) { switch (newState) { case UNINITIALISED: - Loop loop = clampClient.getstatus(LOOP); + var loop = clampClient.getstatus(LOOP); if (loop != null) { clampClient.undeploy(LOOP); intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, @@ -113,7 +115,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { } private Loop getStatus() throws PfModelException { - Loop loop = clampClient.getstatus(LOOP); + var loop = clampClient.getstatus(LOOP); if (loop == null) { loop = clampClient.create(LOOP, TEMPLATE); } @@ -143,12 +145,12 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate) throws PfModelException { try { - Loop loop = getStatus(); + var loop = getStatus(); if (BLUEPRINT_DEPLOYED.equals(ClampHttpClient.getStatusCode(loop))) { deploy(); - boolean deployedFlag = false; - for (int i = 0; i < checkCount; i++) { + var deployedFlag = false; + for (var i = 0; i < checkCount; i++) { // sleep 10 seconds TimeUnit.SECONDS.sleep(secCount); loop = getStatus(); @@ -168,6 +170,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { } } catch (PfModelException e) { throw e; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new PfModelException(null, e.getMessage(), e); } catch (Exception e) { throw new PfModelException(null, e.getMessage(), e); } @@ -180,9 +185,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { */ @Override public void handleStatistics(UUID controlLoopElementId) { - ControlLoopElement clElement = intermediaryApi.getControlLoopElement(controlLoopElementId); + var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId); if (clElement != null) { - ClElementStatistics clElementStatistics = new ClElementStatistics(); + var clElementStatistics = new ClElementStatistics(); clElementStatistics.setControlLoopState(clElement.getState()); clElementStatistics.setTimeStamp(Instant.now()); intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics); -- cgit 1.2.3-korg