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.StaleObjectStateException;
38 import org.hibernate.exception.ConstraintViolationException;
39 import org.hibernate.exception.LockAcquisitionException;
40 import org.onap.sdc.api.notification.IArtifactInfo;
41 import org.onap.sdc.api.notification.IResourceInstance;
42 import org.onap.sdc.api.notification.IStatusData;
43 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
44 import org.onap.sdc.tosca.parser.enums.SdcTypes;
45 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
46 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
47 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
48 import org.onap.sdc.toscaparser.api.Group;
49 import org.onap.sdc.toscaparser.api.NodeTemplate;
50 import org.onap.sdc.toscaparser.api.Policy;
51 import org.onap.sdc.toscaparser.api.Property;
52 import org.onap.sdc.toscaparser.api.RequirementAssignment;
53 import org.onap.sdc.toscaparser.api.RequirementAssignments;
54 import org.onap.sdc.toscaparser.api.elements.Metadata;
55 import org.onap.sdc.toscaparser.api.functions.GetInput;
56 import org.onap.sdc.toscaparser.api.parameters.Input;
57 import org.onap.sdc.utils.DistributionStatusEnum;
58 import org.onap.so.asdc.client.ASDCConfiguration;
59 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
60 import org.onap.so.asdc.installer.ASDCElementInfo;
61 import org.onap.so.asdc.installer.BigDecimalVersion;
62 import org.onap.so.asdc.installer.IVfModuleData;
63 import org.onap.so.asdc.installer.ToscaResourceStructure;
64 import org.onap.so.asdc.installer.VfModuleArtifact;
65 import org.onap.so.asdc.installer.VfModuleStructure;
66 import org.onap.so.asdc.installer.VfResourceStructure;
67 import org.onap.so.asdc.util.YamlEditor;
68 import org.onap.so.db.catalog.beans.AllottedResource;
69 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
70 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
71 import org.onap.so.db.catalog.beans.CollectionResource;
72 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
73 import org.onap.so.db.catalog.beans.ConfigurationResource;
74 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
75 import org.onap.so.db.catalog.beans.CvnfcCustomization;
76 import org.onap.so.db.catalog.beans.HeatEnvironment;
77 import org.onap.so.db.catalog.beans.HeatFiles;
78 import org.onap.so.db.catalog.beans.HeatTemplate;
79 import org.onap.so.db.catalog.beans.HeatTemplateParam;
80 import org.onap.so.db.catalog.beans.InstanceGroupType;
81 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
82 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
83 import org.onap.so.db.catalog.beans.NetworkResource;
84 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
85 import org.onap.so.db.catalog.beans.Service;
86 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
87 import org.onap.so.db.catalog.beans.SubType;
88 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
89 import org.onap.so.db.catalog.beans.ToscaCsar;
90 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
91 import org.onap.so.db.catalog.beans.VfModule;
92 import org.onap.so.db.catalog.beans.VfModuleCustomization;
93 import org.onap.so.db.catalog.beans.VnfResource;
94 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
95 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
96 import org.onap.so.db.catalog.beans.VnfcCustomization;
97 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
98 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
99 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
100 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
101 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
102 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
103 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
104 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
105 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
106 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
107 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
108 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
109 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
110 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
111 import org.onap.so.db.catalog.data.repository.ServiceRepository;
112 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
113 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
114 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
115 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
116 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
117 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
118 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
119 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
120 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
121 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
122 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
123 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
124 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
125 import org.onap.so.logger.MessageEnum;
126 import org.onap.so.logger.MsoLogger;
127 import org.springframework.beans.factory.annotation.Autowired;
128 import org.springframework.orm.ObjectOptimisticLockingFailureException;
129 import org.springframework.stereotype.Component;
130 import org.springframework.transaction.annotation.Transactional;
132 import com.fasterxml.jackson.core.JsonProcessingException;
133 import com.fasterxml.jackson.databind.ObjectMapper;
136 public class ToscaResourceInstaller {
138 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
140 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
142 protected static final String SCALABLE = "scalable";
144 protected static final String BASIC = "BASIC";
146 protected static final String PROVIDER = "PROVIDER";
148 protected static final String HEAT = "HEAT";
150 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
152 protected static final String MSO = "SO";
156 protected ServiceRepository serviceRepo;
159 protected InstanceGroupRepository instanceGroupRepo;
162 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
165 protected CollectionResourceRepository collectionRepo;
168 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
171 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
174 protected ConfigurationResourceRepository configRepo;
177 protected VnfResourceRepository vnfRepo;
180 protected VnfCustomizationRepository vnfCustomizationRepo;
183 protected VFModuleRepository vfModuleRepo;
186 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
189 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
192 protected VnfcCustomizationRepository vnfcCustomizationRepo;
195 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
198 protected AllottedResourceRepository allottedRepo;
201 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
204 protected NetworkResourceRepository networkRepo;
207 protected HeatTemplateRepository heatRepo;
210 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
213 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
215 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
217 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
220 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
223 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
225 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
227 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
228 boolean status = false;
229 VfResourceStructure vfResourceStructure = vfResourceStruct;
231 status = vfResourceStructure.isDeployedSuccessfully();
232 } catch (RuntimeException e) {
236 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
237 if(existingService != null)
240 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
241 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
242 vfResourceStructure.getNotification().getServiceName(),
243 BigDecimalVersion.castAndCheckNotificationVersionToString(
244 vfResourceStructure.getNotification().getServiceVersion()),
245 vfResourceStructure.getNotification().getServiceUUID(),
246 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
247 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
248 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
249 watchdogCDStatusRepository.saveAndFlush(wdStatus);
251 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
252 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
253 vfResourceStructure.getNotification().getServiceName(),
254 BigDecimalVersion.castAndCheckNotificationVersionToString(
255 vfResourceStructure.getNotification().getServiceVersion()),
256 vfResourceStructure.getNotification().getServiceUUID(),
257 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
260 } catch (Exception e) {
261 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
262 "Exception - isResourceAlreadyDeployed");
263 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
267 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
268 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
269 + " and ComponentName " + iStatus.getComponentName());
272 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
273 iStatus.getComponentName());
274 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
275 watchdogCDStatusRepository.save(cdStatus);
277 } catch (Exception e) {
278 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
279 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
283 @Transactional(rollbackFor = { ArtifactInstallerException.class })
284 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
285 throws ArtifactInstallerException {
286 VfResourceStructure vfResourceStructure = vfResourceStruct;
287 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
289 // PCLO: in case of deployment failure, use a string that will represent
290 // the type of artifact that failed...
291 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
293 createToscaCsar(toscaResourceStruct);
294 createService(toscaResourceStruct, vfResourceStruct);
295 Service service = toscaResourceStruct.getCatalogService();
296 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
299 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
301 Metadata metadata = nodeTemplate.getMetaData();
302 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
303 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
304 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
305 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
306 vfCustomizationCategory);
309 processResourceSequence(toscaResourceStruct, service);
310 processVFResources(toscaResourceStruct, service, vfResourceStructure);
311 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
312 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
313 processNetworks(toscaResourceStruct, service);
314 // process Network Collections
315 processNetworkCollections(toscaResourceStruct, service);
316 // Process Service Proxy & Configuration
317 processServiceProxyAndConfiguration(toscaResourceStruct, service);
319 serviceRepo.save(service);
321 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
322 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
323 watchdogCDStatusRepository.save(status);
325 toscaResourceStruct.setSuccessfulDeployment();
327 } catch (Exception e) {
328 logger.debug("Exception :", e);
329 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
330 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
331 watchdogCDStatusRepository.save(status);
332 Throwable dbExceptionToCapture = e;
333 while (!(dbExceptionToCapture instanceof ConstraintViolationException
334 || dbExceptionToCapture instanceof LockAcquisitionException)
335 && (dbExceptionToCapture.getCause() != null)) {
336 dbExceptionToCapture = dbExceptionToCapture.getCause();
339 if (dbExceptionToCapture instanceof ConstraintViolationException
340 || dbExceptionToCapture instanceof LockAcquisitionException) {
341 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
342 vfResourceStructure.getResourceInstance().getResourceName(),
343 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
345 String elementToLog = (!artifactListForLogging.isEmpty()
346 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
347 : "No element listed");
348 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
349 "Exception caught during installation of "
350 + vfResourceStructure.getResourceInstance().getResourceName()
351 + ". Transaction rollback",
353 throw new ArtifactInstallerException("Exception caught during installation of "
354 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
360 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
361 ISdcCsarHelper iSdcCsarHelper) {
363 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
364 nodes.addAll(nodeTemplates);
366 for (NodeTemplate nodeTemplate : nodeTemplates) {
367 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
368 List<RequirementAssignment> reqAs = requirement.getAll();
369 for (RequirementAssignment ra : reqAs) {
370 String reqNode = ra.getNodeTemplateName();
371 for (NodeTemplate rNode : resultList) {
372 if (rNode.getName().equals(reqNode)) {
373 if(!resultList.contains(nodeTemplate)) {
374 resultList.add(nodeTemplate);
376 if(nodes.contains(nodeTemplate)) {
377 nodes.remove(nodeTemplate);
385 if (!nodes.isEmpty()) {
386 getRequirementList(resultList, nodes, iSdcCsarHelper);
392 // This method retrieve resource sequence from csar file
393 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
394 List<String> resouceSequence = new ArrayList<String>();
395 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
397 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
398 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
399 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
400 nodes.addAll(nodeTemplates);
402 for (NodeTemplate nodeTemplate : nodeTemplates) {
403 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
405 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
406 resultList.add(nodeTemplate);
407 nodes.remove(nodeTemplate);
411 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
413 for (NodeTemplate node : resultList) {
414 String templateName = node.getMetaData().getValue("name");
415 if (!resouceSequence.contains(templateName)) {
416 resouceSequence.add(templateName);
420 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
421 service.setResourceOrder(resourceSeqStr);
422 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
425 private static String CUSTOMIZATION_UUID = "customizationUUID";
427 private static String getValue(Object value, List<Input> servInputs) {
428 String output = null;
429 if(value instanceof Map) {
430 // currently this logic handles only one level of nesting.
431 return ((LinkedHashMap) value).values().toArray()[0].toString();
432 } else if(value instanceof GetInput) {
433 String inputName = ((GetInput)value).getInputName();
435 for(Input input : servInputs) {
436 if(input.getName().equals(inputName)) {
437 // keep both input name and default value
438 // if service input does not supplies value the use default value
439 String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
440 output = inputName + "|" + defaultValue;// return default value
445 output = value != null ? value.toString() : "";
447 return output; // return property value
450 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
451 Map<String, String> resouceRequest = new HashMap<>();
452 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
454 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
455 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
456 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
457 if(nodeTemplateOpt.isPresent()) {
458 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
459 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
461 for(String key : resourceProperties.keySet()) {
462 Property property = resourceProperties.get(key);
464 String value = getValue(property.getValue(), serInput);
465 resouceRequest.put(key, value);
470 ObjectMapper objectMapper = new ObjectMapper();
471 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
473 jsonStr = jsonStr.replace("\"", "\\\"");
474 logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
476 } catch (JsonProcessingException e) {
477 logger.error("resource input could not be deserialized for resource customization id ("
478 + resourceCustomizationUuid + ")");
479 throw new ArtifactInstallerException("resource input could not be parsed", e);
483 protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
484 Service service) throws ArtifactInstallerException {
485 List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
487 if (nodeTemplatesVLList != null) {
488 for (NodeTemplate vlNode : nodeTemplatesVLList) {
489 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
491 TempNetworkHeatTemplateLookup tempNetworkLookUp =
492 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
494 if (tempNetworkLookUp != null) {
495 HeatTemplate heatTemplate =
496 heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
497 if (heatTemplate != null) {
498 NetworkResourceCustomization networkCustomization =
499 createNetwork (vlNode,
502 tempNetworkLookUp.getAicVersionMax (),
503 tempNetworkLookUp.getAicVersionMin (),
505 service.getNetworkCustomizations ().add (networkCustomization);
507 throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
508 + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
511 NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
517 service.getNetworkCustomizations().add (networkCustomization);
518 logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
519 + networkResourceModelName);
526 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
527 List<NodeTemplate> allottedResourceList) {
528 if (allottedResourceList != null) {
529 for (NodeTemplate allottedNode : allottedResourceList) {
530 service.getAllottedCustomizations()
531 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
536 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
538 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
540 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
542 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();
543 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
545 ServiceProxyResourceCustomization serviceProxy = null;
547 if (serviceProxyResourceList != null) {
548 for (NodeTemplate spNode : serviceProxyResourceList) {
549 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
551 serviceProxyList.add(serviceProxy);
553 for (NodeTemplate configNode : configurationNodeTemplatesList) {
555 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
556 for (RequirementAssignment requirement : requirementsList) {
557 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
558 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
560 Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream()
561 .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID()))
563 if(!matchingObject.isPresent()){
564 configurationResourceList.add(configurationResource);
575 service.setConfigurationCustomizations(configurationResourceList);
576 service.setServiceProxyCustomizations(serviceProxyList);
579 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
581 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
583 if (networkCollectionList != null) {
584 for (NodeTemplate crNode : networkCollectionList) {
586 createNetworkCollection(crNode, toscaResourceStruct, service);
587 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
589 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
590 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
591 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
596 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
600 protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
602 logger.debug("processVFResources");
604 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
605 // String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
606 // String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
608 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
609 Metadata metadata = nodeTemplate.getMetaData();
610 String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
611 logger.debug("VF Category is : " + vfCustomizationCategory);
613 // Do not treat Allotted Resources as VNF resources
614 if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
618 String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
619 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
621 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
623 // Make sure the VF ResourceCustomizationUUID from the notification and tosca
624 // customizations match before comparing their VF Modules UUID's
625 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
626 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
627 + vfCustomizationUUID);
629 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
630 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
631 + " matches vfNotificationResource CustomizationUUID");
633 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
634 vfCustomizationCategory);
636 logger.debug("Notification VF ResourceCustomizationUUID: "
637 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
638 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
644 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
645 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
647 logger.debug("VF Category is : " + vfCustomizationCategory);
649 if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
652 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
653 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
654 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
656 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
658 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
659 logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() +
660 " matches Tosca VF Customization UUID: " + vfCustomizationUUID);
662 if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
664 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
666 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
668 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>();
669 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
671 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
673 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
674 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
675 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
676 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
678 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
680 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
681 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
682 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
684 if(matchingObject.isPresent()){
685 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct,
686 vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
687 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
689 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
692 service.getVnfCustomizations().add(vnfResource);
694 logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
695 "Tosca VF Customization UUID: " + vfCustomizationUUID);
700 public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
702 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID,
703 distributionNotification, consumerId);
704 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
708 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
709 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
711 } catch(ObjectOptimisticLockingFailureException e){
712 logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
717 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
718 VfResourceStructure vfResourceStructure) {
719 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
721 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
722 case ASDCConfiguration.HEAT:
723 case ASDCConfiguration.HEAT_NESTED:
724 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
727 case ASDCConfiguration.HEAT_VOL:
728 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
730 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
731 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
733 case ASDCConfiguration.HEAT_ENV:
734 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
736 case ASDCConfiguration.HEAT_ARTIFACT:
737 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
738 toscaResourceStruct);
740 case ASDCConfiguration.HEAT_NET:
741 case ASDCConfiguration.OTHER:
742 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
743 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
744 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
745 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
754 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
755 VfModuleArtifact vfModuleArtifact) {
756 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
757 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
758 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
759 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
760 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
761 return moduleArtifact;
767 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
768 List<String> listTypes) {
769 String newFileBody = filebody;
770 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
772 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
774 newFileBody = verifyTheFilePrefixInString(newFileBody,
775 moduleArtifact.getArtifactInfo().getArtifactName());
781 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
783 String needlePrefix = "file:///";
784 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
786 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
790 StringBuilder sb = new StringBuilder(body.length());
792 int currentIndex = 0;
795 while (currentIndex != -1) {
796 startIndex = currentIndex;
797 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
799 if (currentIndex == -1) {
802 // We append from the startIndex up to currentIndex (start of File
804 sb.append(body.substring(startIndex, currentIndex));
805 sb.append(filenameToVerify);
807 currentIndex += prefixedFilenameToVerify.length();
810 sb.append(body.substring(startIndex));
812 return sb.toString();
815 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
816 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
817 HeatTemplate heatTemplate = new HeatTemplate();
818 List<String> typeList = new ArrayList<>();
819 typeList.add(ASDCConfiguration.HEAT_NESTED);
820 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
822 heatTemplate.setTemplateBody(
823 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
824 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
826 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
827 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
829 heatTemplate.setTimeoutMinutes(240);
832 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
833 heatTemplate.setVersion(BigDecimalVersion
834 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
835 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
837 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
838 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
840 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
843 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
844 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
845 heatTemplate.setParameters(heatParam);
846 vfModuleArtifact.setHeatTemplate(heatTemplate);
849 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
850 VfModuleArtifact vfModuleArtifact) {
851 HeatEnvironment heatEnvironment = new HeatEnvironment();
852 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
853 List<String> typeList = new ArrayList<>();
854 typeList.add(ASDCConfiguration.HEAT);
855 typeList.add(ASDCConfiguration.HEAT_VOL);
856 heatEnvironment.setEnvironment(
857 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
858 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
859 heatEnvironment.setVersion(BigDecimalVersion
860 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
861 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
863 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
864 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
866 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
868 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
871 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
872 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
874 HeatFiles heatFile = new HeatFiles();
875 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
876 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
877 heatFile.setFileBody(vfModuleArtifact.getResult());
878 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
879 heatFile.setVersion(BigDecimalVersion
880 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
881 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
882 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
883 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
885 heatFile.setArtifactChecksum(MANUAL_RECORD);
887 vfModuleArtifact.setHeatFiles(heatFile);
890 protected Service createService(ToscaResourceStructure toscaResourceStructure,
891 VfResourceStructure vfResourceStructure) {
893 toscaResourceStructure.getServiceMetadata();
895 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
897 Service service = new Service();
899 if (serviceMetadata != null) {
901 if (toscaResourceStructure.getServiceVersion() != null) {
902 service.setModelVersion(toscaResourceStructure.getServiceVersion());
905 service.setServiceType(serviceMetadata.getValue("serviceType"));
906 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
908 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
909 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
910 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
911 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
913 if (vfResourceStructure != null)
914 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
916 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
917 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
921 toscaResourceStructure.setCatalogService(service);
925 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
927 Metadata spMetadata = nodeTemplate.getMetaData();
929 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
931 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
933 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
934 spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
935 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
936 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
937 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
939 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
940 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
941 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
943 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
945 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);
947 spCustomizationResource.setSourceService(sourceService);
948 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
949 serviceProxyCustomizationSet.add(spCustomizationResource);
952 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
954 return spCustomizationResource;
957 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
959 Metadata metadata = nodeTemplate.getMetaData();
961 ConfigurationResource configResource = new ConfigurationResource();
963 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
964 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
965 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
966 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
967 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
968 configResource.setToscaNodeType(nodeTemplate.getType());
970 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
972 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
974 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
975 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
977 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
978 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
979 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
980 configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
981 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
982 configCustomizationResource.setConfigurationResource(configResource);
983 configResourceCustomizationSet.add(configCustomizationResource);
985 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
987 toscaResourceStructure.setCatalogConfigurationResource(configResource);
989 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
991 return configCustomizationResource;
994 protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
996 Metadata fabricMetadata = nodeTemplate.getMetaData();
998 ConfigurationResource configResource = new ConfigurationResource();
1000 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1001 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1002 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1003 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1004 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1005 configResource.setToscaNodeType(nodeTemplate.getType());
1007 return configResource;
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));
1059 boolean networkUUIDsMatch = true;
1060 // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from the distribution.
1061 // If not we'll update the Customization record with latest from the distribution
1062 if(networkResourceCustomization != null){
1063 String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
1064 String latestNetworkModelUUID = networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
1066 if(!existingNetworkModelUUID.equals(latestNetworkModelUUID)){
1067 networkUUIDsMatch = false;
1072 if (networkResourceCustomization!=null && !networkUUIDsMatch){
1074 NetworkResource networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1077 networkResourceCustomization.setNetworkResource(networkResource);
1079 networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
1082 else if(networkResourceCustomization==null){
1083 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1084 toscaResourceStructure);
1086 NetworkResource networkResource = findExistingNetworkResource(service,
1087 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1088 if(networkResource == null)
1089 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1092 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1093 networkResourceCustomization.setNetworkResource(networkResource);
1096 return networkResourceCustomization;
1099 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1100 NetworkResource networkResource = null;
1101 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1102 if (networkCustom.getNetworkResource() != null
1103 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1104 networkResource = networkCustom.getNetworkResource();
1107 if(networkResource==null)
1108 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1110 return networkResource;
1113 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1114 ToscaResourceStructure toscaResourceStructure) {
1115 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1116 networkResourceCustomization.setModelInstanceName(
1117 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1118 networkResourceCustomization.setModelCustomizationUUID(
1119 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1121 networkResourceCustomization.setNetworkTechnology(
1122 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1123 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1124 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1125 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1126 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1127 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1128 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1129 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1130 return networkResourceCustomization;
1133 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1134 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1135 NetworkResource networkResource = new NetworkResource();
1136 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1137 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1139 if ("true".equalsIgnoreCase(providerNetwork)) {
1140 networkResource.setNeutronNetworkType(PROVIDER);
1142 networkResource.setNeutronNetworkType(BASIC);
1145 networkResource.setModelName(
1146 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1148 networkResource.setModelInvariantUUID(
1149 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1150 networkResource.setModelUUID(
1151 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1152 networkResource.setModelVersion(
1153 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1155 networkResource.setAicVersionMax(aicMax);
1156 networkResource.setAicVersionMin(aicMin);
1157 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1158 networkResource.setDescription(
1159 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1160 networkResource.setOrchestrationMode(HEAT);
1161 networkResource.setHeatTemplate(heatTemplate);
1162 return networkResource;
1165 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1166 ToscaResourceStructure toscaResourceStructure, Service service) {
1168 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1170 // **** Build Object to populate Collection_Resource table
1171 CollectionResource collectionResource = new CollectionResource();
1174 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1175 collectionResource.setModelInvariantUUID(
1176 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1178 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1180 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1182 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1183 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1185 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1187 // **** Build object to populate Collection_Resource_Customization table
1188 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1190 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1192 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1194 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1197 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1198 ncfc.setModelCustomizationUUID(
1199 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1201 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1202 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1204 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1206 ncfc.setCollectionResource(collectionResource);
1207 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1209 //*** Build object to populate the Instance_Group table
1210 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1211 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1212 "org.openecomp.groups.NetworkCollection");
1214 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1216 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1218 for (Group group : groupList) {
1220 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1221 Metadata instanceMetadata = group.getMetadata();
1222 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1223 networkInstanceGroup
1224 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1225 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1226 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1227 networkInstanceGroup.setToscaNodeType(group.getType());
1228 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1230 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1232 networkInstanceGroup.setCollectionResource(collectionResource);
1234 // ****Build object to populate
1235 // Collection_Resource_Instance_Group_Customization table
1236 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1237 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1238 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1239 crInstanceGroupCustomization.setModelCustomizationUUID(
1240 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1242 // Loop through the template policy to find the subinterface_network_quantity property name. Then extract the value for it.
1243 List<Policy> policyList = toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(networkNodeTemplate, "org.openecomp.policies.scaling.Fixed");
1245 if(policyList != null){
1246 for(Policy policy : policyList){
1247 for(String policyNetworkCollection : policy.getTargets()){
1249 if(policyNetworkCollection.equalsIgnoreCase(group.getName())){
1251 Map<String, Object> propMap = policy.getPolicyProperties();
1253 if(propMap.get("quantity") != null){
1255 String quantity = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, getPropertyInput(propMap.get("quantity").toString()));
1257 if(quantity != null){
1258 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
1268 crInstanceGroupCustomization.setDescription(
1269 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1270 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1271 + "_network_collection_description"));
1272 crInstanceGroupCustomization.setFunction(
1273 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1274 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1275 + "_network_collection_function"));
1276 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1277 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1279 networkInstanceGroup
1280 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1282 networkInstanceGroupList.add(networkInstanceGroup);
1285 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1287 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1288 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1290 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1292 //*****Build object to populate the NetworkResource table
1293 NetworkResource networkResource = new NetworkResource();
1295 for(NodeTemplate vlNodeTemplate : vlNodeList){
1297 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1298 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1300 if ("true".equalsIgnoreCase(providerNetwork)) {
1301 networkResource.setNeutronNetworkType(PROVIDER);
1303 networkResource.setNeutronNetworkType(BASIC);
1306 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1308 networkResource.setModelInvariantUUID(
1309 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1310 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1312 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1314 networkResource.setAicVersionMax(
1315 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1317 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1318 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1320 if (tempNetworkLookUp != null ) {
1322 HeatTemplate heatTemplate = heatRepo
1323 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1324 networkResource.setHeatTemplate(heatTemplate);
1326 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1330 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1332 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1333 networkResource.setOrchestrationMode(HEAT);
1335 // Build object to populate the
1336 // Collection_Network_Resource_Customization table
1337 for (NodeTemplate memberNode : group.getMemberNodes()) {
1338 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1341 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1342 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1344 collectionNetworkResourceCustomization.setNetworkTechnology(
1345 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1346 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1347 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1348 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1349 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1350 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1351 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1352 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1353 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1354 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1355 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1357 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1362 return collectionNetworkResourceCustomization;
1365 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1366 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1368 Metadata instanceMetadata = group.getMetadata();
1369 // Populate InstanceGroup
1370 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1372 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1373 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1374 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1375 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1376 vfcInstanceGroup.setToscaNodeType(group.getType());
1377 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1378 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1380 //Populate VNFCInstanceGroupCustomization
1381 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1383 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1384 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1385 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1387 String getInputName = null;
1388 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function");
1389 if (groupProperty != null) {
1390 int getInputIndex = groupProperty.indexOf("{get_input=");
1391 if (getInputIndex > -1) {
1392 getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1);
1395 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1397 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1398 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1400 return vfcInstanceGroupCustom;
1404 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
1405 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1406 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1408 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1409 vfModuleData.getVfModuleModelCustomizationUUID());
1410 if(vfModuleCustomization == null){
1411 VfModule vfModule = findExistingVfModule(vnfResource,
1412 vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1413 Metadata vfMetadata = group.getMetadata();
1415 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1417 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1418 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1420 vfModuleCustomization.setVfModule(vfModule);
1421 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1422 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1424 vfResourceStructure.setAlreadyDeployed(true);
1427 //******************************************************************************************************************
1428 //* Extract VFC's and CVFC's then add them to VFModule
1429 //******************************************************************************************************************
1431 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();
1432 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1433 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1435 // Only set the CVNFC if this vfModule group is a member of it.
1436 List<NodeTemplate> groupMembers = toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group);
1437 String vfModuleMemberName = null;
1439 for(NodeTemplate node : groupMembers){
1440 vfModuleMemberName = node.getName();
1444 // Extract CVFC lists
1445 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC);
1447 for(NodeTemplate cvfcTemplate : cvfcList) {
1449 CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1451 if(existingCvnfcCustomization == null && (vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName()))){
1453 //Extract associated VFC - Should always be just one
1454 List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1456 for(NodeTemplate vfcTemplate : vfcList) {
1458 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1459 VnfcCustomization existingVnfcCustomization = null;
1461 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1463 // Only Add Abstract VNFC's to our DB, ignore all others
1464 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1465 vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1466 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1467 vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1468 vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1469 vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1471 vnfcCustomization.setModelVersion(
1472 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1473 vnfcCustomization.setDescription(
1474 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1475 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1477 vnfcCustomizations.add(vnfcCustomization);
1478 existingVnfcSet.add(vnfcCustomization);
1481 // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB.
1482 if(vnfcCustomization.getModelCustomizationUUID() != null){
1484 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1485 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1486 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1487 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1488 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1489 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1491 cvnfcCustomization.setModelVersion(
1492 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1493 cvnfcCustomization.setDescription(
1494 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1495 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1497 if(existingVnfcCustomization != null){
1498 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1500 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1503 cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function"));
1504 cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code"));
1505 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1506 cvnfcCustomization.setVnfResourceCustomization(vnfResource);
1508 cvnfcCustomizations.add(cvnfcCustomization);
1509 existingCvnfcSet.add(cvnfcCustomization);
1511 //*****************************************************************************************************************************************
1512 //* Extract Fabric Configuration
1513 //*****************************************************************************************************************************************
1515 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION);
1517 for(NodeTemplate fabricTemplate : fabricConfigList) {
1519 ConfigurationResource fabricConfig = null;
1521 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1523 if(existingConfig == null){
1525 fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1528 fabricConfig = existingConfig;
1531 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure,
1532 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, vfModuleMemberName);
1534 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1545 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1546 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1548 return vfModuleCustomization;
1551 protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct,
1552 VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1553 ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) {
1555 Metadata fabricMetadata = fabricTemplate.getMetaData();
1558 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1560 vfModuleToCvnfc.setConfigurationResource(configResource);
1561 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1562 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1563 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1564 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1565 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1567 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External");
1569 if(policyList != null){
1570 for(Policy policy : policyList){
1572 for(String policyCvfcTarget : policy.getTargets()){
1574 if(policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)){
1576 Map<String, Object> propMap = policy.getPolicyProperties();
1578 if(propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")){
1579 vfModuleToCvnfc.setPolicyName(propMap.get("name").toString());
1586 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function"));
1587 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role"));
1588 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type"));
1590 return vfModuleToCvnfc;
1593 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1594 ConfigurationResource configResource = null;
1595 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1596 if (configurationResourceCustom.getConfigurationResource() != null
1597 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1598 configResource = configurationResourceCustom.getConfigurationResource();
1601 if(configResource==null)
1602 configResource = configRepo.findResourceByModelUUID(modelUUID);
1604 return configResource;
1607 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1608 String vfModuleModelCustomizationUUID) {
1609 VfModuleCustomization vfModuleCustomization = null;
1610 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1611 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1612 vfModuleCustomization = vfModuleCustom;
1615 if(vfModuleCustomization==null)
1616 vfModuleCustomization = vfModuleCustomizationRepo
1617 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1619 return vfModuleCustomization;
1622 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1623 VfModule vfModule = null;
1624 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1625 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1626 vfModule = vfModuleCustom.getVfModule();
1630 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1635 protected VfModuleCustomization createVfModuleCustomization(Group group,
1636 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1637 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1639 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1641 vfModuleCustomization.setVfModule(vfModule);
1643 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1644 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1645 if (initialCount != null && initialCount.length() > 0) {
1646 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1649 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1650 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1652 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1653 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1654 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1655 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1658 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1659 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1661 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1662 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1663 if (maxInstances != null && maxInstances.length() > 0) {
1664 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1667 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1668 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1669 if (minInstances != null && minInstances.length() > 0) {
1670 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1672 return vfModuleCustomization;
1675 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1676 IVfModuleData vfModuleData, Metadata vfMetadata) {
1677 VfModule vfModule = new VfModule();
1678 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1680 if(vfModuleModelUUID == null) {
1681 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1682 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1683 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1684 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1687 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1688 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1689 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1690 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1691 vfModule.setModelUUID(vfModuleModelUUID);
1692 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1693 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1694 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1695 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1697 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1698 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1699 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1700 vfModule.setIsBase(true);
1702 vfModule.setIsBase(false);
1707 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1708 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1709 Metadata vfMetadata) {
1711 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1712 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1713 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1714 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1717 if (matchingObject.isPresent()) {
1718 List<HeatFiles> heatFilesList = new ArrayList<>();
1719 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1720 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1721 HeatTemplate parentHeatTemplate = new HeatTemplate();
1722 String parentArtifactType = null;
1723 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1724 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1726 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1728 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1729 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1730 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1733 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1734 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1736 if(!childNestedHeatTemplates.isEmpty()){
1738 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1739 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1741 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1747 if(!heatFilesList.isEmpty()){
1748 vfModule.setHeatFiles(heatFilesList);
1752 // Set all Child Templates related to HEAT_VOLUME
1753 if(!volumeHeatChildTemplates.isEmpty()){
1754 if(vfModule.getVolumeHeatTemplate() != null){
1755 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1757 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1761 // Set all Child Templates related to HEAT
1762 if(!heatChildTemplates.isEmpty()){
1763 if(vfModule.getModuleHeatTemplate() != null){
1764 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1766 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1772 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1773 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1774 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1775 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1776 vfModuleArtifact.incrementDeployedInDB();
1777 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1778 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1779 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1780 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1781 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1782 vfModuleArtifact.incrementDeployedInDB();
1783 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1784 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1785 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1787 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1789 vfModuleArtifact.incrementDeployedInDB();
1790 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1791 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1792 vfModuleArtifact.incrementDeployedInDB();
1793 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1794 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1795 vfModuleArtifact.incrementDeployedInDB();
1799 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1800 ToscaResourceStructure toscaResourceStructure, Service service) {
1801 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1802 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1803 if(vnfResourceCustomization == null){
1804 VnfResource vnfResource = findExistingVnfResource(service,
1805 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1807 if(vnfResource==null)
1808 vnfResource=createVnfResource(vfNodeTemplate);
1810 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1812 vnfResourceCustomization.setVnfResources(vnfResource);
1813 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1815 // Fetch VNFC Instance Group Info
1816 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1817 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1818 "org.openecomp.groups.VfcInstanceGroup");
1820 for (Group group : groupList) {
1822 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure);
1824 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1827 return vnfResourceCustomization;
1830 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1831 VnfResource vnfResource = null;
1832 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1833 if (vnfResourceCustom.getVnfResources() != null
1834 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1835 vnfResource = vnfResourceCustom.getVnfResources();
1838 if(vnfResource==null)
1839 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1844 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1845 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1846 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1847 vnfResourceCustomization.setModelCustomizationUUID(
1848 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1849 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1851 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1852 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1853 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1854 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1855 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1856 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1857 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1858 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1860 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1861 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1863 vnfResourceCustomization.setVnfResources(vnfResource);
1864 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1865 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1867 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1868 .getCapabilitiesOf(vfNodeTemplate);
1870 if (vnfCustomizationCapability != null) {
1871 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1873 if (capAssign != null) {
1874 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1875 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1876 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1877 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1882 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1884 return vnfResourceCustomization;
1887 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1888 VnfResource vnfResource = new VnfResource();
1889 vnfResource.setModelInvariantUUID(
1890 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1891 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1892 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1894 vnfResource.setModelVersion(
1895 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1896 vnfResource.setDescription(
1897 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1898 vnfResource.setOrchestrationMode(HEAT);
1899 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1900 vnfResource.setAicVersionMax(
1901 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1902 vnfResource.setAicVersionMin(
1903 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1904 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1905 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1910 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1911 ToscaResourceStructure toscaResourceStructure, Service service) {
1912 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1913 .findOneByModelCustomizationUUID(
1914 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1916 if(allottedResourceCustomization == null){
1917 AllottedResource allottedResource = findExistingAllottedResource(service,
1918 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1920 if(allottedResource==null)
1921 allottedResource=createAR(nodeTemplate);
1923 toscaResourceStructure.setAllottedResource(allottedResource);
1924 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1925 allottedResourceCustomization.setAllottedResource(allottedResource);
1926 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1928 return allottedResourceCustomization;
1931 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1932 AllottedResource allottedResource = null;
1933 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1934 if (allottedResourceCustom.getAllottedResource() != null
1935 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1936 allottedResource = allottedResourceCustom.getAllottedResource();
1939 if(allottedResource==null)
1940 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1942 return allottedResource;
1945 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1946 ToscaResourceStructure toscaResourceStructure) {
1947 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1948 allottedResourceCustomization.setModelCustomizationUUID(
1949 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1950 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1953 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1954 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1955 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1956 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1957 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1958 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1959 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1960 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1962 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1964 if(vfcNodes != null){
1965 for(NodeTemplate vfcNode : vfcNodes){
1967 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1968 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1969 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1974 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1975 .getCapabilitiesOf(nodeTemplate);
1977 if (arCustomizationCapability != null) {
1978 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1980 if (capAssign != null) {
1981 allottedResourceCustomization.setMinInstances(
1982 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1983 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1984 allottedResourceCustomization.setMaxInstances(
1985 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1986 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1989 return allottedResourceCustomization;
1992 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1993 AllottedResource allottedResource = new AllottedResource();
1995 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1996 allottedResource.setModelInvariantUUID(
1997 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1999 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2001 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2002 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
2003 allottedResource.setSubcategory(
2004 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
2006 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
2007 return allottedResource;
2010 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
2011 // Scan the payload downloadResult and extract the HeatTemplate
2013 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
2014 return yamlEditor.getParameterList(artifactUUID);
2017 protected String testNull(Object object) {
2019 if (object == null) {
2021 } else if (object.equals("NULL")) {
2023 } else if (object instanceof Integer) {
2024 return object.toString();
2025 } else if (object instanceof String) {
2026 return (String) object;
2028 return "Type not recognized";
2032 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
2033 VfModuleArtifact heatNestedArtifact) {
2035 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
2036 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
2037 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
2038 .getArtifactInfo().getRelatedArtifacts()) {
2039 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2040 return ASDCConfiguration.HEAT;
2046 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
2047 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2048 .getRelatedArtifacts() != null) {
2049 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2050 .get(0).getArtifactInfo().getRelatedArtifacts()) {
2051 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2052 return ASDCConfiguration.HEAT_VOL;
2058 // Does not belong to anything
2063 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2065 return vfResourceStructure.getNotification().getServiceName() + "/"
2066 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2069 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2071 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2072 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2075 protected String getPropertyInput(String propertyName){
2077 String inputName = new String();
2079 if (propertyName != null) {
2080 int getInputIndex = propertyName.indexOf("{get_input=");
2081 if (getInputIndex > -1) {
2082 inputName = propertyName.substring(getInputIndex+11, propertyName.length()-1);
2090 protected static Timestamp getCurrentTimeStamp() {
2092 return new Timestamp(new Date().getTime());