[VID-6] Initial rebase push
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / model / VNF.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.vid.model;\r
22 \r
23 import java.util.Map;\r
24 import java.text.DateFormat;\r
25 import java.text.SimpleDateFormat;\r
26 import java.util.Date;\r
27 import java.util.HashMap;\r
28 import java.util.Map.Entry;\r
29 import java.util.regex.Pattern;\r
30 \r
31 import org.openecomp.vid.asdc.beans.tosca.NodeTemplate;\r
32 \r
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
34 import org.openecomp.vid.controller.VidController;\r
35 \r
36 import org.openecomp.vid.asdc.beans.tosca.Group;\r
37 import org.openecomp.vid.asdc.beans.tosca.Input;\r
38 \r
39 /**\r
40  * The Class VNF.\r
41  */\r
42 public class VNF extends Node {\r
43         \r
44         /** The Constant LOG. */\r
45         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VNF.class);\r
46         \r
47         /** The Constant dateFormat. */\r
48         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");\r
49 \r
50         /** The pattern used to normalize VNF names */\r
51         final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+");\r
52         \r
53         /** The model customization name. */\r
54         private String modelCustomizationName;\r
55         \r
56         /** The vf modules. */\r
57         private Map<String, VfModule> vfModules = new HashMap<String, VfModule>();\r
58         \r
59         /** The volume groups. */\r
60         private Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup>();\r
61         \r
62         /**\r
63          * Instantiates a new vnf.\r
64          */\r
65         public VNF() {\r
66                 super();\r
67         }\r
68 \r
69         /**\r
70          * Gets the model customization name.\r
71          *\r
72          * @return the model customization name\r
73          */\r
74         public String getModelCustomizationName() {\r
75                 return modelCustomizationName;\r
76         }\r
77         \r
78         /**\r
79          * Gets the vf modules.\r
80          *\r
81          * @return the vf modules\r
82          */\r
83         public Map<String, VfModule> getVfModules() {\r
84                 return vfModules;\r
85         }\r
86 \r
87         /**\r
88          * Sets the vf modules.\r
89          *\r
90          * @param vfModules the vf modules\r
91          */\r
92         public void setVfModules(Map<String, VfModule> vfModules) {\r
93                 this.vfModules = vfModules;\r
94         }\r
95 \r
96         /**\r
97          * Gets the volume groups.\r
98          *\r
99          * @return the volume groups\r
100          */\r
101         public Map<String, VolumeGroup> getVolumeGroups() {\r
102                 return volumeGroups;\r
103         }\r
104 \r
105         /**\r
106          * Sets the volume groups.\r
107          *\r
108          * @param volumeGroups the volume groups\r
109          */\r
110         public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {\r
111                 this.volumeGroups = volumeGroups;\r
112         }\r
113 \r
114         /**\r
115          * Extract vnf.\r
116          *\r
117          * @param modelCustomizationName the model customization name\r
118          * @param nodeTemplate the node template\r
119          * @return the vnf\r
120          */\r
121         public void extractVnf(String modelCustomizationName, NodeTemplate nodeTemplate) {\r
122                 \r
123                 super.extractNode(nodeTemplate);        \r
124                 setModelCustomizationName(modelCustomizationName);\r
125                 \r
126         }\r
127 \r
128         /**\r
129          * Sets the model customization name.\r
130          *\r
131          * @param modelCustomizationName the new model customization name\r
132          */\r
133         private void setModelCustomizationName(String modelCustomizationName) {\r
134                 this.modelCustomizationName = modelCustomizationName;\r
135         }\r
136         /**\r
137          * Normalize the VNF name\r
138          * @param originalName\r
139          * @return the normalized name\r
140          */\r
141         public static String normalizeName (String originalName) {\r
142 \r
143                 String normalizedName = originalName.toLowerCase();\r
144                 normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");\r
145                 String[] splitArr = null;\r
146                 \r
147                 try {\r
148                         splitArr = normalizedName.split(" ");\r
149                 }\r
150                 catch (Exception ex ) {\r
151                         return (normalizedName);\r
152                 }\r
153                 StringBuffer sb = new StringBuffer();\r
154                 if ( splitArr != null ) {\r
155                         for (String splitElement : splitArr) {\r
156                                 sb.append(splitElement);\r
157                         }\r
158                         return (sb.toString());\r
159                 }\r
160                 else {\r
161                         return (normalizedName);\r
162                 }\r
163                 \r
164         }\r
165 }\r