9da88870c73a952733b5878a6bc1fd6945c21ab2
[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         private Map<String, VfcInstanceGroup> vfcInstanceGroups = new HashMap<>();
61
62
63         /**
64          * Instantiates a new vnf.
65          */
66         public VNF() {
67                 super();
68         }
69
70         /**
71          * Gets the model customization name.
72          *
73          * @return the model customization name
74          */
75         public String getModelCustomizationName() {
76                 return modelCustomizationName;
77         }
78         
79         /**
80          * Gets the vf modules.
81          *
82          * @return the vf modules
83          */
84         public Map<String, VfModule> getVfModules() {
85                 return vfModules;
86         }
87
88         /**
89          * Sets the vf modules.
90          *
91          * @param vfModules the vf modules
92          */
93         public void setVfModules(Map<String, VfModule> vfModules) {
94                 this.vfModules = vfModules;
95         }
96
97         /**
98          * Gets the volume groups.
99          *
100          * @return the volume groups
101          */
102         public Map<String, VolumeGroup> getVolumeGroups() {
103                 return volumeGroups;
104         }
105
106         /**
107          * Sets the volume groups.
108          *
109          * @param volumeGroups the volume groups
110          */
111         public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
112                 this.volumeGroups = volumeGroups;
113         }
114
115
116         public Map<String, VfcInstanceGroup> getVfcInstanceGroups() {
117                 return vfcInstanceGroups;
118         }
119
120         public void setVfcInstanceGroups(Map<String, VfcInstanceGroup> vfcInstanceGroups) {
121                 this.vfcInstanceGroups = vfcInstanceGroups;
122         }
123
124         /**
125          * Extract vnf.
126          *
127          * @param modelCustomizationName the model customization name
128          * @param nodeTemplate the node template
129          * @return the vnf
130          */
131         public void extractVnf(String modelCustomizationName, NodeTemplate nodeTemplate) {
132                 
133                 super.extractNode(nodeTemplate);        
134                 setModelCustomizationName(modelCustomizationName);
135                 
136         }
137
138         /**
139          * Sets the model customization name.
140          *
141          * @param modelCustomizationName the new model customization name
142          */
143         public void setModelCustomizationName(String modelCustomizationName) {
144                 this.modelCustomizationName = modelCustomizationName;
145         }
146         /**
147          * Normalize the VNF name
148          * @param originalName
149          * @return the normalized name
150          */
151         public static String normalizeName (String originalName) {
152
153                 String normalizedName = originalName.toLowerCase();
154                 normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
155                 String[] splitArr = null;
156                 
157                 try {
158                         splitArr = normalizedName.split(" ");
159                 }
160                 catch (Exception ex ) {
161                         return (normalizedName);
162                 }
163                 StringBuffer sb = new StringBuffer();
164                 if ( splitArr != null ) {
165                         for (String splitElement : splitArr) {
166                                 sb.append(splitElement);
167                         }
168                         return (sb.toString());
169                 }
170                 else {
171                         return (normalizedName);
172                 }
173                 
174         }
175 }