RA: Support for using allocated number in the entity id
[ccsdk/sli.git] / northbound / ueb-listener / src / main / java / org / onap / ccsdk / sli / northbound / uebclient / SdncVFModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.northbound.uebclient;
23
24 import java.io.IOException;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.onap.sdc.tosca.parser.enums.SdcTypes;
31 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
32 import org.onap.sdc.tosca.parser.api.IEntityDetails;
33 import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
34 import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
35 import org.onap.sdc.toscaparser.api.Property;
36 import org.onap.sdc.toscaparser.api.elements.Metadata;
37 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class SdncVFModel extends SdncBaseModel {
42         
43         private static final Logger LOG = LoggerFactory
44                         .getLogger(SdncVFModel.class);
45
46         private String vendor = null;
47         private String vendorModelDescription = null;
48         private String nfNamingCode = null;
49         private String serviceUUID = null;
50         private String serviceInvariantUUID = null;
51
52         public SdncVFModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException {
53
54                 super(sdcCsarHelper, entityDetails, jdbcDataSource, config);
55                 
56                 // extract metadata
57                 Metadata metadata = entityDetails.getMetadata();
58                 addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME));
59                 vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR);
60                 addParameter("vendor", vendor); 
61                 vendorModelDescription = extractValue (metadata, "description");
62                 addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); 
63                 
64                 // extract properties
65                 addParameter("ecomp_generated_naming", extractBooleanValue(entityDetails, "nf_naming", "ecomp_generated_naming"));
66                 addParameter("naming_policy", extractValue(entityDetails, "nf_naming", "naming_policy"));
67                 addParameter("nf_type", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
68                 addParameter("nf_role", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFROLE));
69                 nfNamingCode = extractValue(entityDetails, "nf_naming_code");
70                 addParameter("nf_code", nfNamingCode);
71                 addParameter("nf_function", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
72                 addIntParameter("avail_zone_max_count", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT));
73                 addParameter("sdnc_model_name", extractValue(entityDetails, "sdnc_model_name"));
74                 addParameter("sdnc_model_version", extractValue(entityDetails, "sdnc_model_version"));
75                 addParameter("sdnc_artifact_name", extractValue(entityDetails, "sdnc_artifact_name"));
76                 
77                 // store additional properties in ATTRIBUTE_VALUE_PAIR
78                 // additional complex properties are extracted via VfcInstanceGroup
79                 EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build();
80                 String vfCustomizationUuid = getCustomizationUUIDNoQuotes();
81                 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
82                                 .customizationUUID(vfCustomizationUuid).build();
83                 List<IEntityDetails> vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
84                 if (vfcInstanceGroupListForVf != null) {
85                         
86                         for (IEntityDetails group : vfcInstanceGroupListForVf){
87                         
88                                 String vfcInstanceGroupFunction = extractGetInputValue(group, entityDetails, "vfc_instance_group_function");
89                                 addParameter("vfc_instance_group_function", vfcInstanceGroupFunction, attributeValueParams);
90                                 String networkCollectionFunction = extractGetInputValue(group, entityDetails, "network_collection_function");
91                                 addParameter("network_collection_function", networkCollectionFunction, attributeValueParams);
92                                 String initSubinterfaceQuantity = extractGetInputValue(group, entityDetails, "init_subinterface_quantity");
93                                 addParameter("init_subinterface_quantity", initSubinterfaceQuantity, attributeValueParams);
94                         }
95                 }
96         }
97         
98         public void insertData() throws IOException {
99                 
100                 insertVFModelData();
101                 insertVFModuleData();
102                 insertVFtoNetworkRoleMappingData();
103                 insertVFCData();
104                 insertVFCInstanceGroupData();
105                 insertVFPolicyData();
106         }
107         
108         private void insertVFModelData () throws IOException {
109
110                 try {
111                         cleanUpExistingToscaData("VF_MODEL", "customization_uuid", getCustomizationUUID()) ;
112                         //cleanUpExistingToscaData("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, "vf_uuid", getUUID());
113                         
114                         // insert into VF_MODEL/ATTRIBUTE_VALUE_PAIR and SERVICE_MODEL_TO_VF_MODEL_MAPPING
115                         LOG.info("Call insertToscaData for VF_MODEL where customization_uuid = " + getCustomizationUUID());
116                         insertToscaData(buildSql("VF_MODEL", model_yaml), null);
117                         //insertRelevantAttributeData();
118                         
119                         Map<String, String> mappingParams = new HashMap<String, String>();
120                         addParameter("service_invariant_uuid", serviceInvariantUUID, mappingParams);
121                         addParameter("vf_uuid", getUUID(), mappingParams);
122                         addParameter("vf_customization_uuid", getCustomizationUUIDNoQuotes(), mappingParams);
123                         //insertToscaData(buildSql("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, model_yaml, mappingParams), null);
124
125                 } catch (IOException e) {
126                         LOG.error("Could not insert Tosca CSAR data into the VF_MODEL table");
127                         throw new IOException (e);
128                 }
129                 
130         }
131
132         private void insertVFModuleData () throws IOException {
133                 
134                 // Pre-Step: Get all CVFC with VFC inside use this list to filter before insert into VF_MODULE_TO_VFC_MAPPING
135                 // Get all VFC in all CFVC in entire model (getEntity VFC, CVFC, true) and then check resulting entity has parent that matches member
136                 // if parent of VFC has customizationUUID that matches customizationUUID of group member, then insert into VF_MODULE_TO_VFC_MAPPING
137                 // then get count property
138                 EntityQuery vfcEntityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build();
139                 TopologyTemplateQuery cvfcTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).build();
140                 List<IEntityDetails> allVfcsInsideAllCvfcs = sdcCsarHelper.getEntity(vfcEntityQuery, cvfcTopologyTemplateQuery, true);
141                 
142                 // Step 1: Get all the VF Module groups (entities) in this Service              
143                 EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfModule").build();
144                 String vfCustomizationUuid = getCustomizationUUIDNoQuotes();
145                 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
146                 List<IEntityDetails> vfModules = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
147                 if (vfModules == null) {
148                         return;
149                 }
150         
151                 // Insert each VF Module group (entity) into VF_MODULE_MODEL if its name is prefixed with the VF name           
152                 for (IEntityDetails vfModule : vfModules){
153                         
154                         // If this vfModule name is prefixed with the VF name of the VF being processed, insert this VF Module in VF_MODULE_MODEL
155                         String normailizedVfName = entityDetails.getName().toLowerCase().replace(" ", "").replace("-", "").replace(".", "");  // need full set of normalization rules from ASDC
156                         if (!vfModule.getName().startsWith(normailizedVfName)) {
157                                 continue;
158                         }
159                         
160                         SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, vfModule, this);
161                         
162                         try {
163                                 cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID());
164                                 cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID());
165                                 LOG.info("Call insertToscaData for VF_MODULE_MODEL where customization_uuid = " + vfModuleModel.getCustomizationUUID());
166                                 insertToscaData(vfModuleModel.buildSql("VF_MODULE_MODEL", model_yaml), null);
167                         } catch (IOException e) {
168                                 LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table ");
169                                 throw new IOException (e);
170                         }
171                         
172                         // Step 2: Get the non-catalog VF Module in order to get the group members
173                         String vfModuleUuid = vfModuleModel.getUUID().replace("\"", "");
174                         EntityQuery entityQuery2 = EntityQuery.newBuilder("org.openecomp.groups.VfModule")
175                                         .uUID(vfModuleUuid)
176                                         .build();
177                         TopologyTemplateQuery topologyTemplateQuery2 = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
178                                         .customizationUUID(vfCustomizationUuid)                 // customization UUID of the VF if exists
179                                         .build();
180                         List<IEntityDetails> vfModulesNonCatalog  = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false);
181                         if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) {
182                                 LOG.debug("insertVFModuleData: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING");
183                                 continue;
184                         }                               
185
186                         List<IEntityDetails> vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes();  // does getMemberNodes give nested CFVCs?
187                         
188                         // Find all members for each VF Module that are of type CVFC and insert it and any nested CFVCs into VF_MODULE_TO_VFC_MAPPING
189                         for (IEntityDetails vfModuleMember: vfModuleMembers) {
190                             if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) {               
191                                 
192                                 String cvfcCustomizationUuid = extractValue(vfModuleMember.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
193
194                                 // Additional check to see if this CVFC has a VFC in it?  We only are to map CVFCs with VFC in it.
195                                 if (cvfcContainsVfc(allVfcsInsideAllCvfcs, vfModuleMember) == true) {
196                                         
197                                         // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING
198                                         String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG);  // extracted as vm_type_tag
199                                         String vfcVmCount = "";
200                                         if (vfModuleMember.getProperties().containsKey("service_template_filter")) {
201                                                 vfcVmCount = extractIntegerValue (vfModuleMember.getProperties().get("service_template_filter"), "count");
202                                         }
203                                         if (vfcVmCount.isEmpty()) {
204                                                 vfcVmCount = "0"; // vm_count can not be null
205                                         }
206                                         
207                                         try {
208                                                 LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID());
209                                                 insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" +
210                                                                 vfModuleModel.getCustomizationUUID() + ", \"" + cvfcCustomizationUuid + "\", \"" + vfcVmType + "\", \"" + vfcVmCount + "\")", null);
211                                         } catch (IOException e) {
212                                                 LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table");
213                                                 throw new IOException (e);
214                                         }       
215                                 }                                                        
216                                 
217                                 // Step 3: Get any nested CVFCs under this CVFC
218                                 EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC).build();
219                                 TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
220                                                 .customizationUUID(cvfcCustomizationUuid)                 // customization UUID of the CVFC if exists
221                                                 .build();
222                                 List<IEntityDetails> nestedCvfcs  = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true);  // true allows for nested search
223                                 if (nestedCvfcs == null || nestedCvfcs.isEmpty()) {
224                                         LOG.debug("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid);
225                                         continue;
226                                 }                               
227                                 
228                                 for (IEntityDetails nestedCvfc: nestedCvfcs) {
229                                                 
230                                         // Additional check to see if this CVFC has a VFC in it?  We only are to map CVFCs with VFC in it.
231                                         if (cvfcContainsVfc(allVfcsInsideAllCvfcs, nestedCvfc) == false) {
232                                                 continue; // continue to next CVFC
233                                         }
234                                         
235                                         // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING
236                                         String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
237                                         String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG);  // extracted as vm_type_tag
238                                         String nestedVfcVmCount = "";
239                                         if (nestedCvfc.getProperties().containsKey("service_template_filter")) {
240                                                 nestedVfcVmCount = extractIntegerValue (nestedCvfc.getProperties().get("service_template_filter"), "count");
241                                         }
242                                         if (nestedVfcVmCount.isEmpty()) {
243                                                 nestedVfcVmCount = "0"; // vm_count can not be null
244                                         }
245                                         
246                                         try {
247                                                 LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID());
248                                                 insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" +
249                                                                 vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null);
250                                         } catch (IOException e) {
251                                                 LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table");
252                                                 throw new IOException (e);
253                                         }       
254                                 }
255                             }   
256                         }       // For each VF Module member
257                 }   // For each VF Module
258         }
259         
260         private boolean cvfcContainsVfc (List<IEntityDetails> allVfcsInsideAllCvfcs, IEntityDetails cvfcEntity) {
261                 boolean containsVfc = false;
262                 
263                 for (IEntityDetails vfcEntity: allVfcsInsideAllCvfcs) {
264                         IEntityDetails vfcParentEntity = vfcEntity.getParent();
265                         String parentCustomizationUuid = extractValue (vfcParentEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
266                         String cvfcEntityCustomizationUuid = extractValue (cvfcEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
267                         if (parentCustomizationUuid == cvfcEntityCustomizationUuid) {
268                                 return true;
269                         }
270                 }
271         
272                 return containsVfc;
273         }
274                 
275         private void insertVFtoNetworkRoleMappingData () throws IOException {
276                 
277                 // Cleanup existing VF_TO_NETWORK_ROLE_MAPPING for this VF
278                 try {
279                         cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID());
280                 } catch (IOException e) {
281                         LOG.error("Could not cleanup Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table");
282                         throw new IOException (e);
283                 }       
284                 
285                 // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data. network_role is a property on the CPs for this VF.
286                 // Use getEntity to extract all the CPs on this VF
287                 EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build();
288             TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build();
289             List<IEntityDetails> cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true);
290                 if (cpEntities == null || cpEntities.isEmpty()) {
291                         LOG.debug("insertVFtoNetworkRoleMappingData: Could not find CPs for VF: " + getCustomizationUUIDNoQuotes());
292                         return;
293                 }                               
294
295                 for (IEntityDetails entity: cpEntities ) {              
296                         
297                         Map<String, Property> properties = entity.getProperties();
298                         if (properties.containsKey("network_role")) {
299
300                                 Property networkRoleProperty = properties.get("network_role");
301                                 if (networkRoleProperty != null && networkRoleProperty.getValue() != null) {
302                                         String cpNetworkRole = networkRoleProperty.getValue().toString();
303                                         LOG.debug("insertVFtoNetworkRoleMappingData: " + "VF: "  + getCustomizationUUID() + ", networkRole = " + cpNetworkRole);
304                                         
305                                         // Only insert unique network_role values for this VF
306                                         boolean networkRoleExists = false;
307                                         Map<String, String> networkRoleyKeys = new HashMap<String, String>();
308                                         networkRoleyKeys.put("vf_customization_uuid", getCustomizationUUID());
309                                         networkRoleyKeys.put("network_role", "\"" + cpNetworkRole + "\"");                      
310                                         networkRoleExists = checkForExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", networkRoleyKeys);
311                                         
312                                         if (networkRoleExists == false) {
313                                                 try {
314                                                         //cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID());
315                                                         LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID());
316                                                         insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" +
317                                                         getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null);
318                                                 } catch (IOException e) {
319                                                         LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table");
320                                                         throw new IOException (e);
321                                                 }                                                       
322                                         }
323                                 }
324                         }
325
326                 } // CP loop
327
328         }
329         
330         private void insertVFCData() throws IOException {
331                 
332                 /* For each VF, insert VFC_MODEL, VFC_TO_NETWORK_ROLE_MAPPING, VNF_RELATED_NETWORK_ROLE and VFC_RELATED_NETWORK_ROLE data
333                 
334                 try {
335                         cleanUpExistingToscaData("VNF_RELATED_NETWORK_ROLE", "vnf_customization_uuid", getCustomizationUUID());
336                 } catch (IOException e) {
337                         LOG.error("Could not clean up Tosca CSAR data in the VNF_RELATED_NETWORK_ROLE table");
338                         throw new IOException (e);
339                 }*/
340
341         // Get any CVFCs under this VF (top-level and nested)
342                 String vfCustomizationUid = customizationUUID;
343                 EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CVFC)
344                                 .build();
345                 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
346                                 .customizationUUID(vfCustomizationUid)                 // customization UUID of the VF if exists
347                                 .build();
348                 List<IEntityDetails> cvfcEntities  = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, true);  // true allows for nested search
349                 if (cvfcEntities == null || cvfcEntities.isEmpty()) {
350                         LOG.debug("insertVFCDataEntity: Could not find the CVFCs for: " + vfCustomizationUid);
351                 }               
352                 
353                 for (IEntityDetails cvfcEntity: cvfcEntities) {
354                         
355                 // Insert this CVFC data into VFC_MODEL         
356                         try {
357                                 
358                                 SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, cvfcEntity, jdbcDataSource, config);
359                                 
360                                 vfcModel.insertVFCModelData();
361                                 vfcModel.insertVFCtoNetworkRoleMappingData(cvfcEntity);
362                                 //vfcModel.insertVFCRelatedNetworkRoleData(getCustomizationUUID(), cvfcEntity);
363                                                                 
364                         } catch (IOException e) {
365                                 LOG.error("Could not insert Tosca CSAR VFC data");
366                                 throw new IOException (e);
367                         }       
368                 }
369                 
370         }
371         
372         public void insertVFCInstanceGroupData () throws IOException {
373                 
374                 // Insert Group data in RESOURCE_GROUP
375                 // Store group capabilities and capability properties in NODE_CAPABILITY and NODE_CAPABILITY_PROPERTY table
376                 
377                 // For each VF, insert VFC Instance Group data (convert to use getEntity in 19.08)
378                 EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build();
379                 String vfCustomizationUuid = getCustomizationUUIDNoQuotes();
380                 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
381                                 .customizationUUID(vfCustomizationUuid).build();
382                 List<IEntityDetails> vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
383                 if (vfcInstanceGroupListForVf == null) {
384                         return;
385                 }
386
387                 for (IEntityDetails group : vfcInstanceGroupListForVf){
388
389                         SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, entityDetails, config, jdbcDataSource);   
390                         groupModel.insertGroupData(getUUID());
391                 
392                         // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY
393                         insertNodeCapabilitiesEntityData(group.getCapabilities());
394                         
395                         // Store relationship between VfcInstanceGroup and node-type=VFC in RESOURCE_GROUP_TO_TARGET_NODE_MAPPING table
396                         // target is each VFC in targets section of group
397                         List<IEntityDetails> targetNodeList = group.getMemberNodes();
398                         for (IEntityDetails targetNode : targetNodeList) {
399                                 
400                                 String targetNodeUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
401                                 String targetNodeCustomizationUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
402                                 String targetNodeType = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE);
403                                 
404                                 // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING
405                                 try {
406                                         Map<String, String> mappingCleanupParams = new HashMap<String, String>();
407                                         addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); 
408                                         addParameter("parent_uuid", getUUID(), mappingCleanupParams);
409                                         addParameter("target_node_uuid", targetNodeUuid, mappingCleanupParams);
410                                         cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams);
411                                         
412                                         Map<String, String> mappingParams = new HashMap<String, String>();
413                                         addParameter("parent_uuid", getUUID(), mappingParams);
414                                         addParameter("target_node_uuid", targetNodeUuid, mappingParams);
415                                         addParameter("target_type", targetNodeType, mappingParams);
416                                         String tableName = "";
417                                         switch (targetNodeType) {
418                                         case "CVFC":
419                                                 tableName = "VFC_MODEL";
420                                                 break;
421                                         case "VL":
422                                                 tableName = "NETWORK_MODEL";
423                                                 break;
424                                         }                                       
425                                         addParameter("table_name", tableName, mappingParams); 
426                                         LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID() + " and target_node_uuid = \"" + targetNodeUuid + "\"");
427                                         insertToscaData(buildSql("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", "group_uuid", groupModel.getUUID(), model_yaml, mappingParams), null);
428                                 } catch (IOException e) {
429                                         LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP_TO_TARGET_NODE_MAPPING");
430                                         throw new IOException (e);
431                                 }                       
432                                 
433                                 // For each target node, get External policies
434                                 SdcTypes queryType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE));
435                                 insertEntityPolicyData(getCustomizationUUIDNoQuotes(), getUUID().replace("\"", ""), queryType, targetNodeCustomizationUuid, targetNodeUuid, targetNodeType, "org.openecomp.policies.External");  // AFTER getEntity
436                         }                                                       
437                 }
438         }
439
440         private void insertVFPolicyData() throws IOException {
441                 
442                 // For each VF node, ingest External Policy data
443                 insertEntityPolicyData (getCustomizationUUIDNoQuotes(), getUUID(), serviceUUID.replace("\"", ""), "org.openecomp.policies.External", SdcTypes.VF);
444         }       
445
446         public String getVendor() {
447                 return vendor;
448         }
449
450         public void setVendor(String vendor) {
451                 this.vendor = vendor;
452         }
453
454         public String getVendorModelDescription() {
455                 return vendorModelDescription;
456         }
457
458         public void setVendorModelDescription(String vendorModelDescription) {
459                 this.vendorModelDescription = vendorModelDescription;
460         }
461
462         public String getNfNamingCode() {
463                 return nfNamingCode;
464         }
465
466         public void setNfNamingCode(String nfNamingCode) {
467                 this.nfNamingCode = nfNamingCode;
468         }
469         
470         public String getServiceUUID() {
471                 return serviceUUID;
472         }
473         public void setServiceUUID(String serviceUUID) {
474                 this.serviceUUID = serviceUUID;
475         }
476
477         public String getServiceInvariantUUID() {
478                 return serviceInvariantUUID;
479         }
480
481         public void setServiceInvariantUUID(String serviceInvariantUUID) {
482                 this.serviceInvariantUUID = serviceInvariantUUID;
483         }
484
485 }