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;
24 import java.io.UnsupportedEncodingException;
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
30 import org.openecomp.sdc.api.IDistributionClient;
31 import org.openecomp.sdc.api.notification.IArtifactInfo;
32 import org.openecomp.sdc.api.notification.INotificationData;
33 import org.openecomp.sdc.api.notification.IResourceInstance;
34 import org.openecomp.sdc.api.notification.IVfModuleMetadata;
35 import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
36 import org.openecomp.mso.asdc.client.ASDCConfiguration;
37 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
38 import org.openecomp.mso.db.catalog.beans.Service;
39 import org.openecomp.mso.db.catalog.beans.VnfResource;
42 * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure).
46 public final class VfResourceStructure {
48 private boolean isDeployedSuccessfully=false;
50 * The Raw notification data.
52 private final INotificationData notification;
55 * The resource we will try to deploy.
57 private final IResourceInstance resourceInstance;
60 * The list of VfModules defined for this resource.
62 private final List<VfModuleStructure> vfModulesStructureList;
65 * The list of VfModulesMetadata defined for this resource.
67 private List<IVfModuleMetadata> vfModulesMetadataList;
69 private VnfResource catalogVnfResource;
71 private Service catalogService;
74 * The list of artifacts existing in this resource hashed by UUID.
76 private final Map<String, VfModuleArtifact> artifactsMapByUUID;
79 public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
80 notification=notificationdata;
81 resourceInstance=resourceinstance;
84 vfModulesStructureList = new LinkedList<VfModuleStructure>();
85 artifactsMapByUUID = new HashMap<String, VfModuleArtifact>();
88 public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
89 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
91 switch(artifactinfo.getArtifactType()) {
92 case ASDCConfiguration.HEAT:
93 case ASDCConfiguration.HEAT_ENV:
94 case ASDCConfiguration.HEAT_VOL:
95 case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported
96 case ASDCConfiguration.HEAT_ARTIFACT:
97 case ASDCConfiguration.HEAT_NET:
98 case ASDCConfiguration.OTHER:
99 artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact);
102 case ASDCConfiguration.VF_MODULES_METADATA:
103 vfModulesMetadataList = distributionClient.decodeVfModuleArtifact(clientResult.getArtifactPayload());
112 public void createVfModuleStructures() throws ArtifactInstallerException {
114 if (vfModulesMetadataList == null) {
115 throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification");
117 for (IVfModuleMetadata vfModuleMeta:vfModulesMetadataList) {
118 vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
122 public INotificationData getNotification() {
126 public IResourceInstance getResourceInstance() {
127 return resourceInstance;
130 public List<VfModuleStructure> getVfModuleStructure() {
131 return vfModulesStructureList;
134 public boolean isDeployedSuccessfully() {
135 return isDeployedSuccessfully;
138 public void setSuccessfulDeployment() {
139 isDeployedSuccessfully = true;
142 public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
143 return artifactsMapByUUID;
146 public List<VfModuleStructure> getVfModulesStructureList() {
147 return vfModulesStructureList;
150 public VnfResource getCatalogVnfResource() {
151 return catalogVnfResource;
154 public void setCatalogVnfResource(VnfResource catalogVnfResource) {
155 this.catalogVnfResource = catalogVnfResource;
158 public Service getCatalogService() {
159 return catalogService;
162 public void setCatalogService(Service catalogService) {
163 this.catalogService = catalogService;