Merge 'origin/casablanca' into master
[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                                 ServiceProxyResourceCustomization serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getModelCustomizationUUID());
550                                 
551                                 if(serviceProxyResource == null){
552                                 
553                                 serviceProxyList.add(serviceProxy);
554
555                                 for (NodeTemplate configNode : configurationNodeTemplatesList) {
556                                                                                 
557                                                 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
558                                                 for (RequirementAssignment requirement :  requirementsList) {
559                                                         if (requirement.getNodeTemplateName().equals(spNode.getName())) {
560                                                                 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
561                                                                                                                                 
562                                                                 configurationResourceList.add(configurationResource);
563                                                                 break;
564                                                         }
565                                                 }
566                                 }
567                                 
568                                 }
569         
570                         }
571                 }
572                 
573                 service.setConfigurationCustomizations(configurationResourceList);
574                 service.setServiceProxyCustomizations(serviceProxyList);
575         }
576         
577         protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
578                 
579                 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
580                 
581                 if (networkCollectionList != null) {
582                         for (NodeTemplate crNode : networkCollectionList) {     
583                                 
584                                 createNetworkCollection(crNode, toscaResourceStruct, service);
585                                 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
586                                 
587                                 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
588                                 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
589                                         instanceGroupRepo.saveAndFlush(networkInstanceGroup);
590                                 }
591         
592                         }
593                 }
594                 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
595         }
596
597
598         protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
599                         throws Exception{
600                 logger.debug("processVFResources");
601                 
602                 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
603 //              String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
604 //              String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
605                 
606                 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
607                         Metadata metadata = nodeTemplate.getMetaData();
608                         String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
609                         logger.debug("VF Category is : " + vfCustomizationCategory);
610                         
611                         // Do not treat Allotted Resources as VNF resources
612                         if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
613                                 continue;
614                         }
615
616                         String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
617                         logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
618
619                         IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
620
621                         // Make sure the VF ResourceCustomizationUUID from the notification and tosca
622                         // customizations match before comparing their VF Modules UUID's
623                         logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
624                                         + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
625                                         + vfCustomizationUUID);
626
627                         if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
628                                 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
629                                                 + " matches vfNotificationResource CustomizationUUID");                         
630                                 
631                                 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
632                                                 vfCustomizationCategory);
633                         } else {
634                                 logger.debug("Notification VF ResourceCustomizationUUID: "
635                                                 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
636                                                 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
637                         }
638                 }
639         }
640         
641         
642         protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
643                         Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
644                 
645                 logger.debug("VF Category is : " + vfCustomizationCategory);
646                 
647                 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
648                 {
649
650                         String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
651                                         .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
652                         logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);     
653                         
654                         IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();           
655                         
656                         // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
657                         logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + 
658                                                    " matches Tosca VF Customization UUID: " +  vfCustomizationUUID);
659                         
660                         if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
661                                 
662                                 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
663                         
664                                 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
665                                 
666                                 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>(); 
667                                 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
668                                                                 
669                                 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
670                                         
671                                         logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
672                                         List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
673                                                         .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
674                                         IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();     
675                                         
676                                         logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
677                                         
678                                         Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
679                                                         .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
680                                                     .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
681                                                     .findFirst();
682                                         if(matchingObject.isPresent()){
683                                                 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, 
684                                                                                                                                                                                          vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
685                                                 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
686                                         }else
687                                                 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
688                                         
689                                 }
690                                 service.getVnfCustomizations().add(vnfResource);
691                         } else{
692                                 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
693                                                      "Tosca VF Customization UUID: " +  vfCustomizationUUID);
694                         }
695                 }
696         }
697
698         public void processWatchdog(String distributionId, String servideUUID) {
699                 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
700                 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
701                 
702                 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
703                 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
704         }
705
706         protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
707                         VfResourceStructure vfResourceStructure) {
708                 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
709
710                         switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
711                         case ASDCConfiguration.HEAT:
712                         case ASDCConfiguration.HEAT_NESTED:
713                                 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
714                                                 vfModuleArtifact);
715                                 break;
716                         case ASDCConfiguration.HEAT_VOL:
717                                 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
718                                                 vfModuleArtifact);
719                                 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
720                                 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
721                                 break;
722                         case ASDCConfiguration.HEAT_ENV:
723                                 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
724                                 break;
725                         case ASDCConfiguration.HEAT_ARTIFACT:
726                                 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
727                                                 toscaResourceStruct);
728                                 break;
729                         case ASDCConfiguration.HEAT_NET:
730                         case ASDCConfiguration.OTHER:
731                                 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
732                                                 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
733                                                                 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
734                                                 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
735                                 break;
736                         default:
737                                 break;
738
739                         }
740                 }
741         }
742
743         protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
744                         VfModuleArtifact vfModuleArtifact) {
745                 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
746                 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
747                 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
748                         if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
749                                         && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
750                                 return moduleArtifact;
751                         }
752                 }
753                 return null;
754         }
755
756         public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
757                         List<String> listTypes) {
758                 String newFileBody = filebody;
759                 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
760
761                         if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
762
763                                 newFileBody = verifyTheFilePrefixInString(newFileBody,
764                                                 moduleArtifact.getArtifactInfo().getArtifactName());
765                         }
766                 }
767                 return newFileBody;
768         }
769
770         public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
771
772                 String needlePrefix = "file:///";
773                 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
774
775                 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
776                         return body;
777                 }
778
779                 StringBuilder sb = new StringBuilder(body.length());
780
781                 int currentIndex = 0;
782                 int startIndex = 0;
783
784                 while (currentIndex != -1) {
785                         startIndex = currentIndex;
786                         currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
787
788                         if (currentIndex == -1) {
789                                 break;
790                         }
791                         // We append from the startIndex up to currentIndex (start of File
792                         // Name)
793                         sb.append(body.substring(startIndex, currentIndex));
794                         sb.append(filenameToVerify);
795
796                         currentIndex += prefixedFilenameToVerify.length();
797                 }
798
799                 sb.append(body.substring(startIndex));
800
801                 return sb.toString();
802         }
803
804         protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
805                         ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
806                 HeatTemplate heatTemplate = new HeatTemplate();
807                 List<String> typeList = new ArrayList<>();
808                 typeList.add(ASDCConfiguration.HEAT_NESTED);
809                 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
810
811                 heatTemplate.setTemplateBody(
812                                 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
813                 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
814
815                 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
816                         heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
817                 } else {
818                         heatTemplate.setTimeoutMinutes(240);
819                 }
820
821                 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
822                 heatTemplate.setVersion(BigDecimalVersion
823                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
824                 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
825
826                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
827                         heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
828                 } else {
829                         heatTemplate.setArtifactChecksum(MANUAL_RECORD);
830                 }
831
832                 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
833                                 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
834                 heatTemplate.setParameters(heatParam);  
835                 vfModuleArtifact.setHeatTemplate(heatTemplate);
836         }
837
838         protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
839                         VfModuleArtifact vfModuleArtifact) {
840                 HeatEnvironment heatEnvironment = new HeatEnvironment();
841                 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
842                 List<String> typeList = new ArrayList<>();
843                 typeList.add(ASDCConfiguration.HEAT);
844                 typeList.add(ASDCConfiguration.HEAT_VOL);
845                 heatEnvironment.setEnvironment(
846                                 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
847                 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
848                 heatEnvironment.setVersion(BigDecimalVersion
849                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));     
850                 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
851
852                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
853                         heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
854                 } else {
855                         heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
856                 }               
857                 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
858         }
859
860         protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
861                 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
862                 
863                 HeatFiles heatFile = new HeatFiles();   
864                 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
865                 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
866                 heatFile.setFileBody(vfModuleArtifact.getResult());
867                 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
868                 heatFile.setVersion(BigDecimalVersion
869                                 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
870                 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
871                 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
872                         heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
873                 } else {
874                         heatFile.setArtifactChecksum(MANUAL_RECORD);
875                 }
876                 vfModuleArtifact.setHeatFiles(heatFile);
877         }
878
879         protected Service createService(ToscaResourceStructure toscaResourceStructure,
880                         VfResourceStructure vfResourceStructure) {
881
882                 toscaResourceStructure.getServiceMetadata();
883
884                 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
885
886                 Service service = new Service();
887
888                 if (serviceMetadata != null) {
889
890                         if (toscaResourceStructure.getServiceVersion() != null) {
891                                 service.setModelVersion(toscaResourceStructure.getServiceVersion());
892                         }
893
894                         service.setServiceType(serviceMetadata.getValue("serviceType"));
895                         service.setServiceRole(serviceMetadata.getValue("serviceRole"));
896
897                         service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
898                         service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
899                         service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
900                         service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
901
902                         if (vfResourceStructure != null) 
903                                 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
904                                                 
905                         service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
906                         service.setCsar(toscaResourceStructure.getCatalogToscaCsar());                  
907                 }
908                 
909                 
910                 toscaResourceStructure.setCatalogService(service); 
911                 return service;
912         }
913         
914         protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
915
916                 Metadata spMetadata = nodeTemplate.getMetaData();
917                 
918                 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
919                 
920                 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
921                 
922                 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
923                 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
924                 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
925                 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
926                 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));        
927                                 
928                 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
929                 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
930                 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
931                 spCustomizationResource.setSourceService(service);
932                 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
933                 serviceProxyCustomizationSet.add(spCustomizationResource);
934
935                 
936                 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
937                 
938                 return spCustomizationResource;
939         }
940         
941         protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
942
943                 Metadata metadata = nodeTemplate.getMetaData();
944                 
945                 ConfigurationResource configResource = new ConfigurationResource();
946                 
947                 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
948                 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
949                 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
950                 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
951                 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
952                 configResource.setToscaNodeType(nodeTemplate.getType());
953                 
954                 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
955                 
956                 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
957                 
958                 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
959                 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
960                 
961                 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
962                 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
963                 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
964                 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
965                 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
966                 configCustomizationResource.setConfigurationResource(configResource);
967                 configResourceCustomizationSet.add(configCustomizationResource);
968
969                 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);   
970                 
971                 toscaResourceStructure.setCatalogConfigurationResource(configResource);
972                 
973                 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
974                 
975                 return configCustomizationResource;
976         }
977         
978         protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
979                 
980                 Metadata fabricMetadata = nodeTemplate.getMetaData();
981                 
982                 ConfigurationResource configResource = new ConfigurationResource();
983                 
984                 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
985                 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
986                 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
987                 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
988                 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
989                 configResource.setToscaNodeType(nodeTemplate.getType());
990                 
991                 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
992                 
993                 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
994                 
995                 configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
996                 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
997                 
998                 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
999                 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
1000                 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
1001                 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
1002                 configCustomizationResource.setConfigurationResource(configResource);
1003                 configResourceCustomizationSet.add(configCustomizationResource);
1004
1005                 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1006                 
1007                 return configCustomizationResource;
1008         }
1009
1010         protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1011                 ToscaCsar toscaCsar = new ToscaCsar();
1012                 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1013                         toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1014                 } else {
1015                         toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1016                 }
1017                 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1018                 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1019                 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1020                 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1021                 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1022
1023                 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1024         }
1025         
1026         protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1027                 VnfcCustomization vnfcCustomization = null;
1028                 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1029                         if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1030                                 vnfcCustomization = vnfcCustom;
1031                         }
1032                 }
1033                 
1034                 if(vnfcCustomization==null)
1035                         vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1036                 
1037                 return vnfcCustomization;
1038         }
1039         
1040         protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1041                 CvnfcCustomization cvnfcCustomization = null;
1042                 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1043                         if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1044                                 cvnfcCustomization = cvnfcCustom;
1045                         }
1046                 }
1047                 
1048                 if(cvnfcCustomization==null)
1049                         cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1050                 
1051                 return cvnfcCustomization;
1052         }
1053
1054         protected  NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1055                         ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1056                 
1057                 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1058                                 if(networkResourceCustomization==null){
1059                         networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1060                                         toscaResourceStructure);
1061                                         
1062                         NetworkResource networkResource = findExistingNetworkResource(service,
1063                                         networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1064                                         if(networkResource == null)
1065                                 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1066                                                 aicMax, aicMin);
1067
1068                                         networkResource.addNetworkResourceCustomization(networkResourceCustomization);          
1069                                         networkResourceCustomization.setNetworkResource(networkResource);
1070                                 }
1071                 return networkResourceCustomization;
1072         }
1073         
1074         protected  NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1075                 NetworkResource networkResource = null;
1076                 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1077                         if (networkCustom.getNetworkResource() != null
1078                                         && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1079                                         networkResource = networkCustom.getNetworkResource();
1080                         }
1081                 }
1082                 if(networkResource==null)
1083                         networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1084                 
1085                 return networkResource;
1086         }
1087         
1088         protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1089                         ToscaResourceStructure toscaResourceStructure) {
1090                 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1091                 networkResourceCustomization.setModelInstanceName(
1092                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1093                 networkResourceCustomization.setModelCustomizationUUID(
1094                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));                
1095
1096                 networkResourceCustomization.setNetworkTechnology(
1097                                 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1098                                                 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1099                 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1100                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1101                 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1102                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1103                 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1104                                 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1105                 return networkResourceCustomization;
1106         }
1107
1108         protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1109                         ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1110                 NetworkResource networkResource = new NetworkResource();
1111                 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1112                                 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1113
1114                 if ("true".equalsIgnoreCase(providerNetwork)) {
1115                         networkResource.setNeutronNetworkType(PROVIDER);
1116                 } else {
1117                         networkResource.setNeutronNetworkType(BASIC);
1118                 }
1119
1120                 networkResource.setModelName(
1121                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1122
1123                 networkResource.setModelInvariantUUID(
1124                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1125                 networkResource.setModelUUID(
1126                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1127                 networkResource.setModelVersion(
1128                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1129
1130                 networkResource.setAicVersionMax(aicMax);               
1131                 networkResource.setAicVersionMin(aicMin);
1132                 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1133                 networkResource.setDescription(
1134                                 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1135                 networkResource.setOrchestrationMode(HEAT);     
1136                 networkResource.setHeatTemplate(heatTemplate); 
1137                 return networkResource;
1138         }
1139         
1140         protected  CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1141                         ToscaResourceStructure toscaResourceStructure, Service service) {
1142
1143                 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1144
1145                 // **** Build Object to populate Collection_Resource table
1146                 CollectionResource collectionResource = new CollectionResource();
1147
1148                 collectionResource
1149                                 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1150                 collectionResource.setModelInvariantUUID(
1151                                 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1152                 collectionResource
1153                                 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1154                 collectionResource
1155                                 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1156                 collectionResource
1157                                 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1158                 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1159
1160                 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1161
1162                 // **** Build object to populate Collection_Resource_Customization table
1163                 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1164                 
1165                 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1166                                 "cr_function"));
1167                 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1168                                 "cr_role"));
1169                 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1170                                 "cr_type"));
1171
1172                 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1173                 ncfc.setModelCustomizationUUID(
1174                                 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1175                 
1176                 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1177                 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1178
1179                 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1180
1181                 ncfc.setCollectionResource(collectionResource);
1182                 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1183                 
1184                 //*** Build object to populate the Instance_Group table
1185                 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1186                                 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1187                                                 "org.openecomp.groups.NetworkCollection");
1188                 
1189                 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1190
1191                 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1192
1193                 for (Group group : groupList) { 
1194                         
1195                         NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1196                         Metadata instanceMetadata = group.getMetadata();
1197                         networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1198                         networkInstanceGroup
1199                                         .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1200                         networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1201                         networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1202                         networkInstanceGroup.setToscaNodeType(group.getType());
1203                         networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1204                                                                                                                                                         // Role
1205                         networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1206                                                                                                                                                 // type
1207                         networkInstanceGroup.setCollectionResource(collectionResource);
1208                 
1209                         // ****Build object to populate
1210                         // Collection_Resource_Instance_Group_Customization table
1211                         CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1212                         crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1213                         crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1214                         crInstanceGroupCustomization.setModelCustomizationUUID(
1215                                         networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1216                 
1217                         String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
1218                         String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
1219                         if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1220                                         fixedQuantity + "_quantity") != null) {
1221
1222                                 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
1223                                                 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1224                                                                 fixedQuantity + "_quantity"))); 
1225                         }
1226                 
1227                         crInstanceGroupCustomization.setDescription(
1228                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1229                                                         instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1230                                                                         + "_network_collection_description"));
1231                         crInstanceGroupCustomization.setFunction(
1232                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1233                                                         instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1234                                                                         + "_network_collection_function"));
1235                         crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1236                         collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1237
1238                         networkInstanceGroup
1239                                         .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1240
1241                         networkInstanceGroupList.add(networkInstanceGroup);
1242
1243                 //}
1244
1245                 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1246
1247                 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1248                                 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1249                 
1250                 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1251                 
1252                 //*****Build object to populate the NetworkResource table
1253                 NetworkResource networkResource = new NetworkResource();
1254                 
1255                 for(NodeTemplate vlNodeTemplate : vlNodeList){
1256
1257                         String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1258                                         vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1259
1260                         if ("true".equalsIgnoreCase(providerNetwork)) {
1261                                 networkResource.setNeutronNetworkType(PROVIDER);
1262                         } else {
1263                                 networkResource.setNeutronNetworkType(BASIC);
1264                         }
1265
1266                         networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1267
1268                         networkResource.setModelInvariantUUID(
1269                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1270                         networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1271                         networkResource
1272                                         .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1273
1274                         networkResource.setAicVersionMax(
1275                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1276                         
1277                         TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1278                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1279                         
1280                         if (tempNetworkLookUp != null ) {       
1281                                         
1282                                 HeatTemplate heatTemplate = heatRepo
1283                                                 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1284                                         networkResource.setHeatTemplate(heatTemplate);
1285                                         
1286                                         networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1287                                         
1288                         }
1289
1290                         networkResource.setToscaNodeType(vlNodeTemplate.getType());
1291                         networkResource
1292                                         .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1293                         networkResource.setOrchestrationMode(HEAT);
1294                         
1295                         // Build object to populate the
1296                         // Collection_Network_Resource_Customization table
1297                         for (NodeTemplate memberNode : group.getMemberNodes()) {
1298                                 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1299                         }
1300
1301                         collectionNetworkResourceCustomization.setModelCustomizationUUID(
1302                                         vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1303
1304                         collectionNetworkResourceCustomization.setNetworkTechnology(
1305                                         toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1306                                                         SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1307                         collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1308                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1309                         collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1310                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1311                         collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1312                                         .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1313                         collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1314                         collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1315                         collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1316                         
1317                         collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1318                    }
1319
1320                 }
1321                 
1322                 return collectionNetworkResourceCustomization;
1323         }
1324         
1325         protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1326                         VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1327
1328                         Metadata instanceMetadata = group.getMetadata();
1329                         // Populate InstanceGroup
1330                         VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1331                         
1332                         vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1333                         vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1334                         vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1335                         vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1336                         vfcInstanceGroup.setToscaNodeType(group.getType());
1337                         vfcInstanceGroup.setRole("SUB-INTERFACE");   // Set Role
1338                         vfcInstanceGroup.setType(InstanceGroupType.VNFC);  // Set type  
1339                         
1340                         //Populate VNFCInstanceGroupCustomization
1341                         VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1342                         
1343                         vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1344                         vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1345                         vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1346                                                 
1347                         String getInputName = null;
1348                         String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function"); 
1349                         if (groupProperty != null) { 
1350                         int getInputIndex = groupProperty.indexOf("{get_input="); 
1351                                 if (getInputIndex > -1) { 
1352                                         getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); 
1353                                 } 
1354                         }
1355                         vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1356                         
1357                         vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1358                         vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);            
1359                         
1360                 return vfcInstanceGroupCustom;
1361
1362         }
1363                 
1364         protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1365                         ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1366                         IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1367                 
1368                 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1369                                 vfModuleData.getVfModuleModelCustomizationUUID());
1370                 if(vfModuleCustomization == null){              
1371                         VfModule vfModule = findExistingVfModule(vnfResource,
1372                                         nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1373                         Metadata vfMetadata = group.getMetadata();
1374                         if(vfModule==null)
1375                                 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1376                         
1377                         vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1378                         setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1379                                         vfMetadata);
1380                         vfModuleCustomization.setVfModule(vfModule);
1381                         vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1382                         vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1383                 } else {
1384                         vfResourceStructure.setAlreadyDeployed(true);
1385                 }
1386                 
1387                 //******************************************************************************************************************
1388                 //* Extract VFC's and CVFC's then add them to VFModule
1389                 //******************************************************************************************************************
1390                 
1391                 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();                
1392                 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1393                 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1394
1395                 // Extract CVFC lists
1396                 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
1397                                                 
1398                 for(NodeTemplate cvfcTemplate : cvfcList) {
1399                                                                         
1400                         CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1401                         
1402                         if(existingCvnfcCustomization == null){
1403                         
1404                         //Extract associated VFC - Should always be just one
1405                         List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1406                                                 
1407                         for(NodeTemplate vfcTemplate : vfcList) {
1408                                 
1409                                 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1410                                 VnfcCustomization existingVnfcCustomization = null;
1411                                 
1412                                 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1413                                         
1414                                 // Only Add Abstract VNFC's to our DB, ignore all others
1415                                 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1416                                         vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1417                                         vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1418                                         vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1419                                         vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1420                                         vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1421         
1422                                         vnfcCustomization.setModelVersion(
1423                                                         testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1424                                         vnfcCustomization.setDescription(
1425                                                         testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1426                                         vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1427                                         
1428                                         vnfcCustomizations.add(vnfcCustomization);
1429                                         existingVnfcSet.add(vnfcCustomization);
1430                                 }
1431                         
1432                         // 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.
1433                         if(vnfcCustomization.getModelCustomizationUUID() != null){
1434                                 
1435                                 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1436                                 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1437                                 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1438                                 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1439                                 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1440                                 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1441         
1442                                 cvnfcCustomization.setModelVersion(
1443                                                 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1444                                 cvnfcCustomization.setDescription(
1445                                                 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1446                                 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1447                                 
1448                                 if(existingVnfcCustomization != null){
1449                                         cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1450                                 }else{
1451                                         cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1452                                 }
1453                                 
1454                                 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1455                                 cvnfcCustomization.setVnfResourceCustomization(vnfResource);                                    
1456                                 
1457                                 cvnfcCustomizations.add(cvnfcCustomization);
1458                                 existingCvnfcSet.add(cvnfcCustomization);
1459                         
1460                         //*****************************************************************************************************************************************
1461                         //* Extract Fabric Configuration
1462                         //*****************************************************************************************************************************************
1463                         
1464                         List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
1465                                                                 
1466                         for(NodeTemplate fabricTemplate : fabricConfigList) {
1467                                                                                 
1468                                 ConfigurationResource fabricConfig = null;
1469                                 
1470                                 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1471                                                                 
1472                                 if(existingConfig == null){
1473                                         
1474                                         ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1475                                         
1476                                         fabricConfig = fabricConfigCustomization.getConfigurationResource();
1477                                         
1478                                         service.getConfigurationCustomizations().add(fabricConfigCustomization);
1479                                 }else {
1480                                         fabricConfig = existingConfig;
1481                                 }
1482                                 
1483                                 
1484                                 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure, 
1485                                                                                                                                                            vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
1486                                 
1487                                 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1488                         }
1489                         
1490                         }
1491                         
1492                    }
1493                         
1494                   }
1495                         
1496                 } 
1497                 
1498                 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1499                 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1500                 
1501                 return vfModuleCustomization;
1502         }
1503         
1504         protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct, 
1505             VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1506             ConfigurationResource configResource) {
1507
1508                 Metadata fabricMetadata = fabricTemplate.getMetaData();
1509                 
1510                 
1511                 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1512                 
1513                 vfModuleToCvnfc.setConfigurationResource(configResource);
1514                 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1515                 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1516                 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1517                 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1518                 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1519                 vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
1520                 
1521                 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
1522                 
1523                 if(policyList != null){
1524                         for(Policy policy : policyList){
1525                                 vfModuleToCvnfc.setPolicyName(policy.getName());
1526                         }
1527                 }
1528                 
1529                 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
1530                 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
1531                 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
1532                 
1533                 return vfModuleToCvnfc;
1534         }
1535                 
1536         protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1537                 ConfigurationResource configResource = null;
1538                 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1539                         if (configurationResourceCustom.getConfigurationResource() != null
1540                                         && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1541                                 configResource = configurationResourceCustom.getConfigurationResource();
1542                         }
1543                 }
1544                 if(configResource==null)
1545                         configResource = configRepo.findResourceByModelUUID(modelUUID);
1546                 
1547                 return configResource;
1548         }
1549         
1550         protected ServiceProxyResourceCustomization findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelCustomizationUUID) {
1551                 ServiceProxyResourceCustomization serviceProxyResourceCustomization = null;
1552                 for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){
1553                         if (serviceProxyResourceCustom != null
1554                                         && serviceProxyResourceCustom.getModelCustomizationUUID().equals(modelCustomizationUUID)) {
1555                                 serviceProxyResourceCustomization = serviceProxyResourceCustom;
1556                         }
1557                 }
1558                 if(serviceProxyResourceCustomization==null)
1559                         serviceProxyResourceCustomization = serviceProxyCustomizationRepo.findResourceByModelCustomizationUUID(modelCustomizationUUID);
1560                 
1561                 return serviceProxyResourceCustomization;
1562         }
1563         
1564         protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1565                         String vfModuleModelCustomizationUUID) {
1566                 VfModuleCustomization vfModuleCustomization = null;
1567                 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1568                         if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1569                                 vfModuleCustomization = vfModuleCustom;
1570                         }
1571                 }
1572                 if(vfModuleCustomization==null)
1573                         vfModuleCustomization = vfModuleCustomizationRepo
1574                                         .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1575                 
1576                 return vfModuleCustomization;
1577         }
1578
1579         protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1580                 VfModule vfModule = null;
1581                 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1582                         if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1583                                 vfModule = vfModuleCustom.getVfModule();
1584                         }
1585                 }
1586                 if(vfModule==null)
1587                         vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1588                 
1589                 return vfModule;
1590         }
1591
1592         protected VfModuleCustomization createVfModuleCustomization(Group group,
1593                         ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1594                 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1595                 
1596                 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1597
1598                 vfModuleCustomization.setVfModule(vfModule);
1599
1600                 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1601                                 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1602                 if (initialCount != null && initialCount.length() > 0) {
1603                         vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1604                 }
1605
1606                 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1607                                 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1608
1609                 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1610                                 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1611                 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1612                         vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1613                 }
1614
1615                 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1616                                 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1617
1618                 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1619                                 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1620                 if (maxInstances != null && maxInstances.length() > 0) {
1621                         vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1622                 }
1623
1624                 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1625                                 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1626                 if (minInstances != null && minInstances.length() > 0) {
1627                         vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1628                 }
1629                 return vfModuleCustomization;
1630         }
1631
1632         protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1633                         IVfModuleData vfModuleData, Metadata vfMetadata) {
1634                 VfModule vfModule = new VfModule();
1635                 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1636
1637                 if(vfModuleModelUUID == null) {
1638                         vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1639                                         SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1640                 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1641                         vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1642                 }
1643
1644                 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1645                                 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1646                 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1647                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1648                 vfModule.setModelUUID(vfModuleModelUUID);
1649                 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1650                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1651                 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1652                                 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1653
1654                 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1655                                 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1656                 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1657                         vfModule.setIsBase(true);
1658                 } else {
1659                         vfModule.setIsBase(false);
1660                 }
1661                 return vfModule;
1662         }
1663
1664         protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1665                         VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1666                         Metadata vfMetadata) {
1667                 
1668                 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1669                                 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1670                                                 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1671                                                                 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1672                                 .findFirst();
1673
1674                 if (matchingObject.isPresent()) {
1675                         List<HeatFiles> heatFilesList = new ArrayList<>();
1676                         List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1677                         List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1678                         HeatTemplate parentHeatTemplate = new HeatTemplate();
1679                         String parentArtifactType = null;
1680                         Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1681                         for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1682                                 
1683                                 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1684                                 
1685                                 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1686                                         checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1687                                                         childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1688                                 }
1689                                 
1690                                 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1691                                         parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1692                                         
1693                                         if(!childNestedHeatTemplates.isEmpty()){
1694                                         
1695                                                 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1696                                                         volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1697                                                 } else {
1698                                                         heatChildTemplates.add(childNestedHeatTemplates.get(0));
1699                                                 }
1700                                         }
1701                                 }
1702                                 
1703                         }
1704                         if(!heatFilesList.isEmpty()){
1705                                 vfModule.setHeatFiles(heatFilesList);
1706                         }
1707                         
1708                         
1709                         // Set all Child Templates related to HEAT_VOLUME
1710                         if(!volumeHeatChildTemplates.isEmpty()){
1711                                 if(vfModule.getVolumeHeatTemplate() != null){
1712                                         vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1713                                 }else{
1714                                         logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1715                                 }
1716                         }
1717                         
1718                         // Set all Child Templates related to HEAT
1719                         if(!heatChildTemplates.isEmpty()){
1720                                 if(vfModule.getModuleHeatTemplate() != null){
1721                                         vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1722                                 }else{
1723                                         logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1724                                 }
1725                         }
1726                 }
1727         }
1728
1729         protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1730                         List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1731                         HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1732                 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1733                         vfModuleArtifact.incrementDeployedInDB();
1734                         vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1735                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1736                         vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1737                         VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1738                         vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1739                         vfModuleArtifact.incrementDeployedInDB();
1740                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1741                         if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1742                                 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1743                         } else { 
1744                         vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1745                         }
1746                         vfModuleArtifact.incrementDeployedInDB();
1747                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1748                         heatFilesList.add(vfModuleArtifact.getHeatFiles());                                                     
1749                         vfModuleArtifact.incrementDeployedInDB();
1750                 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1751                         nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());                            
1752                         vfModuleArtifact.incrementDeployedInDB();
1753                 }
1754         }
1755
1756         protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1757                         ToscaResourceStructure toscaResourceStructure, Service service) {
1758                 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1759                                 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1760                 if(vnfResourceCustomization == null){           
1761                         VnfResource vnfResource = findExistingVnfResource(service,
1762                                         vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1763                         
1764                         if(vnfResource==null)
1765                                 vnfResource=createVnfResource(vfNodeTemplate);
1766                         
1767                         vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1768                                         vnfResource);
1769                         vnfResourceCustomization.setVnfResources(vnfResource);
1770                         vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1771                         
1772                         // Fetch VNFC Instance Group Info                               
1773                         List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1774                                         .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1775                                                         "org.openecomp.groups.VfcInstanceGroup");
1776                                 
1777                         for (Group group : groupList) { 
1778                                 
1779                                         VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1780                                         
1781                                         vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);                                
1782                         }                       
1783                 }
1784                 return vnfResourceCustomization;
1785         }
1786         
1787         protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1788                 VnfResource vnfResource = null;
1789                 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1790                         if (vnfResourceCustom.getVnfResources() != null
1791                                         && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1792                                 vnfResource = vnfResourceCustom.getVnfResources();
1793                         }
1794                 }
1795                 if(vnfResource==null)
1796                         vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1797                 
1798                 return vnfResource;
1799         }
1800
1801         protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1802                         ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1803                 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1804                 vnfResourceCustomization.setModelCustomizationUUID(
1805                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1806                 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1807
1808                 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1809                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1810                 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1811                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1812                 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1813                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1814                 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1815                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1816
1817                 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1818                                 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1819
1820                 vnfResourceCustomization.setVnfResources(vnfResource);
1821                 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1822                                 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));  
1823
1824                 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1825                                 .getCapabilitiesOf(vfNodeTemplate);
1826
1827                 if (vnfCustomizationCapability != null) {
1828                         CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1829
1830                         if (capAssign != null) {
1831                                 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1832                                                 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1833                                 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1834                                                 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1835                         }
1836
1837                 }
1838                 
1839                 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1840                 
1841                 return vnfResourceCustomization;
1842         }
1843
1844         protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1845                 VnfResource vnfResource = new VnfResource();
1846                 vnfResource.setModelInvariantUUID(
1847                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1848                 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1849                 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1850
1851                 vnfResource.setModelVersion(
1852                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1853                 vnfResource.setDescription(
1854                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1855                 vnfResource.setOrchestrationMode(HEAT);
1856                 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1857                 vnfResource.setAicVersionMax(
1858                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1859                 vnfResource.setAicVersionMin(
1860                                 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1861                 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1862                 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1863                 
1864                 return vnfResource;
1865         }
1866
1867         protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1868                         ToscaResourceStructure toscaResourceStructure, Service service) {
1869                 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1870                                 .findOneByModelCustomizationUUID(
1871                                 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1872                         
1873                 if(allottedResourceCustomization == null){                      
1874                         AllottedResource allottedResource = findExistingAllottedResource(service,
1875                                         nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1876                         
1877                         if(allottedResource==null)
1878                                 allottedResource=createAR(nodeTemplate);
1879                         
1880                         toscaResourceStructure.setAllottedResource(allottedResource);                   
1881                         allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1882                         allottedResourceCustomization.setAllottedResource(allottedResource);
1883                         allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1884                 }
1885                 return allottedResourceCustomization;
1886         }
1887         
1888         protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1889                 AllottedResource allottedResource = null;
1890                 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1891                         if (allottedResourceCustom.getAllottedResource() != null
1892                                         && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1893                                 allottedResource = allottedResourceCustom.getAllottedResource();
1894                         }
1895                 }
1896                 if(allottedResource==null)
1897                         allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1898                 
1899                 return allottedResource;
1900         }
1901         
1902         protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1903                         ToscaResourceStructure toscaResourceStructure) {
1904                 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1905                 allottedResourceCustomization.setModelCustomizationUUID(
1906                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1907                 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1908                 
1909
1910                 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1911                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1912                 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1913                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1914                 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1915                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1916                 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1917                                 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1918
1919                 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1920                 
1921                 if(vfcNodes != null){
1922                         for(NodeTemplate vfcNode : vfcNodes){
1923                         
1924                                 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1925                                 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1926                                 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1927                         }
1928                 }
1929                 
1930
1931                 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1932                                 .getCapabilitiesOf(nodeTemplate);
1933
1934                 if (arCustomizationCapability != null) {
1935                         CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1936
1937                         if (capAssign != null) {
1938                                 allottedResourceCustomization.setMinInstances(
1939                                                 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1940                                                                 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1941                                 allottedResourceCustomization.setMaxInstances(
1942                                                 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1943                                                                 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1944                         }
1945                 }
1946                 return allottedResourceCustomization;
1947         }
1948
1949         protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1950                 AllottedResource allottedResource = new AllottedResource();
1951                 allottedResource
1952                 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1953                 allottedResource.setModelInvariantUUID(
1954                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1955                 allottedResource
1956                 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1957                 allottedResource
1958                 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1959                 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1960                 allottedResource.setSubcategory(
1961                                 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1962                 allottedResource
1963                 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1964                 return allottedResource;
1965         }
1966
1967         protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1968                 // Scan the payload downloadResult and extract the HeatTemplate
1969                 // parameters
1970                 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1971                 return yamlEditor.getParameterList(artifactUUID);
1972         }       
1973
1974         protected String testNull(Object object) {
1975
1976                 if (object == null) {
1977                         return null;
1978                 } else if (object.equals("NULL")) {
1979                         return null;
1980                 } else if (object instanceof Integer) {
1981                         return object.toString();
1982                 } else if (object instanceof String) {
1983                         return (String) object;
1984                 } else {
1985                         return "Type not recognized";
1986                 }
1987         }
1988         
1989         protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1990                         VfModuleArtifact heatNestedArtifact) {
1991
1992                 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1993                                 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1994                         for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1995                                         .getArtifactInfo().getRelatedArtifacts()) {
1996                                 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1997                                         return ASDCConfiguration.HEAT;
1998                                 }
1999
2000                         }
2001                 } 
2002                 
2003                 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null 
2004                                 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2005                                                 .getRelatedArtifacts() != null) {
2006                         for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2007                                         .get(0).getArtifactInfo().getRelatedArtifacts()) {
2008                                 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2009                                         return ASDCConfiguration.HEAT_VOL;
2010                                 }
2011                         
2012                         }
2013                 }
2014                 
2015                 // Does not belong to anything
2016                 return null;
2017                         
2018         }
2019         
2020         protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2021
2022                 return vfResourceStructure.getNotification().getServiceName() + "/"
2023                                 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2024         }
2025
2026         protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2027                 
2028                 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2029                                 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2030         }
2031         
2032         
2033         protected static Timestamp getCurrentTimeStamp() {
2034                 
2035                 return new Timestamp(new Date().getTime());
2036         }
2037
2038 }