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
41 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add Start Inputs
45 public class StartInputsService {
48 private PgaasNodeService pgaasNodeService;
51 * Creates Start Inputs for Start in Interfaces
53 * @param inputs Inputs
54 * @param onapComponentSpec OnapComponentSpec
57 public Map<String, Object> createStartInputs(
58 Map<String, LinkedHashMap<String, Object>> inputs, OnapComponentSpec onapComponentSpec) {
60 Map<String, Object> response = new HashMap<>();
61 StartInputs startInputs = new StartInputs();
64 List<String> portList = new ArrayList();
65 OnapAuxilary aux = onapComponentSpec.getAuxilary();
67 if (aux.getPorts() != null) {
68 for (Object p : aux.getPorts()) {
69 String[] ports = p.toString().split(":");
71 String.format("concat: [\"%s:\", {get_input: external_port_%d}]", ports[0],
74 LinkedHashMap<String, Object> portType = new LinkedHashMap();
75 portType.put("type", "string");
76 portType.put("default", ports[1]);
77 inputs.put("external_port_" + count, portType);
82 startInputs.setPorts(portList);
84 LinkedHashMap<String, Object> envMap = new LinkedHashMap();
85 if (onapComponentSpec.getAuxilary().getDatabases() != null) {
86 Map<String, Object> envVars =
87 pgaasNodeService.getEnvVariables(onapComponentSpec.getAuxilary().getDatabases());
88 startInputs.setEnvs(envVars);
89 envMap.put("default", "&envs {}");
91 GetInput env = new GetInput();
92 env.setBpInputName("envs");
93 startInputs.setEnvs(env);
94 envMap.put("default", "{}");
96 inputs.put("envs", envMap);
98 response.put("startInputs", startInputs);
99 response.put("inputs", inputs);