Removed check for ServiceProxyCustomization
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / heat / ToscaResourceInstaller.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights 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.so.asdc.installer.heat;
23
24
25 import java.sql.Timestamp;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.LinkedHashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Optional;
34 import java.util.Set;
35 import java.util.stream.Collectors;
36
37 import org.hibernate.exception.ConstraintViolationException;
38 import org.hibernate.exception.LockAcquisitionException;
39 import org.onap.sdc.api.notification.IArtifactInfo;
40 import org.onap.sdc.api.notification.IResourceInstance;
41 import org.onap.sdc.api.notification.IStatusData;
42 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
43 import org.onap.sdc.tosca.parser.enums.SdcTypes;
44 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
45 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
46 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
47 import org.onap.sdc.toscaparser.api.Group;
48 import org.onap.sdc.toscaparser.api.NodeTemplate;
49 import org.onap.sdc.toscaparser.api.Policy;
50 import org.onap.sdc.toscaparser.api.Property;
51 import org.onap.sdc.toscaparser.api.RequirementAssignment;
52 import org.onap.sdc.toscaparser.api.RequirementAssignments;
53 import org.onap.sdc.toscaparser.api.elements.Metadata;
54 import org.onap.sdc.toscaparser.api.functions.GetInput;
55 import org.onap.sdc.toscaparser.api.parameters.Input;
56 import org.onap.sdc.utils.DistributionStatusEnum;
57 import org.onap.so.asdc.client.ASDCConfiguration;
58 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
59 import org.onap.so.asdc.installer.ASDCElementInfo;
60 import org.onap.so.asdc.installer.BigDecimalVersion;
61 import org.onap.so.asdc.installer.IVfModuleData;
62 import org.onap.so.asdc.installer.ToscaResourceStructure;
63 import org.onap.so.asdc.installer.VfModuleArtifact;
64 import org.onap.so.asdc.installer.VfModuleStructure;
65 import org.onap.so.asdc.installer.VfResourceStructure;
66 import org.onap.so.asdc.util.YamlEditor;
67 import org.onap.so.db.catalog.beans.AllottedResource;
68 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
69 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
70 import org.onap.so.db.catalog.beans.CollectionResource;
71 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
72 import org.onap.so.db.catalog.beans.ConfigurationResource;
73 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
74 import org.onap.so.db.catalog.beans.CvnfcCustomization;
75 import org.onap.so.db.catalog.beans.HeatEnvironment;
76 import org.onap.so.db.catalog.beans.HeatFiles;
77 import org.onap.so.db.catalog.beans.HeatTemplate;
78 import org.onap.so.db.catalog.beans.HeatTemplateParam;
79 import org.onap.so.db.catalog.beans.InstanceGroupType;
80 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
81 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
82 import org.onap.so.db.catalog.beans.NetworkResource;
83 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
84 import org.onap.so.db.catalog.beans.Service;
85 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
86 import org.onap.so.db.catalog.beans.SubType;
87 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
88 import org.onap.so.db.catalog.beans.ToscaCsar;
89 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
90 import org.onap.so.db.catalog.beans.VfModule;
91 import org.onap.so.db.catalog.beans.VfModuleCustomization;
92 import org.onap.so.db.catalog.beans.VnfResource;
93 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
94 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
95 import org.onap.so.db.catalog.beans.VnfcCustomization;
96 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
97 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
98 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
99 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
100 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
101 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
102 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
103 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
104 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
105 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
106 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
107 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
108 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
109 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
110 import org.onap.so.db.catalog.data.repository.ServiceRepository;
111 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
112 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
113 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
114 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
115 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
116 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
117 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
118 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
119 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
120 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
121 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
122 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
123 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
124 import org.onap.so.logger.MessageEnum;
125 import org.onap.so.logger.MsoLogger;
126 import org.springframework.beans.factory.annotation.Autowired;
127 import org.springframework.stereotype.Component;
128 import org.springframework.transaction.annotation.Transactional;
129
130 import com.fasterxml.jackson.core.JsonProcessingException;
131 import com.fasterxml.jackson.databind.ObjectMapper;
132
133 @Component
134 public class ToscaResourceInstaller {
135
136         protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
137
138         protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
139
140         protected static final String SCALABLE = "scalable";
141
142         protected static final String BASIC = "BASIC";
143
144         protected static final String PROVIDER = "PROVIDER";
145
146         protected static final String HEAT = "HEAT";
147
148         protected static final String MANUAL_RECORD = "MANUAL_RECORD";
149
150         protected static final String MSO = "SO";
151
152
153         @Autowired
154         protected ServiceRepository serviceRepo;
155         
156         @Autowired
157         protected InstanceGroupRepository instanceGroupRepo;
158         
159         @Autowired
160         protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
161         
162         @Autowired
163         protected CollectionResourceRepository collectionRepo;
164         
165         @Autowired
166         protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
167         
168         @Autowired
169         protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
170         
171         @Autowired
172         protected ConfigurationResourceRepository configRepo;
173
174         @Autowired
175         protected VnfResourceRepository vnfRepo;
176
177         @Autowired
178         protected VnfCustomizationRepository vnfCustomizationRepo;
179         
180         @Autowired
181         protected VFModuleRepository vfModuleRepo;
182
183         @Autowired
184         protected VFModuleCustomizationRepository vfModuleCustomizationRepo;    
185         
186         @Autowired
187         protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;  
188         
189         @Autowired
190         protected VnfcCustomizationRepository vnfcCustomizationRepo;
191         
192         @Autowired
193         protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
194
195         @Autowired
196         protected AllottedResourceRepository allottedRepo;
197
198         @Autowired
199         protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
200
201         @Autowired
202         protected NetworkResourceRepository networkRepo;
203          
204         @Autowired
205         protected HeatTemplateRepository heatRepo;
206
207         @Autowired
208         protected NetworkResourceCustomizationRepository networkCustomizationRepo;
209
210         @Autowired
211         protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
212         @Autowired
213         protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
214         @Autowired
215         protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;     
216         
217         @Autowired
218         protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
219         
220         @Autowired
221         protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
222         
223         protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
224
225         public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
226                 boolean status = false;
227                 VfResourceStructure vfResourceStructure = vfResourceStruct;
228                 try {
229                     status = vfResourceStructure.isDeployedSuccessfully();
230                 } catch (RuntimeException e) {
231                     status = false;
232                 }
233                 try {                                   
234                         Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID()); 
235                         if(existingService != null)
236                                 status = true;
237                         if (status) {
238                                 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
239                                                 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
240                                                 vfResourceStructure.getNotification().getServiceName(),
241                                                 BigDecimalVersion.castAndCheckNotificationVersionToString(
242                                                                 vfResourceStructure.getNotification().getServiceVersion()),
243                                                 vfResourceStructure.getNotification().getServiceUUID(),
244                                                 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
245                                 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
246                                 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
247                                 watchdogCDStatusRepository.saveAndFlush(wdStatus);
248                         } else {                        
249                                 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
250                                                 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
251                                                 vfResourceStructure.getNotification().getServiceName(),
252                                                 BigDecimalVersion.castAndCheckNotificationVersionToString(
253                                                                 vfResourceStructure.getNotification().getServiceVersion()),
254                                                 vfResourceStructure.getNotification().getServiceUUID(),
255                                                 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
256                         }
257                         return status;
258                 } catch (Exception e) {
259                         logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
260                                         "Exception - isResourceAlreadyDeployed");
261                         throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
262                 }
263         }
264
265         public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
266                 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
267                                 + " and ComponentName " + iStatus.getComponentName());
268
269                 try {
270                         WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
271                                         iStatus.getComponentName());
272                         cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
273                         watchdogCDStatusRepository.save(cdStatus);
274
275                 } catch (Exception e) {
276                         logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
277                         throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
278                 }
279         }
280
281         @Transactional(rollbackFor = { ArtifactInstallerException.class })
282         public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
283                         throws ArtifactInstallerException {             
284                 VfResourceStructure vfResourceStructure = vfResourceStruct;
285                 extractHeatInformation(toscaResourceStruct, vfResourceStructure);       
286
287                 // PCLO: in case of deployment failure, use a string that will represent
288                 // the type of artifact that failed...
289                 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
290                 try {
291                         createToscaCsar(toscaResourceStruct);                   
292                         createService(toscaResourceStruct, vfResourceStruct);                   
293                         Service service = toscaResourceStruct.getCatalogService();                              
294                         List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
295                         
296                 
297                         for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { 
298                                 
299                                 Metadata metadata = nodeTemplate.getMetaData();         
300                                 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();                  
301                                 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
302                                                 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
303                                 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
304                                                 vfCustomizationCategory);
305                         }
306                         
307                         processResourceSequence(toscaResourceStruct, service);
308                         processVFResources(toscaResourceStruct, service, vfResourceStructure);
309                         List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
310                         processAllottedResources(toscaResourceStruct, service, allottedResourceList);
311                         processNetworks(toscaResourceStruct, service);  
312                         // process Network Collections
313                         processNetworkCollections(toscaResourceStruct, service);
314                         // Process Service Proxy & Configuration
315                         processServiceProxyAndConfiguration(toscaResourceStruct, service);
316                         
317                         serviceRepo.save(service);
318                         
319                         WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
320                         status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
321                         watchdogCDStatusRepository.save(status);
322
323                         toscaResourceStruct.setSuccessfulDeployment();
324
325                 } catch (Exception e) {
326                         logger.debug("Exception :", e);
327                         WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
328                         status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
329                         watchdogCDStatusRepository.save(status);
330                         Throwable dbExceptionToCapture = e;
331                         while (!(dbExceptionToCapture instanceof ConstraintViolationException
332                                         || dbExceptionToCapture instanceof LockAcquisitionException)
333                                         && (dbExceptionToCapture.getCause() != null)) {
334                                 dbExceptionToCapture = dbExceptionToCapture.getCause();
335                         }
336
337                         if (dbExceptionToCapture instanceof ConstraintViolationException
338                                         || dbExceptionToCapture instanceof LockAcquisitionException) {
339                                 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
340                                                 vfResourceStructure.getResourceInstance().getResourceName(),
341                                                 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
342                         } else {
343                                 String elementToLog = (!artifactListForLogging.isEmpty()
344                                                 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
345                                                 : "No element listed");
346                                 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
347                                                 "Exception caught during installation of "
348                                                                 + vfResourceStructure.getResourceInstance().getResourceName()
349                                                                 + ". Transaction rollback",
350                                                 e);
351                                 throw new ArtifactInstallerException("Exception caught during installation of "
352                                                 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
353                         }
354                 }
355         }
356
357
358         List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
359                                                                                                                  ISdcCsarHelper iSdcCsarHelper) {
360
361                 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
362                 nodes.addAll(nodeTemplates);
363
364                 for (NodeTemplate nodeTemplate : nodeTemplates) {
365                         RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
366                         List<RequirementAssignment> reqAs = requirement.getAll();
367                         for (RequirementAssignment ra : reqAs) {
368                                 String reqNode = ra.getNodeTemplateName();
369                                 for (NodeTemplate rNode : resultList) {
370                                         if (rNode.getName().equals(reqNode)) {
371                                                 if(!resultList.contains(nodeTemplate)) {
372                                                         resultList.add(nodeTemplate);
373                                                 }
374                                                 if(nodes.contains(nodeTemplate)) {
375                                                         nodes.remove(nodeTemplate);
376                                                 }
377                                                 break;
378                                         }
379                                 }
380                         }
381                 }
382
383                 if (!nodes.isEmpty()) {
384                         getRequirementList(resultList, nodes, iSdcCsarHelper);
385                 }
386
387                 return resultList;
388         }
389
390         // This method retrieve resource sequence from csar file
391         void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
392                 List<String> resouceSequence = new ArrayList<String>();
393                 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
394
395                 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
396                 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
397                 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
398                 nodes.addAll(nodeTemplates);
399
400                 for (NodeTemplate nodeTemplate : nodeTemplates) {
401                         RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
402
403                         if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
404                                 resultList.add(nodeTemplate);
405                                 nodes.remove(nodeTemplate);
406                         }
407                 }
408
409                 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
410
411                 for (NodeTemplate node : resultList) {
412                         String templateName = node.getMetaData().getValue("name");
413                         if (!resouceSequence.contains(templateName)) {
414                                 resouceSequence.add(templateName);
415                         }
416                 }
417
418                 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
419                 service.setResourceOrder(resourceSeqStr);
420                 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
421         }
422
423         private static String CUSTOMIZATION_UUID = "customizationUUID";
424
425         private static String getValue(Object value, List<Input> servInputs) {
426                 String output = null;
427                 if(value instanceof Map) {
428                         // currently this logic handles only one level of nesting.
429                         return ((LinkedHashMap) value).values().toArray()[0].toString();
430                 } else if(value instanceof GetInput) {
431                         String inputName = ((GetInput)value).getInputName();
432
433                         for(Input input : servInputs) {
434                                 if(input.getName().equals(inputName)) {
435                                         // keep both input name and default value
436                                         // if service input does not supplies value the use default value
437                                         String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
438                                         output =  inputName + "|" + defaultValue;// return default value
439                                 }
440                         }
441
442                 } else {
443                         output = value != null ? value.toString() : "";
444                 }
445                 return output; // return property value
446         }
447
448         String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
449                 Map<String, String> resouceRequest = new HashMap<>();
450                 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
451
452                 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
453                 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
454                                 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
455                 if(nodeTemplateOpt.isPresent()) {
456                         NodeTemplate nodeTemplate = nodeTemplateOpt.get();
457                         LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
458
459                         for(String key : resourceProperties.keySet()) {
460                                 Property property = resourceProperties.get(key);
461
462                                 String value = getValue(property.getValue(), serInput);
463                                 resouceRequest.put(key, value);
464                         }
465                 }
466
467                 try {
468                         ObjectMapper objectMapper = new ObjectMapper();
469                         String jsonStr = objectMapper.writeValueAsString(resouceRequest);
470
471                         jsonStr = jsonStr.replace("\"", "\\\"");
472                         logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
473                         return jsonStr;
474                 } catch (JsonProcessingException e) {
475                         logger.error("resource input could not be deserialized for resource customization id ("
476                                         + resourceCustomizationUuid + ")");
477                         throw new ArtifactInstallerException("resource input could not be parsed", e);
478                 }
479         }
480
481     protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
482                                     Service service) throws ArtifactInstallerException {
483         List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
484
485                 if (nodeTemplatesVLList != null) {
486                         for (NodeTemplate vlNode : nodeTemplatesVLList) {
487                 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
488
489                 TempNetworkHeatTemplateLookup tempNetworkLookUp =
490                                                                 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
491
492                 if (tempNetworkLookUp != null) {
493                     HeatTemplate heatTemplate =
494                                               heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
495                     if (heatTemplate != null) {
496                         NetworkResourceCustomization networkCustomization =
497                                                                           createNetwork (vlNode,
498                                                                                          toscaResourceStruct,
499                                                                                          heatTemplate,
500                                                                                          tempNetworkLookUp.getAicVersionMax (),
501                                                                                          tempNetworkLookUp.getAicVersionMin (),
502                                                                                          service);
503                         service.getNetworkCustomizations ().add (networkCustomization);
504                     } else {
505                         throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
506                                                               + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
507                                         }
508                                 } else {
509                     NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
510                                                                                        toscaResourceStruct,
511                                                                                        null,
512                                                                                        null,
513                                                                                        null,
514                                                                                        service);
515                     service.getNetworkCustomizations().add (networkCustomization);
516                     logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
517                                                                         + networkResourceModelName);
518                                 }                                       
519                                 
520                         }
521                 }
522         }
523
524         protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
525                         List<NodeTemplate> allottedResourceList) {
526                 if (allottedResourceList != null) {
527                         for (NodeTemplate allottedNode : allottedResourceList) {                                                                        
528                                 service.getAllottedCustomizations()
529                                                 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));                               
530                         }
531                 }
532         }
533                 
534         protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
535                 
536                 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
537                 
538                 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
539                 
540                 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();          
541                 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
542                 
543                 ServiceProxyResourceCustomization serviceProxy = null;
544                 
545                 if (serviceProxyResourceList != null) {
546                         for (NodeTemplate spNode : serviceProxyResourceList) {
547                                 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
548                                                                 
549                                 serviceProxyList.add(serviceProxy);
550
551                                 for (NodeTemplate configNode : configurationNodeTemplatesList) {
552                                                                                 
553                                                 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
554                                                 for (RequirementAssignment requirement :  requirementsList) {
555                                                         if (requirement.getNodeTemplateName().equals(spNode.getName())) {
556                                                                 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
557                                                                                                                                 
558                                                                 configurationResourceList.add(configurationResource);
559                                                                 break;
560                                                         }
561                                                 }
562                                 }
563         
564                         }
565                 }
566                 
567                 service.setConfigurationCustomizations(configurationResourceList);
568                 service.setServiceProxyCustomizations(serviceProxyList);
569         }
570         
571         protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
572                 
573                 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
574                 
575                 if (networkCollectionList != null) {
576                         for (NodeTemplate crNode : networkCollectionList) {     
577                                 
578                                 createNetworkCollection(crNode, toscaResourceStruct, service);
579                                 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
580                                 
581                                 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
582                                 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
583                                         instanceGroupRepo.saveAndFlush(networkInstanceGroup);
584                                 }
585         
586                         }
587                 }
588                 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
589         }
590
591
592         protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
593                         throws Exception{
594                 logger.debug("processVFResources");
595                 
596                 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
597 //              String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
598 //              String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
599                 
600                 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
601                         Metadata metadata = nodeTemplate.getMetaData();
602                         String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
603                         logger.debug("VF Category is : " + vfCustomizationCategory);
604                         
605                         // Do not treat Allotted Resources as VNF resources
606                         if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
607                                 continue;
608                         }
609
610                         String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
611                         logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
612
613                         IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
614
615                         // Make sure the VF ResourceCustomizationUUID from the notification and tosca
616                         // customizations match before comparing their VF Modules UUID's
617                         logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
618                                         + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
619                                         + vfCustomizationUUID);
620
621                         if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
622                                 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
623                                                 + " matches vfNotificationResource CustomizationUUID");                         
624                                 
625                                 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
626                                                 vfCustomizationCategory);
627                         } else {
628                                 logger.debug("Notification VF ResourceCustomizationUUID: "
629                                                 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
630                                                 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
631                         }
632                 }
633         }
634         
635         
636         protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
637                         Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
638                 
639                 logger.debug("VF Category is : " + vfCustomizationCategory);
640                 
641                 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
642                 {
643
644                         String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
645                                         .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
646                         logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);     
647                         
648                         IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();           
649                         
650                         // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
651                         logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + 
652                                                    " matches Tosca VF Customization UUID: " +  vfCustomizationUUID);
653                         
654                         if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
655                                 
656                                 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
657                         
658                                 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
659                                 
660                                 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>(); 
661                                 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
662                                                                 
663                                 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
664                                         
665                                         logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
666                                         List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
667                                                         .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
668                                         IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();     
669                                         
670                                         logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
671                                         
672                                         Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
673                                                         .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
674                                                     .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
675                                                     .findFirst();
676                                         if(matchingObject.isPresent()){
677                                                 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, 
678                                                                                                                                                                                          vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
679                                                 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
680                                         }else
681                                                 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
682                                         
683                                 }
684                                 service.getVnfCustomizations().add(vnfResource);
685                         } else{
686                                 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
687                                                      "Tosca VF Customization UUID: " +  vfCustomizationUUID);
688                         }
689                 }
690         }
691
692         public void processWatchdog(String distributionId, String servideUUID) {
693                 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
694                 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
695                 
696                 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
697                 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
698         }
699
700         protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
701                         VfResourceStructure vfResourceStructure) {
702                 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
703
704                         switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
705                         case ASDCConfiguration.HEAT:
706                         case ASDCConfiguration.HEAT_NESTED:
707                                 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
708                                                 vfModuleArtifact);
709                                 break;
710                         case ASDCConfiguration.HEAT_VOL:
711                                 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
712                                                 vfModuleArtifact);
713                                 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
714                                 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
715                                 break;
716                         case ASDCConfiguration.HEAT_ENV:
717                                 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
718                                 break;
719                         case ASDCConfiguration.HEAT_ARTIFACT:
720                                 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
721                                                 toscaResourceStruct);
722                                 break;
723                         case ASDCConfiguration.HEAT_NET:
724                         case ASDCConfiguration.OTHER:
725                                 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
726                                                 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
727                                                                 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
728                                                 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
729                                 break;
730                         default:
731                                 break;
732
733                         }
734                 }
735         }
736
737         protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
738                         VfModuleArtifact vfModuleArtifact) {
739                 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
740                 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
741                 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
742                         if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
743                                         && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
744                                 return moduleArtifact;
745                         }
746                 }
747                 return null;
748         }
749
750         public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
751                         List<String> listTypes) {
752                 String newFileBody = filebody;
753                 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
754
755                         if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
756
757                                 newFileBody = verifyTheFilePrefixInString(newFileBody,
758                                                 moduleArtifact.getArtifactInfo().getArtifactName());
759                         }
760                 }
761                 return newFileBody;
762         }
763
764         public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
765
766                 String needlePrefix = "file:///";
767                 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
768
769                 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
770                         return body;
771                 }
772
773                 StringBuilder sb = new StringBuilder(body.length());
774
775                 int currentIndex = 0;
776                 int startIndex = 0;
777
778                 while (currentIndex != -1) {
779                         startIndex = currentIndex;
780                         currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
781
782                         if (currentIndex == -1) {
783                                 break;
784                         }
785                         // We append from the startIndex up to currentIndex (start of File
786                         // Name)
787                         sb.append(body.substring(startIndex, currentIndex));
788                         sb.append(filenameToVerify);
789
790                         currentIndex += prefixedFilenameToVerify.length();
791                 }
792
793                 sb.append(body.substring(startIndex));
794
795                 return sb.toString();
796         }
797
798         protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
799                         ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
800                 HeatTemplate heatTemplate = new HeatTemplate();
801                 List<String> typeList = new ArrayList<>();
802                 typeList.add(ASDCConfiguration.HEAT_NESTED);
803                 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
804
805                 heatTemplate.setTemplateBody(
806                                 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
807                 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
808
809                 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
810                         heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
811                 } else {
812                         heatTemplate.setTimeoutMinutes(240);
813                 }
814
815                 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
816                 heatTemplate.setVersion(BigDecimalVersion
817                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
818                 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
819
820                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
821                         heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
822                 } else {
823                         heatTemplate.setArtifactChecksum(MANUAL_RECORD);
824                 }
825
826                 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
827                                 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
828                 heatTemplate.setParameters(heatParam);  
829                 vfModuleArtifact.setHeatTemplate(heatTemplate);
830         }
831
832         protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
833                         VfModuleArtifact vfModuleArtifact) {
834                 HeatEnvironment heatEnvironment = new HeatEnvironment();
835                 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
836                 List<String> typeList = new ArrayList<>();
837                 typeList.add(ASDCConfiguration.HEAT);
838                 typeList.add(ASDCConfiguration.HEAT_VOL);
839                 heatEnvironment.setEnvironment(
840                                 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
841                 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
842                 heatEnvironment.setVersion(BigDecimalVersion
843                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));     
844                 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
845
846                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
847                         heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
848                 } else {
849                         heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
850                 }               
851                 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
852         }
853
854         protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
855                 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
856                 
857                 HeatFiles heatFile = new HeatFiles();   
858                 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
859                 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
860                 heatFile.setFileBody(vfModuleArtifact.getResult());
861                 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
862                 heatFile.setVersion(BigDecimalVersion
863                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
864                 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
865                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
866                         heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
867                 } else {
868                         heatFile.setArtifactChecksum(MANUAL_RECORD);
869                 }
870                 vfModuleArtifact.setHeatFiles(heatFile);
871         }
872
873         protected Service createService(ToscaResourceStructure toscaResourceStructure,
874                         VfResourceStructure vfResourceStructure) {
875
876                 toscaResourceStructure.getServiceMetadata();
877
878                 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
879
880                 Service service = new Service();
881
882                 if (serviceMetadata != null) {
883
884                         if (toscaResourceStructure.getServiceVersion() != null) {
885                                 service.setModelVersion(toscaResourceStructure.getServiceVersion());
886                         }
887
888                         service.setServiceType(serviceMetadata.getValue("serviceType"));
889                         service.setServiceRole(serviceMetadata.getValue("serviceRole"));
890
891                         service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
892                         service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
893                         service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
894                         service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
895
896                         if (vfResourceStructure != null) 
897                                 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
898                                                 
899                         service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
900                         service.setCsar(toscaResourceStructure.getCatalogToscaCsar());                  
901                 }
902                 
903                 
904                 toscaResourceStructure.setCatalogService(service); 
905                 return service;
906         }
907         
908         protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
909
910                 Metadata spMetadata = nodeTemplate.getMetaData();
911                 
912                 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
913                 
914                 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
915                 
916                 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
917                 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
918                 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
919                 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
920                 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));        
921                                 
922                 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
923                 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
924                 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
925                 
926                 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
927                 
928                 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);      
929                 
930                 spCustomizationResource.setSourceService(sourceService);
931                 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
932                 serviceProxyCustomizationSet.add(spCustomizationResource);
933
934                 
935                 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
936                 
937                 return spCustomizationResource;
938         }
939         
940         protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
941
942                 Metadata metadata = nodeTemplate.getMetaData();
943                 
944                 ConfigurationResource configResource = new ConfigurationResource();
945                 
946                 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
947                 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
948                 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
949                 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
950                 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
951                 configResource.setToscaNodeType(nodeTemplate.getType());
952                 
953                 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
954                 
955                 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
956                 
957                 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
958                 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
959                 
960                 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
961                 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
962                 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
963                 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
964                 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
965                 configCustomizationResource.setConfigurationResource(configResource);
966                 configResourceCustomizationSet.add(configCustomizationResource);
967
968                 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);   
969                 
970                 toscaResourceStructure.setCatalogConfigurationResource(configResource);
971                 
972                 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
973                 
974                 return configCustomizationResource;
975         }
976         
977         protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
978                 
979                 Metadata fabricMetadata = nodeTemplate.getMetaData();
980                 
981                 ConfigurationResource configResource = new ConfigurationResource();
982                 
983                 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
984                 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
985                 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
986                 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
987                 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
988                 configResource.setToscaNodeType(nodeTemplate.getType());
989                 
990                 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
991                 
992                 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
993                 
994                 configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
995                 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
996                 
997                 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
998                 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
999                 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
1000                 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
1001                 configCustomizationResource.setConfigurationResource(configResource);
1002                 configResourceCustomizationSet.add(configCustomizationResource);
1003
1004                 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1005                 
1006                 return configCustomizationResource;
1007         }
1008
1009         protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1010                 ToscaCsar toscaCsar = new ToscaCsar();
1011                 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1012                         toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1013                 } else {
1014                         toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1015                 }
1016                 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1017                 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1018                 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1019                 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1020                 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1021
1022                 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1023         }
1024         
1025         protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1026                 VnfcCustomization vnfcCustomization = null;
1027                 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1028                         if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1029                                 vnfcCustomization = vnfcCustom;
1030                         }
1031                 }
1032                 
1033                 if(vnfcCustomization==null)
1034                         vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1035                 
1036                 return vnfcCustomization;
1037         }
1038         
1039         protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1040                 CvnfcCustomization cvnfcCustomization = null;
1041                 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1042                         if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1043                                 cvnfcCustomization = cvnfcCustom;
1044                         }
1045                 }
1046                 
1047                 if(cvnfcCustomization==null)
1048                         cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1049                 
1050                 return cvnfcCustomization;
1051         }
1052
1053         protected  NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1054                         ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1055                 
1056                 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1057                                 if(networkResourceCustomization==null){
1058                         networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1059                                         toscaResourceStructure);
1060                                         
1061                         NetworkResource networkResource = findExistingNetworkResource(service,
1062                                         networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1063                                         if(networkResource == null)
1064                                 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1065                                                 aicMax, aicMin);
1066
1067                                         networkResource.addNetworkResourceCustomization(networkResourceCustomization);          
1068                                         networkResourceCustomization.setNetworkResource(networkResource);
1069                                 }
1070                 return networkResourceCustomization;
1071         }
1072         
1073         protected  NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1074                 NetworkResource networkResource = null;
1075                 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1076                         if (networkCustom.getNetworkResource() != null
1077                                         && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1078                                         networkResource = networkCustom.getNetworkResource();
1079                         }
1080                 }
1081                 if(networkResource==null)
1082                         networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1083                 
1084                 return networkResource;
1085         }
1086         
1087         protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1088                         ToscaResourceStructure toscaResourceStructure) {
1089                 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1090                 networkResourceCustomization.setModelInstanceName(
1091                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1092                 networkResourceCustomization.setModelCustomizationUUID(
1093                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));                
1094
1095                 networkResourceCustomization.setNetworkTechnology(
1096                                 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1097                                                 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1098                 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1099                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1100                 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1101                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1102                 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1103                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1104                 return networkResourceCustomization;
1105         }
1106
1107         protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1108                         ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1109                 NetworkResource networkResource = new NetworkResource();
1110                 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1111                                 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1112
1113                 if ("true".equalsIgnoreCase(providerNetwork)) {
1114                         networkResource.setNeutronNetworkType(PROVIDER);
1115                 } else {
1116                         networkResource.setNeutronNetworkType(BASIC);
1117                 }
1118
1119                 networkResource.setModelName(
1120                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1121
1122                 networkResource.setModelInvariantUUID(
1123                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1124                 networkResource.setModelUUID(
1125                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1126                 networkResource.setModelVersion(
1127                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1128
1129                 networkResource.setAicVersionMax(aicMax);               
1130                 networkResource.setAicVersionMin(aicMin);
1131                 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1132                 networkResource.setDescription(
1133                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1134                 networkResource.setOrchestrationMode(HEAT);     
1135                 networkResource.setHeatTemplate(heatTemplate); 
1136                 return networkResource;
1137         }
1138         
1139         protected  CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1140                         ToscaResourceStructure toscaResourceStructure, Service service) {
1141
1142                 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1143
1144                 // **** Build Object to populate Collection_Resource table
1145                 CollectionResource collectionResource = new CollectionResource();
1146
1147                 collectionResource
1148                                 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1149                 collectionResource.setModelInvariantUUID(
1150                                 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1151                 collectionResource
1152                                 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1153                 collectionResource
1154                                 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1155                 collectionResource
1156                                 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1157                 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1158
1159                 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1160
1161                 // **** Build object to populate Collection_Resource_Customization table
1162                 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1163                 
1164                 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1165                                 "cr_function"));
1166                 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1167                                 "cr_role"));
1168                 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1169                                 "cr_type"));
1170
1171                 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1172                 ncfc.setModelCustomizationUUID(
1173                                 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1174                 
1175                 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1176                 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1177
1178                 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1179
1180                 ncfc.setCollectionResource(collectionResource);
1181                 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1182                 
1183                 //*** Build object to populate the Instance_Group table
1184                 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1185                                 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1186                                                 "org.openecomp.groups.NetworkCollection");
1187                 
1188                 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1189
1190                 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1191
1192                 for (Group group : groupList) { 
1193                         
1194                         NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1195                         Metadata instanceMetadata = group.getMetadata();
1196                         networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1197                         networkInstanceGroup
1198                                         .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1199                         networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1200                         networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1201                         networkInstanceGroup.setToscaNodeType(group.getType());
1202                         networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1203                                                                                                                                                         // Role
1204                         networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1205                                                                                                                                                 // type
1206                         networkInstanceGroup.setCollectionResource(collectionResource);
1207                 
1208                         // ****Build object to populate
1209                         // Collection_Resource_Instance_Group_Customization table
1210                         CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1211                         crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1212                         crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1213                         crInstanceGroupCustomization.setModelCustomizationUUID(
1214                                         networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1215                 
1216                         String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
1217                         String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
1218                         if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1219                                         fixedQuantity + "_quantity") != null) {
1220
1221                                 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
1222                                                 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1223                                                                 fixedQuantity + "_quantity"))); 
1224                         }
1225                 
1226                         crInstanceGroupCustomization.setDescription(
1227                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1228                                                         instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1229                                                                         + "_network_collection_description"));
1230                         crInstanceGroupCustomization.setFunction(
1231                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1232                                                         instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1233                                                                         + "_network_collection_function"));
1234                         crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1235                         collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1236
1237                         networkInstanceGroup
1238                                         .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1239
1240                         networkInstanceGroupList.add(networkInstanceGroup);
1241
1242                 //}
1243
1244                 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1245
1246                 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1247                                 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1248                 
1249                 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1250                 
1251                 //*****Build object to populate the NetworkResource table
1252                 NetworkResource networkResource = new NetworkResource();
1253                 
1254                 for(NodeTemplate vlNodeTemplate : vlNodeList){
1255
1256                         String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1257                                         vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1258
1259                         if ("true".equalsIgnoreCase(providerNetwork)) {
1260                                 networkResource.setNeutronNetworkType(PROVIDER);
1261                         } else {
1262                                 networkResource.setNeutronNetworkType(BASIC);
1263                         }
1264
1265                         networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1266
1267                         networkResource.setModelInvariantUUID(
1268                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1269                         networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1270                         networkResource
1271                                         .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1272
1273                         networkResource.setAicVersionMax(
1274                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1275                         
1276                         TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1277                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1278                         
1279                         if (tempNetworkLookUp != null ) {       
1280                                         
1281                                 HeatTemplate heatTemplate = heatRepo
1282                                                 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1283                                         networkResource.setHeatTemplate(heatTemplate);
1284                                         
1285                                         networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1286                                         
1287                         }
1288
1289                         networkResource.setToscaNodeType(vlNodeTemplate.getType());
1290                         networkResource
1291                                         .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1292                         networkResource.setOrchestrationMode(HEAT);
1293                         
1294                         // Build object to populate the
1295                         // Collection_Network_Resource_Customization table
1296                         for (NodeTemplate memberNode : group.getMemberNodes()) {
1297                                 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1298                         }
1299
1300                         collectionNetworkResourceCustomization.setModelCustomizationUUID(
1301                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1302
1303                         collectionNetworkResourceCustomization.setNetworkTechnology(
1304                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1305                                                         SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1306                         collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1307                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1308                         collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1309                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1310                         collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1311                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1312                         collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1313                         collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1314                         collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1315                         
1316                         collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1317                    }
1318
1319                 }
1320                 
1321                 return collectionNetworkResourceCustomization;
1322         }
1323         
1324         protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1325                         VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1326
1327                         Metadata instanceMetadata = group.getMetadata();
1328                         // Populate InstanceGroup
1329                         VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1330                         
1331                         vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1332                         vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1333                         vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1334                         vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1335                         vfcInstanceGroup.setToscaNodeType(group.getType());
1336                         vfcInstanceGroup.setRole("SUB-INTERFACE");   // Set Role
1337                         vfcInstanceGroup.setType(InstanceGroupType.VNFC);  // Set type  
1338                         
1339                         //Populate VNFCInstanceGroupCustomization
1340                         VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1341                         
1342                         vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1343                         vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1344                         vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1345                                                 
1346                         String getInputName = null;
1347                         String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function"); 
1348                         if (groupProperty != null) { 
1349                         int getInputIndex = groupProperty.indexOf("{get_input="); 
1350                                 if (getInputIndex > -1) { 
1351                                         getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); 
1352                                 } 
1353                         }
1354                         vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1355                         
1356                         vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1357                         vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);            
1358                         
1359                 return vfcInstanceGroupCustom;
1360
1361         }
1362                 
1363         protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1364                         ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1365                         IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1366                 
1367                 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1368                                 vfModuleData.getVfModuleModelCustomizationUUID());
1369                 if(vfModuleCustomization == null){              
1370                         VfModule vfModule = findExistingVfModule(vnfResource,
1371                                         nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1372                         Metadata vfMetadata = group.getMetadata();
1373                         if(vfModule==null)
1374                                 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1375                         
1376                         vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1377                         setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1378                                         vfMetadata);
1379                         vfModuleCustomization.setVfModule(vfModule);
1380                         vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1381                         vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1382                 } else {
1383                         vfResourceStructure.setAlreadyDeployed(true);
1384                 }
1385                 
1386                 //******************************************************************************************************************
1387                 //* Extract VFC's and CVFC's then add them to VFModule
1388                 //******************************************************************************************************************
1389                 
1390                 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();                
1391                 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1392                 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1393
1394                 // Extract CVFC lists
1395                 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
1396                                                 
1397                 for(NodeTemplate cvfcTemplate : cvfcList) {
1398                                                                         
1399                         CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1400                         
1401                         if(existingCvnfcCustomization == null){
1402                         
1403                         //Extract associated VFC - Should always be just one
1404                         List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1405                                                 
1406                         for(NodeTemplate vfcTemplate : vfcList) {
1407                                 
1408                                 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1409                                 VnfcCustomization existingVnfcCustomization = null;
1410                                 
1411                                 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1412                                         
1413                                 // Only Add Abstract VNFC's to our DB, ignore all others
1414                                 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1415                                         vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1416                                         vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1417                                         vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1418                                         vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1419                                         vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1420         
1421                                         vnfcCustomization.setModelVersion(
1422                                                         testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1423                                         vnfcCustomization.setDescription(
1424                                                         testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1425                                         vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1426                                         
1427                                         vnfcCustomizations.add(vnfcCustomization);
1428                                         existingVnfcSet.add(vnfcCustomization);
1429                                 }
1430                         
1431                         // This check is needed incase the VFC subcategory is something other than Abstract.  In that case we want to skip adding that record to our DB.
1432                         if(vnfcCustomization.getModelCustomizationUUID() != null){
1433                                 
1434                                 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1435                                 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1436                                 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1437                                 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1438                                 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1439                                 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1440         
1441                                 cvnfcCustomization.setModelVersion(
1442                                                 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1443                                 cvnfcCustomization.setDescription(
1444                                                 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1445                                 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1446                                 
1447                                 if(existingVnfcCustomization != null){
1448                                         cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1449                                 }else{
1450                                         cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1451                                 }
1452                                 
1453                                 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1454                                 cvnfcCustomization.setVnfResourceCustomization(vnfResource);                                    
1455                                 
1456                                 cvnfcCustomizations.add(cvnfcCustomization);
1457                                 existingCvnfcSet.add(cvnfcCustomization);
1458                         
1459                         //*****************************************************************************************************************************************
1460                         //* Extract Fabric Configuration
1461                         //*****************************************************************************************************************************************
1462                         
1463                         List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
1464                                                                 
1465                         for(NodeTemplate fabricTemplate : fabricConfigList) {
1466                                                                                 
1467                                 ConfigurationResource fabricConfig = null;
1468                                 
1469                                 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1470                                                                 
1471                                 if(existingConfig == null){
1472                                         
1473                                         ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1474                                         
1475                                         fabricConfig = fabricConfigCustomization.getConfigurationResource();
1476                                         
1477                                         service.getConfigurationCustomizations().add(fabricConfigCustomization);
1478                                 }else {
1479                                         fabricConfig = existingConfig;
1480                                 }
1481                                 
1482                                 
1483                                 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure, 
1484                                                                                                                                                            vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
1485                                 
1486                                 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1487                         }
1488                         
1489                         }
1490                         
1491                    }
1492                         
1493                   }
1494                         
1495                 } 
1496                 
1497                 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1498                 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1499                 
1500                 return vfModuleCustomization;
1501         }
1502         
1503         protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct, 
1504             VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1505             ConfigurationResource configResource) {
1506
1507                 Metadata fabricMetadata = fabricTemplate.getMetaData();
1508                 
1509                 
1510                 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1511                 
1512                 vfModuleToCvnfc.setConfigurationResource(configResource);
1513                 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1514                 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1515                 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1516                 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1517                 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1518                 vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
1519                 
1520                 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
1521                 
1522                 if(policyList != null){
1523                         for(Policy policy : policyList){
1524                                 vfModuleToCvnfc.setPolicyName(policy.getName());
1525                         }
1526                 }
1527                 
1528                 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
1529                 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
1530                 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
1531                 
1532                 return vfModuleToCvnfc;
1533         }
1534                 
1535         protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1536                 ConfigurationResource configResource = null;
1537                 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1538                         if (configurationResourceCustom.getConfigurationResource() != null
1539                                         && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1540                                 configResource = configurationResourceCustom.getConfigurationResource();
1541                         }
1542                 }
1543                 if(configResource==null)
1544                         configResource = configRepo.findResourceByModelUUID(modelUUID);
1545                 
1546                 return configResource;
1547         }
1548                 
1549         protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1550                         String vfModuleModelCustomizationUUID) {
1551                 VfModuleCustomization vfModuleCustomization = null;
1552                 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1553                         if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1554                                 vfModuleCustomization = vfModuleCustom;
1555                         }
1556                 }
1557                 if(vfModuleCustomization==null)
1558                         vfModuleCustomization = vfModuleCustomizationRepo
1559                                         .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1560                 
1561                 return vfModuleCustomization;
1562         }
1563
1564         protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1565                 VfModule vfModule = null;
1566                 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1567                         if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1568                                 vfModule = vfModuleCustom.getVfModule();
1569                         }
1570                 }
1571                 if(vfModule==null)
1572                         vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1573                 
1574                 return vfModule;
1575         }
1576
1577         protected VfModuleCustomization createVfModuleCustomization(Group group,
1578                         ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1579                 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1580                 
1581                 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1582
1583                 vfModuleCustomization.setVfModule(vfModule);
1584
1585                 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1586                                 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1587                 if (initialCount != null && initialCount.length() > 0) {
1588                         vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1589                 }
1590
1591                 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1592                                 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1593
1594                 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1595                                 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1596                 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1597                         vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1598                 }
1599
1600                 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1601                                 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1602
1603                 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1604                                 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1605                 if (maxInstances != null && maxInstances.length() > 0) {
1606                         vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1607                 }
1608
1609                 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1610                                 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1611                 if (minInstances != null && minInstances.length() > 0) {
1612                         vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1613                 }
1614                 return vfModuleCustomization;
1615         }
1616
1617         protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1618                         IVfModuleData vfModuleData, Metadata vfMetadata) {
1619                 VfModule vfModule = new VfModule();
1620                 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1621
1622                 if(vfModuleModelUUID == null) {
1623                         vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1624                                         SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1625                 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1626                         vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1627                 }
1628
1629                 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1630                                 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1631                 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1632                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1633                 vfModule.setModelUUID(vfModuleModelUUID);
1634                 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1635                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1636                 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1637                                 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1638
1639                 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1640                                 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1641                 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1642                         vfModule.setIsBase(true);
1643                 } else {
1644                         vfModule.setIsBase(false);
1645                 }
1646                 return vfModule;
1647         }
1648
1649         protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1650                         VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1651                         Metadata vfMetadata) {
1652                 
1653                 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1654                                 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1655                                                 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1656                                                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1657                                 .findFirst();
1658
1659                 if (matchingObject.isPresent()) {
1660                         List<HeatFiles> heatFilesList = new ArrayList<>();
1661                         List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1662                         List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1663                         HeatTemplate parentHeatTemplate = new HeatTemplate();
1664                         String parentArtifactType = null;
1665                         Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1666                         for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1667                                 
1668                                 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1669                                 
1670                                 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1671                                         checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1672                                                         childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1673                                 }
1674                                 
1675                                 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1676                                         parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1677                                         
1678                                         if(!childNestedHeatTemplates.isEmpty()){
1679                                         
1680                                                 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1681                                                         volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1682                                                 } else {
1683                                                         heatChildTemplates.add(childNestedHeatTemplates.get(0));
1684                                                 }
1685                                         }
1686                                 }
1687                                 
1688                         }
1689                         if(!heatFilesList.isEmpty()){
1690                                 vfModule.setHeatFiles(heatFilesList);
1691                         }
1692                         
1693                         
1694                         // Set all Child Templates related to HEAT_VOLUME
1695                         if(!volumeHeatChildTemplates.isEmpty()){
1696                                 if(vfModule.getVolumeHeatTemplate() != null){
1697                                         vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1698                                 }else{
1699                                         logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1700                                 }
1701                         }
1702                         
1703                         // Set all Child Templates related to HEAT
1704                         if(!heatChildTemplates.isEmpty()){
1705                                 if(vfModule.getModuleHeatTemplate() != null){
1706                                         vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1707                                 }else{
1708                                         logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1709                                 }
1710                         }
1711                 }
1712         }
1713
1714         protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1715                         List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1716                         HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1717                 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1718                         vfModuleArtifact.incrementDeployedInDB();
1719                         vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1720                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1721                         vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1722                         VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1723                         vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1724                         vfModuleArtifact.incrementDeployedInDB();
1725                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1726                         if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1727                                 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1728                         } else { 
1729                         vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1730                         }
1731                         vfModuleArtifact.incrementDeployedInDB();
1732                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1733                         heatFilesList.add(vfModuleArtifact.getHeatFiles());                                                     
1734                         vfModuleArtifact.incrementDeployedInDB();
1735                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1736                         nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());                            
1737                         vfModuleArtifact.incrementDeployedInDB();
1738                 }
1739         }
1740
1741         protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1742                         ToscaResourceStructure toscaResourceStructure, Service service) {
1743                 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1744                                 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1745                 if(vnfResourceCustomization == null){           
1746                         VnfResource vnfResource = findExistingVnfResource(service,
1747                                         vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1748                         
1749                         if(vnfResource==null)
1750                                 vnfResource=createVnfResource(vfNodeTemplate);
1751                         
1752                         vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1753                                         vnfResource);
1754                         vnfResourceCustomization.setVnfResources(vnfResource);
1755                         vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1756                         
1757                         // Fetch VNFC Instance Group Info                               
1758                         List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1759                                         .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1760                                                         "org.openecomp.groups.VfcInstanceGroup");
1761                                 
1762                         for (Group group : groupList) { 
1763                                 
1764                                         VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1765                                         
1766                                         vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);                                
1767                         }                       
1768                 }
1769                 return vnfResourceCustomization;
1770         }
1771         
1772         protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1773                 VnfResource vnfResource = null;
1774                 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1775                         if (vnfResourceCustom.getVnfResources() != null
1776                                         && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1777                                 vnfResource = vnfResourceCustom.getVnfResources();
1778                         }
1779                 }
1780                 if(vnfResource==null)
1781                         vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1782                 
1783                 return vnfResource;
1784         }
1785
1786         protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1787                         ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1788                 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1789                 vnfResourceCustomization.setModelCustomizationUUID(
1790                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1791                 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1792
1793                 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1794                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1795                 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1796                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1797                 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1798                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1799                 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1800                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1801
1802                 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1803                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1804
1805                 vnfResourceCustomization.setVnfResources(vnfResource);
1806                 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1807                                 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));  
1808
1809                 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1810                                 .getCapabilitiesOf(vfNodeTemplate);
1811
1812                 if (vnfCustomizationCapability != null) {
1813                         CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1814
1815                         if (capAssign != null) {
1816                                 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1817                                                 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1818                                 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1819                                                 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1820                         }
1821
1822                 }
1823                 
1824                 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1825                 
1826                 return vnfResourceCustomization;
1827         }
1828
1829         protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1830                 VnfResource vnfResource = new VnfResource();
1831                 vnfResource.setModelInvariantUUID(
1832                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1833                 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1834                 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1835
1836                 vnfResource.setModelVersion(
1837                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1838                 vnfResource.setDescription(
1839                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1840                 vnfResource.setOrchestrationMode(HEAT);
1841                 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1842                 vnfResource.setAicVersionMax(
1843                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1844                 vnfResource.setAicVersionMin(
1845                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1846                 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1847                 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1848                 
1849                 return vnfResource;
1850         }
1851
1852         protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1853                         ToscaResourceStructure toscaResourceStructure, Service service) {
1854                 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1855                                 .findOneByModelCustomizationUUID(
1856                                 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1857                         
1858                 if(allottedResourceCustomization == null){                      
1859                         AllottedResource allottedResource = findExistingAllottedResource(service,
1860                                         nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1861                         
1862                         if(allottedResource==null)
1863                                 allottedResource=createAR(nodeTemplate);
1864                         
1865                         toscaResourceStructure.setAllottedResource(allottedResource);                   
1866                         allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1867                         allottedResourceCustomization.setAllottedResource(allottedResource);
1868                         allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1869                 }
1870                 return allottedResourceCustomization;
1871         }
1872         
1873         protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1874                 AllottedResource allottedResource = null;
1875                 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1876                         if (allottedResourceCustom.getAllottedResource() != null
1877                                         && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1878                                 allottedResource = allottedResourceCustom.getAllottedResource();
1879                         }
1880                 }
1881                 if(allottedResource==null)
1882                         allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1883                 
1884                 return allottedResource;
1885         }
1886         
1887         protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1888                         ToscaResourceStructure toscaResourceStructure) {
1889                 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1890                 allottedResourceCustomization.setModelCustomizationUUID(
1891                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1892                 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1893                 
1894
1895                 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1896                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1897                 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1898                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1899                 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1900                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1901                 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1902                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1903
1904                 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1905                 
1906                 if(vfcNodes != null){
1907                         for(NodeTemplate vfcNode : vfcNodes){
1908                         
1909                                 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1910                                 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1911                                 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1912                         }
1913                 }
1914                 
1915
1916                 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1917                                 .getCapabilitiesOf(nodeTemplate);
1918
1919                 if (arCustomizationCapability != null) {
1920                         CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1921
1922                         if (capAssign != null) {
1923                                 allottedResourceCustomization.setMinInstances(
1924                                                 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1925                                                                 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1926                                 allottedResourceCustomization.setMaxInstances(
1927                                                 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1928                                                                 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1929                         }
1930                 }
1931                 return allottedResourceCustomization;
1932         }
1933
1934         protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1935                 AllottedResource allottedResource = new AllottedResource();
1936                 allottedResource
1937                 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1938                 allottedResource.setModelInvariantUUID(
1939                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1940                 allottedResource
1941                 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1942                 allottedResource
1943                 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1944                 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1945                 allottedResource.setSubcategory(
1946                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1947                 allottedResource
1948                 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1949                 return allottedResource;
1950         }
1951
1952         protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1953                 // Scan the payload downloadResult and extract the HeatTemplate
1954                 // parameters
1955                 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1956                 return yamlEditor.getParameterList(artifactUUID);
1957         }       
1958
1959         protected String testNull(Object object) {
1960
1961                 if (object == null) {
1962                         return null;
1963                 } else if (object.equals("NULL")) {
1964                         return null;
1965                 } else if (object instanceof Integer) {
1966                         return object.toString();
1967                 } else if (object instanceof String) {
1968                         return (String) object;
1969                 } else {
1970                         return "Type not recognized";
1971                 }
1972         }
1973         
1974         protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1975                         VfModuleArtifact heatNestedArtifact) {
1976
1977                 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1978                                 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1979                         for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1980                                         .getArtifactInfo().getRelatedArtifacts()) {
1981                                 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1982                                         return ASDCConfiguration.HEAT;
1983                                 }
1984
1985                         }
1986                 } 
1987                 
1988                 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null 
1989                                 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
1990                                                 .getRelatedArtifacts() != null) {
1991                         for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
1992                                         .get(0).getArtifactInfo().getRelatedArtifacts()) {
1993                                 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1994                                         return ASDCConfiguration.HEAT_VOL;
1995                                 }
1996                         
1997                         }
1998                 }
1999                 
2000                 // Does not belong to anything
2001                 return null;
2002                         
2003         }
2004         
2005         protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2006
2007                 return vfResourceStructure.getNotification().getServiceName() + "/"
2008                                 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2009         }
2010
2011         protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2012                 
2013                 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2014                                 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2015         }
2016         
2017         
2018         protected static Timestamp getCurrentTimeStamp() {
2019                 
2020                 return new Timestamp(new Date().getTime());
2021         }
2022
2023 }