aboutsummaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-09-29 15:29:55 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-10-02 16:47:37 +0000
commita70a907e2ad4f49c4807b1914e69b97f7573561e (patch)
tree4024b2a5785129aed25eeacdec22b15e5b5a2027 /participant
parentc706398593f184301d38bd6cba86566da60bece6 (diff)
Fix Sonar Issues for clamp/acm
Issue-ID: POLICY-4834 Change-Id: I4489dc66e9b20c8264ec88593f0b5d89d62f1ef8 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java17
-rwxr-xr-xparticipant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java5
-rwxr-xr-xparticipant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java2
-rwxr-xr-x[-rw-r--r--]participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java24
-rwxr-xr-x[-rw-r--r--]participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java7
-rwxr-xr-xparticipant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java4
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java2
-rwxr-xr-xparticipant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java2
12 files changed, 39 insertions, 40 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java
index f2e150d92..c4a93472f 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.a1pms.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java
index 3442eedf6..081eb035d 100755
--- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java
+++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -27,7 +27,6 @@ import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse;
import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
@@ -43,9 +42,6 @@ public class AcElementErrorController implements ErrorController {
private final ErrorAttributes errorAttributes;
- @Value("${server.error.path}")
- private String path;
-
/**
* Constructor.
*
@@ -56,7 +52,7 @@ public class AcElementErrorController implements ErrorController {
}
protected HttpStatus getStatus(HttpServletRequest request) {
- Integer statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
+ var statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (statusCode == null) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
@@ -73,19 +69,20 @@ public class AcElementErrorController implements ErrorController {
* @param request HttpServletRequest
* @return ResponseEntity
*/
+ @SuppressWarnings("squid:S3752")
@RequestMapping(value = "${server.error.path}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<TypedSimpleResponse<SimpleResponse>> handleError(HttpServletRequest request) {
Map<String, Object> map = this.errorAttributes.getErrorAttributes(new ServletWebRequest(request),
ErrorAttributeOptions.defaults());
var sb = new StringBuilder();
- final Object error = map.get("error");
+ final var error = map.get("error");
if (error != null) {
- sb.append(error.toString() + " ");
+ sb.append(error).append(" ");
}
- final Object message = map.get("message");
+ final var message = map.get("message");
if (message != null) {
- sb.append(message.toString());
+ sb.append(message);
}
TypedSimpleResponse<SimpleResponse> resp = new TypedSimpleResponse<>();
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java
index 1ffe7d11d..a2ed1ca34 100755
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
package org.onap.policy.clamp.acm.element.rest;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
@@ -165,5 +165,4 @@ class AcElementControllerTest {
private String getElementConfigJson() throws IOException {
return FileUtils.readFileToString(new File(ELEMENT_CONFIG_YAML), StandardCharsets.UTF_8);
}
-
}
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java
index 1b43e607f..a1d22038e 100755
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.element.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java
index 0c595d6f2..fa9068a21 100755
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.http.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java
index 0c568e1b5..ab2d28ae1 100755
--- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.kserve.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java
index a05dfbc5f..8aca5245f 100644..100755
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java
@@ -1,6 +1,6 @@
/*-
* ========================LICENSE_START=================================
- * Copyright (C) 2021-2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
* ======================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ======================================================================
@@ -26,7 +26,6 @@ import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
@@ -49,6 +48,9 @@ public class HelmClient {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String PATH_DELIMITER = "/";
+ public static final String COMMAND_SH = "/bin/sh";
+ private static final String COMMAND_HELM = "/usr/local/bin/helm";
+ public static final String COMMAND_KUBECTL = "/usr/local/bin/kubectl";
/**
* Install a chart.
@@ -193,7 +195,7 @@ public class HelmClient {
// @formatter:off
List<String> helmArguments = new ArrayList<>(
List.of(
- "helm",
+ COMMAND_HELM,
"repo",
"add", repo.getRepoName(), repo.getAddress()
));
@@ -206,7 +208,7 @@ public class HelmClient {
private boolean verifyHelmRepoAlreadyExist(HelmRepository repo) {
try {
logger.debug("Verify the repo already exist in helm repositories");
- List<String> helmArguments = List.of("sh", "-c", "helm repo list | grep " + repo.getRepoName());
+ var helmArguments = List.of(COMMAND_SH, "-c", COMMAND_HELM + " repo list | grep " + repo.getRepoName());
String response = executeCommand(new ProcessBuilder().command(helmArguments));
if (StringUtils.isEmpty(response)) {
return false;
@@ -219,7 +221,7 @@ public class HelmClient {
}
private ProcessBuilder prepareVerifyNamespaceCommand(String namespace) {
- List<String> helmArguments = List.of("sh", "-c", "kubectl get ns | grep " + namespace);
+ var helmArguments = List.of(COMMAND_SH, "-c", COMMAND_KUBECTL + " get ns | grep " + namespace);
return new ProcessBuilder().command(helmArguments);
}
@@ -228,7 +230,7 @@ public class HelmClient {
// @formatter:off
List<String> helmArguments = new ArrayList<>(
List.of(
- "helm",
+ COMMAND_HELM,
"install", chart.getReleaseName(), chart.getRepository().getRepoName() + "/"
+ chart.getChartId().getName(),
"--version", chart.getChartId().getVersion(),
@@ -245,7 +247,7 @@ public class HelmClient {
}
if (chart.getOverrideParams() != null) {
- for (Map.Entry<String, String> entry : chart.getOverrideParams().entrySet()) {
+ for (var entry : chart.getOverrideParams().entrySet()) {
helmArguments.addAll(List.of("--set", entry.getKey() + "=" + entry.getValue()));
}
}
@@ -253,23 +255,23 @@ public class HelmClient {
}
private ProcessBuilder prepareUnInstallCommand(ChartInfo chart) {
- return new ProcessBuilder("helm", "delete", chart.getReleaseName(), "--namespace",
+ return new ProcessBuilder(COMMAND_HELM, "delete", chart.getReleaseName(), "--namespace",
chart.getNamespace());
}
private ProcessBuilder prepareCreateNamespaceCommand(String namespace) {
- return new ProcessBuilder().command("kubectl", "create", "namespace", namespace);
+ return new ProcessBuilder().command(COMMAND_KUBECTL, "create", "namespace", namespace);
}
private ProcessBuilder helmRepoVerifyCommand(String chartName) {
- return new ProcessBuilder().command("sh", "-c", "helm search repo | grep " + chartName);
+ return new ProcessBuilder().command(COMMAND_SH, "-c", COMMAND_HELM + " search repo | grep " + chartName);
}
private boolean updateHelmRepo() {
try {
logger.info("Updating local helm repositories before verifying the chart");
- executeCommand(new ProcessBuilder().command("helm", "repo", "update"));
+ executeCommand(new ProcessBuilder().command(COMMAND_HELM, "repo", "update"));
logger.debug("Helm repositories updated successfully");
} catch (ServiceException e) {
logger.error("Failed to update the helm repo: ", e);
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
index 0a1424134..6c9656b78 100644..100755
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
@@ -1,6 +1,6 @@
/*-
* ========================LICENSE_START=================================
- * Copyright (C) 2021-2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2021-2023 Nordix Foundation. 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.
@@ -101,8 +101,9 @@ public class PodStatusValidator {
}
private ProcessBuilder verifyPodStatusCommand(ChartInfo chart) {
- String cmd = "kubectl get pods --namespace " + chart.getNamespace() + " | grep " + getPodName();
- return new ProcessBuilder("sh", "-c", cmd);
+ String cmd = HelmClient.COMMAND_KUBECTL
+ + " get pods --namespace " + chart.getNamespace() + " | grep " + getPodName();
+ return new ProcessBuilder(HelmClient.COMMAND_SH, "-c", cmd);
}
private String getPodName() {
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java
index 2176478f0..4487dbe07 100755
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.kubernetes.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Invocation;
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java
index e5f5aece3..2b77452a5 100755
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.policy.main.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java
index 5c4f06d2d..f52806c84 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.policy.main.utils;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
import java.time.Instant;
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java
index b5e2ff618..2cb013442 100755
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.acm.participant.sim.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;