2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vdu.mapper;
23 import java.util.List;
25 import org.onap.so.adapters.vdu.VduModelInfo;
26 import org.onap.so.adapters.vdu.VduArtifact;
27 import org.onap.so.adapters.vdu.VduArtifact.ArtifactType;
28 import org.onap.so.db.catalog.beans.HeatEnvironment;
29 import org.onap.so.db.catalog.beans.HeatFiles;
30 import org.onap.so.db.catalog.beans.HeatTemplate;
31 import org.onap.so.db.catalog.beans.VfModuleCustomization;
32 import org.springframework.stereotype.Component;
35 public class VfModuleCustomizationToVduMapper {
37 public VduModelInfo mapVfModuleCustomizationToVdu(VfModuleCustomization vfModuleCustom)
39 VduModelInfo vduModel = new VduModelInfo();
40 vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUUID());
42 // Map the cloud templates, attached files, and environment file
43 mapCloudTemplates(vfModuleCustom.getVfModule().getModuleHeatTemplate(), vduModel);
44 mapCloudFiles(vfModuleCustom,vduModel);
45 mapEnvironment(vfModuleCustom.getHeatEnvironment(), vduModel);
50 public VduModelInfo mapVfModuleCustVolumeToVdu(VfModuleCustomization vfModuleCustom)
52 VduModelInfo vduModel = new VduModelInfo();
53 vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUUID());
55 // Map the cloud templates, attached files, and environment file
56 mapCloudTemplates(vfModuleCustom.getVfModule().getVolumeHeatTemplate(), vduModel);
57 mapCloudFiles(vfModuleCustom,vduModel);
58 mapEnvironment(vfModuleCustom.getVolumeHeatEnv(), vduModel);
63 private void mapCloudTemplates(HeatTemplate heatTemplate, VduModelInfo vduModel) {
64 // TODO: These catalog objects will be refactored to be non-Heat-specific
66 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
68 // Main template. Also set the VDU timeout based on the main template.
69 vduArtifacts.add(mapHeatTemplateToVduArtifact(heatTemplate, ArtifactType.MAIN_TEMPLATE));
70 vduModel.setTimeoutMinutes(heatTemplate.getTimeoutMinutes());
73 List<HeatTemplate> childTemplates = heatTemplate.getChildTemplates();
74 if (childTemplates != null) {
75 for(HeatTemplate childTemplate : childTemplates){
76 vduArtifacts.add(mapHeatTemplateToVduArtifact(childTemplate, ArtifactType.NESTED_TEMPLATE));
81 private VduArtifact mapHeatTemplateToVduArtifact(HeatTemplate heatTemplate, ArtifactType artifactType) {
82 VduArtifact vduArtifact = new VduArtifact();
83 vduArtifact.setName(heatTemplate.getTemplateName());
84 vduArtifact.setContent(heatTemplate.getHeatTemplate().getBytes());
85 vduArtifact.setType(artifactType);
89 private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) {
90 // TODO: These catalog objects will be refactored to be non-Heat-specific
92 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
95 List<HeatFiles> heatFiles = vfModuleCustom.getVfModule().getHeatFiles();
96 if (heatFiles != null) {
97 for(HeatFiles file : heatFiles){
98 vduArtifacts.add(mapCloudFileToVduArtifact(file, ArtifactType.TEXT_FILE));
103 private VduArtifact mapCloudFileToVduArtifact(HeatFiles heatFile, ArtifactType artifactType) {
104 VduArtifact vduArtifact = new VduArtifact();
105 vduArtifact.setName(heatFile.getFileName());
106 vduArtifact.setContent(heatFile.getFileBody().getBytes());
107 vduArtifact.setType(artifactType);
111 private void mapEnvironment(HeatEnvironment heatEnvironment, VduModelInfo vduModel) {
112 // TODO: These catalog objects will be refactored to be non-Heat-specific
113 if (heatEnvironment != null) {
114 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
115 vduArtifacts.add(mapEnvironmentFileToVduArtifact(heatEnvironment));
119 private VduArtifact mapEnvironmentFileToVduArtifact(HeatEnvironment heatEnv) {
120 VduArtifact vduArtifact = new VduArtifact();
121 vduArtifact.setName(heatEnv.getName());
122 vduArtifact.setContent(heatEnv.getEnvironment().getBytes());
123 vduArtifact.setType(ArtifactType.ENVIRONMENT);