Initial OpenECOMP MSO commit
[so.git] / asdc-controller / src / main / java / org / openecomp / mso / asdc / installer / VfResourceStructure.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.asdc.installer;
22
23
24 import java.io.UnsupportedEncodingException;
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29
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;
40
41 /**
42  * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure).
43  * 
44  *
45  */
46 public final class VfResourceStructure {
47         
48         private boolean isDeployedSuccessfully=false;
49         /**
50          * The Raw notification data. 
51          */
52         private final INotificationData notification;
53         
54         /**
55          * The resource we will try to deploy.
56          */
57         private final IResourceInstance resourceInstance;
58         
59         /**
60          * The list of VfModules defined for this resource.
61          */
62         private final List<VfModuleStructure> vfModulesStructureList;
63         
64         /**
65          * The list of VfModulesMetadata defined for this resource.
66          */
67         private List<IVfModuleMetadata> vfModulesMetadataList;
68         
69         private VnfResource catalogVnfResource;
70         
71         private Service catalogService;
72         
73         /**
74          * The list of artifacts existing in this resource hashed by UUID.
75          */
76         private final Map<String, VfModuleArtifact> artifactsMapByUUID; 
77         
78                 
79         public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) {
80                 notification=notificationdata;
81                 resourceInstance=resourceinstance;
82                 
83
84                 vfModulesStructureList = new LinkedList<VfModuleStructure>();
85                 artifactsMapByUUID =  new HashMap<String, VfModuleArtifact>();
86         }
87         
88         public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException {
89                 VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult);
90                 
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);
100                                 break;
101
102                         case ASDCConfiguration.VF_MODULES_METADATA:
103                                 vfModulesMetadataList = distributionClient.decodeVfModuleArtifact(clientResult.getArtifactPayload());
104                                 break;
105
106                         default:
107                                 break;
108
109                 }
110         }
111
112         public void createVfModuleStructures() throws ArtifactInstallerException {
113                 
114                 if (vfModulesMetadataList == null) {
115                         throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification");
116                 }
117                 for (IVfModuleMetadata vfModuleMeta:vfModulesMetadataList) {
118                         vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta));
119                 }
120         }
121         
122         public INotificationData getNotification() {
123                 return notification;
124         }
125
126         public IResourceInstance getResourceInstance() {
127                 return resourceInstance;
128         }
129
130         public List<VfModuleStructure> getVfModuleStructure() {
131                 return vfModulesStructureList;
132         }
133
134         public boolean isDeployedSuccessfully() {
135                 return isDeployedSuccessfully;
136         }
137         
138         public void setSuccessfulDeployment() {
139                 isDeployedSuccessfully = true;
140         }
141
142         public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
143                 return artifactsMapByUUID;
144         }
145
146         public List<VfModuleStructure> getVfModulesStructureList() {
147                 return vfModulesStructureList;
148         }
149
150         public VnfResource getCatalogVnfResource() {
151                 return catalogVnfResource;
152         }
153
154         public void setCatalogVnfResource(VnfResource catalogVnfResource) {
155                 this.catalogVnfResource = catalogVnfResource;
156         }
157
158         public Service getCatalogService() {
159                 return catalogService;
160         }
161
162         public void setCatalogService(Service catalogService) {
163                 this.catalogService = catalogService;
164         }
165 }