3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.service.common;
26 import org.onap.blueprintgenerator.model.common.GetInput;
27 import org.onap.blueprintgenerator.model.common.StartInputs;
28 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
29 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
33 import java.util.LinkedHashMap;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
40 * @author : Ravi Mantena
42 * Application: ONAP - Blueprint Generator
43 * Common ONAP Service used by ONAP and DMAAP Blueprint to add Start Inputs Node under Start
48 public class StartInputsService {
51 private PgaasNodeService pgaasNodeService;
53 //Method to create Start Inputs for Start in Interfaces
54 public Map<String, Object> createStartInputs(Map<String, LinkedHashMap<String, Object>> inputs, OnapComponentSpec onapComponentSpec){
56 Map<String,Object> response = new HashMap<>();
57 StartInputs startInputs = new StartInputs();
60 List<String> portList = new ArrayList();
61 OnapAuxilary aux = onapComponentSpec.getAuxilary();
63 if (aux.getPorts() != null) {
64 for(Object p : aux.getPorts()) {
65 String[] ports = p.toString().split(":");
66 portList.add(String.format("concat: [\"%s:\", {get_input: external_port_%d}]" , ports[0], count));
68 LinkedHashMap<String, Object> portType = new LinkedHashMap();
69 portType.put("type", "string");
70 portType.put("default", ports[1]);
71 inputs.put("external_port_" + count, portType);
76 startInputs.setPorts(portList);
78 LinkedHashMap<String, Object> envMap = new LinkedHashMap();
79 if(onapComponentSpec.getAuxilary().getDatabases() != null){
80 Map<String, Object> envVars = pgaasNodeService.getEnvVariables(onapComponentSpec.getAuxilary().getDatabases());
81 startInputs.setEnvs(envVars);
82 envMap.put("default", "&envs {}");
85 GetInput env = new GetInput();
86 env.setBpInputName("envs");
87 startInputs.setEnvs(env);
88 envMap.put("default", "{}");
90 inputs.put("envs", envMap);
92 response.put("startInputs", startInputs);
93 response.put("inputs", inputs);