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;
90 * The list of artifacts existing in this resource hashed by UUID.
92 private final Map<String, VfModuleArtifact> artifactsMapByUUID;
95 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
96 notification=notificationdata;
97 resourceInstance=resourceinstance;
100 vfModulesStructureList = new LinkedList<VfModuleStructure>();
101 artifactsMapByUUID = new HashMap<String, VfModuleArtifact>();
105 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
106 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
108 switch(artifactinfo.getArtifactType()) {
109 case ASDCConfiguration.HEAT:
110 case ASDCConfiguration.HEAT_ENV:
111 case ASDCConfiguration.HEAT_VOL:
112 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
113 case ASDCConfiguration.HEAT_ARTIFACT:
114 case ASDCConfiguration.HEAT_NET:
115 case ASDCConfiguration.OTHER:
116 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
119 case ASDCConfiguration.VF_MODULES_METADATA:
120 vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload());
129 public void createVfModuleStructures() throws ArtifactInstallerException {
131 if (vfModulesMetadataList == null) {
132 throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification");
134 for (IVfModuleData vfModuleMeta:vfModulesMetadataList) {
135 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
139 public INotificationData getNotification() {
143 public IResourceInstance getResourceInstance() {
144 return resourceInstance;
147 public List<VfModuleStructure> getVfModuleStructure() {
148 return vfModulesStructureList;
151 public boolean isDeployedSuccessfully() {
152 return isDeployedSuccessfully;
155 public void setSuccessfulDeployment() {
156 isDeployedSuccessfully = true;
159 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
160 return artifactsMapByUUID;
163 public List<VfModuleStructure> getVfModulesStructureList() {
164 return vfModulesStructureList;
167 public VnfResource getCatalogVnfResource() {
168 return catalogVnfResource;
171 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
172 this.catalogVnfResource = catalogVnfResource;
176 public NetworkResourceCustomization getCatalogNetworkResourceCustomization() {
177 return catalogNetworkResourceCustomization;
180 public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) {
181 this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization;
184 public ServiceToNetworks getCatalogServiceToNetworks() {
185 return catalogServiceToNetworks;
188 public void setCatalogServiceToNetworks(
189 ServiceToNetworks catalogServiceToNetworks) {
190 this.catalogServiceToNetworks = catalogServiceToNetworks;
193 public ServiceToAllottedResources getCatalogServiceToAllottedResources() {
194 return catalogServiceToAllottedResources;
197 public void setCatalogServiceToAllottedResources(
198 ServiceToAllottedResources catalogServiceToAllottedResources) {
199 this.catalogServiceToAllottedResources = catalogServiceToAllottedResources;
202 public AllottedResourceCustomization getCatalogResourceCustomization() {
203 return catalogResourceCustomization;
206 public void setCatalogResourceCustomization(
207 AllottedResourceCustomization catalogResourceCustomization) {
208 this.catalogResourceCustomization = catalogResourceCustomization;
211 public Service getCatalogService() {
212 return catalogService;
215 public void setCatalogService(Service catalogService) {
216 this.catalogService = catalogService;
219 public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) {
221 List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){});
222 return listVFModuleMetaData;
224 } catch (JsonParseException e) {
226 } catch (JsonMappingException e) {
228 } catch (IOException e) {