2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * Copyright (C) 2020 Nokia. 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 package org.onap.dcae.runtime.web.configuration;
21 import java.io.IOException;
22 import java.nio.file.FileAlreadyExistsException;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
30 import org.onap.blueprintgenerator.BlueprintGeneratorConfiguration;
31 import org.onap.blueprintgenerator.service.BlueprintCreatorService;
32 import org.onap.blueprintgenerator.service.base.BlueprintService;
33 import org.onap.blueprintgenerator.service.base.FixesService;
34 import org.onap.blueprintgenerator.service.common.ComponentSpecService;
35 import org.onap.dcae.runtime.core.FlowGraphParser;
36 import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreatorOnap;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Configuration;
41 import org.springframework.context.annotation.Import;
42 import org.springframework.context.annotation.Primary;
43 import org.springframework.context.annotation.Profile;
44 import org.springframework.core.env.Environment;
45 import org.yaml.snakeyaml.Yaml;
48 @Import(BlueprintGeneratorConfiguration.class)
49 public class BlueprintCreatorConfig {
51 private final Environment env;
52 private final BlueprintService blueprintService;
53 private final ComponentSpecService componentSpecService;
54 private final BlueprintCreatorService blueprintCreatorService;
55 private final FixesService fixesService;
57 @Value("${onap.topicUrl}")
58 String onapDublinTopicUrl;
60 @Value("${onap.useDmaapPlugin}")
61 boolean useDmaapPlugin;
63 @Value("${onap.import.cloudifyPlugin}")
64 String onapDublinImportCloudifyPlugin;
66 @Value("${onap.import.k8sPlugin}")
67 String onapDublinImportK8sPlugin;
69 @Value("${onap.import.policyPlugin}")
70 String onapDublinImportPolicyPlugin;
72 @Value("${onap.import.postgresPlugin}")
73 String onapDublinImportPostgresPlugin;
75 @Value("${onap.import.clampPlugin}")
76 String onapDublinImportClampPlugin;
78 @Value("${onap.import.dmaapPlugin}")
79 String onapDublinImportDmaapPlugin;
82 public BlueprintCreatorConfig(Environment env, BlueprintService blueprintService,
83 ComponentSpecService componentSpecService, BlueprintCreatorService blueprintCreatorService,
84 FixesService fixesService) {
86 this.blueprintService = blueprintService;
87 this.componentSpecService = componentSpecService;
88 this.blueprintCreatorService = blueprintCreatorService;
89 this.fixesService = fixesService;
96 public FlowGraphParser getFlowGraphParserForOnapDublin() {
97 BlueprintCreatorOnap blueprintCreatorOnap = new BlueprintCreatorOnap(componentSpecService,
98 blueprintCreatorService, blueprintService, fixesService);
99 blueprintCreatorOnap.setImportFilePath(writeImportsTofile());
100 blueprintCreatorOnap.setUseDmaapPlugin(useDmaapPlugin);
101 FlowGraphParser flowGraphParser = new FlowGraphParser(blueprintCreatorOnap);
102 return flowGraphParser;
105 private String writeImportsTofile() {
106 String contentToWrite = getContentToWrite();
107 String fielPath = "";
109 Path path = createDataImportDirAndImportFile();
110 fielPath = Files.write(path, contentToWrite.getBytes()).toString();
111 new String(Files.readAllBytes(path));
112 } catch (IOException e) {
115 System.out.println(fielPath);
119 private Path createDataImportDirAndImportFile() {
120 Path importDirPath = Paths.get("./data/imports").toAbsolutePath().normalize();
121 Path onapImportFilePath = Paths.get("./data/imports/onapImports.yaml").toAbsolutePath().normalize();
123 Files.createDirectories(importDirPath);
124 Files.createFile(onapImportFilePath);
125 } catch (FileAlreadyExistsException ignored) {
126 } catch (IOException e) {
129 return onapImportFilePath;
132 private String getContentToWrite() {
133 Map<String, Object> result = new HashMap<String, Object>();
134 List<String> importList = new ArrayList<String>();
135 importList.add(onapDublinImportCloudifyPlugin);
136 importList.add(onapDublinImportK8sPlugin);
137 importList.add(onapDublinImportPolicyPlugin);
139 importList.add(onapDublinImportPostgresPlugin);
140 importList.add(onapDublinImportClampPlugin);
141 importList.add(onapDublinImportDmaapPlugin);
143 result.put("imports", importList);
144 return new Yaml().dump(result);