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;
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
50 * Application: ONAP - Blueprint Generator
51 * Service to create ONAP Blueprint
55 public class OnapBlueprintService extends BlueprintService {
58 private NodeService nodeService;
61 private PolicyNodeService policyNodeService;
64 private PgaasNodeService pgaasNodeService;
67 private QuotationService quotationService;
70 protected ImportsService importsService;
72 // Method to generate Onap Blueprint
73 public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) {
75 OnapBlueprint blueprint = new OnapBlueprint();
76 blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION);
78 //if (!"".equals(input.getImportPath()))
79 if (!StringUtils.isEmpty(input.getImportPath()))
80 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
82 blueprint.setImports(importsService.createImports(input.getBpType()));
84 Map<String, Node> nodeTemplate = new TreeMap<>();
85 String nodeName = onapComponentSpec.getSelf().getName();
86 Map<String, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
88 Map<String, Object> onapNodeResponse = nodeService.createOnapNode(inputs, onapComponentSpec, input.getServiceNameOverride());
89 inputs = (Map<String, LinkedHashMap<String, Object>>) onapNodeResponse.get("inputs");
90 nodeTemplate.put(nodeName, (Node) onapNodeResponse.get("onapNode"));
91 blueprint.setNode_templates(nodeTemplate);
93 if (onapComponentSpec.getPolicyInfo() != null)
94 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
96 if (onapComponentSpec.getAuxilary() != null && onapComponentSpec.getAuxilary().getDatabases() != null)
97 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
99 blueprint.setInputs(inputs);
101 return quotationService.setQuotations(blueprint);
102 } catch (Exception ex) {
103 throw new BlueprintException("Unable to create ONAP Blueprint Object from given input parameters", ex);