2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.asdc.installer;
23 import java.io.IOException;
24 import java.io.UnsupportedEncodingException;
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
30 import org.codehaus.jackson.JsonParseException;
31 import org.codehaus.jackson.map.JsonMappingException;
32 import org.codehaus.jackson.map.ObjectMapper;
33 import org.codehaus.jackson.type.TypeReference;
35 import org.openecomp.sdc.api.IDistributionClient;
36 import org.openecomp.sdc.api.notification.IArtifactInfo;
37 import org.openecomp.sdc.api.notification.INotificationData;
38 import org.openecomp.sdc.api.notification.IResourceInstance;
39 import org.openecomp.sdc.api.notification.IVfModuleMetadata;
40 import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
41 import org.openecomp.mso.asdc.client.ASDCConfiguration;
42 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
43 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
44 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
45 import org.openecomp.mso.db.catalog.beans.Service;
46 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
47 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
48 import org.openecomp.mso.db.catalog.beans.VnfResource;
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 private boolean isDeployedSuccessfully=false;
58 * The Raw notification data.
60 private final INotificationData notification;
63 * The resource we will try to deploy.
65 private final IResourceInstance resourceInstance;
68 * The list of VfModules defined for this resource.
70 private final List<VfModuleStructure> vfModulesStructureList;
73 * The list of VfModulesMetadata defined for this resource.
75 private List<IVfModuleData> vfModulesMetadataList;
77 private VnfResource catalogVnfResource;
79 private NetworkResourceCustomization catalogNetworkResourceCustomization;
81 private ServiceToNetworks catalogServiceToNetworks;
83 private ServiceToAllottedResources catalogServiceToAllottedResources;
85 private AllottedResourceCustomization catalogResourceCustomization;
87 private Service catalogService;
89 private List<String> vfArtifactUUIDList;
92 * The list of artifacts existing in this resource hashed by UUID.
94 private final Map<String, VfModuleArtifact> artifactsMapByUUID;
97 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
98 notification=notificationdata;
99 resourceInstance=resourceinstance;
102 vfModulesStructureList = new LinkedList<VfModuleStructure>();
103 artifactsMapByUUID = new HashMap<String, VfModuleArtifact>();
107 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
108 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
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);
121 case ASDCConfiguration.VF_MODULES_METADATA:
122 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
124 for(IVfModuleData moduleData : vfModulesMetadataList){
128 //vfArtifactUUIDList.add(artifactinfo.getArtifactUUID());
129 //vfModulesMetadataList = distributionClient.decodeVfModuleArtifact(clientResult.getArtifactPayload());
138 public void createVfModuleStructures() throws ArtifactInstallerException {
140 if (vfModulesMetadataList == null) {
141 throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification");
143 for (IVfModuleData vfModuleMeta:vfModulesMetadataList) {
144 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
148 public INotificationData getNotification() {
152 public IResourceInstance getResourceInstance() {
153 return resourceInstance;
156 public List<VfModuleStructure> getVfModuleStructure() {
157 return vfModulesStructureList;
160 public boolean isDeployedSuccessfully() {
161 return isDeployedSuccessfully;
164 public void setSuccessfulDeployment() {
165 isDeployedSuccessfully = true;
168 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
169 return artifactsMapByUUID;
172 public List<VfModuleStructure> getVfModulesStructureList() {
173 return vfModulesStructureList;
176 public VnfResource getCatalogVnfResource() {
177 return catalogVnfResource;
180 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
181 this.catalogVnfResource = catalogVnfResource;
185 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
186 return catalogNetworkResourceCustomization;
189 public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) {
190 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
193 public ServiceToNetworks getCatalogServiceToNetworks() {
194 return catalogServiceToNetworks;
197 public void setCatalogServiceToNetworks(
198 ServiceToNetworks catalogServiceToNetworks) {
199 this.catalogServiceToNetworks = catalogServiceToNetworks;
202 public ServiceToAllottedResources getCatalogServiceToAllottedResources() {
203 return catalogServiceToAllottedResources;
206 public void setCatalogServiceToAllottedResources(
207 ServiceToAllottedResources catalogServiceToAllottedResources) {
208 this.catalogServiceToAllottedResources = catalogServiceToAllottedResources;
211 public AllottedResourceCustomization getCatalogResourceCustomization() {
212 return catalogResourceCustomization;
215 public void setCatalogResourceCustomization(
216 AllottedResourceCustomization catalogResourceCustomization) {
217 this.catalogResourceCustomization = catalogResourceCustomization;
220 public Service getCatalogService() {
221 return catalogService;
224 public void setCatalogService(Service catalogService) {
225 this.catalogService = catalogService;
228 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
230 List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){});
231 return listVFModuleMetaData;
233 } catch (JsonParseException e) {
235 } catch (JsonMappingException e) {
237 } catch (IOException e) {