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;
24 import org.onap.so.adapters.vdu.VduModelInfo;
25 import org.onap.so.adapters.vdu.VduArtifact;
26 import org.onap.so.adapters.vdu.VduArtifact.ArtifactType;
27 import org.onap.so.db.catalog.beans.HeatEnvironment;
28 import org.onap.so.db.catalog.beans.HeatFiles;
29 import org.onap.so.db.catalog.beans.HeatTemplate;
30 import org.onap.so.db.catalog.beans.VfModuleCustomization;
31 import org.springframework.stereotype.Component;
34 public class VfModuleCustomizationToVduMapper {
36 public VduModelInfo mapVfModuleCustomizationToVdu(VfModuleCustomization vfModuleCustom) {
37 VduModelInfo vduModel = new VduModelInfo();
38 vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUUID());
39 vduModel.setModelUUID(vfModuleCustom.getVfModule().getModelUUID());
40 vduModel.setModelInvariantUUID(vfModuleCustom.getVfModule().getModelInvariantUUID());
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) {
51 VduModelInfo vduModel = new VduModelInfo();
52 vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUUID());
53 vduModel.setModelUUID(vfModuleCustom.getVfModule().getModelUUID());
54 vduModel.setModelInvariantUUID(vfModuleCustom.getVfModule().getModelInvariantUUID());
56 // Map the cloud templates, attached files, and environment file
57 mapCloudTemplates(vfModuleCustom.getVfModule().getVolumeHeatTemplate(), vduModel);
58 mapCloudFiles(vfModuleCustom, vduModel);
59 mapEnvironment(vfModuleCustom.getVolumeHeatEnv(), vduModel);
64 private void mapCloudTemplates(HeatTemplate heatTemplate, VduModelInfo vduModel) {
65 // TODO: These catalog objects will be refactored to be non-Heat-specific
67 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
69 // Main template. Also set the VDU timeout based on the main template.
70 vduArtifacts.add(mapHeatTemplateToVduArtifact(heatTemplate, ArtifactType.MAIN_TEMPLATE));
71 vduModel.setTimeoutMinutes(heatTemplate.getTimeoutMinutes());
74 List<HeatTemplate> childTemplates = heatTemplate.getChildTemplates();
75 if (childTemplates != null) {
76 for (HeatTemplate childTemplate : childTemplates) {
77 vduArtifacts.add(mapHeatTemplateToVduArtifact(childTemplate, ArtifactType.NESTED_TEMPLATE));
82 private VduArtifact mapHeatTemplateToVduArtifact(HeatTemplate heatTemplate, ArtifactType artifactType) {
83 VduArtifact vduArtifact = new VduArtifact();
84 vduArtifact.setName(heatTemplate.getTemplateName());
85 vduArtifact.setContent(heatTemplate.getHeatTemplate().getBytes());
86 vduArtifact.setType(artifactType);
90 private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) {
91 // TODO: These catalog objects will be refactored to be non-Heat-specific
93 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
96 List<HeatFiles> heatFiles = vfModuleCustom.getVfModule().getHeatFiles();
97 if (heatFiles != null) {
98 for (HeatFiles file : heatFiles) {
99 vduArtifacts.add(mapCloudFileToVduArtifact(file, ArtifactType.TEXT_FILE));
104 private VduArtifact mapCloudFileToVduArtifact(HeatFiles heatFile, ArtifactType artifactType) {
105 VduArtifact vduArtifact = new VduArtifact();
106 vduArtifact.setName(heatFile.getFileName());
107 vduArtifact.setContent(heatFile.getFileBody().getBytes());
108 vduArtifact.setType(artifactType);
112 private void mapEnvironment(HeatEnvironment heatEnvironment, VduModelInfo vduModel) {
113 // TODO: These catalog objects will be refactored to be non-Heat-specific
114 if (heatEnvironment != null) {
115 List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
116 vduArtifacts.add(mapEnvironmentFileToVduArtifact(heatEnvironment));
120 private VduArtifact mapEnvironmentFileToVduArtifact(HeatEnvironment heatEnv) {
121 VduArtifact vduArtifact = new VduArtifact();
122 vduArtifact.setName(heatEnv.getName());
123 vduArtifact.setContent(heatEnv.getEnvironment().getBytes());
124 vduArtifact.setType(ArtifactType.ENVIRONMENT);