e55ba4a4ea3ed6e56cd8960489ccea9b5cb103b3
[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 java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.Map.Entry;
28
29 import org.onap.vid.asdc.beans.tosca.Group;
30 import org.onap.vid.asdc.beans.tosca.ToscaModel;
31 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.vid.properties.VidProperties;
33 /**
34  * The Class ServiceModel.
35  */
36
37 public class NewServiceModel {
38
39         /** The Constant LOG. */
40         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class);
41         
42         /** The Constant dateFormat. */
43         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
44         /** The service. */
45         private Service service;
46         
47         /** The vnfs. */
48         private Map<String, VNF> vnfs;
49         
50         /** The networks. */
51         private Map<String, Network> networks;
52
53         /** 
54          * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
55          * that is not present in the VNF, like the vf module customization String 
56          */
57         private Map<String, VfModule> vfModules;
58         /**
59          * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
60          * for newer models
61          */
62         private Map<String, VolumeGroup> volumeGroups;
63
64         private Map<String, PortMirroringConfig> configurations;
65
66         private Map<String, ServiceProxy> serviceProxies;
67
68         private Map<String, Node> pnfs;
69
70         private Map<String, CR> collectionResource;
71
72
73         /**
74          * Instantiates a new service model.
75          */
76         public NewServiceModel() {}
77         
78         /**
79          * Gets the service.
80          *
81          * @return the service
82          */
83         public Service getService() {
84                 return service;
85         }
86
87         /**
88          * Gets the vnfs.
89          *
90          * @return the vnfs
91          */
92         public Map<String, VNF> getVnfs() {
93                 return vnfs;
94         }
95
96         /**
97          * Gets the networks.
98          *
99          * @return the networks
100          */
101         public Map<String, Network> getNetworks() {
102                 return networks;
103         }
104
105         /**
106          * Sets the service.
107          *
108          * @param service the new service
109          */
110         public void setService(Service service) {
111                 this.service = service;
112         }
113
114         /**
115          * Sets the vnfs.
116          *
117          * @param vnfs the vnfs
118          */
119         public void setVnfs(Map<String, VNF> vnfs) {
120                 this.vnfs = vnfs;
121         }
122
123         /**
124          * Sets the networks.
125          *
126          * @param networks the networks
127          */
128         public void setNetworks(Map<String, Network> networks) {
129                 this.networks = networks;
130         }
131         /**
132          * Gets the vf modules.
133          *
134          * @return the vf modules
135          */
136         public Map<String, VfModule> getVfModules() {
137                 return vfModules;
138         }
139         /**
140          * Gets the volume groups.
141          *
142          * @return the volume groups
143          */
144         public Map<String, VolumeGroup> getVolumeGroups() {
145                 return volumeGroups;
146         }
147
148         public Map<String, PortMirroringConfig> getConfigurations() {
149                 return configurations;
150         }
151
152         public Map<String, ServiceProxy> getServiceProxies() {
153                 return serviceProxies;
154         }
155
156         /**
157          * Sets the vf modules.
158          *
159          * @param vfModules the vf modules
160          */
161
162
163         public void setVfModules(Map<String, VfModule> vfModules) {
164                 this.vfModules = vfModules;
165         }
166         /**
167          * Sets the volume groups.
168          *
169          * @param volumeGroups the volume groups
170          */
171         public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
172                 this.volumeGroups = volumeGroups;
173         }
174
175
176         public Map<String, Node> getPnfs() {
177                 return pnfs;
178         }
179
180         public void setPnfs(Map<String, Node> pnfs) {
181                 this.pnfs = pnfs;
182         }
183
184         public Map<String, CR> getCollectionResource() {
185                 return collectionResource;
186         }
187
188         public void setCollectionResource(Map<String, CR> collectionResource) {
189                 this.collectionResource = collectionResource;
190         }
191
192         /**
193          * Extract service.
194          *
195          * @param serviceToscaModel the service tosca model
196          * @param asdcServiceMetadata the asdc service metadata
197          * @return the service
198          */
199         public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
200                 
201                 final Service service = new Service();
202                 
203                 service.setCategory(serviceToscaModel.getMetadata().getCategory());
204                 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
205                 service.setName(serviceToscaModel.getMetadata().getName());
206                 service.setUuid(serviceToscaModel.getMetadata().getUUID());
207                 service.setDescription(serviceToscaModel.getMetadata().getDescription());
208                 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
209                 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
210                 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
211                 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
212                 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
213                 service.setVersion(asdcServiceMetadata.getVersion());
214
215                 return service;
216         }
217         public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
218                 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
219                 // additional data like the VF module customization String>
220                 
221                 final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
222                 final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
223                 
224                 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
225         String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
226         
227                 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
228                         final Group group = component.getValue();
229                         final String type = group.getType();
230                         final String customizationName = component.getKey();
231                         
232                         if (type.startsWith(vfModuleTag)) {
233                                 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
234                                 vfModules.put(customizationName, vfMod);
235                                 if ( vfMod.isVolumeGroupAllowed() ) {
236                                         //volume groups have the same customization name as the vf module
237                                         volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
238                                 }
239                         }
240                 }
241                 // add this point vfModules and volume groups are disconnected from VNF
242                 serviceModel.setVfModules (vfModules);
243                 serviceModel.setVolumeGroups (volumeGroups);
244                 
245         }
246         /**
247          * Populate the vf modules and volume groups that we may have under the service level under each VNF.
248          */
249 //      public void associateGroups() {
250 //              String methodName = "associateGroups()";
251 //        LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
252 //              // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
253 //              // with vnf + ".."
254 //              String vnfCustomizationName = null;
255 //              String normalizedVnfCustomizationName = null;
256 //              String vfModuleCustomizationName = null;
257 //              NewVNF tmpVnf = null;
258 //
259 //              if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) {
260 //                      for (Entry<String, NewVNF> vnfComponent : getVnfs().entrySet()) {
261 //                              vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
262 //                              normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
263 //
264 //                              LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
265 //                                              " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
266 //
267 //                              // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
268 //
269 //                              if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) {
270 //                                      for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
271 //                                              vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
272 //
273 //                                              LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
274 //                                                              " VF Module customizationName=" + vfModuleCustomizationName );
275 //                                              if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
276 //
277 //                                                      // this vf module belongs to the VNF
278 //                                                      tmpVnf = vnfComponent.getValue();
279 //                                                      (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
280 //
281 //                                                      LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
282 //                                                                      " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
283 //
284 //                                                      // now find if this vf module has volume groups, if so, find the volume group with the same customization name and put it under the VNF
285 //                                                      if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
286 //                                                              if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) {
287 //                                                                      if (getVolumeGroups().containsKey((vfModuleCustomizationName))) {
288 //                                                                              (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
289 //                                                                      }
290 //                                                              }
291 //                                                      }
292 //                                              }
293 //                                      }
294 //                              }
295 //                      }
296 //              }
297                 
298 //      }
299 }