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);
106 switch(artifactinfo.getArtifactType()) {
107 case ASDCConfiguration.HEAT:
108 case ASDCConfiguration.HEAT_ENV:
109 case ASDCConfiguration.HEAT_VOL:
110 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
111 case ASDCConfiguration.HEAT_ARTIFACT:
112 case ASDCConfiguration.HEAT_NET:
113 case ASDCConfiguration.OTHER:
114 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
116 case ASDCConfiguration.VF_MODULES_METADATA:
117 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
124 public void createVfModuleStructures() throws ArtifactInstallerException {
126 //for vender tosca VNF there is no VFModule in VF
127 if (vfModulesMetadataList == null) {
128 LOGGER.info(MessageEnum.ASDC_GENERAL_INFO,"There is no VF mudules in the VF.", "ASDC", "createVfModuleStructures");
131 for (IVfModuleData vfModuleMeta:vfModulesMetadataList) {
132 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
136 public INotificationData getNotification() {
140 public IResourceInstance getResourceInstance() {
141 return resourceInstance;
144 public List<VfModuleStructure> getVfModuleStructure() {
145 return vfModulesStructureList;
148 public boolean isDeployedSuccessfully() {
149 return isDeployedSuccessfully;
152 public void setSuccessfulDeployment() {
153 isDeployedSuccessfully = true;
156 public boolean isAlreadyDeployed() {
157 return isAlreadyDeployed;
160 public void setAlreadyDeployed(boolean isAlreadyDeployed) {
161 this.isAlreadyDeployed = isAlreadyDeployed;
164 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
165 return artifactsMapByUUID;
168 public List<VfModuleStructure> getVfModulesStructureList() {
169 return vfModulesStructureList;
172 public VnfResource getCatalogVnfResource() {
173 return catalogVnfResource;
176 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
177 this.catalogVnfResource = catalogVnfResource;
181 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
182 return catalogNetworkResourceCustomization;
185 public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) {
186 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
189 public AllottedResourceCustomization getCatalogResourceCustomization() {
190 return catalogResourceCustomization;
193 public void setCatalogResourceCustomization(
194 AllottedResourceCustomization catalogResourceCustomization) {
195 this.catalogResourceCustomization = catalogResourceCustomization;
198 public Service getCatalogService() {
199 return catalogService;
202 public void setCatalogService(Service catalogService) {
203 this.catalogService = catalogService;
206 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
208 List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){});
209 return listVFModuleMetaData;
211 } catch (JsonParseException e) {
212 LOGGER.debug("JsonParseException : ",e);
213 } catch (JsonMappingException e) {
214 LOGGER.debug("JsonMappingException : ",e);
215 } catch (IOException e) {
216 LOGGER.debug("IOException : ",e);