Add cmpv2Certificate flag, removed hyphens from config under postgres and enhanced...
[dcaegen2/platform.git] / mod2 / helm-generator / helmchartgenerator-core / src / main / java / org / onap / dcaegen2 / platform / helmchartgenerator / chartbuilder / ChartGenerator.java
1 /*
2  * # ============LICENSE_START=======================================================
3  * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
4  * # ================================================================================
5  * # Licensed under the Apache License, Version 2.0 (the "License");
6  * # you may not use this file except in compliance with the License.
7  * # You may obtain a copy of the License at
8  * #
9  * #      http://www.apache.org/licenses/LICENSE-2.0
10  * #
11  * # Unless required by applicable law or agreed to in writing, software
12  * # distributed under the License is distributed on an "AS IS" BASIS,
13  * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * # See the License for the specific language governing permissions and
15  * # limitations under the License.
16  * # ============LICENSE_END=========================================================
17  */
18
19 package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
20
21 import lombok.extern.slf4j.Slf4j;
22 import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
23 import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Component;
26
27 import java.io.File;
28
29 /**
30  * ChartGenerator interacts with HelmClient and generates a packaged helm chart
31  * @author Dhrumin Desai
32  */
33 @Component
34 @Slf4j
35 public class ChartGenerator {
36
37     @Autowired
38     private HelmClient helmClient;
39
40     @Autowired
41     private KeyValueMerger merger;
42
43     @Autowired
44     private Utils utils;
45
46     @Autowired
47     private AddOnsManager addOnsManager;
48
49     /**
50      * Constructor for ChartGenerator
51      * @param helmClient HelmClient implementation
52      * @param merger KeyValueMerger implementation
53      * @param utils
54      * @param addOnsManager
55      */
56     public ChartGenerator(HelmClient helmClient, KeyValueMerger merger, Utils utils, AddOnsManager addOnsManager) {
57         this.helmClient = helmClient;
58         this.merger = merger;
59         this.utils = utils;
60         this.addOnsManager = addOnsManager;
61     }
62
63     /**
64      * Merges the key-values from the helm base template and parsed spec file and generates a new packaged helm chart
65      * @param chartBlueprintLocation location of the base helm chart template
66      * @param chartInfo chartInfo object with key-values parsed from the specfile.
67      * @param outputLocation location to store the helm chart
68      * @param specFileLocation
69      * @return generated helm chart tgz file
70      */
71     public File generate(String chartBlueprintLocation, ChartInfo chartInfo, String outputLocation, String specFileLocation) {
72         File newChartDir = utils.cloneFileToTempLocation(chartBlueprintLocation + "/base");
73         addOnsManager.includeAddons(specFileLocation, newChartDir, chartBlueprintLocation);
74         merger.mergeValuesToChart(chartInfo, newChartDir);
75         helmClient.lint(newChartDir);
76         final File chartLocation = helmClient.packageChart(newChartDir, outputLocation);
77         utils.deleteTempFileLocation(newChartDir);
78         return chartLocation;
79     }
80 }