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.core.blueprint_creator;
20 import org.onap.dcae.runtime.core.Node;
21 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
22 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
23 import org.yaml.snakeyaml.DumperOptions;
24 import org.yaml.snakeyaml.Yaml;
28 public class BlueprintCreatorOnap implements BlueprintCreator{
30 private String topicUrl;
31 private String importFilePath;
33 public void setTopicUrl(String topicUrl) {
34 this.topicUrl = topicUrl;
37 public void setImportFilePath(String importFilePath) {
38 this.importFilePath = importFilePath;
42 public String createBlueprint(String componentSpecString) {
43 ComponentSpec componentSpec = new ComponentSpec();
44 componentSpec.createComponentSpecFromString(componentSpecString);
45 Blueprint blueprint = new Blueprint().createBlueprint(componentSpec,"",'o',importFilePath,"");
46 return blueprint.blueprintToString();
50 public void resolveDmaapConnection(Node node, String locationPort, String dmaapEntityName) {
51 if(node == null || locationPort == null){
54 String blueprintContent = node.getBlueprintData().getBlueprint_content();
55 locationPort = locationPort.replaceAll("-","_");
56 Yaml yaml = getYamlInstance();
57 Map<String,Object> obj = yaml.load(blueprintContent);
58 Map<String,Object> inputsObj = (Map<String, Object>) obj.get("inputs");
59 for(Map.Entry<String,Object> entry: inputsObj.entrySet()){
60 if(entry.getKey().matches(locationPort+".*url")) {
61 Map<String,String> inputValue = (Map<String, String>) entry.getValue();
62 inputValue.put("default",topicUrl + "/" + dmaapEntityName);
65 node.getBlueprintData().setBlueprint_content(yaml.dump(obj));
68 private Yaml getYamlInstance() {
69 DumperOptions options = new DumperOptions();
70 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
71 options.setPrettyFlow(true);
72 return new Yaml(options);
75 // private String attachSingleQoutes(String str) {
76 // return "'" + str + "'";