summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kubernetes/src/main
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-07-01 07:50:45 +0100
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-07-01 17:39:25 +0100
commit616b0760dca131ec703d667d27c256d109944b2b (patch)
treeea2072db7fe5fe57a91ac969a1963b548a576935 /participant/participant-impl/participant-impl-kubernetes/src/main
parent7d04c23c7c51738d68f325e450ac408c1ae9905f (diff)
Add Junits for kubernetes participant module
Overall coverage for the module: 85% Issue-ID: POLICY-3241 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I00c7866ae598b9768d1616468a4c9bfe4cc76166
Diffstat (limited to 'participant/participant-impl/participant-impl-kubernetes/src/main')
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantConfig.java (renamed from participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/BeanFactory.java)2
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java62
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/models/ChartList.java4
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java2
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartService.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java7
9 files changed, 57 insertions, 32 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java
index 37ecf4e6f..5d9d203fe 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java
@@ -23,12 +23,15 @@ package org.onap.policy.clamp.controlloop.participant.kubernetes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
+import org.springframework.context.annotation.ComponentScan;
/**
* Starter.
*
*/
@SpringBootApplication
+@ComponentScan({"org.onap.policy.clamp.controlloop.participant.kubernetes",
+ "org.onap.policy.clamp.controlloop.participant.intermediary"})
@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.kubernetes.parameters")
public class Application {
/**
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/BeanFactory.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantConfig.java
index 3199d0cd9..94789a74f 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/BeanFactory.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantConfig.java
@@ -31,7 +31,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartResolver;
* Bean Factory class for helm client.
*/
@Configuration
-public class BeanFactory {
+public class ParticipantConfig {
@Value("${server.http-port}")
private int httpPort = 0;
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
index 5560e47a8..23605e641 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
@@ -149,13 +149,12 @@ public class ChartController {
* @param name name of the chart
* @param version version of the chart
* @return Status of operation
- * @throws ServiceException in case of error.
*/
@DeleteMapping(path = "/charts/{name}/{version}")
@ApiOperation(value = "Delete the chart")
@ApiResponses(value = {@ApiResponse(code = 204, message = "Chart Deleted")})
public ResponseEntity<Object> deleteChart(@PathVariable("name") String name,
- @PathVariable("version") String version) throws ServiceException {
+ @PathVariable("version") String version) {
ChartInfo chart = chartService.getChart(name, version);
if (chart == null) {
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 6257c3d19..4f654832d 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
@@ -26,6 +26,8 @@ import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
@@ -57,6 +59,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
private ParticipantIntermediaryApi intermediaryApi;
// Map of CLElement Id and installed Helm charts
+ @Getter(AccessLevel.PACKAGE)
private final Map<UUID, ChartInfo> chartMap = new HashMap<>();
/**
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 343a44617..90d7218da 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
@@ -75,12 +75,33 @@ public class HelmClient {
*/
public String findChartRepository(ChartInfo chart) throws ServiceException, IOException {
updateHelmRepo();
- logger.info("Looking for helm chart {} in all the configured helm repositories", chart.getChartName());
- String repository = null;
+ String repository = verifyConfiguredRepo(chart);
+ if (repository != null) {
+ return repository;
+ }
+ var localHelmChartDir = chartStore.getAppPath(chart.getChartName(), chart.getVersion()).toString();
+ logger.info("Chart not found in helm repositories, verifying local repo {} ", localHelmChartDir);
+ if (verifyLocalHelmRepo(localHelmChartDir + "/" + chart.getChartName())) {
+ repository = localHelmChartDir;
+ }
- var process = helmRepoVerifyCommand(chart.getChartName()).start();
+ return repository;
+ }
- try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+ /**
+ * Verify helm chart in configured repositories.
+ * @param chart chartInfo
+ * @return repo name
+ * @throws IOException incase of error
+ * @throws ServiceException incase of error
+ */
+ public String verifyConfiguredRepo(ChartInfo chart) throws IOException, ServiceException {
+ logger.info("Looking for helm chart {} in all the configured helm repositories", chart.getChartName());
+ String repository = null;
+ var builder = helmRepoVerifyCommand(chart.getChartName());
+ String output = executeCommand(builder);
+ try (var reader = new BufferedReader(new InputStreamReader(IOUtils.toInputStream(output,
+ StandardCharsets.UTF_8)))) {
String line = reader.readLine();
while (line != null) {
if (line.contains(chart.getChartName())) {
@@ -91,13 +112,6 @@ public class HelmClient {
line = reader.readLine();
}
}
-
- var localHelmChartDir = chartStore.getAppPath(chart.getChartName(), chart.getVersion()).toString();
- logger.info("Chart not found in helm repositories, verifying local repo {} ", localHelmChartDir);
- if (verifyLocalHelmRepo(localHelmChartDir + "/" + chart.getChartName())) {
- repository = localHelmChartDir;
- }
-
return repository;
}
@@ -111,7 +125,13 @@ public class HelmClient {
executeCommand(prepareUnInstallCommand(chart));
}
- static String executeCommand(ProcessBuilder processBuilder) throws ServiceException {
+ /**
+ * Execute helm cli bash commands .
+ * @param processBuilder processbuilder
+ * @return string output
+ * @throws ServiceException incase of error.
+ */
+ public static String executeCommand(ProcessBuilder processBuilder) throws ServiceException {
var commandStr = toString(processBuilder);
try {
@@ -123,13 +143,15 @@ public class HelmClient {
var error = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8);
throw new ServiceException("Command execution failed: " + commandStr + " " + error);
}
+
var output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
logger.debug("Command <{}> execution, output: {}", commandStr, output);
return output;
+
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new ServiceException("Failed to execute the Command: " + commandStr + ", the command was interrupted",
- ie);
+ ie);
} catch (Exception exc) {
throw new ServiceException("Failed to execute the Command: " + commandStr, exc);
}
@@ -140,12 +162,12 @@ public class HelmClient {
// @formatter:off
List<String> helmArguments = new ArrayList<>(
Arrays.asList(
- "helm",
- "install", chart.getReleaseName(), chart.getRepository() + "/" + chart.getChartName(),
- "--version", chart.getVersion(),
- "--namespace", chart.getNamespace()
+ "helm",
+ "install", chart.getReleaseName(), chart.getRepository() + "/" + chart.getChartName(),
+ "--version", chart.getVersion(),
+ "--namespace", chart.getNamespace()
)
- );
+ );
// @formatter:on
// Verify if values.yaml available for the chart
@@ -176,9 +198,7 @@ public class HelmClient {
private void updateHelmRepo() throws ServiceException {
logger.info("Updating local helm repositories before verifying the chart");
- List<String> helmArguments = Arrays.asList("helm", "repo", "update");
-
- executeCommand(new ProcessBuilder().command(helmArguments));
+ executeCommand(new ProcessBuilder().command("helm", "repo", "update"));
logger.debug("Helm repositories updated successfully");
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/models/ChartList.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/models/ChartList.java
index c86bff58a..7f46bbde5 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/models/ChartList.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/models/ChartList.java
@@ -18,7 +18,7 @@
package org.onap.policy.clamp.controlloop.participant.kubernetes.models;
-import java.util.Collection;
+import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -27,5 +27,5 @@ import lombok.Setter;
@Setter
@Builder
public class ChartList {
- private Collection<ChartInfo> charts;
+ private List<ChartInfo> charts;
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
index a5731da74..3b2b3732b 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
@@ -20,13 +20,13 @@
package org.onap.policy.clamp.controlloop.participant.kubernetes.parameters;
+import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
-import org.onap.policy.common.parameters.annotations.Valid;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartService.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartService.java
index 29a49a9ff..adb6cf0d1 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartService.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartService.java
@@ -53,9 +53,8 @@ public class ChartService {
* @param name name of the app
* @param version version of the app
* @return chart
- * @throws ServiceException in case of error.
*/
- public ChartInfo getChart(String name, String version) throws ServiceException {
+ public ChartInfo getChart(String name, String version) {
return chartStore.getChart(name, version);
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java
index dcdff62f5..03b35161d 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java
@@ -33,6 +33,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import lombok.AccessLevel;
+import lombok.Getter;
import org.onap.policy.clamp.controlloop.participant.kubernetes.exception.ServiceException;
import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.ParticipantK8sParameters;
@@ -52,9 +54,8 @@ public class ChartStore {
private final ParticipantK8sParameters participantK8sParameters;
- /**
- * The chartStore map contains chart name as key & ChartInfo as value.
- */
+ // ChartStore map contains chart name as key & ChartInfo as value.
+ @Getter(AccessLevel.PACKAGE)
private Map<String, ChartInfo> localChartMap = new ConcurrentHashMap<>();
/**