Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / NewServiceModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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.onap.vid.model;
22
23 import org.onap.vid.asdc.beans.tosca.Group;
24 import org.onap.vid.asdc.beans.tosca.ToscaModel;
25 import org.onap.vid.properties.VidProperties;
26
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Map.Entry;
30 /**
31  * The Class ServiceModel.
32  */
33
34 public class NewServiceModel {
35         /** The service. */
36         private Service service;
37         
38         /** The vnfs. */
39         private Map<String, VNF> vnfs;
40         
41         /** The networks. */
42         private Map<String, Network> networks;
43
44         /** 
45          * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
46          * that is not present in the VNF, like the vf module customization String 
47          */
48         private Map<String, VfModule> vfModules;
49         /**
50          * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
51          * for newer models
52          */
53         private Map<String, VolumeGroup> volumeGroups;
54
55         private Map<String, PortMirroringConfig> configurations;
56
57         private Map<String, Node> fabricConfigurations;
58
59         private Map<String, ServiceProxy> serviceProxies;
60
61         private Map<String, Node> pnfs;
62
63         private Map<String, CR> collectionResource;
64
65         private Map<String, ResourceGroup> vnfGroups;
66
67         /**
68          * Instantiates a new service model.
69          */
70         public NewServiceModel() {}
71         
72         /**
73          * Gets the service.
74          *
75          * @return the service
76          */
77         public Service getService() {
78                 return service;
79         }
80
81         /**
82          * Gets the vnfs.
83          *
84          * @return the vnfs
85          */
86         public Map<String, VNF> getVnfs() {
87                 return vnfs;
88         }
89
90         /**
91          * Gets the networks.
92          *
93          * @return the networks
94          */
95         public Map<String, Network> getNetworks() {
96                 return networks;
97         }
98
99         /**
100          * Sets the service.
101          *
102          * @param service the new service
103          */
104         public void setService(Service service) {
105                 this.service = service;
106         }
107
108         /**
109          * Sets the vnfs.
110          *
111          * @param vnfs the vnfs
112          */
113         public void setVnfs(Map<String, VNF> vnfs) {
114                 this.vnfs = vnfs;
115         }
116
117         /**
118          * Sets the networks.
119          *
120          * @param networks the networks
121          */
122         public void setNetworks(Map<String, Network> networks) {
123                 this.networks = networks;
124         }
125         /**
126          * Gets the vf modules.
127          *
128          * @return the vf modules
129          */
130         public Map<String, VfModule> getVfModules() {
131                 return vfModules;
132         }
133         /**
134          * Gets the volume groups.
135          *
136          * @return the volume groups
137          */
138         public Map<String, VolumeGroup> getVolumeGroups() {
139                 return volumeGroups;
140         }
141
142         public Map<String, PortMirroringConfig> getConfigurations() {
143                 return configurations;
144         }
145
146         public Map<String, ServiceProxy> getServiceProxies() {
147                 return serviceProxies;
148         }
149
150         /**
151          * Sets the vf modules.
152          *
153          * @param vfModules the vf modules
154          */
155
156
157         public void setVfModules(Map<String, VfModule> vfModules) {
158                 this.vfModules = vfModules;
159         }
160         /**
161          * Sets the volume groups.
162          *
163          * @param volumeGroups the volume groups
164          */
165         public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
166                 this.volumeGroups = volumeGroups;
167         }
168
169
170         public Map<String, Node> getPnfs() {
171                 return pnfs;
172         }
173
174         public void setPnfs(Map<String, Node> pnfs) {
175                 this.pnfs = pnfs;
176         }
177
178         public Map<String, CR> getCollectionResource() {
179                 return collectionResource;
180         }
181
182         public void setCollectionResource(Map<String, CR> collectionResource) {
183                 this.collectionResource = collectionResource;
184         }
185
186         public Map<String, Node> getFabricConfigurations() {
187                 return fabricConfigurations;
188         }
189
190         public void setFabricConfigurations(Map<String, Node> fabricConfigurations) {
191                 this.fabricConfigurations = fabricConfigurations;
192         }
193
194         /**
195          * Extract service.
196          *
197          * @param serviceToscaModel the service tosca model
198          * @param asdcServiceMetadata the asdc service metadata
199          * @return the service
200          */
201         public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
202                 
203                 final Service service = new Service();
204                 
205                 service.setCategory(serviceToscaModel.getMetadata().getCategory());
206                 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
207                 service.setName(serviceToscaModel.getMetadata().getName());
208                 service.setUuid(serviceToscaModel.getMetadata().getUUID());
209                 service.setDescription(serviceToscaModel.getMetadata().getDescription());
210                 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
211                 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
212                 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
213                 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
214                 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
215                 service.setVersion(asdcServiceMetadata.getVersion());
216                 return service;
217         }
218         public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
219                 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
220                 // additional data like the VF module customization String>
221                 
222                 final Map<String, VfModule> vfModules = new HashMap<> ();
223                 final Map<String, VolumeGroup> volumeGroups = new HashMap<> ();
224                 
225                 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
226         String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
227         
228                 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
229                         final Group group = component.getValue();
230                         final String type = group.getType();
231                         final String customizationName = component.getKey();
232                         
233                         if (type.startsWith(vfModuleTag)) {
234                                 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
235                                 vfModules.put(customizationName, vfMod);
236                                 if ( vfMod.isVolumeGroupAllowed() ) {
237                                         //volume groups have the same customization name as the vf module
238                                         volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
239                                 }
240                         }
241                 }
242                 // add this point vfModules and volume groups are disconnected from VNF
243                 serviceModel.setVfModules (vfModules);
244                 serviceModel.setVolumeGroups (volumeGroups);
245                 
246         }
247
248         public Map<String, ResourceGroup> getVnfGroups() {
249                 return vnfGroups;
250         }
251
252         public void setVnfGroups(Map<String, ResourceGroup> vnfGroups) {
253                 this.vnfGroups = vnfGroups;
254         }
255         /**
256          * Populate the vf modules and volume groups that we may have under the service level under each VNF.
257          */
258 }