2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.asdc.installer;
26 import java.io.IOException;
27 import java.io.UnsupportedEncodingException;
28 import java.util.HashMap;
29 import java.util.LinkedList;
30 import java.util.List;
32 import org.onap.so.asdc.client.ASDCConfiguration;
33 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
34 import org.onap.so.asdc.util.ASDCNotificationLogging;
35 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
36 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
37 import org.onap.so.db.catalog.beans.Service;
38 import org.onap.so.db.catalog.beans.VnfResource;
39 import org.onap.sdc.api.IDistributionClient;
40 import org.onap.sdc.api.notification.IArtifactInfo;
41 import org.onap.sdc.api.notification.INotificationData;
42 import org.onap.sdc.api.notification.IResourceInstance;
43 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
44 import org.onap.so.logger.MessageEnum;
45 import com.fasterxml.jackson.core.JsonParseException;
46 import com.fasterxml.jackson.core.type.TypeReference;
47 import com.fasterxml.jackson.databind.JsonMappingException;
48 import com.fasterxml.jackson.databind.ObjectMapper;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree
56 public class VfResourceStructure extends ResourceStructure {
58 protected static final Logger logger = LoggerFactory.getLogger(VfResourceStructure.class);
61 * The list of VfModules defined for this resource.
63 private final List<VfModuleStructure> vfModulesStructureList;
66 * The list of VfModulesMetadata defined for this resource.
68 private List<IVfModuleData> vfModulesMetadataList;
70 private VnfResource catalogVnfResource;
72 private NetworkResourceCustomization catalogNetworkResourceCustomization;
74 private AllottedResourceCustomization catalogResourceCustomization;
76 private Service catalogService;
79 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
80 super(notificationdata, resourceinstance);
81 this.resourceType = ResourceType.VF_RESOURCE;
82 vfModulesStructureList = new LinkedList<>();
85 public void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo,
86 IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
87 this.addArtifactToStructure(distributionClient, artifactinfo, clientResult, null);
90 public void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo,
91 IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate)
92 throws UnsupportedEncodingException {
93 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo, clientResult, modifiedHeatTemplate);
94 addArtifactByType(artifactinfo, clientResult, vfModuleArtifact);
95 if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifactinfo.getArtifactType())) {
96 logger.debug("VF_MODULE_ARTIFACT: " + new String(clientResult.getArtifactPayload(), "UTF-8"));
97 logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(vfModulesMetadataList));
101 protected void addArtifactByType(IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult,
102 VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException {
104 switch (artifactinfo.getArtifactType()) {
105 case ASDCConfiguration.HEAT:
106 case ASDCConfiguration.HEAT_ENV:
107 case ASDCConfiguration.HEAT_VOL:
108 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
109 case ASDCConfiguration.HEAT_ARTIFACT:
110 case ASDCConfiguration.HEAT_NET:
111 case ASDCConfiguration.OTHER:
112 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
114 case ASDCConfiguration.VF_MODULES_METADATA:
115 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
122 public void prepareInstall() throws ArtifactInstallerException {
123 createVfModuleStructures();
126 public void createVfModuleStructures() throws ArtifactInstallerException {
128 // for vender tosca VNF there is no VFModule in VF
129 if (vfModulesMetadataList == null) {
130 logger.info("{} {} {} {}", MessageEnum.ASDC_GENERAL_INFO.toString(), "There is no VF mudules in the VF.",
131 "ASDC", "createVfModuleStructures");
134 for (IVfModuleData vfModuleMeta : vfModulesMetadataList) {
135 vfModulesStructureList.add(new VfModuleStructure(this, vfModuleMeta));
137 setNumberOfResources(vfModulesMetadataList.size());
140 public List<VfModuleStructure> getVfModuleStructure() {
141 return vfModulesStructureList;
144 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
145 return artifactsMapByUUID;
148 public List<VfModuleStructure> getVfModulesStructureList() {
149 return vfModulesStructureList;
152 public VnfResource getCatalogVnfResource() {
153 return catalogVnfResource;
156 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
157 this.catalogVnfResource = catalogVnfResource;
161 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
162 return catalogNetworkResourceCustomization;
166 public void setCatalogNetworkResourceCustomization(
167 NetworkResourceCustomization catalogNetworkResourceCustomization) {
168 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
171 public AllottedResourceCustomization getCatalogResourceCustomization() {
172 return catalogResourceCustomization;
175 public void setCatalogResourceCustomization(AllottedResourceCustomization catalogResourceCustomization) {
176 this.catalogResourceCustomization = catalogResourceCustomization;
179 public Service getCatalogService() {
180 return catalogService;
183 public void setCatalogService(Service catalogService) {
184 this.catalogService = catalogService;
187 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
189 List<IVfModuleData> listVFModuleMetaData =
190 new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>() {});
191 return listVFModuleMetaData;
193 } catch (JsonParseException e) {
194 logger.debug("JsonParseException : ", e);
195 } catch (JsonMappingException e) {
196 logger.debug("JsonMappingException : ", e);
197 } catch (IOException e) {
198 logger.debug("IOException : ", e);