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 / ChartBuilder.java
1
2 /*
3  * # ============LICENSE_START=======================================================
4  * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
5  * # ================================================================================
6  * # Licensed under the Apache License, Version 2.0 (the "License");
7  * # you may not use this file except in compliance with the License.
8  * # You may obtain a copy of the License at
9  * #
10  * #      http://www.apache.org/licenses/LICENSE-2.0
11  * #
12  * # Unless required by applicable law or agreed to in writing, software
13  * # distributed under the License is distributed on an "AS IS" BASIS,
14  * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * # See the License for the specific language governing permissions and
16  * # limitations under the License.
17  * # ============LICENSE_END=========================================================
18  */
19
20 package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
21
22 import lombok.extern.slf4j.Slf4j;
23 import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo;
24 import org.onap.dcaegen2.platform.helmchartgenerator.validation.ChartTemplateStructureValidator;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Component;
27
28 import java.io.File;
29
30 /**
31  * ChartBuilder is a main class responsible to generate a helm chart.
32  * @author Dhrumin Desai
33  */
34 @Component
35 @Slf4j
36 public class ChartBuilder {
37
38    @Autowired
39    private ComponentSpecParser specParser;
40
41    @Autowired
42    private ChartGenerator chartGenerator;
43
44    @Autowired
45    private ChartTemplateStructureValidator validator;
46
47     /**
48      * constructor of ChartBuilder
49      * @param specParser implementation of ComponentSpecParser
50      * @param chartGenerator implementation of ChartGenerator
51      * @param validator implementation of Chart Template Validator
52      */
53     public ChartBuilder(ComponentSpecParser specParser, ChartGenerator chartGenerator,
54                         ChartTemplateStructureValidator validator) {
55         this.specParser = specParser;
56         this.chartGenerator = chartGenerator;
57         this.validator = validator;
58     }
59
60     /**
61      * this method validates the inputs and generate a helm chart.
62      * @param specFileLocation location of the application specification json file
63      * @param chartTemplateLocation location of the base helm chart template
64      * @param outputLocation location to store the helm chart
65      * @param specSchemaLocation location of the specification json schema file to validate the application spec
66      * @return generated helm chart tgz file
67      * @throws Exception
68      */
69     public File build(String specFileLocation, String chartTemplateLocation, String outputLocation, String specSchemaLocation ) throws Exception {
70         validator.validateChartTemplateStructure(chartTemplateLocation);
71         ChartInfo chartInfo = specParser.extractChartInfo(specFileLocation, chartTemplateLocation, specSchemaLocation);
72         return chartGenerator.generate(chartTemplateLocation, chartInfo, outputLocation, specFileLocation);
73     }
74 }