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.openecomp.mso.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;
31 import org.openecomp.mso.asdc.client.ASDCConfiguration;
32 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
33 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
34 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
35 import org.openecomp.mso.db.catalog.beans.Service;
36 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
37 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
38 import org.openecomp.mso.db.catalog.beans.VnfResource;
39 import org.openecomp.mso.logger.MsoLogger;
40 import org.onap.sdc.api.IDistributionClient;
41 import org.onap.sdc.api.notification.IArtifactInfo;
42 import org.onap.sdc.api.notification.INotificationData;
43 import org.onap.sdc.api.notification.IResourceInstance;
44 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
45 import org.openecomp.mso.logger.MessageEnum;
46 import com.fasterxml.jackson.core.JsonParseException;
47 import com.fasterxml.jackson.core.type.TypeReference;
48 import com.fasterxml.jackson.databind.JsonMappingException;
49 import com.fasterxml.jackson.databind.ObjectMapper;
51 * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure).
54 public final class VfResourceStructure {
56 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC);
58 private boolean isDeployedSuccessfully=false;
60 * The Raw notification data.
62 private final INotificationData notification;
65 * The resource we will try to deploy.
67 private final IResourceInstance resourceInstance;
70 * The list of VfModules defined for this resource.
72 private final List<VfModuleStructure> vfModulesStructureList;
75 * The list of VfModulesMetadata defined for this resource.
77 private List<IVfModuleData> vfModulesMetadataList;
79 private VnfResource catalogVnfResource;
81 private NetworkResourceCustomization catalogNetworkResourceCustomization;
83 private ServiceToNetworks catalogServiceToNetworks;
85 private ServiceToAllottedResources catalogServiceToAllottedResources;
87 private AllottedResourceCustomization catalogResourceCustomization;
89 private Service catalogService;
91 private List<String> vfArtifactUUIDList;
94 * The list of artifacts existing in this resource hashed by UUID.
96 private final Map<String, VfModuleArtifact> artifactsMapByUUID;
99 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
100 notification=notificationdata;
101 resourceInstance=resourceinstance;
104 vfModulesStructureList = new LinkedList<>();
105 artifactsMapByUUID = new HashMap<>();
109 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
110 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
112 switch(artifactinfo.getArtifactType()) {
113 case ASDCConfiguration.HEAT:
114 case ASDCConfiguration.HEAT_ENV:
115 case ASDCConfiguration.HEAT_VOL:
116 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
117 case ASDCConfiguration.HEAT_ARTIFACT:
118 case ASDCConfiguration.HEAT_NET:
119 case ASDCConfiguration.OTHER:
120 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
123 case ASDCConfiguration.VF_MODULES_METADATA:
124 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
126 for(IVfModuleData moduleData : vfModulesMetadataList){
130 //vfArtifactUUIDList.add(artifactinfo.getArtifactUUID());
131 //vfModulesMetadataList = distributionClient.decodeVfModuleArtifact(clientResult.getArtifactPayload());
140 public void createVfModuleStructures() throws ArtifactInstallerException {
142 //for vender tosca VNF there is no VFModule in VF
143 if (vfModulesMetadataList == null) {
144 LOGGER.info(MessageEnum.ASDC_GENERAL_INFO,"There is no VF mudules in the VF.", "ASDC", "createVfModuleStructures");
147 for (IVfModuleData vfModuleMeta:vfModulesMetadataList) {
148 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
152 public INotificationData getNotification() {
156 public IResourceInstance getResourceInstance() {
157 return resourceInstance;
160 public List<VfModuleStructure> getVfModuleStructure() {
161 return vfModulesStructureList;
164 public boolean isDeployedSuccessfully() {
165 return isDeployedSuccessfully;
168 public void setSuccessfulDeployment() {
169 isDeployedSuccessfully = true;
172 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
173 return artifactsMapByUUID;
176 public List<VfModuleStructure> getVfModulesStructureList() {
177 return vfModulesStructureList;
180 public VnfResource getCatalogVnfResource() {
181 return catalogVnfResource;
184 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
185 this.catalogVnfResource = catalogVnfResource;
189 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
190 return catalogNetworkResourceCustomization;
193 public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) {
194 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
197 public ServiceToNetworks getCatalogServiceToNetworks() {
198 return catalogServiceToNetworks;
201 public void setCatalogServiceToNetworks(
202 ServiceToNetworks catalogServiceToNetworks) {
203 this.catalogServiceToNetworks = catalogServiceToNetworks;
206 public ServiceToAllottedResources getCatalogServiceToAllottedResources() {
207 return catalogServiceToAllottedResources;
210 public void setCatalogServiceToAllottedResources(
211 ServiceToAllottedResources catalogServiceToAllottedResources) {
212 this.catalogServiceToAllottedResources = catalogServiceToAllottedResources;
215 public AllottedResourceCustomization getCatalogResourceCustomization() {
216 return catalogResourceCustomization;
219 public void setCatalogResourceCustomization(
220 AllottedResourceCustomization catalogResourceCustomization) {
221 this.catalogResourceCustomization = catalogResourceCustomization;
224 public Service getCatalogService() {
225 return catalogService;
228 public void setCatalogService(Service catalogService) {
229 this.catalogService = catalogService;
232 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
234 List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){});
235 return listVFModuleMetaData;
237 } catch (JsonParseException e) {
238 LOGGER.debug("JsonParseException : ",e);
239 } catch (JsonMappingException e) {
240 LOGGER.debug("JsonMappingException : ",e);
241 } catch (IOException e) {
242 LOGGER.debug("IOException : ",e);