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 * 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=========================================================
22 package org.onap.so.asdc.installer;
24 import java.io.IOException;
25 import java.io.UnsupportedEncodingException;
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.List;
30 import org.onap.so.asdc.client.ASDCConfiguration;
31 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
32 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
33 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
34 import org.onap.so.db.catalog.beans.Service;
35 import org.onap.so.db.catalog.beans.VnfResource;
36 import org.onap.so.logger.MsoLogger;
37 import org.onap.sdc.api.IDistributionClient;
38 import org.onap.sdc.api.notification.IArtifactInfo;
39 import org.onap.sdc.api.notification.INotificationData;
40 import org.onap.sdc.api.notification.IResourceInstance;
41 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
42 import org.onap.so.logger.MessageEnum;
43 import com.fasterxml.jackson.core.JsonParseException;
44 import com.fasterxml.jackson.core.type.TypeReference;
45 import com.fasterxml.jackson.databind.JsonMappingException;
46 import com.fasterxml.jackson.databind.ObjectMapper;
48 * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure).
53 public class VfResourceStructure {
55 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC, VfResourceStructure.class);
57 private boolean isDeployedSuccessfully=false;
59 * The Raw notification data.
61 private final INotificationData notification;
63 * The Raw notification data.
65 private boolean isAlreadyDeployed=false;
68 * The resource we will try to deploy.
70 private final IResourceInstance resourceInstance;
73 * The list of VfModules defined for this resource.
75 private final List<VfModuleStructure> vfModulesStructureList;
78 * The list of VfModulesMetadata defined for this resource.
80 private List<IVfModuleData> vfModulesMetadataList;
82 private VnfResource catalogVnfResource;
84 private NetworkResourceCustomization catalogNetworkResourceCustomization;
86 private AllottedResourceCustomization catalogResourceCustomization;
88 private Service catalogService;
91 * The list of artifacts existing in this resource hashed by UUID.
93 private final Map<String, VfModuleArtifact> artifactsMapByUUID;
96 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
97 notification=notificationdata;
98 resourceInstance=resourceinstance;
99 vfModulesStructureList = new LinkedList<>();
100 artifactsMapByUUID = new HashMap<>();
103 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
104 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
105 addArtifactByType(artifactinfo,clientResult,vfModuleArtifact);
108 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) throws UnsupportedEncodingException {
109 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult,modifiedHeatTemplate);
110 addArtifactByType(artifactinfo,clientResult,vfModuleArtifact);
113 protected void addArtifactByType(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException {
115 switch(artifactinfo.getArtifactType()) {
116 case ASDCConfiguration.HEAT:
117 case ASDCConfiguration.HEAT_ENV:
118 case ASDCConfiguration.HEAT_VOL:
119 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
120 case ASDCConfiguration.HEAT_ARTIFACT:
121 case ASDCConfiguration.HEAT_NET:
122 case ASDCConfiguration.OTHER:
123 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
125 case ASDCConfiguration.VF_MODULES_METADATA:
126 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
133 public void createVfModuleStructures() throws ArtifactInstallerException {
135 //for vender tosca VNF there is no VFModule in VF
136 if (vfModulesMetadataList == null) {
137 LOGGER.info(MessageEnum.ASDC_GENERAL_INFO,"There is no VF mudules in the VF.", "ASDC", "createVfModuleStructures");
140 for (IVfModuleData vfModuleMeta:vfModulesMetadataList) {
141 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
145 public INotificationData getNotification() {
149 public IResourceInstance getResourceInstance() {
150 return resourceInstance;
153 public List<VfModuleStructure> getVfModuleStructure() {
154 return vfModulesStructureList;
157 public boolean isDeployedSuccessfully() {
158 return isDeployedSuccessfully;
161 public void setSuccessfulDeployment() {
162 isDeployedSuccessfully = true;
165 public boolean isAlreadyDeployed() {
166 return isAlreadyDeployed;
169 public void setAlreadyDeployed(boolean isAlreadyDeployed) {
170 this.isAlreadyDeployed = isAlreadyDeployed;
173 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
174 return artifactsMapByUUID;
177 public List<VfModuleStructure> getVfModulesStructureList() {
178 return vfModulesStructureList;
181 public VnfResource getCatalogVnfResource() {
182 return catalogVnfResource;
185 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
186 this.catalogVnfResource = catalogVnfResource;
190 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
191 return catalogNetworkResourceCustomization;
194 public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) {
195 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
198 public AllottedResourceCustomization getCatalogResourceCustomization() {
199 return catalogResourceCustomization;
202 public void setCatalogResourceCustomization(
203 AllottedResourceCustomization catalogResourceCustomization) {
204 this.catalogResourceCustomization = catalogResourceCustomization;
207 public Service getCatalogService() {
208 return catalogService;
211 public void setCatalogService(Service catalogService) {
212 this.catalogService = catalogService;
215 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
217 List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){});
218 return listVFModuleMetaData;
220 } catch (JsonParseException e) {
221 LOGGER.debug("JsonParseException : ",e);
222 } catch (JsonMappingException e) {
223 LOGGER.debug("JsonMappingException : ",e);
224 } catch (IOException e) {
225 LOGGER.debug("IOException : ",e);