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