summaryrefslogtreecommitdiffstats
path: root/mod2/helm-generator/helmchartgenerator-core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'mod2/helm-generator/helmchartgenerator-core/src/main')
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/Utils.java16
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartBuilder.java10
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartGenerator.java18
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java34
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/HelmClientImpl.java46
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/distribution/ChartMuseumDistributor.java22
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidator.java40
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidatorImpl.java60
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ComponentSpecValidatorImpl.java10
-rw-r--r--mod2/helm-generator/helmchartgenerator-core/src/main/resources/application.properties2
10 files changed, 174 insertions, 84 deletions
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/Utils.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/Utils.java
index 83c67b1..a252886 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/Utils.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/Utils.java
@@ -21,6 +21,7 @@ package org.onap.dcaegen2.platform.helmchartgenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
+import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
@@ -33,13 +34,12 @@ import java.util.Map;
* @author Dhrumin Desai
*/
@Slf4j
+@Component
public class Utils {
- private static final ObjectMapper MAPPER = new ObjectMapper();
+ private final ObjectMapper MAPPER = new ObjectMapper();
- private Utils() {}
-
- public static <T> T deserializeJsonFileToModel(String filePath, Class<T> modelClass) {
+ public <T> T deserializeJsonFileToModel(String filePath, Class<T> modelClass) {
return deserializeJsonFileToModel(new File(filePath), modelClass);
}
@@ -49,7 +49,7 @@ public class Utils {
* @param modelClass target model class for mapping
* @return mapped model instance
*/
- public static <T> T deserializeJsonFileToModel(File file, Class<T> modelClass) {
+ public <T> T deserializeJsonFileToModel(File file, Class<T> modelClass) {
try {
return MAPPER.readValue(file, modelClass);
} catch (IOException e) {
@@ -63,7 +63,7 @@ public class Utils {
* @param srcLocation
* @return
*/
- public static File cloneFileToTempLocation(String srcLocation) {
+ public File cloneFileToTempLocation(String srcLocation) {
File cloneLocation = null;
try {
Path tempRootDir = Files.createTempDirectory("chart");
@@ -81,7 +81,7 @@ public class Utils {
* deletes dir / file from temp location of OS
* @param dir dir to be deleted
*/
- public static void deleteTempFileLocation(File dir) {
+ public void deleteTempFileLocation(File dir) {
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
@@ -95,7 +95,7 @@ public class Utils {
* @param key a key
* @param value a value
*/
- public static void putIfNotNull(Map<String, Object> map, String key, Object value){
+ public void putIfNotNull(Map<String, Object> map, String key, Object value){
if(value != null){
map.put(key, value);
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartBuilder.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartBuilder.java
index ac73544..21f5dae 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartBuilder.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartBuilder.java
@@ -41,14 +41,20 @@ public class ChartBuilder {
@Autowired
private ChartGenerator chartGenerator;
+ @Autowired
+ private ChartTemplateStructureValidator validator;
+
/**
* constructor of ChartBuilder
* @param specParser implementation of ComponentSpecParser
* @param chartGenerator implementation of ChartGenerator
+ * @param validator implementation of Chart Template Validator
*/
- public ChartBuilder(ComponentSpecParser specParser, ChartGenerator chartGenerator) {
+ public ChartBuilder(ComponentSpecParser specParser, ChartGenerator chartGenerator,
+ ChartTemplateStructureValidator validator) {
this.specParser = specParser;
this.chartGenerator = chartGenerator;
+ this.validator = validator;
}
/**
@@ -61,7 +67,7 @@ public class ChartBuilder {
* @throws Exception
*/
public File build(String specFileLocation, String chartTemplateLocation, String outputLocation, String specSchemaLocation ) throws Exception {
- ChartTemplateStructureValidator.validateChartTemplateStructure(chartTemplateLocation);
+ validator.validateChartTemplateStructure(chartTemplateLocation);
ChartInfo chartInfo = specParser.extractChartInfo(specFileLocation, chartTemplateLocation, specSchemaLocation);
return chartGenerator.generate(chartTemplateLocation, chartInfo, outputLocation);
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartGenerator.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartGenerator.java
index b9980d7..be02d68 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartGenerator.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ChartGenerator.java
@@ -18,17 +18,14 @@
package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
-import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
+import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
-import static org.onap.dcaegen2.platform.helmchartgenerator.Utils.cloneFileToTempLocation;
-import static org.onap.dcaegen2.platform.helmchartgenerator.Utils.deleteTempFileLocation;
-
/**
* ChartGenerator interacts with HelmClient and generates a packaged helm chart
* @author Dhrumin Desai
@@ -37,22 +34,25 @@ import static org.onap.dcaegen2.platform.helmchartgenerator.Utils.deleteTempFile
@Slf4j
public class ChartGenerator {
- @Setter
@Autowired
private HelmClient helmClient;
- @Setter
@Autowired
private KeyValueMerger merger;
+ @Autowired
+ private Utils utils;
+
/**
* Constructor for ChartGenerator
* @param helmClient HelmClient implementation
* @param merger KeyValueMerger implementation
+ * @param utils
*/
- public ChartGenerator(HelmClient helmClient, KeyValueMerger merger) {
+ public ChartGenerator(HelmClient helmClient, KeyValueMerger merger, Utils utils) {
this.helmClient = helmClient;
this.merger = merger;
+ this.utils = utils;
}
/**
@@ -63,11 +63,11 @@ public class ChartGenerator {
* @return generated helm chart tgz file
*/
public File generate(String chartBlueprintLocation, ChartInfo chartInfo, String outputLocation) {
- File newChartDir = cloneFileToTempLocation(chartBlueprintLocation + "/base");
+ File newChartDir = utils.cloneFileToTempLocation(chartBlueprintLocation + "/base");
merger.mergeValuesToChart(chartInfo, newChartDir);
helmClient.lint(newChartDir);
final File chartLocation = helmClient.packageChart(newChartDir, outputLocation);
- deleteTempFileLocation(newChartDir);
+ utils.deleteTempFileLocation(newChartDir);
return chartLocation;
}
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java
index 942e5ae..b0830d1 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java
@@ -18,7 +18,6 @@
package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
-import org.jetbrains.annotations.NotNull;
import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo;
import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.Metadata;
@@ -55,12 +54,17 @@ public class ComponentSpecParser {
@Autowired
private ComponentSpecValidator specValidator;
+ @Autowired
+ private Utils utils;
+
/**
* Constructor for ComponentSpecParser
* @param specValidator ComponentSpecValidator implementation
+ * @param utils
*/
- public ComponentSpecParser(ComponentSpecValidator specValidator) {
+ public ComponentSpecParser(ComponentSpecValidator specValidator, Utils utils) {
this.specValidator = specValidator;
+ this.utils = utils;
}
/**
@@ -73,7 +77,7 @@ public class ComponentSpecParser {
*/
public ChartInfo extractChartInfo(String specFileLocation, String chartTemplateLocation, String specSchemaLocation) throws Exception {
specValidator.validateSpecFile(specFileLocation, specSchemaLocation);
- ComponentSpec cs = Utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class);
+ ComponentSpec cs = utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class);
ChartInfo chartInfo = new ChartInfo();
chartInfo.setMetadata(extractMetadata(cs.getSelf()));
chartInfo.setValues(extractValues(cs, chartTemplateLocation));
@@ -83,14 +87,14 @@ public class ComponentSpecParser {
private Map<String, Object> extractValues(ComponentSpec cs, String chartTemplateLocation) {
Map<String, Object> outerValues = new LinkedHashMap<>();
if(cs.getAuxilary() != null && cs.getAuxilary().getTlsInfo() != null){
- Utils.putIfNotNull(outerValues,"certDirectory", cs.getAuxilary().getTlsInfo().getCertDirectory());
- Utils.putIfNotNull(outerValues, "tlsServer", cs.getAuxilary().getTlsInfo().getUseTls());
+ utils.putIfNotNull(outerValues,"certDirectory", cs.getAuxilary().getTlsInfo().getCertDirectory());
+ utils.putIfNotNull(outerValues, "tlsServer", cs.getAuxilary().getTlsInfo().getUseTls());
}
if(cs.getAuxilary() != null && cs.getAuxilary().getLogInfo() != null) {
- Utils.putIfNotNull(outerValues,"logDirectory", cs.getAuxilary().getLogInfo().get("log_directory"));
+ utils.putIfNotNull(outerValues,"logDirectory", cs.getAuxilary().getLogInfo().get("log_directory"));
}
if(imageUriExistsForFirstArtifact(cs)){
- Utils.putIfNotNull(outerValues,"image", cs.getArtifacts()[0].getUri());
+ utils.putIfNotNull(outerValues,"image", cs.getArtifacts()[0].getUri());
}
populateApplicationConfigSection(outerValues, cs);
populateReadinessSection(outerValues, cs);
@@ -115,7 +119,7 @@ public class ComponentSpecParser {
for(Parameters param : parameters){
applicationConfig.put(param.getName(), param.getValue());
}
- Utils.putIfNotNull(outerValues,"applicationConfig", applicationConfig);
+ utils.putIfNotNull(outerValues,"applicationConfig", applicationConfig);
}
private void populateReadinessSection(Map<String, Object> outerValues, ComponentSpec cs) {
@@ -124,7 +128,7 @@ public class ComponentSpecParser {
Map<String, Object> readiness = new LinkedHashMap<>();
final HealthCheck healthcheck = cs.getAuxilary().getHealthcheck();
- Utils.putIfNotNull(readiness, "initialDelaySeconds", healthcheck.getInitialDelaySeconds());
+ utils.putIfNotNull(readiness, "initialDelaySeconds", healthcheck.getInitialDelaySeconds());
if(healthcheck.getInterval() != null) {
readiness.put("periodSeconds", getSeconds(healthcheck.getInterval(), "interval"));
@@ -159,7 +163,7 @@ public class ComponentSpecParser {
private void populateApplicationEnvSection(Map<String, Object> outerValues, ComponentSpec cs){
if(applicationEnvExists(cs)) {
Object applicationEnv = cs.getAuxilary().getHelm().getApplicationEnv();
- Utils.putIfNotNull(outerValues,"applicationEnv", applicationEnv);
+ utils.putIfNotNull(outerValues,"applicationEnv", applicationEnv);
}
}
@@ -178,10 +182,10 @@ public class ComponentSpecParser {
if(serviceFromSpec.getPorts() != null){
List<Object> ports = mapServicePorts(serviceFromSpec.getPorts());
service.put("ports", ports);
- Utils.putIfNotNull(service, "type", serviceFromSpec.getType());
+ utils.putIfNotNull(service, "type", serviceFromSpec.getType());
}
- Utils.putIfNotNull(service,"name", serviceFromSpec.getName());
- Utils.putIfNotNull(service,"has_internal_only_ports", serviceFromSpec.getHasInternalOnlyPorts());
+ utils.putIfNotNull(service,"name", serviceFromSpec.getName());
+ utils.putIfNotNull(service,"has_internal_only_ports", serviceFromSpec.getHasInternalOnlyPorts());
outerValues.put("service", service);
}
@@ -230,8 +234,8 @@ public class ComponentSpecParser {
keystore.put("outputType", List.of("jks"));
keystore.put("passwordSecretRef", passwordsSecretRef);
certificate.put("mountPath", mountPath);
- Utils.putIfNotNull(certificate,"commonName", cs.getSelf().getName());
- Utils.putIfNotNull(certificate,"dnsNames", List.of(cs.getSelf().getName()));
+ utils.putIfNotNull(certificate,"commonName", cs.getSelf().getName());
+ utils.putIfNotNull(certificate,"dnsNames", List.of(cs.getSelf().getName()));
certificate.put("keystore", keystore);
outerValues.put("certificates", List.of(certificate));
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/HelmClientImpl.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/HelmClientImpl.java
index 098ddda..83bc477 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/HelmClientImpl.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/HelmClientImpl.java
@@ -19,6 +19,7 @@
package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
@@ -26,6 +27,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.stream.Collectors;
/**
* HelmClient implementation which uses helm command installed in the runtime environment.
@@ -35,12 +37,40 @@ import java.io.InputStreamReader;
@Slf4j
public class HelmClientImpl implements HelmClient {
+ private final String repoUrl;
+
+ private final String username;
+
+ private final String password;
+
+ public HelmClientImpl(@Value("${chartmuseum.baseurl}")String repoUrl,
+ @Value("${chartmuseum.auth.basic.username}")String username,
+ @Value("${chartmuseum.auth.basic.password}")String password) {
+ this.repoUrl = repoUrl;
+ this.username = username;
+ this.password = password;
+ try{
+ repoAdd(repoUrl, username,password);
+ }catch (Exception e){
+ log.warn("Could not add helm repo.");
+ }
+ }
+
+ private void repoAdd(String repoUrl, String username, String password) {
+ ProcessBuilder builder = new ProcessBuilder();
+ builder.inheritIO();
+ builder.command("helm", "repo", "add", "local", repoUrl,
+ "--username", username, "--password", password);
+ runProcess(builder, "repoAdd");
+ }
+
/**
* performs <code>helm lint</code> operation
* @param chartLocation helm chart location
*/
@Override
public void lint(File chartLocation) {
+ helmDepUp(chartLocation.getAbsolutePath());
ProcessBuilder builder = new ProcessBuilder();
builder.command("helm", "lint", chartLocation.getAbsolutePath());
runProcess(builder, "lint");
@@ -60,16 +90,24 @@ public class HelmClientImpl implements HelmClient {
return runProcess(builder, "package");
}
+ private void helmDepUp(String chartLocation) {
+ ProcessBuilder builder = new ProcessBuilder();
+ builder.inheritIO();
+ builder.command("helm", "dep", "up",chartLocation);
+ runProcess(builder, "helmDepUp");
+ }
+
private File runProcess(ProcessBuilder builder, String command) {
+ log.info("running: " + String.join(" ",builder.command()));
Process process = null;
String chartPath = "";
try {
process = builder.start();
- if(command.equals("lint")) {
- printLintingProcessOutput(process);
+ if(command.equals("package")) {
+ chartPath = printPackagingProcessOutput(process);
}
else {
- chartPath = printPackagingProcessOutput(process);
+ printProcessOutput(process);
}
assertExitCode(process);
} catch (IOException e) {
@@ -83,7 +121,7 @@ public class HelmClientImpl implements HelmClient {
return new File(chartPath);
}
- private void printLintingProcessOutput(Process process) throws IOException {
+ private void printProcessOutput(Process process) throws IOException {
final InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
reader.lines().forEach(log::info);
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/distribution/ChartMuseumDistributor.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/distribution/ChartMuseumDistributor.java
index ed861b0..ab0b964 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/distribution/ChartMuseumDistributor.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/distribution/ChartMuseumDistributor.java
@@ -40,14 +40,19 @@ import java.util.Objects;
@Slf4j
public class ChartMuseumDistributor implements ChartDistributor {
- @Value("${chartmuseum.baseurl}")
- private String chartMuseumUrl;
+ private final String chartMuseumUrl;
- @Value("${chartmuseum.auth.basic.username}")
- private String username;
+ private final String username;
- @Value("${chartmuseum.auth.basic.password}")
- private String password;
+ private final String password;
+
+ public ChartMuseumDistributor( @Value("${chartmuseum.baseurl}") String chartMuseumUrl,
+ @Value("${chartmuseum.auth.basic.username}") String username,
+ @Value("${chartmuseum.auth.basic.password}")String password) {
+ this.chartMuseumUrl = chartMuseumUrl;
+ this.username = username;
+ this.password = password;
+ }
/**
* distributes chart to Chart Museum
@@ -60,6 +65,9 @@ public class ChartMuseumDistributor implements ChartDistributor {
try {
Response response = client.newCall(request).execute();
log.info(Objects.requireNonNull(response.body()).string());
+ if(!response.isSuccessful()){
+ throw new RuntimeException("Distribution Failed.");
+ }
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
@@ -70,7 +78,7 @@ public class ChartMuseumDistributor implements ChartDistributor {
MediaType mediaType = MediaType.parse("application/octet-stream");
RequestBody body = RequestBody.create(chartFile, mediaType);
return new Request.Builder()
- .url(chartMuseumUrl)
+ .url(chartMuseumUrl + "/api/charts")
.method("POST", body)
.addHeader("Content-Type", "application/octet-stream")
.addHeader("Authorization", credential)
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidator.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidator.java
index 796ee91..07b97c9 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidator.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidator.java
@@ -18,43 +18,9 @@
package org.onap.dcaegen2.platform.helmchartgenerator.validation;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
/**
- * A class to validate structure of the base helm directory
+ * An interface to validate structure of the base helm directory
*/
-public class ChartTemplateStructureValidator {
-
- /**
- * validates base helm chart directory and throws error if the structure is not proper.
- * @param chartTemplateLocation base helm chart dir location
- */
- public static void validateChartTemplateStructure(String chartTemplateLocation) {
- checkBaseDirectory(chartTemplateLocation);
- }
-
- private static void checkBaseDirectory(String chartTemplateLocation) {
- Path base = Paths.get(chartTemplateLocation, "base");
- Path charts = Paths.get(chartTemplateLocation, "base/charts");
- Path templates = Paths.get(chartTemplateLocation, "base/templates");
- Path chart = Paths.get(chartTemplateLocation, "base/Chart.yaml");
- Path values = Paths.get(chartTemplateLocation, "base/values.yaml");
- if(!Files.exists(base)){
- throw new RuntimeException("base directory not found in chart template location");
- }
- if(!Files.exists(charts)){
- throw new RuntimeException("charts directory not found in base directory");
- }
- if(!Files.exists(templates)){
- throw new RuntimeException("templates directory not found in base directory");
- }
- if(!Files.exists(chart)){
- throw new RuntimeException("chart.yaml not found in base directory");
- }
- if(!Files.exists(values)){
- throw new RuntimeException("values.yaml not found in base directory");
- }
- }
+public interface ChartTemplateStructureValidator {
+ void validateChartTemplateStructure(String chartTemplateLocation);
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidatorImpl.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidatorImpl.java
new file mode 100644
index 0000000..6c22108
--- /dev/null
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ChartTemplateStructureValidatorImpl.java
@@ -0,0 +1,60 @@
+/*
+ * # ============LICENSE_START=======================================================
+ * # 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
+ * #
+ * # http://www.apache.org/licenses/LICENSE-2.0
+ * #
+ * # Unless required by applicable law or agreed to in writing, software
+ * # distributed under the License is distributed on an "AS IS" BASIS,
+ * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * # See the License for the specific language governing permissions and
+ * # limitations under the License.
+ * # ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.platform.helmchartgenerator.validation;
+
+import org.springframework.stereotype.Component;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * A class to validate structure of the base helm directory
+ */
+@Component
+public class ChartTemplateStructureValidatorImpl implements ChartTemplateStructureValidator {
+
+ /**
+ * validates base helm chart directory and throws error if the structure is not proper.
+ * @param chartTemplateLocation base helm chart dir location
+ */
+ @Override
+ public void validateChartTemplateStructure(String chartTemplateLocation) {
+ checkBaseDirectory(chartTemplateLocation);
+ }
+
+ private void checkBaseDirectory(String chartTemplateLocation) {
+ Path base = Paths.get(chartTemplateLocation, "base");
+ Path templates = Paths.get(chartTemplateLocation, "base/templates");
+ Path chart = Paths.get(chartTemplateLocation, "base/Chart.yaml");
+ Path values = Paths.get(chartTemplateLocation, "base/values.yaml");
+ if(!Files.exists(base)){
+ throw new RuntimeException("base directory not found in chart template location");
+ }
+ if(!Files.exists(templates)){
+ throw new RuntimeException("templates directory not found in base directory");
+ }
+ if(!Files.exists(chart)){
+ throw new RuntimeException("chart.yaml not found in base directory");
+ }
+ if(!Files.exists(values)){
+ throw new RuntimeException("values.yaml not found in base directory");
+ }
+ }
+}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ComponentSpecValidatorImpl.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ComponentSpecValidatorImpl.java
index a74cab1..fd1f19f 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ComponentSpecValidatorImpl.java
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/validation/ComponentSpecValidatorImpl.java
@@ -26,6 +26,7 @@ import org.json.JSONObject;
import org.json.JSONTokener;
import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.base.ComponentSpec;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
@@ -43,6 +44,13 @@ import java.io.InputStream;
@Slf4j
public class ComponentSpecValidatorImpl implements ComponentSpecValidator {
+ @Autowired
+ private Utils utils;
+
+ public ComponentSpecValidatorImpl(Utils utils) {
+ this.utils = utils;
+ }
+
/**
* Validates the spec json file against schema and prints errors if found
* @param specFileLocation specification json file location
@@ -52,7 +60,7 @@ public class ComponentSpecValidatorImpl implements ComponentSpecValidator {
@Override
public void validateSpecFile(String specFileLocation, String specSchemaLocation) throws IOException {
File schemaFile = getSchemaFile(specSchemaLocation);
- ComponentSpec cs = Utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class);
+ ComponentSpec cs = utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class);
validateSpecSchema(new File(specFileLocation), schemaFile);
validateHelmRequirements(cs);
}
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/resources/application.properties b/mod2/helm-generator/helmchartgenerator-core/src/main/resources/application.properties
index df2005a..f033b65 100644
--- a/mod2/helm-generator/helmchartgenerator-core/src/main/resources/application.properties
+++ b/mod2/helm-generator/helmchartgenerator-core/src/main/resources/application.properties
@@ -1,5 +1,5 @@
spring.main.web-application-type=NONE
-chartmuseum.baseurl=http://localhost:8081/api/charts
+chartmuseum.baseurl=http://localhost:8081
chartmuseum.auth.basic.username=TBD
chartmuseum.auth.basic.password=TBD \ No newline at end of file