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 public void addWorkflowArtifactToStructure(IArtifactInfo artifactinfo,
102 IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
103 WorkflowArtifact workflowArtifact = new WorkflowArtifact(artifactinfo, clientResult);
104 workflowArtifactsMapByUUID.put(artifactinfo.getArtifactUUID(), workflowArtifact);
107 protected void addArtifactByType(IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult,
108 VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException {
110 switch (artifactinfo.getArtifactType()) {
111 case ASDCConfiguration.HEAT:
112 case ASDCConfiguration.HEAT_ENV:
113 case ASDCConfiguration.HEAT_VOL:
114 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
115 case ASDCConfiguration.HEAT_ARTIFACT:
116 case ASDCConfiguration.HEAT_NET:
117 case ASDCConfiguration.OTHER:
118 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
120 case ASDCConfiguration.VF_MODULES_METADATA:
121 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
128 public void prepareInstall() throws ArtifactInstallerException {
129 createVfModuleStructures();
132 public void createVfModuleStructures() throws ArtifactInstallerException {
134 // for vender tosca VNF there is no VFModule in VF
135 if (vfModulesMetadataList == null) {
136 logger.info("{} {} {} {}", MessageEnum.ASDC_GENERAL_INFO.toString(), "There is no VF mudules in the VF.",
137 "ASDC", "createVfModuleStructures");
140 for (IVfModuleData vfModuleMeta : vfModulesMetadataList) {
141 vfModulesStructureList.add(new VfModuleStructure(this, vfModuleMeta));
143 setNumberOfResources(vfModulesMetadataList.size());
146 public List<VfModuleStructure> getVfModuleStructure() {
147 return vfModulesStructureList;
150 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
151 return artifactsMapByUUID;
154 public List<VfModuleStructure> getVfModulesStructureList() {
155 return vfModulesStructureList;
158 public VnfResource getCatalogVnfResource() {
159 return catalogVnfResource;
162 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
163 this.catalogVnfResource = catalogVnfResource;
167 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
168 return catalogNetworkResourceCustomization;
172 public void setCatalogNetworkResourceCustomization(
173 NetworkResourceCustomization catalogNetworkResourceCustomization) {
174 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
177 public AllottedResourceCustomization getCatalogResourceCustomization() {
178 return catalogResourceCustomization;
181 public void setCatalogResourceCustomization(AllottedResourceCustomization catalogResourceCustomization) {
182 this.catalogResourceCustomization = catalogResourceCustomization;
185 public Service getCatalogService() {
186 return catalogService;
189 public void setCatalogService(Service catalogService) {
190 this.catalogService = catalogService;
193 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
195 List<IVfModuleData> listVFModuleMetaData =
196 new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>() {});
197 return listVFModuleMetaData;
199 } catch (JsonParseException e) {
200 logger.debug("JsonParseException : ", e);
201 } catch (JsonMappingException e) {
202 logger.debug("JsonMappingException : ", e);
203 } catch (IOException e) {
204 logger.debug("IOException : ", e);