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 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.asdc.installer.heat;
27 import java.sql.Timestamp;
28 import java.util.ArrayList;
29 import java.util.Date;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.LinkedHashMap;
33 import java.util.List;
35 import java.util.Optional;
37 import java.util.stream.Collectors;
39 import org.hibernate.exception.ConstraintViolationException;
40 import org.hibernate.exception.LockAcquisitionException;
41 import org.onap.sdc.api.notification.IArtifactInfo;
42 import org.onap.sdc.api.notification.IResourceInstance;
43 import org.onap.sdc.api.notification.IStatusData;
44 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
45 import org.onap.sdc.tosca.parser.enums.SdcTypes;
46 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
47 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
48 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
49 import org.onap.sdc.toscaparser.api.Group;
50 import org.onap.sdc.toscaparser.api.NodeTemplate;
51 import org.onap.sdc.toscaparser.api.Policy;
52 import org.onap.sdc.toscaparser.api.Property;
53 import org.onap.sdc.toscaparser.api.RequirementAssignment;
54 import org.onap.sdc.toscaparser.api.RequirementAssignments;
55 import org.onap.sdc.toscaparser.api.elements.Metadata;
56 import org.onap.sdc.toscaparser.api.elements.StatefulEntityType;
57 import org.onap.sdc.toscaparser.api.functions.GetInput;
58 import org.onap.sdc.toscaparser.api.parameters.Input;
59 import org.onap.sdc.utils.DistributionStatusEnum;
60 import org.onap.so.asdc.client.ASDCConfiguration;
61 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
62 import org.onap.so.asdc.installer.ASDCElementInfo;
63 import org.onap.so.asdc.installer.BigDecimalVersion;
64 import org.onap.so.asdc.installer.IVfModuleData;
65 import org.onap.so.asdc.installer.ToscaResourceStructure;
66 import org.onap.so.asdc.installer.VfModuleArtifact;
67 import org.onap.so.asdc.installer.VfModuleStructure;
68 import org.onap.so.asdc.installer.VfResourceStructure;
69 import org.onap.so.asdc.util.YamlEditor;
70 import org.onap.so.db.catalog.beans.AllottedResource;
71 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
72 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
73 import org.onap.so.db.catalog.beans.CollectionResource;
74 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
75 import org.onap.so.db.catalog.beans.ConfigurationResource;
76 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
77 import org.onap.so.db.catalog.beans.CvnfcCustomization;
78 import org.onap.so.db.catalog.beans.HeatEnvironment;
79 import org.onap.so.db.catalog.beans.HeatFiles;
80 import org.onap.so.db.catalog.beans.HeatTemplate;
81 import org.onap.so.db.catalog.beans.HeatTemplateParam;
82 import org.onap.so.db.catalog.beans.InstanceGroupType;
83 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
84 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
85 import org.onap.so.db.catalog.beans.NetworkResource;
86 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
87 import org.onap.so.db.catalog.beans.Service;
88 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
89 import org.onap.so.db.catalog.beans.SubType;
90 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
91 import org.onap.so.db.catalog.beans.ToscaCsar;
92 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
93 import org.onap.so.db.catalog.beans.VfModule;
94 import org.onap.so.db.catalog.beans.VfModuleCustomization;
95 import org.onap.so.db.catalog.beans.VnfResource;
96 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
97 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
98 import org.onap.so.db.catalog.beans.VnfcCustomization;
99 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
100 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
101 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
102 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
103 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
104 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
105 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
106 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
107 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
108 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
109 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
110 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
111 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
112 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
113 import org.onap.so.db.catalog.data.repository.ServiceRepository;
114 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
115 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
116 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
117 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
118 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
119 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
120 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
121 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
122 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
123 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
124 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
125 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
126 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
127 import org.onap.so.logger.ErrorCode;
128 import org.onap.so.logger.MessageEnum;
129 import org.slf4j.Logger;
130 import org.slf4j.LoggerFactory;
131 import org.springframework.beans.factory.annotation.Autowired;
132 import org.springframework.orm.ObjectOptimisticLockingFailureException;
133 import org.springframework.stereotype.Component;
134 import org.springframework.transaction.annotation.Transactional;
136 import com.fasterxml.jackson.core.JsonProcessingException;
137 import com.fasterxml.jackson.databind.ObjectMapper;
140 public class ToscaResourceInstaller {
142 protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry";
144 protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor";
146 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
148 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
150 protected static final String SCALABLE = "scalable";
152 protected static final String BASIC = "BASIC";
154 protected static final String PROVIDER = "PROVIDER";
156 protected static final String HEAT = "HEAT";
158 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
160 protected static final String MSO = "SO";
164 protected ServiceRepository serviceRepo;
167 protected InstanceGroupRepository instanceGroupRepo;
170 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
173 protected CollectionResourceRepository collectionRepo;
176 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
179 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
182 protected ConfigurationResourceRepository configRepo;
185 protected VnfResourceRepository vnfRepo;
188 protected VnfCustomizationRepository vnfCustomizationRepo;
191 protected VFModuleRepository vfModuleRepo;
194 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
197 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
200 protected VnfcCustomizationRepository vnfcCustomizationRepo;
203 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
206 protected AllottedResourceRepository allottedRepo;
209 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
212 protected NetworkResourceRepository networkRepo;
215 protected HeatTemplateRepository heatRepo;
218 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
221 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
223 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
225 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
228 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
231 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
233 protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
235 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
236 boolean status = false;
237 VfResourceStructure vfResourceStructure = vfResourceStruct;
239 status = vfResourceStructure.isDeployedSuccessfully();
240 } catch (RuntimeException e) {
244 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
245 if(existingService != null)
248 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
249 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
250 vfResourceStructure.getNotification().getServiceName(),
251 BigDecimalVersion.castAndCheckNotificationVersionToString(
252 vfResourceStructure.getNotification().getServiceVersion()),
253 vfResourceStructure.getNotification().getServiceUUID(),
254 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
255 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
256 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
257 watchdogCDStatusRepository.saveAndFlush(wdStatus);
259 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
260 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
261 vfResourceStructure.getNotification().getServiceName(),
262 BigDecimalVersion.castAndCheckNotificationVersionToString(
263 vfResourceStructure.getNotification().getServiceVersion()),
264 vfResourceStructure.getNotification().getServiceUUID(),
265 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
268 } catch (Exception e) {
270 .error("{} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(),
271 "Exception - isResourceAlreadyDeployed");
272 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
276 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
277 logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}",
278 iStatus.getDistributionID(), iStatus.getComponentName());
281 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
282 iStatus.getComponentName());
283 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
284 watchdogCDStatusRepository.save(cdStatus);
286 } catch (Exception e) {
287 logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
288 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
292 @Transactional(rollbackFor = { ArtifactInstallerException.class })
293 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
294 throws ArtifactInstallerException {
295 VfResourceStructure vfResourceStructure = vfResourceStruct;
296 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
298 // PCLO: in case of deployment failure, use a string that will represent
299 // the type of artifact that failed...
300 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
302 createToscaCsar(toscaResourceStruct);
303 Service service = createService(toscaResourceStruct, vfResourceStruct);
305 processResourceSequence(toscaResourceStruct, service);
306 processVFResources(toscaResourceStruct, service, vfResourceStructure);
307 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
308 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
309 processNetworks(toscaResourceStruct, service);
310 // process Network Collections
311 processNetworkCollections(toscaResourceStruct, service);
312 // Process Service Proxy & Configuration
313 processServiceProxyAndConfiguration(toscaResourceStruct, service);
315 serviceRepo.save(service);
317 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
318 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
319 watchdogCDStatusRepository.save(status);
321 toscaResourceStruct.setSuccessfulDeployment();
323 } catch (Exception e) {
324 logger.debug("Exception :", e);
325 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
326 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
327 watchdogCDStatusRepository.save(status);
328 Throwable dbExceptionToCapture = e;
329 while (!(dbExceptionToCapture instanceof ConstraintViolationException
330 || dbExceptionToCapture instanceof LockAcquisitionException)
331 && (dbExceptionToCapture.getCause() != null)) {
332 dbExceptionToCapture = dbExceptionToCapture.getCause();
335 if (dbExceptionToCapture instanceof ConstraintViolationException
336 || dbExceptionToCapture instanceof LockAcquisitionException) {
337 logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
338 vfResourceStructure.getResourceInstance().getResourceName(),
339 vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
340 "Exception - ASCDC Artifact already deployed", e);
342 String elementToLog = (!artifactListForLogging.isEmpty()
343 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
344 : "No element listed");
345 logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
346 ErrorCode.DataError.getValue(),
347 "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName()
348 + ". Transaction rollback", e);
349 throw new ArtifactInstallerException("Exception caught during installation of "
350 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
356 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
357 ISdcCsarHelper iSdcCsarHelper) {
359 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
360 nodes.addAll(nodeTemplates);
362 for (NodeTemplate nodeTemplate : nodeTemplates) {
363 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
364 List<RequirementAssignment> reqAs = requirement.getAll();
365 for (RequirementAssignment ra : reqAs) {
366 String reqNode = ra.getNodeTemplateName();
367 for (NodeTemplate rNode : resultList) {
368 if (rNode.getName().equals(reqNode)) {
369 if(!resultList.contains(nodeTemplate)) {
370 resultList.add(nodeTemplate);
372 if(nodes.contains(nodeTemplate)) {
373 nodes.remove(nodeTemplate);
381 if (!nodes.isEmpty()) {
382 getRequirementList(resultList, nodes, iSdcCsarHelper);
388 // This method retrieve resource sequence from csar file
389 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
390 List<String> resouceSequence = new ArrayList<String>();
391 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
393 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
394 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
395 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
396 nodes.addAll(nodeTemplates);
398 for (NodeTemplate nodeTemplate : nodeTemplates) {
399 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
401 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
402 resultList.add(nodeTemplate);
403 nodes.remove(nodeTemplate);
407 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
409 for (NodeTemplate node : resultList) {
410 String templateName = node.getMetaData().getValue("name");
411 if (!resouceSequence.contains(templateName)) {
412 resouceSequence.add(templateName);
416 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
417 service.setResourceOrder(resourceSeqStr);
418 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
421 private static String CUSTOMIZATION_UUID = "customizationUUID";
423 private static String getValue(Object value, List<Input> servInputs) {
424 String output = null;
425 if(value instanceof Map) {
426 // currently this logic handles only one level of nesting.
427 return ((LinkedHashMap) value).values().toArray()[0].toString();
428 } else if(value instanceof GetInput) {
429 String inputName = ((GetInput)value).getInputName();
431 for(Input input : servInputs) {
432 if(input.getName().equals(inputName)) {
433 // keep both input name and default value
434 // if service input does not supplies value the use default value
435 String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
436 output = inputName + "|" + defaultValue;// return default value
441 output = value != null ? value.toString() : "";
443 return output; // return property value
446 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
447 Map<String, String> resouceRequest = new HashMap<>();
448 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
450 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
451 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
452 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
453 if(nodeTemplateOpt.isPresent()) {
454 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
455 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
457 for(String key : resourceProperties.keySet()) {
458 Property property = resourceProperties.get(key);
460 String value = getValue(property.getValue(), serInput);
461 resouceRequest.put(key, value);
466 ObjectMapper objectMapper = new ObjectMapper();
467 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
469 jsonStr = jsonStr.replace("\"", "\\\"");
470 logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
472 } catch (JsonProcessingException e) {
473 logger.error("resource input could not be deserialized for resource customization id ("
474 + resourceCustomizationUuid + ")");
475 throw new ArtifactInstallerException("resource input could not be parsed", e);
479 protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
480 Service service) throws ArtifactInstallerException {
481 List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
483 if (nodeTemplatesVLList != null) {
484 for (NodeTemplate vlNode : nodeTemplatesVLList) {
485 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
487 TempNetworkHeatTemplateLookup tempNetworkLookUp =
488 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
490 if (tempNetworkLookUp != null) {
491 HeatTemplate heatTemplate =
492 heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
493 if (heatTemplate != null) {
494 NetworkResourceCustomization networkCustomization =
495 createNetwork (vlNode,
498 tempNetworkLookUp.getAicVersionMax (),
499 tempNetworkLookUp.getAicVersionMin (),
501 service.getNetworkCustomizations ().add (networkCustomization);
503 throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
504 + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
507 NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
513 service.getNetworkCustomizations().add (networkCustomization);
514 logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
515 + networkResourceModelName);
522 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
523 List<NodeTemplate> allottedResourceList) {
524 if (allottedResourceList != null) {
525 for (NodeTemplate allottedNode : allottedResourceList) {
526 service.getAllottedCustomizations()
527 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
533 protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) {
534 Metadata metadata = nodeTemplate.getMetaData();
535 ConfigurationResource configResource = new ConfigurationResource();
536 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
537 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
538 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
539 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
540 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
541 configResource.setToscaNodeType(nodeTemplate.getType());
542 return configResource;
545 protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure,
546 ServiceProxyResourceCustomization spResourceCustomization ) {
547 Metadata metadata = nodeTemplate.getMetaData();
549 ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
551 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
553 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
555 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
556 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
558 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
559 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
560 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
561 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
563 configCustomizationResource.setConfigurationResource(configResource);
564 configResourceCustomizationSet.add(configCustomizationResource);
566 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
567 return configCustomizationResource;
571 protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate(List<NodeTemplate> configurationNodeTemplatesList,
572 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
573 Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty();
574 for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) {
575 StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
576 String type = entityType.getType();
578 if(VLAN_NETWORK_RECEPTOR.equals(type)) {
579 configurationResourceCust= Optional.of(getConfigurationResourceCustomization(nodeTemplate,
580 toscaResourceStructure,spResourceCustomization));
585 return configurationResourceCust;
588 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
590 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
592 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
594 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();
595 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
597 ServiceProxyResourceCustomization serviceProxy = null;
599 if (serviceProxyResourceList != null) {
600 for (NodeTemplate spNode : serviceProxyResourceList) {
601 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
602 serviceProxyList.add(serviceProxy);
603 Optional<ConfigurationResourceCustomization> vnrResourceCustomization = getVnrNodeTemplate(configurationNodeTemplatesList,toscaResourceStruct,serviceProxy);
605 for (NodeTemplate configNode : configurationNodeTemplatesList) {
607 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
608 for (RequirementAssignment requirement : requirementsList) {
609 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
610 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy, vnrResourceCustomization);
612 Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream()
613 .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID()))
615 if(!matchingObject.isPresent()){
616 configurationResourceList.add(configurationResource);
627 service.setConfigurationCustomizations(configurationResourceList);
628 service.setServiceProxyCustomizations(serviceProxyList);
631 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
633 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
635 if (networkCollectionList != null) {
636 for (NodeTemplate crNode : networkCollectionList) {
638 createNetworkCollection(crNode, toscaResourceStruct, service);
639 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
641 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
642 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
643 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
648 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
652 protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
654 logger.debug("processVFResources");
656 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
657 // String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
658 // String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
660 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
661 Metadata metadata = nodeTemplate.getMetaData();
662 String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
663 logger.debug("VF Category is : " + vfCustomizationCategory);
665 // Do not treat Allotted Resources as VNF resources
666 if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
670 String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
671 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
673 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
675 // Make sure the VF ResourceCustomizationUUID from the notification and tosca
676 // customizations match before comparing their VF Modules UUID's
677 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
678 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
679 + vfCustomizationUUID);
681 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
682 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
683 + " matches vfNotificationResource CustomizationUUID");
685 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
686 vfCustomizationCategory);
688 logger.debug("Notification VF ResourceCustomizationUUID: "
689 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
690 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
696 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
697 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
699 logger.debug("VF Category is : " + vfCustomizationCategory);
701 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
704 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
705 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
706 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
708 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
710 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
711 logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() +
712 " matches Tosca VF Customization UUID: " + vfCustomizationUUID);
714 if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
716 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
718 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
720 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>();
721 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
723 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
725 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
726 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
727 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
728 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
730 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
732 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
733 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
734 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
736 if(matchingObject.isPresent()){
737 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct,
738 vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
739 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
741 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
744 service.getVnfCustomizations().add(vnfResource);
746 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
747 "Tosca VF Customization UUID: " + vfCustomizationUUID);
752 public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
754 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID,
755 distributionNotification, consumerId);
756 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
760 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
761 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
763 } catch(ObjectOptimisticLockingFailureException e){
764 logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
769 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
770 VfResourceStructure vfResourceStructure) {
771 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
773 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
774 case ASDCConfiguration.HEAT:
775 case ASDCConfiguration.HEAT_NESTED:
776 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
779 case ASDCConfiguration.HEAT_VOL:
780 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
782 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
783 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
785 case ASDCConfiguration.HEAT_ENV:
786 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
788 case ASDCConfiguration.HEAT_ARTIFACT:
789 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
790 toscaResourceStruct);
792 case ASDCConfiguration.HEAT_NET:
793 case ASDCConfiguration.OTHER:
794 logger.warn("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(),
795 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:" + vfModuleArtifact.getArtifactInfo()
796 .getArtifactName() + ")", ErrorCode.DataError.getValue(), "Artifact type not supported");
805 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
806 VfModuleArtifact vfModuleArtifact) {
807 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
808 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
809 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
810 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
811 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
812 return moduleArtifact;
818 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
819 List<String> listTypes) {
820 String newFileBody = filebody;
821 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
823 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
825 newFileBody = verifyTheFilePrefixInString(newFileBody,
826 moduleArtifact.getArtifactInfo().getArtifactName());
832 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
834 String needlePrefix = "file:///";
835 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
837 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
841 StringBuilder sb = new StringBuilder(body.length());
843 int currentIndex = 0;
846 while (currentIndex != -1) {
847 startIndex = currentIndex;
848 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
850 if (currentIndex == -1) {
853 // We append from the startIndex up to currentIndex (start of File
855 sb.append(body.substring(startIndex, currentIndex));
856 sb.append(filenameToVerify);
858 currentIndex += prefixedFilenameToVerify.length();
861 sb.append(body.substring(startIndex));
863 return sb.toString();
866 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
867 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
868 HeatTemplate heatTemplate = new HeatTemplate();
869 List<String> typeList = new ArrayList<>();
870 typeList.add(ASDCConfiguration.HEAT_NESTED);
871 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
873 heatTemplate.setTemplateBody(
874 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
875 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
877 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
878 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
880 heatTemplate.setTimeoutMinutes(240);
883 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
884 heatTemplate.setVersion(BigDecimalVersion
885 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
886 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
888 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
889 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
891 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
894 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
895 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
896 heatTemplate.setParameters(heatParam);
897 vfModuleArtifact.setHeatTemplate(heatTemplate);
900 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
901 VfModuleArtifact vfModuleArtifact) {
902 HeatEnvironment heatEnvironment = new HeatEnvironment();
903 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
904 List<String> typeList = new ArrayList<>();
905 typeList.add(ASDCConfiguration.HEAT);
906 typeList.add(ASDCConfiguration.HEAT_VOL);
907 heatEnvironment.setEnvironment(
908 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
909 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
910 heatEnvironment.setVersion(BigDecimalVersion
911 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
912 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
914 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
915 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
917 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
919 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
922 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
923 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
925 HeatFiles heatFile = new HeatFiles();
926 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
927 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
928 heatFile.setFileBody(vfModuleArtifact.getResult());
929 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
930 heatFile.setVersion(BigDecimalVersion
931 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
932 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
933 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
934 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
936 heatFile.setArtifactChecksum(MANUAL_RECORD);
938 vfModuleArtifact.setHeatFiles(heatFile);
941 protected Service createService(ToscaResourceStructure toscaResourceStructure,
942 VfResourceStructure vfResourceStructure) {
944 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
946 Service service = new Service();
948 if (serviceMetadata != null) {
950 if (toscaResourceStructure.getServiceVersion() != null) {
951 service.setModelVersion(toscaResourceStructure.getServiceVersion());
954 service.setServiceType(serviceMetadata.getValue("serviceType"));
955 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
957 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
958 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
959 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
960 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
962 if (vfResourceStructure != null)
963 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
965 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
966 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
970 toscaResourceStructure.setCatalogService(service);
974 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
976 Metadata spMetadata = nodeTemplate.getMetaData();
978 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
980 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
982 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
983 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
984 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
985 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
986 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
988 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
989 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
990 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
992 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
994 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);
996 spCustomizationResource.setSourceService(sourceService);
997 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
998 serviceProxyCustomizationSet.add(spCustomizationResource);
1001 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
1003 return spCustomizationResource;
1006 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate,
1007 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
1008 Optional<ConfigurationResourceCustomization> vnrResourceCustomization) {
1010 ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(nodeTemplate,
1011 toscaResourceStructure,spResourceCustomization);
1013 ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
1015 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
1017 StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
1018 String type = entityType.getType();
1020 if(NODES_VRF_ENTRY.equals(type)) {
1021 configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null));
1024 configCustomizationResource.setConfigurationResource(configResource);
1026 configResourceCustomizationSet.add(configCustomizationResource);
1028 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1030 toscaResourceStructure.setCatalogConfigurationResource(configResource);
1032 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
1034 return configCustomizationResource;
1037 protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
1039 Metadata fabricMetadata = nodeTemplate.getMetaData();
1041 ConfigurationResource configResource = new ConfigurationResource();
1043 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1044 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1045 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1046 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1047 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1048 configResource.setToscaNodeType(nodeTemplate.getType());
1050 return configResource;
1053 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1054 ToscaCsar toscaCsar = new ToscaCsar();
1055 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1056 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1058 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1060 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1061 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1062 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1063 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1064 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1066 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1069 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1070 VnfcCustomization vnfcCustomization = null;
1071 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1072 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1073 vnfcCustomization = vnfcCustom;
1077 if(vnfcCustomization==null)
1078 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1080 return vnfcCustomization;
1083 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1084 CvnfcCustomization cvnfcCustomization = null;
1085 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1086 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1087 cvnfcCustomization = cvnfcCustom;
1091 if(cvnfcCustomization==null)
1092 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1094 return cvnfcCustomization;
1097 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1098 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1100 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1102 boolean networkUUIDsMatch = true;
1103 // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from the distribution.
1104 // If not we'll update the Customization record with latest from the distribution
1105 if(networkResourceCustomization != null){
1106 String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
1107 String latestNetworkModelUUID = networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
1109 if(!existingNetworkModelUUID.equals(latestNetworkModelUUID)){
1110 networkUUIDsMatch = false;
1115 if (networkResourceCustomization!=null && !networkUUIDsMatch){
1117 NetworkResource networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1120 networkResourceCustomization.setNetworkResource(networkResource);
1122 networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
1125 else if(networkResourceCustomization==null){
1126 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1127 toscaResourceStructure);
1129 NetworkResource networkResource = findExistingNetworkResource(service,
1130 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1131 if(networkResource == null)
1132 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1135 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1136 networkResourceCustomization.setNetworkResource(networkResource);
1139 return networkResourceCustomization;
1142 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1143 NetworkResource networkResource = null;
1144 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1145 if (networkCustom.getNetworkResource() != null
1146 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1147 networkResource = networkCustom.getNetworkResource();
1150 if(networkResource==null)
1151 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1153 return networkResource;
1156 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1157 ToscaResourceStructure toscaResourceStructure) {
1158 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1159 networkResourceCustomization.setModelInstanceName(
1160 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1161 networkResourceCustomization.setModelCustomizationUUID(
1162 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1164 networkResourceCustomization.setNetworkTechnology(
1165 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1166 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1167 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1168 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1169 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1170 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1171 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1172 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1173 return networkResourceCustomization;
1176 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1177 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1178 NetworkResource networkResource = new NetworkResource();
1179 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1180 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1182 if ("true".equalsIgnoreCase(providerNetwork)) {
1183 networkResource.setNeutronNetworkType(PROVIDER);
1185 networkResource.setNeutronNetworkType(BASIC);
1188 networkResource.setModelName(
1189 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1191 networkResource.setModelInvariantUUID(
1192 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1193 networkResource.setModelUUID(
1194 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1195 networkResource.setModelVersion(
1196 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1198 networkResource.setAicVersionMax(aicMax);
1199 networkResource.setAicVersionMin(aicMin);
1200 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1201 networkResource.setDescription(
1202 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1203 networkResource.setOrchestrationMode(HEAT);
1204 networkResource.setHeatTemplate(heatTemplate);
1205 return networkResource;
1208 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1209 ToscaResourceStructure toscaResourceStructure, Service service) {
1211 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1213 // **** Build Object to populate Collection_Resource table
1214 CollectionResource collectionResource = new CollectionResource();
1217 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1218 collectionResource.setModelInvariantUUID(
1219 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1221 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1223 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1225 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1226 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1228 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1230 // **** Build object to populate Collection_Resource_Customization table
1231 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1233 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1235 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1237 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1240 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1241 ncfc.setModelCustomizationUUID(
1242 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1244 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1245 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1247 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1249 ncfc.setCollectionResource(collectionResource);
1250 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1252 //*** Build object to populate the Instance_Group table
1253 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1254 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1255 "org.openecomp.groups.NetworkCollection");
1257 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1259 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1261 for (Group group : groupList) {
1263 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1264 Metadata instanceMetadata = group.getMetadata();
1265 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1266 networkInstanceGroup
1267 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1268 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1269 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1270 networkInstanceGroup.setToscaNodeType(group.getType());
1271 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1273 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1275 networkInstanceGroup.setCollectionResource(collectionResource);
1277 // ****Build object to populate
1278 // Collection_Resource_Instance_Group_Customization table
1279 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1280 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1281 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1282 crInstanceGroupCustomization.setModelCustomizationUUID(
1283 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1285 // Loop through the template policy to find the subinterface_network_quantity property name. Then extract the value for it.
1286 List<Policy> policyList = toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(networkNodeTemplate, "org.openecomp.policies.scaling.Fixed");
1288 if(policyList != null){
1289 for(Policy policy : policyList){
1290 for(String policyNetworkCollection : policy.getTargets()){
1292 if(policyNetworkCollection.equalsIgnoreCase(group.getName())){
1294 Map<String, Object> propMap = policy.getPolicyProperties();
1296 if(propMap.get("quantity") != null){
1298 String quantity = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, getPropertyInput(propMap.get("quantity").toString()));
1300 if(quantity != null){
1301 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
1311 crInstanceGroupCustomization.setDescription(
1312 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1313 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1314 + "_network_collection_description"));
1315 crInstanceGroupCustomization.setFunction(
1316 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1317 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1318 + "_network_collection_function"));
1319 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1320 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1322 networkInstanceGroup
1323 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1325 networkInstanceGroupList.add(networkInstanceGroup);
1328 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1330 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1331 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1333 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1335 //*****Build object to populate the NetworkResource table
1336 NetworkResource networkResource = new NetworkResource();
1338 for(NodeTemplate vlNodeTemplate : vlNodeList){
1340 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1341 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1343 if ("true".equalsIgnoreCase(providerNetwork)) {
1344 networkResource.setNeutronNetworkType(PROVIDER);
1346 networkResource.setNeutronNetworkType(BASIC);
1349 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1351 networkResource.setModelInvariantUUID(
1352 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1353 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1355 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1357 networkResource.setAicVersionMax(
1358 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1360 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1361 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1363 if (tempNetworkLookUp != null ) {
1365 HeatTemplate heatTemplate = heatRepo
1366 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1367 networkResource.setHeatTemplate(heatTemplate);
1369 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1373 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1375 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1376 networkResource.setOrchestrationMode(HEAT);
1378 // Build object to populate the
1379 // Collection_Network_Resource_Customization table
1380 for (NodeTemplate memberNode : group.getMemberNodes()) {
1381 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1384 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1385 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1387 collectionNetworkResourceCustomization.setNetworkTechnology(
1388 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1389 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1390 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1391 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1392 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1393 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1394 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1395 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1396 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1397 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1398 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1400 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1405 return collectionNetworkResourceCustomization;
1408 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1409 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1411 Metadata instanceMetadata = group.getMetadata();
1412 // Populate InstanceGroup
1413 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1415 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1416 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1417 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1418 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1419 vfcInstanceGroup.setToscaNodeType(group.getType());
1420 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1421 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1423 //Populate VNFCInstanceGroupCustomization
1424 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1426 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1427 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1428 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1430 String getInputName = null;
1431 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function");
1432 if (groupProperty != null) {
1433 int getInputIndex = groupProperty.indexOf("{get_input=");
1434 if (getInputIndex > -1) {
1435 getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1);
1438 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1440 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1441 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1443 return vfcInstanceGroupCustom;
1447 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
1448 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1449 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1451 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1452 vfModuleData.getVfModuleModelCustomizationUUID());
1453 if(vfModuleCustomization == null){
1454 VfModule vfModule = findExistingVfModule(vnfResource,
1455 vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1456 Metadata vfMetadata = group.getMetadata();
1458 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1460 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1461 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1463 vfModuleCustomization.setVfModule(vfModule);
1464 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1465 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1467 vfResourceStructure.setAlreadyDeployed(true);
1470 //******************************************************************************************************************
1471 //* Extract VFC's and CVFC's then add them to VFModule
1472 //******************************************************************************************************************
1474 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();
1475 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1476 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1478 // Only set the CVNFC if this vfModule group is a member of it.
1479 List<NodeTemplate> groupMembers = toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group);
1480 String vfModuleMemberName = null;
1482 for(NodeTemplate node : groupMembers){
1483 vfModuleMemberName = node.getName();
1486 // Extract CVFC lists
1487 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC);
1489 for(NodeTemplate cvfcTemplate : cvfcList) {
1491 if(vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())){
1493 //Extract associated VFC - Should always be just one
1494 List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1496 for(NodeTemplate vfcTemplate : vfcList) {
1498 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1499 VnfcCustomization existingVnfcCustomization = null;
1501 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1503 if(existingVnfcCustomization == null){
1504 vnfcCustomization = new VnfcCustomization();
1506 vnfcCustomization = existingVnfcCustomization;
1509 // Only Add Abstract VNFC's to our DB, ignore all others
1510 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1511 vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1512 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1513 vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1514 vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1515 vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1517 vnfcCustomization.setModelVersion(
1518 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1519 vnfcCustomization.setDescription(
1520 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1521 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1523 vnfcCustomizations.add(vnfcCustomization);
1524 existingVnfcSet.add(vnfcCustomization);
1527 // 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.
1528 if(vnfcCustomization.getModelCustomizationUUID() != null){
1530 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1532 cvnfcCustomization = new CvnfcCustomization();
1533 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1534 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1535 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1536 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1537 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1539 cvnfcCustomization.setModelVersion(
1540 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1541 cvnfcCustomization.setDescription(
1542 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1543 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1545 if(existingVnfcCustomization != null){
1546 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1548 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1551 cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function"));
1552 cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code"));
1553 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1554 cvnfcCustomization.setVnfResourceCustomization(vnfResource);
1556 cvnfcCustomizations.add(cvnfcCustomization);
1557 existingCvnfcSet.add(cvnfcCustomization);
1559 //*****************************************************************************************************************************************
1560 //* Extract Fabric Configuration
1561 //*****************************************************************************************************************************************
1563 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION);
1565 for(NodeTemplate fabricTemplate : fabricConfigList) {
1567 ConfigurationResource fabricConfig = null;
1569 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1571 if(existingConfig == null){
1573 fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1576 fabricConfig = existingConfig;
1579 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure,
1580 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, vfModuleMemberName);
1581 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1583 cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1590 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1591 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1593 return vfModuleCustomization;
1596 protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct,
1597 VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1598 ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) {
1600 Metadata fabricMetadata = fabricTemplate.getMetaData();
1602 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1604 vfModuleToCvnfc.setConfigurationResource(configResource);
1605 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1606 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1607 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1608 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1609 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1611 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External");
1613 if(policyList != null){
1614 for(Policy policy : policyList){
1616 for(String policyCvfcTarget : policy.getTargets()){
1618 if(policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)){
1620 Map<String, Object> propMap = policy.getPolicyProperties();
1622 if(propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")){
1623 vfModuleToCvnfc.setPolicyName(propMap.get("name").toString());
1630 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function"));
1631 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role"));
1632 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type"));
1634 return vfModuleToCvnfc;
1637 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1638 ConfigurationResource configResource = null;
1639 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1640 if (configurationResourceCustom.getConfigurationResource() != null
1641 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1642 configResource = configurationResourceCustom.getConfigurationResource();
1645 if(configResource==null)
1646 configResource = configRepo.findResourceByModelUUID(modelUUID);
1648 return configResource;
1651 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1652 String vfModuleModelCustomizationUUID) {
1653 VfModuleCustomization vfModuleCustomization = null;
1654 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1655 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1656 vfModuleCustomization = vfModuleCustom;
1659 if(vfModuleCustomization==null)
1660 vfModuleCustomization = vfModuleCustomizationRepo
1661 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1663 return vfModuleCustomization;
1666 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1667 VfModule vfModule = null;
1668 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1669 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1670 vfModule = vfModuleCustom.getVfModule();
1674 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1679 protected VfModuleCustomization createVfModuleCustomization(Group group,
1680 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1681 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1683 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1685 vfModuleCustomization.setVfModule(vfModule);
1687 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1688 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1689 if (initialCount != null && initialCount.length() > 0) {
1690 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1693 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1694 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1696 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1697 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1698 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1699 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1702 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1703 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1705 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1706 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1707 if (maxInstances != null && maxInstances.length() > 0) {
1708 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1711 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1712 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1713 if (minInstances != null && minInstances.length() > 0) {
1714 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1716 return vfModuleCustomization;
1719 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1720 IVfModuleData vfModuleData, Metadata vfMetadata) {
1721 VfModule vfModule = new VfModule();
1722 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1724 if(vfModuleModelUUID == null) {
1725 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1726 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1727 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1728 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1731 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1732 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1733 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1734 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1735 vfModule.setModelUUID(vfModuleModelUUID);
1736 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1737 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1738 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1739 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1741 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1742 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1743 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1744 vfModule.setIsBase(true);
1746 vfModule.setIsBase(false);
1751 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1752 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1753 Metadata vfMetadata) {
1755 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1756 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1757 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1758 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1761 if (matchingObject.isPresent()) {
1762 List<HeatFiles> heatFilesList = new ArrayList<>();
1763 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1764 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1765 HeatTemplate parentHeatTemplate = new HeatTemplate();
1766 String parentArtifactType = null;
1767 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1768 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1770 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1772 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1773 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1774 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1777 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1778 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1780 if(!childNestedHeatTemplates.isEmpty()){
1782 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1783 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1785 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1791 if(!heatFilesList.isEmpty()){
1792 vfModule.setHeatFiles(heatFilesList);
1796 // Set all Child Templates related to HEAT_VOLUME
1797 if(!volumeHeatChildTemplates.isEmpty()){
1798 if(vfModule.getVolumeHeatTemplate() != null){
1799 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1801 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1805 // Set all Child Templates related to HEAT
1806 if(!heatChildTemplates.isEmpty()){
1807 if(vfModule.getModuleHeatTemplate() != null){
1808 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1810 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1816 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1817 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1818 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1819 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1820 vfModuleArtifact.incrementDeployedInDB();
1821 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1822 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1823 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1824 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1825 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1826 vfModuleArtifact.incrementDeployedInDB();
1827 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1828 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1829 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1831 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1833 vfModuleArtifact.incrementDeployedInDB();
1834 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1835 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1836 vfModuleArtifact.incrementDeployedInDB();
1837 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1838 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1839 vfModuleArtifact.incrementDeployedInDB();
1843 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1844 ToscaResourceStructure toscaResourceStructure, Service service) {
1845 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1846 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1847 if(vnfResourceCustomization == null){
1848 VnfResource vnfResource = findExistingVnfResource(service,
1849 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1851 if(vnfResource==null)
1852 vnfResource=createVnfResource(vfNodeTemplate);
1854 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1856 vnfResourceCustomization.setVnfResources(vnfResource);
1857 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1859 // Fetch VNFC Instance Group Info
1860 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1861 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1862 "org.openecomp.groups.VfcInstanceGroup");
1864 for (Group group : groupList) {
1866 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1868 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1871 return vnfResourceCustomization;
1874 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1875 VnfResource vnfResource = null;
1876 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1877 if (vnfResourceCustom.getVnfResources() != null
1878 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1879 vnfResource = vnfResourceCustom.getVnfResources();
1882 if(vnfResource==null)
1883 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1888 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1889 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1890 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1891 vnfResourceCustomization.setModelCustomizationUUID(
1892 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1893 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1895 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1896 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1897 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1898 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1899 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1900 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1901 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1902 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1904 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1905 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1907 vnfResourceCustomization.setVnfResources(vnfResource);
1908 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1909 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1911 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1912 .getCapabilitiesOf(vfNodeTemplate);
1914 if (vnfCustomizationCapability != null) {
1915 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1917 if (capAssign != null) {
1918 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1919 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1920 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1921 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1926 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1928 return vnfResourceCustomization;
1931 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1932 VnfResource vnfResource = new VnfResource();
1933 vnfResource.setModelInvariantUUID(
1934 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1935 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1936 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1938 vnfResource.setModelVersion(
1939 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1940 vnfResource.setDescription(
1941 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1942 vnfResource.setOrchestrationMode(HEAT);
1943 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1944 vnfResource.setAicVersionMax(
1945 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1946 vnfResource.setAicVersionMin(
1947 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1948 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1949 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1954 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1955 ToscaResourceStructure toscaResourceStructure, Service service) {
1956 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1957 .findOneByModelCustomizationUUID(
1958 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1960 if(allottedResourceCustomization == null){
1961 AllottedResource allottedResource = findExistingAllottedResource(service,
1962 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1964 if(allottedResource==null)
1965 allottedResource=createAR(nodeTemplate);
1967 toscaResourceStructure.setAllottedResource(allottedResource);
1968 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1969 allottedResourceCustomization.setAllottedResource(allottedResource);
1970 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1972 return allottedResourceCustomization;
1975 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1976 AllottedResource allottedResource = null;
1977 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1978 if (allottedResourceCustom.getAllottedResource() != null
1979 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1980 allottedResource = allottedResourceCustom.getAllottedResource();
1983 if(allottedResource==null)
1984 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1986 return allottedResource;
1989 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1990 ToscaResourceStructure toscaResourceStructure) {
1991 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1992 allottedResourceCustomization.setModelCustomizationUUID(
1993 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1994 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1997 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1998 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1999 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
2000 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
2001 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
2002 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
2003 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
2004 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
2006 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
2008 if(vfcNodes != null){
2009 for(NodeTemplate vfcNode : vfcNodes){
2011 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
2012 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
2013 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
2018 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
2019 .getCapabilitiesOf(nodeTemplate);
2021 if (arCustomizationCapability != null) {
2022 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
2024 if (capAssign != null) {
2025 allottedResourceCustomization.setMinInstances(
2026 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2027 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2028 allottedResourceCustomization.setMaxInstances(
2029 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2030 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2033 return allottedResourceCustomization;
2036 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
2037 AllottedResource allottedResource = new AllottedResource();
2039 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
2040 allottedResource.setModelInvariantUUID(
2041 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
2043 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2045 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2046 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
2047 allottedResource.setSubcategory(
2048 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
2050 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
2051 return allottedResource;
2054 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
2055 // Scan the payload downloadResult and extract the HeatTemplate
2057 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
2058 return yamlEditor.getParameterList(artifactUUID);
2061 protected String testNull(Object object) {
2063 if (object == null) {
2065 } else if (object.equals("NULL")) {
2067 } else if (object instanceof Integer) {
2068 return object.toString();
2069 } else if (object instanceof String) {
2070 return (String) object;
2072 return "Type not recognized";
2076 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
2077 VfModuleArtifact heatNestedArtifact) {
2079 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
2080 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
2081 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
2082 .getArtifactInfo().getRelatedArtifacts()) {
2083 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2084 return ASDCConfiguration.HEAT;
2090 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
2091 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2092 .getRelatedArtifacts() != null) {
2093 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2094 .get(0).getArtifactInfo().getRelatedArtifacts()) {
2095 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2096 return ASDCConfiguration.HEAT_VOL;
2102 // Does not belong to anything
2107 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2109 return vfResourceStructure.getNotification().getServiceName() + "/"
2110 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2113 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2115 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2116 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2119 protected String getPropertyInput(String propertyName){
2121 String inputName = new String();
2123 if (propertyName != null) {
2124 int getInputIndex = propertyName.indexOf("{get_input=");
2125 if (getInputIndex > -1) {
2126 inputName = propertyName.substring(getInputIndex+11, propertyName.length()-1);
2134 protected static Timestamp getCurrentTimeStamp() {
2136 return new Timestamp(new Date().getTime());