Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / VNF.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.NodeTemplate;
24
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.regex.Pattern;
28
29 /**
30  * The Class VNF.
31  */
32 public class VNF extends Node {
33         /** The pattern used to normalize VNF names */
34         static final Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+");
35         
36         /** The model customization name. */
37         private String modelCustomizationName;
38         
39         /** The vf modules. */
40         private Map<String, VfModule> vfModules = new HashMap<>();
41         
42         /** The volume groups. */
43         private Map<String, VolumeGroup> volumeGroups = new HashMap<>();
44
45         private Map<String, VfcInstanceGroup> vfcInstanceGroups = new HashMap<>();
46
47
48         /**
49          * Instantiates a new vnf.
50          */
51         public VNF() {
52                 super();
53         }
54
55         /**
56          * Gets the model customization name.
57          *
58          * @return the model customization name
59          */
60         public String getModelCustomizationName() {
61                 return modelCustomizationName;
62         }
63         
64         /**
65          * Gets the vf modules.
66          *
67          * @return the vf modules
68          */
69         public Map<String, VfModule> getVfModules() {
70                 return vfModules;
71         }
72
73         /**
74          * Sets the vf modules.
75          *
76          * @param vfModules the vf modules
77          */
78         public void setVfModules(Map<String, VfModule> vfModules) {
79                 this.vfModules = vfModules;
80         }
81
82         /**
83          * Gets the volume groups.
84          *
85          * @return the volume groups
86          */
87         public Map<String, VolumeGroup> getVolumeGroups() {
88                 return volumeGroups;
89         }
90
91         /**
92          * Sets the volume groups.
93          *
94          * @param volumeGroups the volume groups
95          */
96         public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
97                 this.volumeGroups = volumeGroups;
98         }
99
100
101         public Map<String, VfcInstanceGroup> getVfcInstanceGroups() {
102                 return vfcInstanceGroups;
103         }
104
105         public void setVfcInstanceGroups(Map<String, VfcInstanceGroup> vfcInstanceGroups) {
106                 this.vfcInstanceGroups = vfcInstanceGroups;
107         }
108
109         /**
110          * Extract vnf.
111          *
112          * @param modelCustomizationName the model customization name
113          * @param nodeTemplate the node template
114          * @return the vnf
115          */
116         public void extractVnf(String modelCustomizationName, NodeTemplate nodeTemplate) {
117                 
118                 super.extractNode(nodeTemplate);        
119                 setModelCustomizationName(modelCustomizationName);
120                 
121         }
122
123         /**
124          * Sets the model customization name.
125          *
126          * @param modelCustomizationName the new model customization name
127          */
128         public void setModelCustomizationName(String modelCustomizationName) {
129                 this.modelCustomizationName = modelCustomizationName;
130         }
131         /**
132          * Normalize the VNF name
133          * @param originalName
134          * @return the normalized name
135          */
136         public static String normalizeName (String originalName) {
137
138                 String normalizedName = originalName.toLowerCase();
139                 normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
140                 String[] splitArr = null;
141                 
142                 try {
143                         splitArr = normalizedName.split(" ");
144                 }
145                 catch (Exception ex ) {
146                         return (normalizedName);
147                 }
148                 StringBuilder sb = new StringBuilder();
149                 if ( splitArr != null ) {
150                         for (String splitElement : splitArr) {
151                                 sb.append(splitElement);
152                         }
153                         return (sb.toString());
154                 }
155                 else {
156                         return (normalizedName);
157                 }
158                 
159         }
160 }