summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-dcae/src
diff options
context:
space:
mode:
authorTaka Cho <takamune.cho@att.com>2021-08-17 14:23:26 -0400
committerTaka Cho <takamune.cho@att.com>2021-08-20 17:16:49 -0400
commitbf06e83f40cdbfcfc1428040bf8fa58a518cdea4 (patch)
tree6bf66e14c5e340f4faa8e08cf7404e40cc6e4096 /participant/participant-impl/participant-impl-dcae/src
parent172f990bd92e1441eca6dd161458efddb674b2fc (diff)
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 <takamune.cho@att.com>
Diffstat (limited to 'participant/participant-impl/participant-impl-dcae/src')
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java4
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java19
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java24
3 files changed, 28 insertions, 19 deletions
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);
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java
index 8a7f403f4..74728a974 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.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
@@ -96,7 +98,7 @@ class ControlLoopElementHandlerTest {
ControlLoopElementHandler controlLoopElementHandler =
new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters());
- when(clampClient.getstatus(eq(LOOP))).thenReturn(new Loop());
+ when(clampClient.getstatus(LOOP)).thenReturn(new Loop());
ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class);
controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
@@ -105,7 +107,7 @@ class ControlLoopElementHandlerTest {
controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId, ControlLoopState.PASSIVE,
ControlLoopOrderedState.UNINITIALISED);
- verify(clampClient).undeploy(eq(LOOP));
+ verify(clampClient).undeploy(LOOP);
controlLoopElementHandler.handleStatistics(controlLoopElementId);
assertThat(intermediaryApi.getControlLoopElement(controlLoopElementId)).isNull();
}
@@ -114,12 +116,12 @@ class ControlLoopElementHandlerTest {
void testCreate_ControlLoopElementUpdate() throws PfModelException, JSONException, CoderException {
ClampHttpClient clampClient = spy(mock(ClampHttpClient.class));
Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class);
- when(clampClient.create(eq(LOOP), eq(TEMPLATE))).thenReturn(loopDeployed);
- when(clampClient.deploy(eq(LOOP))).thenReturn(true);
+ when(clampClient.create(LOOP, TEMPLATE)).thenReturn(loopDeployed);
+ when(clampClient.deploy(LOOP)).thenReturn(true);
Loop loopInstalled =
CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class);
- when(clampClient.getstatus(eq(LOOP))).thenReturn(null, loopInstalled);
+ when(clampClient.getstatus(LOOP)).thenReturn(null, loopInstalled);
ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class));
when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true);
@@ -139,9 +141,9 @@ class ControlLoopElementHandlerTest {
controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates()
.get("org.onap.domain.pmsh.PMSH_DCAEMicroservice"));
- verify(clampClient).create(eq(LOOP), eq(TEMPLATE));
+ verify(clampClient).create(LOOP, TEMPLATE);
verify(consulClient).deploy(any(String.class), any(String.class));
- verify(clampClient).deploy(eq(LOOP));
+ verify(clampClient).deploy(LOOP);
}
@Test
@@ -150,8 +152,8 @@ class ControlLoopElementHandlerTest {
Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class);
Loop loopInstalled =
CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class);
- when(clampClient.getstatus(eq(LOOP))).thenReturn(loopDeployed, loopInstalled);
- when(clampClient.deploy(eq(LOOP))).thenReturn(true);
+ when(clampClient.getstatus(LOOP)).thenReturn(loopDeployed, loopInstalled);
+ when(clampClient.deploy(LOOP)).thenReturn(true);
ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class));
when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true);
@@ -171,8 +173,8 @@ class ControlLoopElementHandlerTest {
controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates()
.get("org.onap.domain.pmsh.PMSH_DCAEMicroservice"));
- verify(clampClient, times(0)).create(eq(LOOP), eq(TEMPLATE));
+ verify(clampClient, times(0)).create(LOOP, TEMPLATE);
verify(consulClient).deploy(any(String.class), any(String.class));
- verify(clampClient).deploy(eq(LOOP));
+ verify(clampClient).deploy(LOOP);
}
}