From 4371989e7a50d015b6eefa074d4988033223551b Mon Sep 17 00:00:00 2001 From: "Desai, Dhrumin (dd303q)" Date: Fri, 27 Aug 2021 17:53:06 -0400 Subject: integrate helm-chart-generator to runtime api Issue-ID: DCAEGEN2-2694 Issue-ID: DCAEGEN2-2805 Change-Id: I1b7d1bd7d2254280e0faa561e49223357c615090 Signed-off-by: Dhrumin Desai --- .../runtime/web/service/GraphServiceHelmProxy.java | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java (limited to 'mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java') diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java new file mode 100644 index 0000000..89c9d47 --- /dev/null +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java @@ -0,0 +1,120 @@ +/*- + * ============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.dcae.runtime.web.service; + +import org.onap.dcae.runtime.core.BlueprintData; +import org.onap.dcae.runtime.core.Edge; +import org.onap.dcae.runtime.core.FlowGraph; +import org.onap.dcae.runtime.core.FlowGraphParser; +import org.onap.dcae.runtime.core.Node; +import org.onap.dcae.runtime.core.helm.HelmChartGeneratorClient; +import org.onap.dcae.runtime.web.models.DistributeGraphRequest; +import org.onap.dcae.runtime.web.models.GraphRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * A proxy class which will be enable if artifact.type is set to HELM + */ +@Service +@Primary +@ConditionalOnProperty( + value="artifact.type", + havingValue = "HELM", + matchIfMissing = true) +@ComponentScan(basePackages = "org.onap.dcae.runtime.core") +public class GraphServiceHelmProxy implements GraphService { + + @Autowired + private GraphService defaultGraphService; + + @Autowired + private HelmChartGeneratorClient helmChartGeneratorClient; + + @Autowired + private GraphActionsParser actionsParser; + + /** + * returns a main graph + * @return main graph + */ + @Override + public FlowGraph getMainGraph() { + return defaultGraphService.getMainGraph(); + } + + /** + * initialize a main graph + * @param mainGraph a main graph request + */ + @Override + public boolean initializeMainGraph(GraphRequest mainGraph) { + return defaultGraphService.initializeMainGraph(mainGraph); + } + + /** + * apply actions on the main graph and creates, distributes helm charts + * @param distributeGraphRequest distribute request + * @return list of distributed charts + */ + @Override + public List distribute(DistributeGraphRequest distributeGraphRequest) { + actionsParser.applyActionsToGraph(getMainGraph(), distributeGraphRequest); + return createHelmCharts(); + } + + public List createHelmCharts() { + final FlowGraph flowGraph = getMainGraph(); + List blueprints = new ArrayList<>(); + for(Node node : flowGraph.getNodes()){ + if(node.getComponentId().equals("dummy_id")){ + continue; + } + final File helmChart = helmChartGeneratorClient.generateHelmChart(node.getComponentSpec()); + helmChartGeneratorClient.distribute(helmChart); + BlueprintData blueprintData = new BlueprintData("1", helmChart.getName()); + node.setBlueprintData(blueprintData); + blueprints.add(createBlueprintVessel(helmChart)); + } + return blueprints; + } + + private FlowGraphParser.BlueprintVessel createBlueprintVessel(File helmChart) { + FlowGraphParser.BlueprintVessel bpv = new FlowGraphParser.BlueprintVessel(); + bpv.blueprint = helmChart.getName(); + bpv.version = 1; + bpv.name = helmChart.getName(); + return bpv; + } + + /** + * deletes main graph + */ + @Override + public void deleteMainGraph() { + defaultGraphService.deleteMainGraph(); + } +} -- cgit 1.2.3-korg