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