2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.asdc.installer.heat;
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;
33 import java.util.Optional;
35 import java.util.stream.Collectors;
37 import org.hibernate.exception.ConstraintViolationException;
38 import org.hibernate.exception.LockAcquisitionException;
39 import org.onap.sdc.api.notification.IArtifactInfo;
40 import org.onap.sdc.api.notification.IResourceInstance;
41 import org.onap.sdc.api.notification.IStatusData;
42 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
43 import org.onap.sdc.tosca.parser.enums.SdcTypes;
44 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
45 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
46 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
47 import org.onap.sdc.toscaparser.api.Group;
48 import org.onap.sdc.toscaparser.api.NodeTemplate;
49 import org.onap.sdc.toscaparser.api.Policy;
50 import org.onap.sdc.toscaparser.api.Property;
51 import org.onap.sdc.toscaparser.api.RequirementAssignment;
52 import org.onap.sdc.toscaparser.api.RequirementAssignments;
53 import org.onap.sdc.toscaparser.api.elements.Metadata;
54 import org.onap.sdc.toscaparser.api.functions.GetInput;
55 import org.onap.sdc.toscaparser.api.parameters.Input;
56 import org.onap.sdc.utils.DistributionStatusEnum;
57 import org.onap.so.asdc.client.ASDCConfiguration;
58 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
59 import org.onap.so.asdc.installer.ASDCElementInfo;
60 import org.onap.so.asdc.installer.BigDecimalVersion;
61 import org.onap.so.asdc.installer.IVfModuleData;
62 import org.onap.so.asdc.installer.ToscaResourceStructure;
63 import org.onap.so.asdc.installer.VfModuleArtifact;
64 import org.onap.so.asdc.installer.VfModuleStructure;
65 import org.onap.so.asdc.installer.VfResourceStructure;
66 import org.onap.so.asdc.util.YamlEditor;
67 import org.onap.so.db.catalog.beans.AllottedResource;
68 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
69 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
70 import org.onap.so.db.catalog.beans.CollectionResource;
71 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
72 import org.onap.so.db.catalog.beans.ConfigurationResource;
73 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
74 import org.onap.so.db.catalog.beans.CvnfcCustomization;
75 import org.onap.so.db.catalog.beans.HeatEnvironment;
76 import org.onap.so.db.catalog.beans.HeatFiles;
77 import org.onap.so.db.catalog.beans.HeatTemplate;
78 import org.onap.so.db.catalog.beans.HeatTemplateParam;
79 import org.onap.so.db.catalog.beans.InstanceGroupType;
80 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
81 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
82 import org.onap.so.db.catalog.beans.NetworkResource;
83 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
84 import org.onap.so.db.catalog.beans.Service;
85 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
86 import org.onap.so.db.catalog.beans.SubType;
87 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
88 import org.onap.so.db.catalog.beans.ToscaCsar;
89 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
90 import org.onap.so.db.catalog.beans.VfModule;
91 import org.onap.so.db.catalog.beans.VfModuleCustomization;
92 import org.onap.so.db.catalog.beans.VnfResource;
93 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
94 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
95 import org.onap.so.db.catalog.beans.VnfcCustomization;
96 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
97 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
98 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
99 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
100 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
101 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
102 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
103 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
104 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
105 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
106 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
107 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
108 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
109 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
110 import org.onap.so.db.catalog.data.repository.ServiceRepository;
111 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
112 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
113 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
114 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
115 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
116 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
117 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
118 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
119 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
120 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
121 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
122 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
123 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
124 import org.onap.so.logger.MessageEnum;
125 import org.onap.so.logger.MsoLogger;
126 import org.springframework.beans.factory.annotation.Autowired;
127 import org.springframework.stereotype.Component;
128 import org.springframework.transaction.annotation.Transactional;
130 import com.fasterxml.jackson.core.JsonProcessingException;
131 import com.fasterxml.jackson.databind.ObjectMapper;
134 public class ToscaResourceInstaller {
136 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
138 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
140 protected static final String SCALABLE = "scalable";
142 protected static final String BASIC = "BASIC";
144 protected static final String PROVIDER = "PROVIDER";
146 protected static final String HEAT = "HEAT";
148 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
150 protected static final String MSO = "SO";
154 protected ServiceRepository serviceRepo;
157 protected InstanceGroupRepository instanceGroupRepo;
160 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
163 protected CollectionResourceRepository collectionRepo;
166 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
169 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
172 protected ConfigurationResourceRepository configRepo;
175 protected VnfResourceRepository vnfRepo;
178 protected VnfCustomizationRepository vnfCustomizationRepo;
181 protected VFModuleRepository vfModuleRepo;
184 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
187 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
190 protected VnfcCustomizationRepository vnfcCustomizationRepo;
193 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
196 protected AllottedResourceRepository allottedRepo;
199 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
202 protected NetworkResourceRepository networkRepo;
205 protected HeatTemplateRepository heatRepo;
208 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
211 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
213 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
215 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
218 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
221 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
223 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
225 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
226 boolean status = false;
227 VfResourceStructure vfResourceStructure = vfResourceStruct;
229 status = vfResourceStructure.isDeployedSuccessfully();
230 } catch (RuntimeException e) {
234 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
235 if(existingService != null)
238 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
239 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
240 vfResourceStructure.getNotification().getServiceName(),
241 BigDecimalVersion.castAndCheckNotificationVersionToString(
242 vfResourceStructure.getNotification().getServiceVersion()),
243 vfResourceStructure.getNotification().getServiceUUID(),
244 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
245 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
246 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
247 watchdogCDStatusRepository.saveAndFlush(wdStatus);
249 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
250 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
251 vfResourceStructure.getNotification().getServiceName(),
252 BigDecimalVersion.castAndCheckNotificationVersionToString(
253 vfResourceStructure.getNotification().getServiceVersion()),
254 vfResourceStructure.getNotification().getServiceUUID(),
255 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
258 } catch (Exception e) {
259 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
260 "Exception - isResourceAlreadyDeployed");
261 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
265 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
266 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
267 + " and ComponentName " + iStatus.getComponentName());
270 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
271 iStatus.getComponentName());
272 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
273 watchdogCDStatusRepository.save(cdStatus);
275 } catch (Exception e) {
276 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
277 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
281 @Transactional(rollbackFor = { ArtifactInstallerException.class })
282 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
283 throws ArtifactInstallerException {
284 VfResourceStructure vfResourceStructure = vfResourceStruct;
285 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
287 // PCLO: in case of deployment failure, use a string that will represent
288 // the type of artifact that failed...
289 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
291 createToscaCsar(toscaResourceStruct);
292 createService(toscaResourceStruct, vfResourceStruct);
293 Service service = toscaResourceStruct.getCatalogService();
294 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
297 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
299 Metadata metadata = nodeTemplate.getMetaData();
300 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
301 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
302 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
303 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
304 vfCustomizationCategory);
307 processResourceSequence(toscaResourceStruct, service);
308 processVFResources(toscaResourceStruct, service, vfResourceStructure);
309 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
310 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
311 processNetworks(toscaResourceStruct, service);
312 // process Network Collections
313 processNetworkCollections(toscaResourceStruct, service);
314 // Process Service Proxy & Configuration
315 processServiceProxyAndConfiguration(toscaResourceStruct, service);
317 serviceRepo.save(service);
319 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
320 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
321 watchdogCDStatusRepository.save(status);
323 toscaResourceStruct.setSuccessfulDeployment();
325 } catch (Exception e) {
326 logger.debug("Exception :", e);
327 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
328 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
329 watchdogCDStatusRepository.save(status);
330 Throwable dbExceptionToCapture = e;
331 while (!(dbExceptionToCapture instanceof ConstraintViolationException
332 || dbExceptionToCapture instanceof LockAcquisitionException)
333 && (dbExceptionToCapture.getCause() != null)) {
334 dbExceptionToCapture = dbExceptionToCapture.getCause();
337 if (dbExceptionToCapture instanceof ConstraintViolationException
338 || dbExceptionToCapture instanceof LockAcquisitionException) {
339 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
340 vfResourceStructure.getResourceInstance().getResourceName(),
341 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
343 String elementToLog = (!artifactListForLogging.isEmpty()
344 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
345 : "No element listed");
346 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
347 "Exception caught during installation of "
348 + vfResourceStructure.getResourceInstance().getResourceName()
349 + ". Transaction rollback",
351 throw new ArtifactInstallerException("Exception caught during installation of "
352 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
358 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
359 ISdcCsarHelper iSdcCsarHelper) {
361 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
362 nodes.addAll(nodeTemplates);
364 for (NodeTemplate nodeTemplate : nodeTemplates) {
365 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
366 List<RequirementAssignment> reqAs = requirement.getAll();
367 for (RequirementAssignment ra : reqAs) {
368 String reqNode = ra.getNodeTemplateName();
369 for (NodeTemplate rNode : resultList) {
370 if (rNode.getName().equals(reqNode)) {
371 if(!resultList.contains(nodeTemplate)) {
372 resultList.add(nodeTemplate);
374 if(nodes.contains(nodeTemplate)) {
375 nodes.remove(nodeTemplate);
383 if (!nodes.isEmpty()) {
384 getRequirementList(resultList, nodes, iSdcCsarHelper);
390 // This method retrieve resource sequence from csar file
391 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
392 List<String> resouceSequence = new ArrayList<String>();
393 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
395 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
396 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
397 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
398 nodes.addAll(nodeTemplates);
400 for (NodeTemplate nodeTemplate : nodeTemplates) {
401 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
403 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
404 resultList.add(nodeTemplate);
405 nodes.remove(nodeTemplate);
409 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
411 for (NodeTemplate node : resultList) {
412 String templateName = node.getMetaData().getValue("name");
413 if (!resouceSequence.contains(templateName)) {
414 resouceSequence.add(templateName);
418 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
419 service.setResourceOrder(resourceSeqStr);
420 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
423 private static String CUSTOMIZATION_UUID = "customizationUUID";
425 private static String getValue(Object value, List<Input> servInputs) {
426 String output = null;
427 if(value instanceof Map) {
428 // currently this logic handles only one level of nesting.
429 return ((LinkedHashMap) value).values().toArray()[0].toString();
430 } else if(value instanceof GetInput) {
431 String inputName = ((GetInput)value).getInputName();
433 for(Input input : servInputs) {
434 if(input.getName().equals(inputName)) {
435 // keep both input name and default value
436 // if service input does not supplies value the use default value
437 String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
438 output = inputName + "|" + defaultValue;// return default value
443 output = value != null ? value.toString() : "";
445 return output; // return property value
448 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
449 Map<String, String> resouceRequest = new HashMap<>();
450 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
452 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
453 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
454 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
455 if(nodeTemplateOpt.isPresent()) {
456 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
457 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
459 for(String key : resourceProperties.keySet()) {
460 Property property = resourceProperties.get(key);
462 String value = getValue(property.getValue(), serInput);
463 resouceRequest.put(key, value);
468 ObjectMapper objectMapper = new ObjectMapper();
469 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
471 jsonStr = jsonStr.replace("\"", "\\\"");
472 logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
474 } catch (JsonProcessingException e) {
475 logger.error("resource input could not be deserialized for resource customization id ("
476 + resourceCustomizationUuid + ")");
477 throw new ArtifactInstallerException("resource input could not be parsed", e);
481 protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
482 Service service) throws ArtifactInstallerException {
483 List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
485 if (nodeTemplatesVLList != null) {
486 for (NodeTemplate vlNode : nodeTemplatesVLList) {
487 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
489 TempNetworkHeatTemplateLookup tempNetworkLookUp =
490 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
492 if (tempNetworkLookUp != null) {
493 HeatTemplate heatTemplate =
494 heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
495 if (heatTemplate != null) {
496 NetworkResourceCustomization networkCustomization =
497 createNetwork (vlNode,
500 tempNetworkLookUp.getAicVersionMax (),
501 tempNetworkLookUp.getAicVersionMin (),
503 service.getNetworkCustomizations ().add (networkCustomization);
505 throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
506 + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
509 NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
515 service.getNetworkCustomizations().add (networkCustomization);
516 logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
517 + networkResourceModelName);
524 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
525 List<NodeTemplate> allottedResourceList) {
526 if (allottedResourceList != null) {
527 for (NodeTemplate allottedNode : allottedResourceList) {
528 service.getAllottedCustomizations()
529 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
534 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
536 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
538 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
540 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();
541 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
543 ServiceProxyResourceCustomization serviceProxy = null;
545 if (serviceProxyResourceList != null) {
546 for (NodeTemplate spNode : serviceProxyResourceList) {
547 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
549 serviceProxyList.add(serviceProxy);
551 for (NodeTemplate configNode : configurationNodeTemplatesList) {
553 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
554 for (RequirementAssignment requirement : requirementsList) {
555 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
556 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
558 configurationResourceList.add(configurationResource);
567 service.setConfigurationCustomizations(configurationResourceList);
568 service.setServiceProxyCustomizations(serviceProxyList);
571 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
573 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
575 if (networkCollectionList != null) {
576 for (NodeTemplate crNode : networkCollectionList) {
578 createNetworkCollection(crNode, toscaResourceStruct, service);
579 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
581 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
582 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
583 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
588 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
592 protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
594 logger.debug("processVFResources");
596 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
597 // String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
598 // String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
600 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
601 Metadata metadata = nodeTemplate.getMetaData();
602 String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
603 logger.debug("VF Category is : " + vfCustomizationCategory);
605 // Do not treat Allotted Resources as VNF resources
606 if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
610 String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
611 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
613 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
615 // Make sure the VF ResourceCustomizationUUID from the notification and tosca
616 // customizations match before comparing their VF Modules UUID's
617 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
618 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
619 + vfCustomizationUUID);
621 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
622 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
623 + " matches vfNotificationResource CustomizationUUID");
625 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
626 vfCustomizationCategory);
628 logger.debug("Notification VF ResourceCustomizationUUID: "
629 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
630 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
636 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
637 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
639 logger.debug("VF Category is : " + vfCustomizationCategory);
641 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
644 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
645 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
646 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
648 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
650 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
651 logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() +
652 " matches Tosca VF Customization UUID: " + vfCustomizationUUID);
654 if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
656 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
658 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
660 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>();
661 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
663 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
665 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
666 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
667 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
668 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
670 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
672 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
673 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
674 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
676 if(matchingObject.isPresent()){
677 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct,
678 vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
679 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
681 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
684 service.getVnfCustomizations().add(vnfResource);
686 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
687 "Tosca VF Customization UUID: " + vfCustomizationUUID);
692 public void processWatchdog(String distributionId, String servideUUID) {
693 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
694 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
696 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
697 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
700 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
701 VfResourceStructure vfResourceStructure) {
702 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
704 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
705 case ASDCConfiguration.HEAT:
706 case ASDCConfiguration.HEAT_NESTED:
707 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
710 case ASDCConfiguration.HEAT_VOL:
711 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
713 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
714 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
716 case ASDCConfiguration.HEAT_ENV:
717 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
719 case ASDCConfiguration.HEAT_ARTIFACT:
720 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
721 toscaResourceStruct);
723 case ASDCConfiguration.HEAT_NET:
724 case ASDCConfiguration.OTHER:
725 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
726 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
727 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
728 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
737 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
738 VfModuleArtifact vfModuleArtifact) {
739 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
740 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
741 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
742 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
743 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
744 return moduleArtifact;
750 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
751 List<String> listTypes) {
752 String newFileBody = filebody;
753 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
755 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
757 newFileBody = verifyTheFilePrefixInString(newFileBody,
758 moduleArtifact.getArtifactInfo().getArtifactName());
764 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
766 String needlePrefix = "file:///";
767 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
769 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
773 StringBuilder sb = new StringBuilder(body.length());
775 int currentIndex = 0;
778 while (currentIndex != -1) {
779 startIndex = currentIndex;
780 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
782 if (currentIndex == -1) {
785 // We append from the startIndex up to currentIndex (start of File
787 sb.append(body.substring(startIndex, currentIndex));
788 sb.append(filenameToVerify);
790 currentIndex += prefixedFilenameToVerify.length();
793 sb.append(body.substring(startIndex));
795 return sb.toString();
798 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
799 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
800 HeatTemplate heatTemplate = new HeatTemplate();
801 List<String> typeList = new ArrayList<>();
802 typeList.add(ASDCConfiguration.HEAT_NESTED);
803 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
805 heatTemplate.setTemplateBody(
806 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
807 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
809 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
810 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
812 heatTemplate.setTimeoutMinutes(240);
815 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
816 heatTemplate.setVersion(BigDecimalVersion
817 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
818 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
820 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
821 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
823 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
826 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
827 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
828 heatTemplate.setParameters(heatParam);
829 vfModuleArtifact.setHeatTemplate(heatTemplate);
832 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
833 VfModuleArtifact vfModuleArtifact) {
834 HeatEnvironment heatEnvironment = new HeatEnvironment();
835 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
836 List<String> typeList = new ArrayList<>();
837 typeList.add(ASDCConfiguration.HEAT);
838 typeList.add(ASDCConfiguration.HEAT_VOL);
839 heatEnvironment.setEnvironment(
840 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
841 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
842 heatEnvironment.setVersion(BigDecimalVersion
843 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
844 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
846 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
847 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
849 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
851 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
854 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
855 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
857 HeatFiles heatFile = new HeatFiles();
858 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
859 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
860 heatFile.setFileBody(vfModuleArtifact.getResult());
861 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
862 heatFile.setVersion(BigDecimalVersion
863 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
864 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
865 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
866 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
868 heatFile.setArtifactChecksum(MANUAL_RECORD);
870 vfModuleArtifact.setHeatFiles(heatFile);
873 protected Service createService(ToscaResourceStructure toscaResourceStructure,
874 VfResourceStructure vfResourceStructure) {
876 toscaResourceStructure.getServiceMetadata();
878 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
880 Service service = new Service();
882 if (serviceMetadata != null) {
884 if (toscaResourceStructure.getServiceVersion() != null) {
885 service.setModelVersion(toscaResourceStructure.getServiceVersion());
888 service.setServiceType(serviceMetadata.getValue("serviceType"));
889 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
891 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
892 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
893 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
894 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
896 if (vfResourceStructure != null)
897 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
899 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
900 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
904 toscaResourceStructure.setCatalogService(service);
908 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
910 Metadata spMetadata = nodeTemplate.getMetaData();
912 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
914 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
916 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
917 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
918 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
919 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
920 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
922 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
923 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
924 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
926 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
928 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);
930 spCustomizationResource.setSourceService(sourceService);
931 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
932 serviceProxyCustomizationSet.add(spCustomizationResource);
935 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
937 return spCustomizationResource;
940 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
942 Metadata metadata = nodeTemplate.getMetaData();
944 ConfigurationResource configResource = new ConfigurationResource();
946 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
947 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
948 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
949 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
950 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
951 configResource.setToscaNodeType(nodeTemplate.getType());
953 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
955 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
957 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
958 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
960 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
961 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
962 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
963 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
964 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
965 configCustomizationResource.setConfigurationResource(configResource);
966 configResourceCustomizationSet.add(configCustomizationResource);
968 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
970 toscaResourceStructure.setCatalogConfigurationResource(configResource);
972 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
974 return configCustomizationResource;
977 protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
979 Metadata fabricMetadata = nodeTemplate.getMetaData();
981 ConfigurationResource configResource = new ConfigurationResource();
983 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
984 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
985 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
986 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
987 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
988 configResource.setToscaNodeType(nodeTemplate.getType());
990 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
992 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
994 configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
995 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
997 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
998 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
999 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
1000 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
1001 configCustomizationResource.setConfigurationResource(configResource);
1002 configResourceCustomizationSet.add(configCustomizationResource);
1004 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1006 return configCustomizationResource;
1009 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1010 ToscaCsar toscaCsar = new ToscaCsar();
1011 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1012 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1014 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1016 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1017 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1018 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1019 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1020 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1022 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1025 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1026 VnfcCustomization vnfcCustomization = null;
1027 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1028 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1029 vnfcCustomization = vnfcCustom;
1033 if(vnfcCustomization==null)
1034 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1036 return vnfcCustomization;
1039 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1040 CvnfcCustomization cvnfcCustomization = null;
1041 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1042 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1043 cvnfcCustomization = cvnfcCustom;
1047 if(cvnfcCustomization==null)
1048 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1050 return cvnfcCustomization;
1053 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1054 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1056 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1057 if(networkResourceCustomization==null){
1058 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1059 toscaResourceStructure);
1061 NetworkResource networkResource = findExistingNetworkResource(service,
1062 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1063 if(networkResource == null)
1064 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1067 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1068 networkResourceCustomization.setNetworkResource(networkResource);
1070 return networkResourceCustomization;
1073 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1074 NetworkResource networkResource = null;
1075 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1076 if (networkCustom.getNetworkResource() != null
1077 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1078 networkResource = networkCustom.getNetworkResource();
1081 if(networkResource==null)
1082 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1084 return networkResource;
1087 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1088 ToscaResourceStructure toscaResourceStructure) {
1089 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1090 networkResourceCustomization.setModelInstanceName(
1091 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1092 networkResourceCustomization.setModelCustomizationUUID(
1093 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1095 networkResourceCustomization.setNetworkTechnology(
1096 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1097 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1098 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1099 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1100 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1101 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1102 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1103 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1104 return networkResourceCustomization;
1107 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1108 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1109 NetworkResource networkResource = new NetworkResource();
1110 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1111 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1113 if ("true".equalsIgnoreCase(providerNetwork)) {
1114 networkResource.setNeutronNetworkType(PROVIDER);
1116 networkResource.setNeutronNetworkType(BASIC);
1119 networkResource.setModelName(
1120 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1122 networkResource.setModelInvariantUUID(
1123 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1124 networkResource.setModelUUID(
1125 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1126 networkResource.setModelVersion(
1127 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1129 networkResource.setAicVersionMax(aicMax);
1130 networkResource.setAicVersionMin(aicMin);
1131 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1132 networkResource.setDescription(
1133 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1134 networkResource.setOrchestrationMode(HEAT);
1135 networkResource.setHeatTemplate(heatTemplate);
1136 return networkResource;
1139 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1140 ToscaResourceStructure toscaResourceStructure, Service service) {
1142 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1144 // **** Build Object to populate Collection_Resource table
1145 CollectionResource collectionResource = new CollectionResource();
1148 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1149 collectionResource.setModelInvariantUUID(
1150 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1152 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1154 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1156 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1157 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1159 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1161 // **** Build object to populate Collection_Resource_Customization table
1162 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1164 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1166 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1168 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1171 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1172 ncfc.setModelCustomizationUUID(
1173 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1175 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1176 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1178 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1180 ncfc.setCollectionResource(collectionResource);
1181 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1183 //*** Build object to populate the Instance_Group table
1184 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1185 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1186 "org.openecomp.groups.NetworkCollection");
1188 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1190 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1192 for (Group group : groupList) {
1194 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1195 Metadata instanceMetadata = group.getMetadata();
1196 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1197 networkInstanceGroup
1198 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1199 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1200 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1201 networkInstanceGroup.setToscaNodeType(group.getType());
1202 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1204 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1206 networkInstanceGroup.setCollectionResource(collectionResource);
1208 // ****Build object to populate
1209 // Collection_Resource_Instance_Group_Customization table
1210 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1211 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1212 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1213 crInstanceGroupCustomization.setModelCustomizationUUID(
1214 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1216 String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
1217 String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
1218 if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1219 fixedQuantity + "_quantity") != null) {
1221 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
1222 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1223 fixedQuantity + "_quantity")));
1226 crInstanceGroupCustomization.setDescription(
1227 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1228 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1229 + "_network_collection_description"));
1230 crInstanceGroupCustomization.setFunction(
1231 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1232 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1233 + "_network_collection_function"));
1234 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1235 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1237 networkInstanceGroup
1238 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1240 networkInstanceGroupList.add(networkInstanceGroup);
1244 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1246 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1247 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1249 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1251 //*****Build object to populate the NetworkResource table
1252 NetworkResource networkResource = new NetworkResource();
1254 for(NodeTemplate vlNodeTemplate : vlNodeList){
1256 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1257 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1259 if ("true".equalsIgnoreCase(providerNetwork)) {
1260 networkResource.setNeutronNetworkType(PROVIDER);
1262 networkResource.setNeutronNetworkType(BASIC);
1265 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1267 networkResource.setModelInvariantUUID(
1268 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1269 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1271 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1273 networkResource.setAicVersionMax(
1274 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1276 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1277 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1279 if (tempNetworkLookUp != null ) {
1281 HeatTemplate heatTemplate = heatRepo
1282 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1283 networkResource.setHeatTemplate(heatTemplate);
1285 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1289 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1291 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1292 networkResource.setOrchestrationMode(HEAT);
1294 // Build object to populate the
1295 // Collection_Network_Resource_Customization table
1296 for (NodeTemplate memberNode : group.getMemberNodes()) {
1297 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1300 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1301 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1303 collectionNetworkResourceCustomization.setNetworkTechnology(
1304 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1305 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1306 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1307 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1308 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1309 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1310 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1311 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1312 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1313 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1314 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1316 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1321 return collectionNetworkResourceCustomization;
1324 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1325 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1327 Metadata instanceMetadata = group.getMetadata();
1328 // Populate InstanceGroup
1329 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1331 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1332 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1333 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1334 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1335 vfcInstanceGroup.setToscaNodeType(group.getType());
1336 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1337 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1339 //Populate VNFCInstanceGroupCustomization
1340 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1342 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1343 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1344 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1346 String getInputName = null;
1347 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function");
1348 if (groupProperty != null) {
1349 int getInputIndex = groupProperty.indexOf("{get_input=");
1350 if (getInputIndex > -1) {
1351 getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1);
1354 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1356 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1357 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1359 return vfcInstanceGroupCustom;
1363 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1364 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1365 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1367 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1368 vfModuleData.getVfModuleModelCustomizationUUID());
1369 if(vfModuleCustomization == null){
1370 VfModule vfModule = findExistingVfModule(vnfResource,
1371 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1372 Metadata vfMetadata = group.getMetadata();
1374 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1376 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1377 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1379 vfModuleCustomization.setVfModule(vfModule);
1380 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1381 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1383 vfResourceStructure.setAlreadyDeployed(true);
1386 //******************************************************************************************************************
1387 //* Extract VFC's and CVFC's then add them to VFModule
1388 //******************************************************************************************************************
1390 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();
1391 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1392 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1394 // Extract CVFC lists
1395 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
1397 for(NodeTemplate cvfcTemplate : cvfcList) {
1399 CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1401 if(existingCvnfcCustomization == null){
1403 //Extract associated VFC - Should always be just one
1404 List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1406 for(NodeTemplate vfcTemplate : vfcList) {
1408 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1409 VnfcCustomization existingVnfcCustomization = null;
1411 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1413 // Only Add Abstract VNFC's to our DB, ignore all others
1414 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1415 vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1416 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1417 vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1418 vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1419 vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1421 vnfcCustomization.setModelVersion(
1422 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1423 vnfcCustomization.setDescription(
1424 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1425 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1427 vnfcCustomizations.add(vnfcCustomization);
1428 existingVnfcSet.add(vnfcCustomization);
1431 // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB.
1432 if(vnfcCustomization.getModelCustomizationUUID() != null){
1434 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1435 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1436 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1437 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1438 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1439 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1441 cvnfcCustomization.setModelVersion(
1442 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1443 cvnfcCustomization.setDescription(
1444 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1445 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1447 if(existingVnfcCustomization != null){
1448 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1450 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1453 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1454 cvnfcCustomization.setVnfResourceCustomization(vnfResource);
1456 cvnfcCustomizations.add(cvnfcCustomization);
1457 existingCvnfcSet.add(cvnfcCustomization);
1459 //*****************************************************************************************************************************************
1460 //* Extract Fabric Configuration
1461 //*****************************************************************************************************************************************
1463 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
1465 for(NodeTemplate fabricTemplate : fabricConfigList) {
1467 ConfigurationResource fabricConfig = null;
1469 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1471 if(existingConfig == null){
1473 ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1475 fabricConfig = fabricConfigCustomization.getConfigurationResource();
1477 service.getConfigurationCustomizations().add(fabricConfigCustomization);
1479 fabricConfig = existingConfig;
1483 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure,
1484 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
1486 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1497 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1498 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1500 return vfModuleCustomization;
1503 protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct,
1504 VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1505 ConfigurationResource configResource) {
1507 Metadata fabricMetadata = fabricTemplate.getMetaData();
1510 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1512 vfModuleToCvnfc.setConfigurationResource(configResource);
1513 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1514 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1515 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1516 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1517 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1518 vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
1520 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
1522 if(policyList != null){
1523 for(Policy policy : policyList){
1524 vfModuleToCvnfc.setPolicyName(policy.getName());
1528 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
1529 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
1530 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
1532 return vfModuleToCvnfc;
1535 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1536 ConfigurationResource configResource = null;
1537 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1538 if (configurationResourceCustom.getConfigurationResource() != null
1539 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1540 configResource = configurationResourceCustom.getConfigurationResource();
1543 if(configResource==null)
1544 configResource = configRepo.findResourceByModelUUID(modelUUID);
1546 return configResource;
1549 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1550 String vfModuleModelCustomizationUUID) {
1551 VfModuleCustomization vfModuleCustomization = null;
1552 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1553 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1554 vfModuleCustomization = vfModuleCustom;
1557 if(vfModuleCustomization==null)
1558 vfModuleCustomization = vfModuleCustomizationRepo
1559 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1561 return vfModuleCustomization;
1564 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1565 VfModule vfModule = null;
1566 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1567 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1568 vfModule = vfModuleCustom.getVfModule();
1572 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1577 protected VfModuleCustomization createVfModuleCustomization(Group group,
1578 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1579 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1581 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1583 vfModuleCustomization.setVfModule(vfModule);
1585 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1586 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1587 if (initialCount != null && initialCount.length() > 0) {
1588 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1591 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1592 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1594 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1595 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1596 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1597 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1600 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1601 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1603 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1604 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1605 if (maxInstances != null && maxInstances.length() > 0) {
1606 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1609 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1610 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1611 if (minInstances != null && minInstances.length() > 0) {
1612 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1614 return vfModuleCustomization;
1617 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1618 IVfModuleData vfModuleData, Metadata vfMetadata) {
1619 VfModule vfModule = new VfModule();
1620 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1622 if(vfModuleModelUUID == null) {
1623 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1624 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1625 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1626 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1629 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1630 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1631 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1632 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1633 vfModule.setModelUUID(vfModuleModelUUID);
1634 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1635 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1636 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1637 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1639 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1640 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1641 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1642 vfModule.setIsBase(true);
1644 vfModule.setIsBase(false);
1649 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1650 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1651 Metadata vfMetadata) {
1653 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1654 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1655 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1656 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1659 if (matchingObject.isPresent()) {
1660 List<HeatFiles> heatFilesList = new ArrayList<>();
1661 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1662 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1663 HeatTemplate parentHeatTemplate = new HeatTemplate();
1664 String parentArtifactType = null;
1665 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1666 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1668 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1670 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1671 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1672 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1675 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1676 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1678 if(!childNestedHeatTemplates.isEmpty()){
1680 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1681 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1683 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1689 if(!heatFilesList.isEmpty()){
1690 vfModule.setHeatFiles(heatFilesList);
1694 // Set all Child Templates related to HEAT_VOLUME
1695 if(!volumeHeatChildTemplates.isEmpty()){
1696 if(vfModule.getVolumeHeatTemplate() != null){
1697 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1699 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1703 // Set all Child Templates related to HEAT
1704 if(!heatChildTemplates.isEmpty()){
1705 if(vfModule.getModuleHeatTemplate() != null){
1706 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1708 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1714 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1715 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1716 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1717 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1718 vfModuleArtifact.incrementDeployedInDB();
1719 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1720 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1721 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1722 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1723 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1724 vfModuleArtifact.incrementDeployedInDB();
1725 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1726 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1727 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1729 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1731 vfModuleArtifact.incrementDeployedInDB();
1732 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1733 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1734 vfModuleArtifact.incrementDeployedInDB();
1735 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1736 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1737 vfModuleArtifact.incrementDeployedInDB();
1741 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1742 ToscaResourceStructure toscaResourceStructure, Service service) {
1743 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1744 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1745 if(vnfResourceCustomization == null){
1746 VnfResource vnfResource = findExistingVnfResource(service,
1747 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1749 if(vnfResource==null)
1750 vnfResource=createVnfResource(vfNodeTemplate);
1752 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1754 vnfResourceCustomization.setVnfResources(vnfResource);
1755 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1757 // Fetch VNFC Instance Group Info
1758 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1759 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1760 "org.openecomp.groups.VfcInstanceGroup");
1762 for (Group group : groupList) {
1764 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1766 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1769 return vnfResourceCustomization;
1772 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1773 VnfResource vnfResource = null;
1774 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1775 if (vnfResourceCustom.getVnfResources() != null
1776 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1777 vnfResource = vnfResourceCustom.getVnfResources();
1780 if(vnfResource==null)
1781 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1786 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1787 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1788 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1789 vnfResourceCustomization.setModelCustomizationUUID(
1790 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1791 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1793 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1794 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1795 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1796 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1797 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1798 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1799 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1800 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1802 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1803 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1805 vnfResourceCustomization.setVnfResources(vnfResource);
1806 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1807 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1809 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1810 .getCapabilitiesOf(vfNodeTemplate);
1812 if (vnfCustomizationCapability != null) {
1813 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1815 if (capAssign != null) {
1816 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1817 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1818 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1819 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1824 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1826 return vnfResourceCustomization;
1829 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1830 VnfResource vnfResource = new VnfResource();
1831 vnfResource.setModelInvariantUUID(
1832 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1833 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1834 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1836 vnfResource.setModelVersion(
1837 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1838 vnfResource.setDescription(
1839 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1840 vnfResource.setOrchestrationMode(HEAT);
1841 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1842 vnfResource.setAicVersionMax(
1843 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1844 vnfResource.setAicVersionMin(
1845 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1846 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1847 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1852 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1853 ToscaResourceStructure toscaResourceStructure, Service service) {
1854 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1855 .findOneByModelCustomizationUUID(
1856 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1858 if(allottedResourceCustomization == null){
1859 AllottedResource allottedResource = findExistingAllottedResource(service,
1860 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1862 if(allottedResource==null)
1863 allottedResource=createAR(nodeTemplate);
1865 toscaResourceStructure.setAllottedResource(allottedResource);
1866 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1867 allottedResourceCustomization.setAllottedResource(allottedResource);
1868 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1870 return allottedResourceCustomization;
1873 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1874 AllottedResource allottedResource = null;
1875 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1876 if (allottedResourceCustom.getAllottedResource() != null
1877 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1878 allottedResource = allottedResourceCustom.getAllottedResource();
1881 if(allottedResource==null)
1882 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1884 return allottedResource;
1887 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1888 ToscaResourceStructure toscaResourceStructure) {
1889 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1890 allottedResourceCustomization.setModelCustomizationUUID(
1891 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1892 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1895 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1896 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1897 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1898 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1899 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1900 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1901 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1902 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1904 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1906 if(vfcNodes != null){
1907 for(NodeTemplate vfcNode : vfcNodes){
1909 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1910 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1911 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1916 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1917 .getCapabilitiesOf(nodeTemplate);
1919 if (arCustomizationCapability != null) {
1920 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1922 if (capAssign != null) {
1923 allottedResourceCustomization.setMinInstances(
1924 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1925 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1926 allottedResourceCustomization.setMaxInstances(
1927 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1928 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1931 return allottedResourceCustomization;
1934 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1935 AllottedResource allottedResource = new AllottedResource();
1937 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1938 allottedResource.setModelInvariantUUID(
1939 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1941 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1943 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1944 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1945 allottedResource.setSubcategory(
1946 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1948 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1949 return allottedResource;
1952 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1953 // Scan the payload downloadResult and extract the HeatTemplate
1955 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1956 return yamlEditor.getParameterList(artifactUUID);
1959 protected String testNull(Object object) {
1961 if (object == null) {
1963 } else if (object.equals("NULL")) {
1965 } else if (object instanceof Integer) {
1966 return object.toString();
1967 } else if (object instanceof String) {
1968 return (String) object;
1970 return "Type not recognized";
1974 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1975 VfModuleArtifact heatNestedArtifact) {
1977 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1978 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1979 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1980 .getArtifactInfo().getRelatedArtifacts()) {
1981 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1982 return ASDCConfiguration.HEAT;
1988 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
1989 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
1990 .getRelatedArtifacts() != null) {
1991 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
1992 .get(0).getArtifactInfo().getRelatedArtifacts()) {
1993 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1994 return ASDCConfiguration.HEAT_VOL;
2000 // Does not belong to anything
2005 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2007 return vfResourceStructure.getNotification().getServiceName() + "/"
2008 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2011 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2013 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2014 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2018 protected static Timestamp getCurrentTimeStamp() {
2020 return new Timestamp(new Date().getTime());