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