2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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=========================================================
18 package org.onap.dcae.runtime.web.configuration;
20 import org.onap.dcae.runtime.core.FlowGraphParser;
21 import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreatorOnap;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.beans.factory.annotation.Value;
24 import org.springframework.context.annotation.Bean;
25 import org.springframework.context.annotation.Configuration;
26 import org.springframework.context.annotation.Primary;
27 import org.springframework.context.annotation.Profile;
28 import org.springframework.core.env.Environment;
29 import org.yaml.snakeyaml.Yaml;
31 import java.io.IOException;
32 import java.nio.file.FileAlreadyExistsException;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
42 public class BlueprintCreatorConfig {
47 @Value("${onap.topicUrl}")
48 String onapDublinTopicUrl;
50 @Value("${onap.import.cloudifyPlugin}")
51 String onapDublinImportCloudifyPlugin;
53 @Value("${onap.import.k8sPlugin}")
54 String onapDublinImportK8sPlugin;
56 @Value("${onap.import.policyPlugin}")
57 String onapDublinImportPolicyPlugin;
59 @Value("${onap.import.postgresPlugin}")
60 String onapDublinImportPostgresPlugin;
62 @Value("${onap.import.clampPlugin}")
63 String onapDublinImportClampPlugin;
65 @Value("${onap.import.dmaapPlugin}")
66 String onapDublinImportDmaapPlugin;
72 public FlowGraphParser getFlowGraphParserForOnapDublin(){
73 BlueprintCreatorOnap blueprintCreatorOnap = new BlueprintCreatorOnap();
74 blueprintCreatorOnap.setImportFilePath(writeImportsTofile());
75 FlowGraphParser flowGraphParser = new FlowGraphParser(blueprintCreatorOnap);
76 return flowGraphParser;
79 private String writeImportsTofile() {
80 String contentToWrite = getContentToWrite();
83 Path path = createDataImportDirAndImportFile();
84 fielPath = Files.write(path,contentToWrite.getBytes()).toString();
85 new String(Files.readAllBytes(path));
86 } catch (IOException e) {
89 System.out.println(fielPath);
93 private Path createDataImportDirAndImportFile() {
94 Path importDirPath = Paths.get("./data/imports").toAbsolutePath().normalize();
95 Path onapImportFilePath = Paths.get("./data/imports/onapImports.yaml").toAbsolutePath().normalize();
97 Files.createDirectories(importDirPath);
98 Files.createFile(onapImportFilePath);
100 catch (FileAlreadyExistsException ignored){
102 catch (IOException e) {
105 return onapImportFilePath;
108 private String getContentToWrite() {
109 Map<String,Object> result = new HashMap<String, Object>();
110 List<String> importList = new ArrayList<String>();
111 importList.add(onapDublinImportCloudifyPlugin);
112 importList.add(onapDublinImportK8sPlugin);
113 importList.add(onapDublinImportPolicyPlugin);
115 importList.add(onapDublinImportPostgresPlugin);
116 importList.add(onapDublinImportClampPlugin);
117 importList.add(onapDublinImportDmaapPlugin);
121 result.put("imports",importList);
122 return new Yaml().dump(result);