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 --- mod/runtimeapi/Changelog.md | 5 + mod/runtimeapi/pom.xml | 11 +- mod/runtimeapi/runtime-core/pom.xml | 14 +- .../core/helm/HelmChartGeneratorClient.java | 28 ++ .../core/helm/HelmChartGeneratorClientImpl.java | 112 +++++ .../src/test/data/compspecs/vesWithDb.json | 452 +++++++++++++++++++++ .../helm/HelmChartGeneratorClientImplTest.java | 67 +++ mod/runtimeapi/runtime-web/pom.xml | 15 +- .../runtime/web/controllers/GraphController.java | 25 +- .../runtime/web/service/BlueprintInventory.java | 20 +- .../runtime/web/service/GraphActionsParser.java | 92 +++++ .../runtime/web/service/GraphServiceHelmProxy.java | 120 ++++++ .../dcae/runtime/web/service/GraphServiceImpl.java | 66 +-- .../src/main/resources/application.properties | 12 + 14 files changed, 947 insertions(+), 92 deletions(-) create mode 100644 mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClient.java create mode 100644 mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClientImpl.java create mode 100644 mod/runtimeapi/runtime-core/src/test/data/compspecs/vesWithDb.json create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClientImplTest.java create mode 100644 mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphActionsParser.java create mode 100644 mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceHelmProxy.java diff --git a/mod/runtimeapi/Changelog.md b/mod/runtimeapi/Changelog.md index 3dd643c..5baa372 100644 --- a/mod/runtimeapi/Changelog.md +++ b/mod/runtimeapi/Changelog.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.3.0] - 2021-09-16 +- [DCAEGEN2-2694] Integrate helm chart generator + - create a switch to toggle between blueprint and helm based deployment types +- [DCAEGEN2-2805] Update commons-io version to 2.8.0 + ## [1.2.3] - Update BPGenerator 1.7.3 - Update default k8splugin import diff --git a/mod/runtimeapi/pom.xml b/mod/runtimeapi/pom.xml index 11e5580..db6d2e2 100644 --- a/mod/runtimeapi/pom.xml +++ b/mod/runtimeapi/pom.xml @@ -34,7 +34,7 @@ limitations under the License. org.onap.dcaegen2.platform.mod runtimeapi - 1.2.3 + 1.3.0 dcaegen2-platform-mod-runtimeapi MOD Runtime API @@ -42,6 +42,7 @@ limitations under the License. yyyyMMdd'T'HHmmss ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml + true @@ -66,7 +67,13 @@ limitations under the License. - + + + commons-io + commons-io + 2.8.0 + + diff --git a/mod/runtimeapi/runtime-core/pom.xml b/mod/runtimeapi/runtime-core/pom.xml index 5514cc9..ff22a58 100644 --- a/mod/runtimeapi/runtime-core/pom.xml +++ b/mod/runtimeapi/runtime-core/pom.xml @@ -25,12 +25,12 @@ limitations under the License. runtimeapi org.onap.dcaegen2.platform.mod - 1.2.3 + 1.3.0 4.0.0 runtime-core - 1.2.3 + 1.3.0 @@ -48,11 +48,11 @@ limitations under the License. blueprint-generator-onap 1.7.3 - - org.json - json - 20190722 - + + org.onap.dcaegen2.platform + helmchartgenerator-core + 1.0.1-SNAPSHOT + org.yaml snakeyaml diff --git a/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClient.java b/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClient.java new file mode 100644 index 0000000..cc5fdca --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClient.java @@ -0,0 +1,28 @@ +/*- + * ============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.core.helm; + +import java.io.File; + +public interface HelmChartGeneratorClient { + + File generateHelmChart(String componentSpec); + + void distribute(File helmChart); +} diff --git a/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClientImpl.java b/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClientImpl.java new file mode 100644 index 0000000..49ca3de --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/main/java/org/onap/dcae/runtime/core/helm/HelmChartGeneratorClientImpl.java @@ -0,0 +1,112 @@ +/*- + * ============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.core.helm; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.ChartBuilder; +import org.onap.dcaegen2.platform.helmchartgenerator.distribution.ChartDistributor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; + +/** + * Implementation class for Helm Chart Generator Client + */ +@Slf4j +@Component +@ComponentScan(basePackages = "org.onap.dcaegen2.platform.helmchartgenerator") +public class HelmChartGeneratorClientImpl implements HelmChartGeneratorClient { + + @Autowired + private final ChartBuilder chartBuilder; + + @Autowired + private final ChartDistributor distributor; + + @Value("${helm.base.chart.template.location}") + private String templateLocation; + + public HelmChartGeneratorClientImpl(ChartBuilder chartBuilder, ChartDistributor distributor) { + this.chartBuilder = chartBuilder; + this.distributor = distributor; + } + + /** + * Generate Helm Chart for a component spec + * @param componentSpec component spec as String + * @return packaged helm chart + */ + @Override + public File generateHelmChart(String componentSpec){ + try { + return chartBuilder.build(createTempSpecFile(componentSpec),templateLocation, + createTempChartOutputLocation(), ""); + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new RuntimeException("Error while generating the helm chart."); + } + } + + private String createTempChartOutputLocation() { + try { + return Files.createTempDirectory("chart").toAbsolutePath().toString(); + } catch (IOException e) { + log.error(e.getMessage(), e); + throw new RuntimeException("Error creating a temporary chart dir."); + } + } + + private String createTempSpecFile(String componentSpec) throws IOException{ + File tmpFile = File.createTempFile("spec",".json"); + try (FileWriter writer = new FileWriter(tmpFile)) { + writer.write(componentSpec); + } + return tmpFile.getAbsolutePath(); + } + + /** + * Distributes helm chart to Chart Museum + * @param helmChart packaged chart location + */ + @Override + public void distribute(File helmChart) { + try { + distributor.distribute(helmChart); + }catch (Exception e){ + throw e; + } finally { + removeChartLocally(helmChart); + } + } + + private void removeChartLocally(File helmChart) { + try { + FileUtils.forceDelete(helmChart); + } catch (IOException e) { + log.warn("Could not delete a temporary helm chart " + helmChart.getName()); + } + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/data/compspecs/vesWithDb.json b/mod/runtimeapi/runtime-core/src/test/data/compspecs/vesWithDb.json new file mode 100644 index 0000000..207be6d --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/data/compspecs/vesWithDb.json @@ -0,0 +1,452 @@ +{ + "self": { + "version": "1.8.0", + "name": "dcae-ves-collector", + "description": "Collector for receiving VES events through restful interface", + "component_type": "docker" + }, + "streams": { + "subscribes": [], + "publishes": [ + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-fault" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-measurement" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-syslog" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-heartbeat" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-other" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-mobileflow" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-statechange" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-thresholdCrossingAlert" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-voicequality" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-sipsignaling" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-pnfRegistration" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-notification" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-perf3gpp" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-3gpp-fault-supervision" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-3gpp-provisioning" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-3gpp-heartbeat" + }, + { + "format": "VES_specification", + "version": "7.30.2", + "type": "message router", + "config_key": "ves-3gpp-performance-assurance" + } + ] + }, + "services": { + "calls": [], + "provides": [ + { + "route": "/eventListener/v1", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v2", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v3", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v4", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v5", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "5.28.4" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v7", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "7.30.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + } + ] + }, + "parameters": [ + { + "name": "streams_publishes", + "value": { + "ves-fault": { + "dmaap_info": { + "topic_url": "http://message-router:3904/events/unauthenticated.SEC_FAULT_OUTPUT" + }, + "type": "message_router" + } + }, + "description": "standard http port collector will open for listening;", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + } + , + { + "name": "collector.service.port", + "value": 8080, + "description": "standard http port collector will open for listening;", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.service.secure.port", + "value": 8443, + "description": "secure http port collector will open for listening ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": true + }, + { + "name": "collector.keystore.file.location", + "value": "/opt/app/dcae-certificate/cert.jks", + "description": "fs location of keystore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.keystore.passwordfile", + "value": "/opt/app/dcae-certificate/jks.pass", + "description": "location of keystore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.file.location", + "value": "/opt/app/dcae-certificate/trust.jks", + "description": "fs location of truststore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.passwordfile", + "value": "/opt/app/dcae-certificate/trust.pass", + "description": "location of truststore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.dmaap.streamid", + "value": "fault=ves-fault|syslog=ves-syslog|heartbeat=ves-heartbeat|measurementsForVfScaling=ves-measurement|mobileFlow=ves-mobileflow|other=ves-other|stateChange=ves-statechange|thresholdCrossingAlert=ves-thresholdCrossingAlert|voiceQuality=ves-voicequality|sipSignaling=ves-sipsignaling|notification=ves-notification|pnfRegistration=ves-pnfRegistration|3GPP-FaultSupervision=ves-3gpp-fault-supervision|3GPP-Heartbeat=ves-3gpp-heartbeat|3GPP-Provisioning=ves-3gpp-provisioning|3GPP-PerformanceAssurance=ves-3gpp-performance-assurance", + "description": "domain-to-streamid mapping used by VESCollector to distributes events based on domain. Both primary and secondary config_key are included for resilency (multiple streamid can be included commma separated). The streamids MUST match to topic config_keys. For single site without resiliency deployment - configkeys with -secondary suffix can be removed", + "sourced_at_deployment": true, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "auth.method", + "value": "noAuth", + "description": "Property to manage application mode, possible configurations: noAuth - default option - no security (http) , certOnly - auth by certificate (https), basicAuth - auth by basic auth username and password (https),certBasicAuth - auth by certificate and basic auth username / password (https),", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "header.authlist", + "value": "sample1,$2a$10$pgjaxDzSuc6XVFEeqvxQ5u90DKJnM/u7TJTcinAlFJVaavXMWf/Zi|userid1,$2a$10$61gNubgJJl9lh3nvQvY9X.x4e5ETWJJ7ao7ZhJEvmfJigov26Z6uq|userid2,$2a$10$G52y/3uhuhWAMy.bx9Se8uzWinmbJa.dlm1LW6bYPdPkkywLDPLiy", + "description": "List of id and base 64 encoded password.For each onboarding VNF - unique userid and password should be assigned and communicated to VNF owner. Password value should be base64 encoded in config here", + "policy_editable": false, + "sourced_at_deployment": true, + "designer_editable": true + }, + { + "name": "collector.schema.checkflag", + "value": 1, + "description": "Schema check validation flag. When enabled, collector will validate input VES events against VES Schema defined on collector.schema.file ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.schema.file", + "value": "{\"v1\":\"./etc/CommonEventFormat_27.2.json\",\"v2\":\"./etc/CommonEventFormat_27.2.json\",\"v3\":\"./etc/CommonEventFormat_27.2.json\",\"v4\":\"./etc/CommonEventFormat_27.2.json\",\"v5\":\"./etc/CommonEventFormat_28.4.1.json\",\"v7\":\"./etc/CommonEventFormat_30.2.1_ONAP.json\"}", + "description": "VES schema file name per version used for validation", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false + }, + { + "name": "event.transform.flag", + "value": 1, + "description": "flag to enable tranformation rules defined under eventTransform.json; this is applicable when event tranformation rules preset should be activated for transforming org.onap.dcaegen2.platform.mod runtimeapi - 1.2.3 + 1.3.0 runtime-web - 1.2.3-SNAPSHOT + 1.3.0-SNAPSHOT jar runtime-web MOD Runtime Web Module @@ -35,7 +35,7 @@ limitations under the License. org.onap.dcaegen2.platform.mod runtime-core - 1.2.3 + 1.3.0 org.springframework.boot @@ -73,11 +73,6 @@ limitations under the License. springfox-swagger-ui 3.0.0 - - org.json - json - 20190722 - org.apache.httpcomponents httpclient @@ -121,7 +116,9 @@ limitations under the License. artifact - groupadd -r dcaemod && useradd -ms /bin/bash dcaemod -g dcaemod && mkdir -p /maven/data && chown -R dcaemod:dcaemod /maven/data + apt-get update && apt-get install -y wget + wget https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz && tar xvf helm-v3.0.2-linux-amd64.tar.gz && mv linux-amd64/helm /usr/local/bin/ + groupadd -r dcaemod && useradd -ms /bin/bash dcaemod -g dcaemod && mkdir -p /maven/data && chown -R dcaemod:dcaemod /maven/data /maven diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java index fc222f2..484a426 100644 --- a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -17,28 +17,35 @@ */ package org.onap.dcae.runtime.web.controllers; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.onap.dcae.runtime.core.Edge; import org.onap.dcae.runtime.core.FlowGraph; -import org.onap.dcae.runtime.core.Node; import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel; +import org.onap.dcae.runtime.core.Node; import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException; -import org.onap.dcae.runtime.web.models.*; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; import org.onap.dcae.runtime.web.models.DistributeGraphRequest; import org.onap.dcae.runtime.web.models.GraphRequest; +import org.onap.dcae.runtime.web.service.GraphService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.onap.dcae.runtime.web.service.GraphServiceImpl; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; -import java.util.Map; import java.util.HashMap; import java.util.List; +import java.util.Map; @RestController @RequestMapping(value = "/api/graph") @@ -46,7 +53,7 @@ import java.util.List; public class GraphController { @Autowired - private GraphServiceImpl graphService; + private GraphService graphService; Logger logger = LoggerFactory.getLogger(GraphController.class); diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/BlueprintInventory.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/BlueprintInventory.java index 789c9d1..d63deeb 100644 --- a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/BlueprintInventory.java +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/BlueprintInventory.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * 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. @@ -17,6 +17,7 @@ */ package org.onap.dcae.runtime.web.service; +import org.json.JSONException; import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel; import org.onap.dcae.runtime.web.models.DashboardConfig; import org.json.JSONObject; @@ -46,7 +47,6 @@ public class BlueprintInventory { JSONObject body = prepareBlueprintJsonObject(bpv.name, bpv.version, bpv.blueprint); postToDashboard(body); logger.info(String.format("Distributed: %s", bpv.toString())); - //System.out.println(bpv.blueprint); } } @@ -74,12 +74,16 @@ public class BlueprintInventory { private JSONObject prepareBlueprintJsonObject(String blueprintName, int version, String blueprintContent) { JSONObject blueprintJsonObject = new JSONObject(); - blueprintJsonObject.put("owner","dcae_mod"); - blueprintJsonObject.put("typeName",blueprintName); - blueprintJsonObject.put("typeVersion",version); - blueprintJsonObject.put("blueprintTemplate",blueprintContent); - blueprintJsonObject.put("application","DCAE"); - blueprintJsonObject.put("component","dcae"); + try { + blueprintJsonObject.put("owner","dcae_mod"); + blueprintJsonObject.put("typeName",blueprintName); + blueprintJsonObject.put("typeVersion",version); + blueprintJsonObject.put("blueprintTemplate",blueprintContent); + blueprintJsonObject.put("application","DCAE"); + blueprintJsonObject.put("component","dcae"); + } catch (JSONException e) { + e.printStackTrace(); + } return blueprintJsonObject; } diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphActionsParser.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphActionsParser.java new file mode 100644 index 0000000..5d290a7 --- /dev/null +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphActionsParser.java @@ -0,0 +1,92 @@ +/*- + * ============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 com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcae.runtime.core.Edge; +import org.onap.dcae.runtime.core.EdgeLocation; +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.web.exception.ActionsNotDefinedException; +import org.onap.dcae.runtime.web.models.Action; +import org.onap.dcae.runtime.web.models.DistributeGraphRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * A helper class that parses the actions from the request and apply them to the main graph + */ +@Component +public class GraphActionsParser { + + @Autowired + private FlowGraphParser flowGraphParser; + + void applyActionsToGraph(FlowGraph mainFlowGraph, DistributeGraphRequest distributeGraphRequest) { + if(distributeGraphRequest.getActions() == null){ + throw new ActionsNotDefinedException("Action(s) must be defined in the request"); + } + for(Action action : distributeGraphRequest.getActions()){ + if(action.getCommand().equals("addnode")){ + Node node = prepareNodeFromAddNAddNodeAction(action); + mainFlowGraph.addNode(node); + } + else if(action.getCommand().equals("addedge")) { + Edge edge = prepareEdgeFromAddEdgeAction(action); + Node srcNode = flowGraphParser.getNodeFromId(edge.getSrc().getNode()); + Node tgtNode = flowGraphParser.getNodeFromId(edge.getTgt().getNode()); + srcNode = fillPlaceholderIfNodeIsEmpty(srcNode); + tgtNode =fillPlaceholderIfNodeIsEmpty(tgtNode); + mainFlowGraph.addEdge(srcNode,tgtNode,edge); + } + } + } + + private Node fillPlaceholderIfNodeIsEmpty(Node node) { + if (node == null) { + node = flowGraphParser.getNodeFromId("dummy_id"); + } + return node; + } + + + private Edge prepareEdgeFromAddEdgeAction(Action action) { + ObjectMapper objectMapper = new ObjectMapper(); + Edge edge = objectMapper.convertValue(action.getPayload(),Edge.class); + return edge; + } + + private void fillPlaceholderIfLocaionsAreEmpty(Edge edge) { + if(edge.getSrc().getNode() == null && edge.getSrc().getPort() == null){ + EdgeLocation src = new EdgeLocation("node-id-placeholder", "node-port-placeholder"); + edge.setSrc(src); + } + if(edge.getTgt().getNode() == null && edge.getTgt().getPort() == null){ + EdgeLocation tgt = new EdgeLocation("node-id-placeholder", "node-port-placeholder"); + edge.setTgt(tgt); + } + } + + private Node prepareNodeFromAddNAddNodeAction(Action action) { + String componentId = (String) action.getPayload().get("component_id"); + String componentName = (String) action.getPayload().get("name"); + String componentSpec = (String) action.getPayload().get("component_spec"); + return new Node(componentId,componentName,componentSpec); + } +} 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(); + } +} diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java index f1329c1..94d4b40 100644 --- a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -17,15 +17,15 @@ */ package org.onap.dcae.runtime.web.service; -import org.onap.dcae.runtime.core.*; +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.FlowGraphParser.BlueprintVessel; -import org.onap.dcae.runtime.web.exception.ActionsNotDefinedException; +import org.onap.dcae.runtime.core.Node; import org.onap.dcae.runtime.web.exception.MainGraphAlreadyExistException; import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException; -import org.onap.dcae.runtime.web.models.Action; import org.onap.dcae.runtime.web.models.DistributeGraphRequest; import org.onap.dcae.runtime.web.models.GraphRequest; -import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -46,6 +46,9 @@ public class GraphServiceImpl implements GraphService{ @Autowired private FlowGraphParser flowGraphParser; + @Autowired + private GraphActionsParser actionsParser; + @Override public FlowGraph getMainGraph() { if(mainFlowGraph == null){ @@ -74,7 +77,7 @@ public class GraphServiceImpl implements GraphService{ public List distribute(DistributeGraphRequest distributeGraphRequest) { //1.Iterate through list of actions logger.info("applying actions to graph"); - applyActionsToGraph(distributeGraphRequest); + actionsParser.applyActionsToGraph(mainFlowGraph, distributeGraphRequest); //2. generate blueprint from compspec of the node logger.info("generating blueprints for the affected nodes"); @@ -99,56 +102,5 @@ public class GraphServiceImpl implements GraphService{ return flowGraphParser.createAndProcessBlueprints(); } - private void applyActionsToGraph(DistributeGraphRequest distributeGraphRequest) { - if(distributeGraphRequest.getActions() == null){ - throw new ActionsNotDefinedException("Action(s) must be defined in the request"); - } - for(Action action : distributeGraphRequest.getActions()){ - if(action.getCommand().equals("addnode")){ - Node node = prepareNodeFromAddNAddNodeAction(action); - mainFlowGraph.addNode(node); - } - else if(action.getCommand().equals("addedge")) { - Edge edge = prepareEdgeFromAddEdgeAction(action); - Node srcNode = flowGraphParser.getNodeFromId(edge.getSrc().getNode()); - Node tgtNode = flowGraphParser.getNodeFromId(edge.getTgt().getNode()); - srcNode = fillPlaceholderIfNodeIsEmpty(srcNode); - tgtNode =fillPlaceholderIfNodeIsEmpty(tgtNode); - mainFlowGraph.addEdge(srcNode,tgtNode,edge); - } - } - } - - private Node fillPlaceholderIfNodeIsEmpty(Node node) { - if (node == null) { - node = flowGraphParser.getNodeFromId("dummy_id"); - } - return node; - } - - - private Edge prepareEdgeFromAddEdgeAction(Action action) { - ObjectMapper objectMapper = new ObjectMapper(); - Edge edge = objectMapper.convertValue(action.getPayload(),Edge.class); - return edge; - } - - private void fillPlaceholderIfLocaionsAreEmpty(Edge edge) { - if(edge.getSrc().getNode() == null && edge.getSrc().getPort() == null){ - EdgeLocation src = new EdgeLocation("node-id-placeholder", "node-port-placeholder"); - edge.setSrc(src); - } - if(edge.getTgt().getNode() == null && edge.getTgt().getPort() == null){ - EdgeLocation tgt = new EdgeLocation("node-id-placeholder", "node-port-placeholder"); - edge.setTgt(tgt); - } - } - - private Node prepareNodeFromAddNAddNodeAction(Action action) { - String componentId = (String) action.getPayload().get("component_id"); - String componentName = (String) action.getPayload().get("name"); - String componentSpec = (String) action.getPayload().get("component_spec"); - return new Node(componentId,componentName,componentSpec); - } } diff --git a/mod/runtimeapi/runtime-web/src/main/resources/application.properties b/mod/runtimeapi/runtime-web/src/main/resources/application.properties index f3b06aa..31d56d8 100644 --- a/mod/runtimeapi/runtime-web/src/main/resources/application.properties +++ b/mod/runtimeapi/runtime-web/src/main/resources/application.properties @@ -24,3 +24,15 @@ onap.import.postgresPlugin=https://nexus.onap.org/service/local/repositories/raw onap.import.clampPlugin=https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R6/clamppolicyplugin/1.1.0/clamppolicyplugin_types.yaml onap.import.dmaapPlugin= https://nexus.onap.org/content/repositories/raw/org.onap.ccsdk.platform.plugins/type_files/dmaap/dmaap.yaml + +# The artifact type can be BLUEPRINT or HELM +artifact.type=BLUEPRINT + +#set these properties if artifact.type is HELM +helm.base.chart.template.location=./data/helm-base-template + +chartmuseum.baseurl=http://localhost:8081 + +chartmuseum.auth.basic.username= + +chartmuseum.auth.basic.password= -- cgit 1.2.3-korg