2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.asdc.installer.heat;
25 import java.sql.Timestamp;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.Optional;
35 import java.util.stream.Collectors;
37 import org.hibernate.exception.ConstraintViolationException;
38 import org.hibernate.exception.LockAcquisitionException;
39 import org.onap.sdc.api.notification.IArtifactInfo;
40 import org.onap.sdc.api.notification.IResourceInstance;
41 import org.onap.sdc.api.notification.IStatusData;
42 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
43 import org.onap.sdc.tosca.parser.enums.SdcTypes;
44 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
45 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
46 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
47 import org.onap.sdc.toscaparser.api.Group;
48 import org.onap.sdc.toscaparser.api.NodeTemplate;
49 import org.onap.sdc.toscaparser.api.Policy;
50 import org.onap.sdc.toscaparser.api.Property;
51 import org.onap.sdc.toscaparser.api.RequirementAssignment;
52 import org.onap.sdc.toscaparser.api.RequirementAssignments;
53 import org.onap.sdc.toscaparser.api.elements.Metadata;
54 import org.onap.sdc.toscaparser.api.functions.GetInput;
55 import org.onap.sdc.toscaparser.api.parameters.Input;
56 import org.onap.sdc.utils.DistributionStatusEnum;
57 import org.onap.so.asdc.client.ASDCConfiguration;
58 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
59 import org.onap.so.asdc.installer.ASDCElementInfo;
60 import org.onap.so.asdc.installer.BigDecimalVersion;
61 import org.onap.so.asdc.installer.IVfModuleData;
62 import org.onap.so.asdc.installer.ToscaResourceStructure;
63 import org.onap.so.asdc.installer.VfModuleArtifact;
64 import org.onap.so.asdc.installer.VfModuleStructure;
65 import org.onap.so.asdc.installer.VfResourceStructure;
66 import org.onap.so.asdc.util.YamlEditor;
67 import org.onap.so.db.catalog.beans.AllottedResource;
68 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
69 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
70 import org.onap.so.db.catalog.beans.CollectionResource;
71 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
72 import org.onap.so.db.catalog.beans.ConfigurationResource;
73 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
74 import org.onap.so.db.catalog.beans.CvnfcCustomization;
75 import org.onap.so.db.catalog.beans.HeatEnvironment;
76 import org.onap.so.db.catalog.beans.HeatFiles;
77 import org.onap.so.db.catalog.beans.HeatTemplate;
78 import org.onap.so.db.catalog.beans.HeatTemplateParam;
79 import org.onap.so.db.catalog.beans.InstanceGroupType;
80 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
81 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
82 import org.onap.so.db.catalog.beans.NetworkResource;
83 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
84 import org.onap.so.db.catalog.beans.Service;
85 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
86 import org.onap.so.db.catalog.beans.SubType;
87 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
88 import org.onap.so.db.catalog.beans.ToscaCsar;
89 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
90 import org.onap.so.db.catalog.beans.VfModule;
91 import org.onap.so.db.catalog.beans.VfModuleCustomization;
92 import org.onap.so.db.catalog.beans.VnfResource;
93 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
94 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
95 import org.onap.so.db.catalog.beans.VnfcCustomization;
96 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
97 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
98 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
99 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
100 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
101 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
102 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
103 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
104 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
105 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
106 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
107 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
108 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
109 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
110 import org.onap.so.db.catalog.data.repository.ServiceRepository;
111 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
112 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
113 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
114 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
115 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
116 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
117 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
118 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
119 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
120 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
121 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
122 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
123 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
124 import org.onap.so.logger.MessageEnum;
125 import org.onap.so.logger.MsoLogger;
126 import org.springframework.beans.factory.annotation.Autowired;
127 import org.springframework.stereotype.Component;
128 import org.springframework.transaction.annotation.Transactional;
130 import com.fasterxml.jackson.core.JsonProcessingException;
131 import com.fasterxml.jackson.databind.ObjectMapper;
134 public class ToscaResourceInstaller {
136 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
138 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
140 protected static final String SCALABLE = "scalable";
142 protected static final String BASIC = "BASIC";
144 protected static final String PROVIDER = "PROVIDER";
146 protected static final String HEAT = "HEAT";
148 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
150 protected static final String MSO = "SO";
154 protected ServiceRepository serviceRepo;
157 protected InstanceGroupRepository instanceGroupRepo;
160 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
163 protected CollectionResourceRepository collectionRepo;
166 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
169 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
172 protected ConfigurationResourceRepository configRepo;
175 protected VnfResourceRepository vnfRepo;
178 protected VnfCustomizationRepository vnfCustomizationRepo;
181 protected VFModuleRepository vfModuleRepo;
184 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
187 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
190 protected VnfcCustomizationRepository vnfcCustomizationRepo;
193 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
196 protected AllottedResourceRepository allottedRepo;
199 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
202 protected NetworkResourceRepository networkRepo;
205 protected HeatTemplateRepository heatRepo;
208 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
211 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
213 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
215 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
218 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
221 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
223 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
225 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
226 boolean status = false;
227 VfResourceStructure vfResourceStructure = vfResourceStruct;
229 status = vfResourceStructure.isDeployedSuccessfully();
230 } catch (RuntimeException e) {
234 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
235 if(existingService != null)
238 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
239 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
240 vfResourceStructure.getNotification().getServiceName(),
241 BigDecimalVersion.castAndCheckNotificationVersionToString(
242 vfResourceStructure.getNotification().getServiceVersion()),
243 vfResourceStructure.getNotification().getServiceUUID(),
244 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
245 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
246 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
247 watchdogCDStatusRepository.saveAndFlush(wdStatus);
249 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
250 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
251 vfResourceStructure.getNotification().getServiceName(),
252 BigDecimalVersion.castAndCheckNotificationVersionToString(
253 vfResourceStructure.getNotification().getServiceVersion()),
254 vfResourceStructure.getNotification().getServiceUUID(),
255 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
258 } catch (Exception e) {
259 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
260 "Exception - isResourceAlreadyDeployed");
261 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
265 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
266 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
267 + " and ComponentName " + iStatus.getComponentName());
270 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
271 iStatus.getComponentName());
272 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
273 watchdogCDStatusRepository.save(cdStatus);
275 } catch (Exception e) {
276 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
277 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
281 @Transactional(rollbackFor = { ArtifactInstallerException.class })
282 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
283 throws ArtifactInstallerException {
284 VfResourceStructure vfResourceStructure = vfResourceStruct;
285 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
287 // PCLO: in case of deployment failure, use a string that will represent
288 // the type of artifact that failed...
289 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
291 createToscaCsar(toscaResourceStruct);
292 createService(toscaResourceStruct, vfResourceStruct);
293 Service service = toscaResourceStruct.getCatalogService();
294 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
297 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
299 Metadata metadata = nodeTemplate.getMetaData();
300 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
301 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
302 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
303 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
304 vfCustomizationCategory);
307 processResourceSequence(toscaResourceStruct, service);
308 processVFResources(toscaResourceStruct, service, vfResourceStructure);
309 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
310 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
311 processNetworks(toscaResourceStruct, service);
312 // process Network Collections
313 processNetworkCollections(toscaResourceStruct, service);
314 // Process Service Proxy & Configuration
315 processServiceProxyAndConfiguration(toscaResourceStruct, service);
317 serviceRepo.save(service);
319 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
320 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
321 watchdogCDStatusRepository.save(status);
323 toscaResourceStruct.setSuccessfulDeployment();
325 } catch (Exception e) {
326 logger.debug("Exception :", e);
327 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
328 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
329 watchdogCDStatusRepository.save(status);
330 Throwable dbExceptionToCapture = e;
331 while (!(dbExceptionToCapture instanceof ConstraintViolationException
332 || dbExceptionToCapture instanceof LockAcquisitionException)
333 && (dbExceptionToCapture.getCause() != null)) {
334 dbExceptionToCapture = dbExceptionToCapture.getCause();
337 if (dbExceptionToCapture instanceof ConstraintViolationException
338 || dbExceptionToCapture instanceof LockAcquisitionException) {
339 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
340 vfResourceStructure.getResourceInstance().getResourceName(),
341 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
343 String elementToLog = (!artifactListForLogging.isEmpty()
344 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
345 : "No element listed");
346 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
347 "Exception caught during installation of "
348 + vfResourceStructure.getResourceInstance().getResourceName()
349 + ". Transaction rollback",
351 throw new ArtifactInstallerException("Exception caught during installation of "
352 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
358 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
359 ISdcCsarHelper iSdcCsarHelper) {
361 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
362 nodes.addAll(nodeTemplates);
364 for (NodeTemplate nodeTemplate : nodeTemplates) {
365 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
366 List<RequirementAssignment> reqAs = requirement.getAll();
367 for (RequirementAssignment ra : reqAs) {
368 String reqNode = ra.getNodeTemplateName();
369 for (NodeTemplate rNode : resultList) {
370 if (rNode.getName().equals(reqNode)) {
371 if(!resultList.contains(nodeTemplate)) {
372 resultList.add(nodeTemplate);
374 if(nodes.contains(nodeTemplate)) {
375 nodes.remove(nodeTemplate);
383 if (!nodes.isEmpty()) {
384 getRequirementList(resultList, nodes, iSdcCsarHelper);
390 // This method retrieve resource sequence from csar file
391 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
392 List<String> resouceSequence = new ArrayList<String>();
393 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
395 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
396 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
397 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
398 nodes.addAll(nodeTemplates);
400 for (NodeTemplate nodeTemplate : nodeTemplates) {
401 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
403 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
404 resultList.add(nodeTemplate);
405 nodes.remove(nodeTemplate);
409 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
411 for (NodeTemplate node : resultList) {
412 String templateName = node.getMetaData().getValue("name");
413 if (!resouceSequence.contains(templateName)) {
414 resouceSequence.add(templateName);
418 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
419 service.setResourceOrder(resourceSeqStr);
420 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
423 private static String CUSTOMIZATION_UUID = "customizationUUID";
425 private static String getValue(Object value, List<Input> servInputs) {
426 String output = null;
427 if(value instanceof Map) {
428 // currently this logic handles only one level of nesting.
429 return ((LinkedHashMap) value).values().toArray()[0].toString();
430 } else if(value instanceof GetInput) {
431 String inputName = ((GetInput)value).getInputName();
433 for(Input input : servInputs) {
434 if(input.getName().equals(inputName)) {
435 // keep both input name and default value
436 // if service input does not supplies value the use default value
437 String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
438 output = inputName + "|" + defaultValue;// return default value
443 output = value != null ? value.toString() : "";
445 return output; // return property value
448 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
449 Map<String, String> resouceRequest = new HashMap<>();
450 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
452 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
453 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
454 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
455 if(nodeTemplateOpt.isPresent()) {
456 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
457 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
459 for(String key : resourceProperties.keySet()) {
460 Property property = resourceProperties.get(key);
462 String value = getValue(property.getValue(), serInput);
463 resouceRequest.put(key, value);
468 ObjectMapper objectMapper = new ObjectMapper();
469 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
471 jsonStr = jsonStr.replace("\"", "\\\"");
472 logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
474 } catch (JsonProcessingException e) {
475 logger.error("resource input could not be deserialized for resource customization id ("
476 + resourceCustomizationUuid + ")");
477 throw new ArtifactInstallerException("resource input could not be parsed", e);
481 protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
482 Service service) throws ArtifactInstallerException {
483 List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
485 if (nodeTemplatesVLList != null) {
486 for (NodeTemplate vlNode : nodeTemplatesVLList) {
487 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
489 TempNetworkHeatTemplateLookup tempNetworkLookUp =
490 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
492 if (tempNetworkLookUp != null) {
493 HeatTemplate heatTemplate =
494 heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
495 if (heatTemplate != null) {
496 NetworkResourceCustomization networkCustomization =
497 createNetwork (vlNode,
500 tempNetworkLookUp.getAicVersionMax (),
501 tempNetworkLookUp.getAicVersionMin (),
503 service.getNetworkCustomizations ().add (networkCustomization);
505 throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
506 + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
509 NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
515 service.getNetworkCustomizations().add (networkCustomization);
516 logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
517 + networkResourceModelName);
524 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
525 List<NodeTemplate> allottedResourceList) {
526 if (allottedResourceList != null) {
527 for (NodeTemplate allottedNode : allottedResourceList) {
528 service.getAllottedCustomizations()
529 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
534 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
536 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
538 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
540 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();
541 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
543 ServiceProxyResourceCustomization serviceProxy = null;
545 if (serviceProxyResourceList != null) {
546 for (NodeTemplate spNode : serviceProxyResourceList) {
547 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
549 ServiceProxyResourceCustomization serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getModelCustomizationUUID());
551 if(serviceProxyResource == null){
553 serviceProxyList.add(serviceProxy);
555 for (NodeTemplate configNode : configurationNodeTemplatesList) {
557 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
558 for (RequirementAssignment requirement : requirementsList) {
559 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
560 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
562 configurationResourceList.add(configurationResource);
573 service.setConfigurationCustomizations(configurationResourceList);
574 service.setServiceProxyCustomizations(serviceProxyList);
577 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
579 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
581 if (networkCollectionList != null) {
582 for (NodeTemplate crNode : networkCollectionList) {
584 createNetworkCollection(crNode, toscaResourceStruct, service);
585 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
587 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
588 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
589 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
594 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
598 protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
600 logger.debug("processVFResources");
602 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
603 // String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
604 // String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
606 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
607 Metadata metadata = nodeTemplate.getMetaData();
608 String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
609 logger.debug("VF Category is : " + vfCustomizationCategory);
611 // Do not treat Allotted Resources as VNF resources
612 if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
616 String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
617 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
619 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
621 // Make sure the VF ResourceCustomizationUUID from the notification and tosca
622 // customizations match before comparing their VF Modules UUID's
623 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
624 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
625 + vfCustomizationUUID);
627 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
628 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
629 + " matches vfNotificationResource CustomizationUUID");
631 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
632 vfCustomizationCategory);
634 logger.debug("Notification VF ResourceCustomizationUUID: "
635 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
636 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
642 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
643 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
645 logger.debug("VF Category is : " + vfCustomizationCategory);
647 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
650 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
651 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
652 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
654 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
656 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
657 logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() +
658 " matches Tosca VF Customization UUID: " + vfCustomizationUUID);
660 if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
662 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
664 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
666 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>();
667 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
669 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
671 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
672 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
673 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
674 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
676 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
678 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
679 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
680 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
682 if(matchingObject.isPresent()){
683 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct,
684 vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
685 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
687 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
690 service.getVnfCustomizations().add(vnfResource);
692 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
693 "Tosca VF Customization UUID: " + vfCustomizationUUID);
698 public void processWatchdog(String distributionId, String servideUUID) {
699 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
700 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
702 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
703 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
706 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
707 VfResourceStructure vfResourceStructure) {
708 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
710 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
711 case ASDCConfiguration.HEAT:
712 case ASDCConfiguration.HEAT_NESTED:
713 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
716 case ASDCConfiguration.HEAT_VOL:
717 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
719 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
720 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
722 case ASDCConfiguration.HEAT_ENV:
723 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
725 case ASDCConfiguration.HEAT_ARTIFACT:
726 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
727 toscaResourceStruct);
729 case ASDCConfiguration.HEAT_NET:
730 case ASDCConfiguration.OTHER:
731 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
732 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
733 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
734 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
743 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
744 VfModuleArtifact vfModuleArtifact) {
745 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
746 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
747 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
748 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
749 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
750 return moduleArtifact;
756 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
757 List<String> listTypes) {
758 String newFileBody = filebody;
759 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
761 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
763 newFileBody = verifyTheFilePrefixInString(newFileBody,
764 moduleArtifact.getArtifactInfo().getArtifactName());
770 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
772 String needlePrefix = "file:///";
773 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
775 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
779 StringBuilder sb = new StringBuilder(body.length());
781 int currentIndex = 0;
784 while (currentIndex != -1) {
785 startIndex = currentIndex;
786 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
788 if (currentIndex == -1) {
791 // We append from the startIndex up to currentIndex (start of File
793 sb.append(body.substring(startIndex, currentIndex));
794 sb.append(filenameToVerify);
796 currentIndex += prefixedFilenameToVerify.length();
799 sb.append(body.substring(startIndex));
801 return sb.toString();
804 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
805 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
806 HeatTemplate heatTemplate = new HeatTemplate();
807 List<String> typeList = new ArrayList<>();
808 typeList.add(ASDCConfiguration.HEAT_NESTED);
809 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
811 heatTemplate.setTemplateBody(
812 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
813 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
815 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
816 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
818 heatTemplate.setTimeoutMinutes(240);
821 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
822 heatTemplate.setVersion(BigDecimalVersion
823 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
824 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
826 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
827 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
829 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
832 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
833 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
834 heatTemplate.setParameters(heatParam);
835 vfModuleArtifact.setHeatTemplate(heatTemplate);
838 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
839 VfModuleArtifact vfModuleArtifact) {
840 HeatEnvironment heatEnvironment = new HeatEnvironment();
841 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
842 List<String> typeList = new ArrayList<>();
843 typeList.add(ASDCConfiguration.HEAT);
844 typeList.add(ASDCConfiguration.HEAT_VOL);
845 heatEnvironment.setEnvironment(
846 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
847 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
848 heatEnvironment.setVersion(BigDecimalVersion
849 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
850 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
852 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
853 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
855 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
857 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
860 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
861 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
863 HeatFiles heatFile = new HeatFiles();
864 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
865 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
866 heatFile.setFileBody(vfModuleArtifact.getResult());
867 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
868 heatFile.setVersion(BigDecimalVersion
869 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
870 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
871 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
872 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
874 heatFile.setArtifactChecksum(MANUAL_RECORD);
876 vfModuleArtifact.setHeatFiles(heatFile);
879 protected Service createService(ToscaResourceStructure toscaResourceStructure,
880 VfResourceStructure vfResourceStructure) {
882 toscaResourceStructure.getServiceMetadata();
884 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
886 Service service = new Service();
888 if (serviceMetadata != null) {
890 if (toscaResourceStructure.getServiceVersion() != null) {
891 service.setModelVersion(toscaResourceStructure.getServiceVersion());
894 service.setServiceType(serviceMetadata.getValue("serviceType"));
895 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
897 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
898 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
899 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
900 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
902 if (vfResourceStructure != null)
903 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
905 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
906 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
910 toscaResourceStructure.setCatalogService(service);
914 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
916 Metadata spMetadata = nodeTemplate.getMetaData();
918 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
920 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
922 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
923 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
924 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
925 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
926 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
928 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
929 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
930 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
931 spCustomizationResource.setSourceService(service);
932 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
933 serviceProxyCustomizationSet.add(spCustomizationResource);
936 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
938 return spCustomizationResource;
941 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
943 Metadata metadata = nodeTemplate.getMetaData();
945 ConfigurationResource configResource = new ConfigurationResource();
947 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
948 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
949 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
950 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
951 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
952 configResource.setToscaNodeType(nodeTemplate.getType());
954 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
956 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
958 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
959 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
961 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
962 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
963 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
964 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
965 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
966 configCustomizationResource.setConfigurationResource(configResource);
967 configResourceCustomizationSet.add(configCustomizationResource);
969 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
971 toscaResourceStructure.setCatalogConfigurationResource(configResource);
973 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
975 return configCustomizationResource;
978 protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
980 Metadata fabricMetadata = nodeTemplate.getMetaData();
982 ConfigurationResource configResource = new ConfigurationResource();
984 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
985 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
986 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
987 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
988 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
989 configResource.setToscaNodeType(nodeTemplate.getType());
991 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
993 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
995 configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
996 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
998 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
999 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
1000 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
1001 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
1002 configCustomizationResource.setConfigurationResource(configResource);
1003 configResourceCustomizationSet.add(configCustomizationResource);
1005 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1007 return configCustomizationResource;
1010 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1011 ToscaCsar toscaCsar = new ToscaCsar();
1012 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1013 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1015 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1017 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1018 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1019 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1020 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1021 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1023 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1026 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1027 VnfcCustomization vnfcCustomization = null;
1028 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1029 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1030 vnfcCustomization = vnfcCustom;
1034 if(vnfcCustomization==null)
1035 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1037 return vnfcCustomization;
1040 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1041 CvnfcCustomization cvnfcCustomization = null;
1042 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1043 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1044 cvnfcCustomization = cvnfcCustom;
1048 if(cvnfcCustomization==null)
1049 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1051 return cvnfcCustomization;
1054 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1055 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1057 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1058 if(networkResourceCustomization==null){
1059 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1060 toscaResourceStructure);
1062 NetworkResource networkResource = findExistingNetworkResource(service,
1063 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1064 if(networkResource == null)
1065 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1068 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1069 networkResourceCustomization.setNetworkResource(networkResource);
1071 return networkResourceCustomization;
1074 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1075 NetworkResource networkResource = null;
1076 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1077 if (networkCustom.getNetworkResource() != null
1078 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1079 networkResource = networkCustom.getNetworkResource();
1082 if(networkResource==null)
1083 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1085 return networkResource;
1088 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1089 ToscaResourceStructure toscaResourceStructure) {
1090 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1091 networkResourceCustomization.setModelInstanceName(
1092 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1093 networkResourceCustomization.setModelCustomizationUUID(
1094 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1096 networkResourceCustomization.setNetworkTechnology(
1097 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1098 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1099 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1100 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1101 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1102 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1103 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1104 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1105 return networkResourceCustomization;
1108 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1109 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1110 NetworkResource networkResource = new NetworkResource();
1111 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1112 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1114 if ("true".equalsIgnoreCase(providerNetwork)) {
1115 networkResource.setNeutronNetworkType(PROVIDER);
1117 networkResource.setNeutronNetworkType(BASIC);
1120 networkResource.setModelName(
1121 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1123 networkResource.setModelInvariantUUID(
1124 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1125 networkResource.setModelUUID(
1126 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1127 networkResource.setModelVersion(
1128 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1130 networkResource.setAicVersionMax(aicMax);
1131 networkResource.setAicVersionMin(aicMin);
1132 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1133 networkResource.setDescription(
1134 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1135 networkResource.setOrchestrationMode(HEAT);
1136 networkResource.setHeatTemplate(heatTemplate);
1137 return networkResource;
1140 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1141 ToscaResourceStructure toscaResourceStructure, Service service) {
1143 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1145 // **** Build Object to populate Collection_Resource table
1146 CollectionResource collectionResource = new CollectionResource();
1149 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1150 collectionResource.setModelInvariantUUID(
1151 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1153 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1155 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1157 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1158 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1160 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1162 // **** Build object to populate Collection_Resource_Customization table
1163 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1165 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1167 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1169 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1172 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1173 ncfc.setModelCustomizationUUID(
1174 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1176 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1177 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1179 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1181 ncfc.setCollectionResource(collectionResource);
1182 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1184 //*** Build object to populate the Instance_Group table
1185 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1186 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1187 "org.openecomp.groups.NetworkCollection");
1189 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1191 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1193 for (Group group : groupList) {
1195 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1196 Metadata instanceMetadata = group.getMetadata();
1197 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1198 networkInstanceGroup
1199 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1200 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1201 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1202 networkInstanceGroup.setToscaNodeType(group.getType());
1203 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1205 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1207 networkInstanceGroup.setCollectionResource(collectionResource);
1209 // ****Build object to populate
1210 // Collection_Resource_Instance_Group_Customization table
1211 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1212 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1213 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1214 crInstanceGroupCustomization.setModelCustomizationUUID(
1215 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1217 String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
1218 String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
1219 if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1220 fixedQuantity + "_quantity") != null) {
1222 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
1223 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1224 fixedQuantity + "_quantity")));
1227 crInstanceGroupCustomization.setDescription(
1228 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1229 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1230 + "_network_collection_description"));
1231 crInstanceGroupCustomization.setFunction(
1232 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1233 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1234 + "_network_collection_function"));
1235 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1236 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1238 networkInstanceGroup
1239 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1241 networkInstanceGroupList.add(networkInstanceGroup);
1245 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1247 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1248 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1250 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1252 //*****Build object to populate the NetworkResource table
1253 NetworkResource networkResource = new NetworkResource();
1255 for(NodeTemplate vlNodeTemplate : vlNodeList){
1257 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1258 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1260 if ("true".equalsIgnoreCase(providerNetwork)) {
1261 networkResource.setNeutronNetworkType(PROVIDER);
1263 networkResource.setNeutronNetworkType(BASIC);
1266 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1268 networkResource.setModelInvariantUUID(
1269 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1270 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1272 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1274 networkResource.setAicVersionMax(
1275 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1277 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1278 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1280 if (tempNetworkLookUp != null ) {
1282 HeatTemplate heatTemplate = heatRepo
1283 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1284 networkResource.setHeatTemplate(heatTemplate);
1286 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1290 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1292 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1293 networkResource.setOrchestrationMode(HEAT);
1295 // Build object to populate the
1296 // Collection_Network_Resource_Customization table
1297 for (NodeTemplate memberNode : group.getMemberNodes()) {
1298 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1301 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1302 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1304 collectionNetworkResourceCustomization.setNetworkTechnology(
1305 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1306 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1307 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1308 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1309 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1310 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1311 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1312 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1313 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1314 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1315 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1317 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1322 return collectionNetworkResourceCustomization;
1325 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1326 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1328 Metadata instanceMetadata = group.getMetadata();
1329 // Populate InstanceGroup
1330 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1332 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1333 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1334 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1335 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1336 vfcInstanceGroup.setToscaNodeType(group.getType());
1337 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1338 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1340 //Populate VNFCInstanceGroupCustomization
1341 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1343 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1344 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1345 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1347 String getInputName = null;
1348 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function");
1349 if (groupProperty != null) {
1350 int getInputIndex = groupProperty.indexOf("{get_input=");
1351 if (getInputIndex > -1) {
1352 getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1);
1355 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1357 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1358 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1360 return vfcInstanceGroupCustom;
1364 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1365 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1366 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1368 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1369 vfModuleData.getVfModuleModelCustomizationUUID());
1370 if(vfModuleCustomization == null){
1371 VfModule vfModule = findExistingVfModule(vnfResource,
1372 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1373 Metadata vfMetadata = group.getMetadata();
1375 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1377 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1378 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1380 vfModuleCustomization.setVfModule(vfModule);
1381 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1382 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1384 vfResourceStructure.setAlreadyDeployed(true);
1387 //******************************************************************************************************************
1388 //* Extract VFC's and CVFC's then add them to VFModule
1389 //******************************************************************************************************************
1391 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();
1392 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1393 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1395 // Extract CVFC lists
1396 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
1398 for(NodeTemplate cvfcTemplate : cvfcList) {
1400 CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1402 if(existingCvnfcCustomization == null){
1404 //Extract associated VFC - Should always be just one
1405 List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1407 for(NodeTemplate vfcTemplate : vfcList) {
1409 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1410 VnfcCustomization existingVnfcCustomization = null;
1412 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1414 // Only Add Abstract VNFC's to our DB, ignore all others
1415 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1416 vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1417 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1418 vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1419 vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1420 vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1422 vnfcCustomization.setModelVersion(
1423 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1424 vnfcCustomization.setDescription(
1425 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1426 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1428 vnfcCustomizations.add(vnfcCustomization);
1429 existingVnfcSet.add(vnfcCustomization);
1432 // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB.
1433 if(vnfcCustomization.getModelCustomizationUUID() != null){
1435 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1436 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1437 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1438 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1439 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1440 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1442 cvnfcCustomization.setModelVersion(
1443 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1444 cvnfcCustomization.setDescription(
1445 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1446 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1448 if(existingVnfcCustomization != null){
1449 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1451 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1454 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1455 cvnfcCustomization.setVnfResourceCustomization(vnfResource);
1457 cvnfcCustomizations.add(cvnfcCustomization);
1458 existingCvnfcSet.add(cvnfcCustomization);
1460 //*****************************************************************************************************************************************
1461 //* Extract Fabric Configuration
1462 //*****************************************************************************************************************************************
1464 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
1466 for(NodeTemplate fabricTemplate : fabricConfigList) {
1468 ConfigurationResource fabricConfig = null;
1470 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1472 if(existingConfig == null){
1474 ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1476 fabricConfig = fabricConfigCustomization.getConfigurationResource();
1478 service.getConfigurationCustomizations().add(fabricConfigCustomization);
1480 fabricConfig = existingConfig;
1484 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure,
1485 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
1487 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1498 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1499 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1501 return vfModuleCustomization;
1504 protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct,
1505 VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1506 ConfigurationResource configResource) {
1508 Metadata fabricMetadata = fabricTemplate.getMetaData();
1511 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1513 vfModuleToCvnfc.setConfigurationResource(configResource);
1514 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1515 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1516 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1517 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1518 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1519 vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
1521 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
1523 if(policyList != null){
1524 for(Policy policy : policyList){
1525 vfModuleToCvnfc.setPolicyName(policy.getName());
1529 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
1530 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
1531 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
1533 return vfModuleToCvnfc;
1536 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1537 ConfigurationResource configResource = null;
1538 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1539 if (configurationResourceCustom.getConfigurationResource() != null
1540 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1541 configResource = configurationResourceCustom.getConfigurationResource();
1544 if(configResource==null)
1545 configResource = configRepo.findResourceByModelUUID(modelUUID);
1547 return configResource;
1550 protected ServiceProxyResourceCustomization findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelCustomizationUUID) {
1551 ServiceProxyResourceCustomization serviceProxyResourceCustomization = null;
1552 for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){
1553 if (serviceProxyResourceCustom != null
1554 && serviceProxyResourceCustom.getModelCustomizationUUID().equals(modelCustomizationUUID)) {
1555 serviceProxyResourceCustomization = serviceProxyResourceCustom;
1558 if(serviceProxyResourceCustomization==null)
1559 serviceProxyResourceCustomization = serviceProxyCustomizationRepo.findResourceByModelCustomizationUUID(modelCustomizationUUID);
1561 return serviceProxyResourceCustomization;
1564 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1565 String vfModuleModelCustomizationUUID) {
1566 VfModuleCustomization vfModuleCustomization = null;
1567 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1568 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1569 vfModuleCustomization = vfModuleCustom;
1572 if(vfModuleCustomization==null)
1573 vfModuleCustomization = vfModuleCustomizationRepo
1574 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1576 return vfModuleCustomization;
1579 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1580 VfModule vfModule = null;
1581 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1582 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1583 vfModule = vfModuleCustom.getVfModule();
1587 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1592 protected VfModuleCustomization createVfModuleCustomization(Group group,
1593 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1594 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1596 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1598 vfModuleCustomization.setVfModule(vfModule);
1600 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1601 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1602 if (initialCount != null && initialCount.length() > 0) {
1603 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1606 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1607 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1609 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1610 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1611 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1612 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1615 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1616 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1618 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1619 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1620 if (maxInstances != null && maxInstances.length() > 0) {
1621 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1624 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1625 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1626 if (minInstances != null && minInstances.length() > 0) {
1627 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1629 return vfModuleCustomization;
1632 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1633 IVfModuleData vfModuleData, Metadata vfMetadata) {
1634 VfModule vfModule = new VfModule();
1635 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1637 if(vfModuleModelUUID == null) {
1638 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1639 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1640 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1641 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1644 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1645 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1646 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1647 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1648 vfModule.setModelUUID(vfModuleModelUUID);
1649 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1650 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1651 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1652 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1654 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1655 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1656 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1657 vfModule.setIsBase(true);
1659 vfModule.setIsBase(false);
1664 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1665 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1666 Metadata vfMetadata) {
1668 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1669 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1670 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1671 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1674 if (matchingObject.isPresent()) {
1675 List<HeatFiles> heatFilesList = new ArrayList<>();
1676 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1677 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1678 HeatTemplate parentHeatTemplate = new HeatTemplate();
1679 String parentArtifactType = null;
1680 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1681 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1683 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1685 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1686 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1687 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1690 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1691 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1693 if(!childNestedHeatTemplates.isEmpty()){
1695 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1696 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1698 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1704 if(!heatFilesList.isEmpty()){
1705 vfModule.setHeatFiles(heatFilesList);
1709 // Set all Child Templates related to HEAT_VOLUME
1710 if(!volumeHeatChildTemplates.isEmpty()){
1711 if(vfModule.getVolumeHeatTemplate() != null){
1712 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1714 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1718 // Set all Child Templates related to HEAT
1719 if(!heatChildTemplates.isEmpty()){
1720 if(vfModule.getModuleHeatTemplate() != null){
1721 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1723 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1729 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1730 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1731 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1732 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1733 vfModuleArtifact.incrementDeployedInDB();
1734 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1735 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1736 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1737 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1738 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1739 vfModuleArtifact.incrementDeployedInDB();
1740 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1741 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1742 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1744 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1746 vfModuleArtifact.incrementDeployedInDB();
1747 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1748 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1749 vfModuleArtifact.incrementDeployedInDB();
1750 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1751 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1752 vfModuleArtifact.incrementDeployedInDB();
1756 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1757 ToscaResourceStructure toscaResourceStructure, Service service) {
1758 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1759 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1760 if(vnfResourceCustomization == null){
1761 VnfResource vnfResource = findExistingVnfResource(service,
1762 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1764 if(vnfResource==null)
1765 vnfResource=createVnfResource(vfNodeTemplate);
1767 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1769 vnfResourceCustomization.setVnfResources(vnfResource);
1770 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1772 // Fetch VNFC Instance Group Info
1773 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1774 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1775 "org.openecomp.groups.VfcInstanceGroup");
1777 for (Group group : groupList) {
1779 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1781 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1784 return vnfResourceCustomization;
1787 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1788 VnfResource vnfResource = null;
1789 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1790 if (vnfResourceCustom.getVnfResources() != null
1791 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1792 vnfResource = vnfResourceCustom.getVnfResources();
1795 if(vnfResource==null)
1796 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1801 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1802 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1803 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1804 vnfResourceCustomization.setModelCustomizationUUID(
1805 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1806 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1808 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1809 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1810 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1811 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1812 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1813 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1814 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1815 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1817 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1818 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1820 vnfResourceCustomization.setVnfResources(vnfResource);
1821 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1822 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1824 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1825 .getCapabilitiesOf(vfNodeTemplate);
1827 if (vnfCustomizationCapability != null) {
1828 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1830 if (capAssign != null) {
1831 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1832 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1833 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1834 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1839 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1841 return vnfResourceCustomization;
1844 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1845 VnfResource vnfResource = new VnfResource();
1846 vnfResource.setModelInvariantUUID(
1847 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1848 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1849 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1851 vnfResource.setModelVersion(
1852 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1853 vnfResource.setDescription(
1854 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1855 vnfResource.setOrchestrationMode(HEAT);
1856 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1857 vnfResource.setAicVersionMax(
1858 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1859 vnfResource.setAicVersionMin(
1860 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1861 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1862 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1867 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1868 ToscaResourceStructure toscaResourceStructure, Service service) {
1869 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1870 .findOneByModelCustomizationUUID(
1871 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1873 if(allottedResourceCustomization == null){
1874 AllottedResource allottedResource = findExistingAllottedResource(service,
1875 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1877 if(allottedResource==null)
1878 allottedResource=createAR(nodeTemplate);
1880 toscaResourceStructure.setAllottedResource(allottedResource);
1881 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1882 allottedResourceCustomization.setAllottedResource(allottedResource);
1883 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1885 return allottedResourceCustomization;
1888 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1889 AllottedResource allottedResource = null;
1890 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1891 if (allottedResourceCustom.getAllottedResource() != null
1892 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1893 allottedResource = allottedResourceCustom.getAllottedResource();
1896 if(allottedResource==null)
1897 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1899 return allottedResource;
1902 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1903 ToscaResourceStructure toscaResourceStructure) {
1904 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1905 allottedResourceCustomization.setModelCustomizationUUID(
1906 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1907 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1910 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1911 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1912 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1913 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1914 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1915 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1916 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1917 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1919 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1921 if(vfcNodes != null){
1922 for(NodeTemplate vfcNode : vfcNodes){
1924 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1925 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1926 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1931 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1932 .getCapabilitiesOf(nodeTemplate);
1934 if (arCustomizationCapability != null) {
1935 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1937 if (capAssign != null) {
1938 allottedResourceCustomization.setMinInstances(
1939 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1940 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1941 allottedResourceCustomization.setMaxInstances(
1942 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1943 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1946 return allottedResourceCustomization;
1949 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1950 AllottedResource allottedResource = new AllottedResource();
1952 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1953 allottedResource.setModelInvariantUUID(
1954 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1956 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1958 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1959 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1960 allottedResource.setSubcategory(
1961 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1963 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1964 return allottedResource;
1967 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1968 // Scan the payload downloadResult and extract the HeatTemplate
1970 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1971 return yamlEditor.getParameterList(artifactUUID);
1974 protected String testNull(Object object) {
1976 if (object == null) {
1978 } else if (object.equals("NULL")) {
1980 } else if (object instanceof Integer) {
1981 return object.toString();
1982 } else if (object instanceof String) {
1983 return (String) object;
1985 return "Type not recognized";
1989 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1990 VfModuleArtifact heatNestedArtifact) {
1992 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1993 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1994 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1995 .getArtifactInfo().getRelatedArtifacts()) {
1996 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1997 return ASDCConfiguration.HEAT;
2003 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
2004 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2005 .getRelatedArtifacts() != null) {
2006 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2007 .get(0).getArtifactInfo().getRelatedArtifacts()) {
2008 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2009 return ASDCConfiguration.HEAT_VOL;
2015 // Does not belong to anything
2020 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2022 return vfResourceStructure.getNotification().getServiceName() + "/"
2023 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2026 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2028 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2029 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2033 protected static Timestamp getCurrentTimeStamp() {
2035 return new Timestamp(new Date().getTime());