3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2020 Nokia. All rights reserved.
8 * * ================================================================================
9 * * Licensed under the Apache License, Version 2.0 (the "License");
10 * * you may not use this file except in compliance with the License.
11 * * You may obtain a copy of the License at
13 * * http://www.apache.org/licenses/LICENSE-2.0
15 * * Unless required by applicable law or agreed to in writing, software
16 * * distributed under the License is distributed on an "AS IS" BASIS,
17 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * * See the License for the specific language governing permissions and
19 * * limitations under the License.
20 * * ============LICENSE_END=========================================================
25 package org.onap.blueprintgenerator.service.onap;
27 import org.onap.blueprintgenerator.constants.Constants;
28 import org.onap.blueprintgenerator.exception.BlueprintException;
29 import org.onap.blueprintgenerator.model.common.Input;
30 import org.onap.blueprintgenerator.model.common.Node;
31 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
32 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
33 import org.onap.blueprintgenerator.service.base.BlueprintService;
34 import org.onap.blueprintgenerator.service.common.ImportsService;
35 import org.onap.blueprintgenerator.service.common.NodeService;
36 import org.onap.blueprintgenerator.service.common.PgaasNodeService;
37 import org.onap.blueprintgenerator.service.common.PolicyNodeService;
38 import org.onap.blueprintgenerator.service.common.QuotationService;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Service;
41 import org.springframework.util.StringUtils;
43 import java.util.LinkedHashMap;
45 import java.util.TreeMap;
48 * @author : Ravi Mantena
49 * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create ONAP Blueprint
52 public class OnapBlueprintCreatorService {
55 private NodeService nodeService;
58 private PolicyNodeService policyNodeService;
61 private PgaasNodeService pgaasNodeService;
64 private QuotationService quotationService;
67 protected ImportsService importsService;
70 * Creates Onap Blueprint
72 * @param onapComponentSpec OnapComponentSpec
76 public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) {
78 OnapBlueprint blueprint = new OnapBlueprint();
79 blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION);
81 // if (!"".equals(input.getImportPath()))
82 if (!StringUtils.isEmpty(input.getImportPath())) {
83 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
85 blueprint.setImports(importsService.createImports(input.getBpType()));
88 Map<String, Node> nodeTemplate = new TreeMap<>();
89 String nodeName = onapComponentSpec.getSelf().getName();
90 Map<String, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
92 Map<String, Object> onapNodeResponse =
94 .createOnapNode(inputs, onapComponentSpec, input.getServiceNameOverride());
95 inputs = (Map<String, LinkedHashMap<String, Object>>) onapNodeResponse.get("inputs");
96 nodeTemplate.put(nodeName, (Node) onapNodeResponse.get("onapNode"));
97 blueprint.setNode_templates(nodeTemplate);
99 if (onapComponentSpec.getPolicyInfo() != null) {
100 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
103 if (onapComponentSpec.getAuxilary() != null
104 && onapComponentSpec.getAuxilary().getDatabases() != null) {
105 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
108 blueprint.setInputs(inputs);
110 return quotationService.setQuotations(blueprint);
111 } catch (Exception ex) {
112 throw new BlueprintException(
113 "Unable to create ONAP Blueprint Object from given input parameters", ex);