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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 package org.onap.dcae.runtime.web.service;
21 import org.onap.dcae.runtime.core.BlueprintData;
22 import org.onap.dcae.runtime.core.Edge;
23 import org.onap.dcae.runtime.core.FlowGraph;
24 import org.onap.dcae.runtime.core.FlowGraphParser;
25 import org.onap.dcae.runtime.core.Node;
26 import org.onap.dcae.runtime.core.helm.HelmChartGeneratorClient;
27 import org.onap.dcae.runtime.web.models.DistributeGraphRequest;
28 import org.onap.dcae.runtime.web.models.GraphRequest;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
31 import org.springframework.context.annotation.ComponentScan;
32 import org.springframework.context.annotation.Primary;
33 import org.springframework.stereotype.Service;
36 import java.util.ArrayList;
37 import java.util.List;
40 * A proxy class which will be enable if artifact.type is set to HELM
44 @ConditionalOnProperty(
45 value="artifact.type",
47 matchIfMissing = true)
48 @ComponentScan(basePackages = "org.onap.dcae.runtime.core")
49 public class GraphServiceHelmProxy implements GraphService {
52 private GraphService defaultGraphService;
55 private HelmChartGeneratorClient helmChartGeneratorClient;
58 private GraphActionsParser actionsParser;
61 * returns a main graph
65 public FlowGraph<Node, Edge> getMainGraph() {
66 return defaultGraphService.getMainGraph();
70 * initialize a main graph
71 * @param mainGraph a main graph request
74 public boolean initializeMainGraph(GraphRequest mainGraph) {
75 return defaultGraphService.initializeMainGraph(mainGraph);
79 * apply actions on the main graph and creates, distributes helm charts
80 * @param distributeGraphRequest distribute request
81 * @return list of distributed charts
84 public List<FlowGraphParser.BlueprintVessel> distribute(DistributeGraphRequest distributeGraphRequest) {
85 actionsParser.applyActionsToGraph(getMainGraph(), distributeGraphRequest);
86 return createHelmCharts();
89 public List<FlowGraphParser.BlueprintVessel> createHelmCharts() {
90 final FlowGraph<Node, Edge> flowGraph = getMainGraph();
91 List<FlowGraphParser.BlueprintVessel> blueprints = new ArrayList<>();
92 for(Node node : flowGraph.getNodes()){
93 if(node.getComponentId().equals("dummy_id")){
96 final File helmChart = helmChartGeneratorClient.generateHelmChart(node.getComponentSpec());
97 helmChartGeneratorClient.distribute(helmChart);
98 BlueprintData blueprintData = new BlueprintData("1", helmChart.getName());
99 node.setBlueprintData(blueprintData);
100 blueprints.add(createBlueprintVessel(helmChart));
105 private FlowGraphParser.BlueprintVessel createBlueprintVessel(File helmChart) {
106 FlowGraphParser.BlueprintVessel bpv = new FlowGraphParser.BlueprintVessel();
107 bpv.blueprint = helmChart.getName();
109 bpv.name = helmChart.getName();
117 public void deleteMainGraph() {
118 defaultGraphService.deleteMainGraph();