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 com.fasterxml.jackson.core.JsonProcessingException;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import com.google.gson.Gson;
40 import org.hibernate.exception.ConstraintViolationException;
41 import org.hibernate.exception.LockAcquisitionException;
42 import org.onap.sdc.api.notification.IArtifactInfo;
43 import org.onap.sdc.api.notification.IResourceInstance;
44 import org.onap.sdc.api.notification.IStatusData;
45 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
46 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
47 import org.onap.sdc.tosca.parser.enums.SdcTypes;
48 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
49 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
50 import org.onap.sdc.toscaparser.api.Group;
51 import org.onap.sdc.toscaparser.api.NodeTemplate;
52 import org.onap.sdc.toscaparser.api.Policy;
53 import org.onap.sdc.toscaparser.api.Property;
54 import org.onap.sdc.toscaparser.api.RequirementAssignment;
55 import org.onap.sdc.toscaparser.api.RequirementAssignments;
56 import org.onap.sdc.toscaparser.api.elements.Metadata;
57 import org.onap.sdc.toscaparser.api.functions.GetInput;
58 import org.onap.sdc.toscaparser.api.parameters.Input;
59 import org.onap.sdc.utils.DistributionStatusEnum;
60 import org.onap.so.asdc.client.ASDCConfiguration;
61 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
62 import org.onap.so.asdc.installer.ASDCElementInfo;
63 import org.onap.so.asdc.installer.BigDecimalVersion;
64 import org.onap.so.asdc.installer.IVfModuleData;
65 import org.onap.so.asdc.installer.ToscaResourceStructure;
66 import org.onap.so.asdc.installer.VfModuleArtifact;
67 import org.onap.so.asdc.installer.VfModuleStructure;
68 import org.onap.so.asdc.installer.VfResourceStructure;
69 import org.onap.so.asdc.util.YamlEditor;
70 import org.onap.so.db.catalog.beans.AllottedResource;
71 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
72 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
73 import org.onap.so.db.catalog.beans.CollectionResource;
74 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
75 import org.onap.so.db.catalog.beans.ConfigurationResource;
76 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
77 import org.onap.so.db.catalog.beans.CvnfcCustomization;
78 import org.onap.so.db.catalog.beans.HeatEnvironment;
79 import org.onap.so.db.catalog.beans.HeatFiles;
80 import org.onap.so.db.catalog.beans.HeatTemplate;
81 import org.onap.so.db.catalog.beans.HeatTemplateParam;
82 import org.onap.so.db.catalog.beans.InstanceGroupType;
83 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
84 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
85 import org.onap.so.db.catalog.beans.NetworkResource;
86 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
87 import org.onap.so.db.catalog.beans.Service;
88 import org.onap.so.db.catalog.beans.ServiceProxyResource;
89 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
90 import org.onap.so.db.catalog.beans.SubType;
91 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
92 import org.onap.so.db.catalog.beans.ToscaCsar;
93 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
94 import org.onap.so.db.catalog.beans.VfModule;
95 import org.onap.so.db.catalog.beans.VfModuleCustomization;
96 import org.onap.so.db.catalog.beans.VnfResource;
97 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
98 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
99 import org.onap.so.db.catalog.beans.VnfcCustomization;
100 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
101 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
102 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
103 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
104 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
105 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
106 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
107 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
108 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
109 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
110 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
111 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
112 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
113 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
114 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceRepository;
115 import org.onap.so.db.catalog.data.repository.ServiceRepository;
116 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
117 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
118 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
119 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
120 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
121 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
122 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
123 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
124 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
125 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
126 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
127 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
128 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
129 import org.onap.so.logger.MessageEnum;
130 import org.onap.so.logger.MsoLogger;
131 import org.springframework.beans.factory.annotation.Autowired;
132 import org.springframework.stereotype.Component;
133 import org.springframework.transaction.annotation.Transactional;
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";
155 protected ServiceRepository serviceRepo;
158 protected InstanceGroupRepository instanceGroupRepo;
161 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
164 protected ServiceProxyResourceRepository serviceProxyRepo;
167 protected CollectionResourceRepository collectionRepo;
170 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
173 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
176 protected ConfigurationResourceRepository configRepo;
179 protected VnfResourceRepository vnfRepo;
182 protected VnfCustomizationRepository vnfCustomizationRepo;
185 protected VFModuleRepository vfModuleRepo;
188 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
191 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
194 protected VnfcCustomizationRepository vnfcCustomizationRepo;
197 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
200 protected AllottedResourceRepository allottedRepo;
203 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
206 protected NetworkResourceRepository networkRepo;
209 protected HeatTemplateRepository heatRepo;
212 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
215 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
217 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
219 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
222 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
225 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
227 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
229 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
230 boolean status = false;
231 VfResourceStructure vfResourceStructure = vfResourceStruct;
233 status = vfResourceStructure.isDeployedSuccessfully();
234 } catch (RuntimeException e) {
238 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
239 if(existingService != null)
242 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
243 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
244 vfResourceStructure.getNotification().getServiceName(),
245 BigDecimalVersion.castAndCheckNotificationVersionToString(
246 vfResourceStructure.getNotification().getServiceVersion()),
247 vfResourceStructure.getNotification().getServiceUUID(),
248 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
249 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
250 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
251 watchdogCDStatusRepository.saveAndFlush(wdStatus);
253 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
254 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
255 vfResourceStructure.getNotification().getServiceName(),
256 BigDecimalVersion.castAndCheckNotificationVersionToString(
257 vfResourceStructure.getNotification().getServiceVersion()),
258 vfResourceStructure.getNotification().getServiceUUID(),
259 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
262 } catch (Exception e) {
263 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
264 "Exception - isResourceAlreadyDeployed");
265 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
269 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
270 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
271 + " and ComponentName " + iStatus.getComponentName());
274 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
275 iStatus.getComponentName());
276 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
277 watchdogCDStatusRepository.save(cdStatus);
279 } catch (Exception e) {
280 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
281 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
285 @Transactional(rollbackFor = { ArtifactInstallerException.class })
286 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
287 throws ArtifactInstallerException {
288 VfResourceStructure vfResourceStructure = vfResourceStruct;
289 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
291 // PCLO: in case of deployment failure, use a string that will represent
292 // the type of artifact that failed...
293 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
295 createToscaCsar(toscaResourceStruct);
296 createService(toscaResourceStruct, vfResourceStruct);
297 Service service = toscaResourceStruct.getCatalogService();
299 processResourceSequence(toscaResourceStruct, service);
300 processVFResources(toscaResourceStruct, service, vfResourceStructure);
301 processAllottedResources(toscaResourceStruct, service);
302 processNetworks(toscaResourceStruct, service);
303 // process Network Collections
304 processNetworkCollections(toscaResourceStruct, service);
305 // Process Service Proxy & Configuration
306 processServiceProxyAndConfiguration(toscaResourceStruct, service);
308 serviceRepo.save(service);
310 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
311 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
312 watchdogCDStatusRepository.save(status);
314 toscaResourceStruct.setSuccessfulDeployment();
316 } catch (Exception e) {
317 logger.debug("Exception :", e);
318 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
319 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
320 watchdogCDStatusRepository.save(status);
321 Throwable dbExceptionToCapture = e;
322 while (!(dbExceptionToCapture instanceof ConstraintViolationException
323 || dbExceptionToCapture instanceof LockAcquisitionException)
324 && (dbExceptionToCapture.getCause() != null)) {
325 dbExceptionToCapture = dbExceptionToCapture.getCause();
328 if (dbExceptionToCapture instanceof ConstraintViolationException
329 || dbExceptionToCapture instanceof LockAcquisitionException) {
330 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
331 vfResourceStructure.getResourceInstance().getResourceName(),
332 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
334 String elementToLog = (!artifactListForLogging.isEmpty()
335 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
336 : "No element listed");
337 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
338 "Exception caught during installation of "
339 + vfResourceStructure.getResourceInstance().getResourceName()
340 + ". Transaction rollback",
342 throw new ArtifactInstallerException("Exception caught during installation of "
343 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
349 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
350 ISdcCsarHelper iSdcCsarHelper) {
352 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
353 nodes.addAll(nodeTemplates);
355 for (NodeTemplate nodeTemplate : nodeTemplates) {
356 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
357 List<RequirementAssignment> reqAs = requirement.getAll();
358 for (RequirementAssignment ra : reqAs) {
359 String reqNode = ra.getNodeTemplateName();
360 for (NodeTemplate rNode : resultList) {
361 if (rNode.getName().equals(reqNode)) {
362 if(!resultList.contains(nodeTemplate)) {
363 resultList.add(nodeTemplate);
365 if(nodes.contains(nodeTemplate)) {
366 nodes.remove(nodeTemplate);
374 if (!nodes.isEmpty()) {
375 getRequirementList(resultList, nodes, iSdcCsarHelper);
381 // This method retrieve resource sequence from csar file
382 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
383 List<String> resouceSequence = new ArrayList<String>();
384 List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
386 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
387 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
388 List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
389 nodes.addAll(nodeTemplates);
391 for (NodeTemplate nodeTemplate : nodeTemplates) {
392 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
394 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
395 resultList.add(nodeTemplate);
396 nodes.remove(nodeTemplate);
400 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
402 for (NodeTemplate node : resultList) {
403 String templateName = node.getMetaData().getValue("name");
404 if (!resouceSequence.contains(templateName)) {
405 resouceSequence.add(templateName);
409 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
410 service.setResourceOrder(resourceSeqStr);
411 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
414 private static String CUSTOMIZATION_UUID = "customizationUUID";
416 private static String getValue(Object value, List<Input> servInputs) {
417 String output = null;
418 if(value instanceof Map) {
419 // currently this logic handles only one level of nesting.
420 return ((LinkedHashMap) value).values().toArray()[0].toString();
421 } else if(value instanceof GetInput) {
422 String inputName = ((GetInput)value).getInputName();
424 for(Input input : servInputs) {
425 if(input.getName().equals(inputName)) {
426 // keep both input name and default value
427 // if service input does not supplies value the use default value
428 String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
429 output = inputName + "|" + defaultValue;// return default value
434 output = value != null ? value.toString() : "";
436 return output; // return property value
439 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
440 Map<String, String> resouceRequest = new HashMap<>();
441 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
443 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
444 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
445 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
446 if(nodeTemplateOpt.isPresent()) {
447 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
448 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
450 for(String key : resourceProperties.keySet()) {
451 Property property = resourceProperties.get(key);
453 String value = getValue(property.getValue(), serInput);
454 resouceRequest.put(key, value);
459 ObjectMapper objectMapper = new ObjectMapper();
460 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
462 jsonStr = jsonStr.replace("\"", "\\\"");
463 logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
465 } catch (JsonProcessingException e) {
466 logger.error("resource input could not be deserialized for resource customization id ("
467 + resourceCustomizationUuid + ")");
468 throw new ArtifactInstallerException("resource input could not be parsed", e);
472 protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
473 Service service) throws ArtifactInstallerException {
474 List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
476 if (nodeTemplatesVLList != null) {
477 for (NodeTemplate vlNode : nodeTemplatesVLList) {
478 String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
480 TempNetworkHeatTemplateLookup tempNetworkLookUp =
481 tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
483 if (tempNetworkLookUp != null) {
484 HeatTemplate heatTemplate =
485 heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
486 if (heatTemplate != null) {
487 NetworkResourceCustomization networkCustomization =
488 createNetwork (vlNode,
491 tempNetworkLookUp.getAicVersionMax (),
492 tempNetworkLookUp.getAicVersionMin (),
494 service.getNetworkCustomizations ().add (networkCustomization);
496 throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
497 + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
500 NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
506 networkCustomization.setResourceInput(getResourceInput(toscaResourceStruct, networkCustomization.getModelCustomizationUUID()));
507 service.getNetworkCustomizations().add (networkCustomization);
508 logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
509 + networkResourceModelName);
516 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException {
517 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
519 if (allottedResourceList != null) {
520 for (NodeTemplate allottedNode : allottedResourceList) {
521 AllottedResourceCustomization allottedResource = createAllottedResource(allottedNode, toscaResourceStruct, service);
522 allottedResource.setResourceInput(getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID()));
523 service.getAllottedCustomizations().add(allottedResource);
528 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
530 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
532 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
534 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();
535 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
537 ServiceProxyResourceCustomization serviceProxy = null;
539 if (serviceProxyResourceList != null) {
540 for (NodeTemplate spNode : serviceProxyResourceList) {
541 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
543 ServiceProxyResource serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getServiceProxyResource().getModelUUID());
545 if(serviceProxyResource == null){
547 serviceProxyList.add(serviceProxy);
549 for (NodeTemplate configNode : configurationNodeTemplatesList) {
551 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
552 for (RequirementAssignment requirement : requirementsList) {
553 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
554 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
556 configurationResourceList.add(configurationResource);
567 service.setConfigurationCustomizations(configurationResourceList);
568 service.setServiceProxyCustomizations(serviceProxyList);
571 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
573 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
575 if (networkCollectionList != null) {
576 for (NodeTemplate crNode : networkCollectionList) {
578 createNetworkCollection(crNode, toscaResourceStruct, service);
579 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
581 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
582 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
583 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
588 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
592 protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure)
594 logger.debug("processVFResources");
596 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
597 // String servicecategory = toscaResourceStruct.getCatalogService().getCategory();
598 // String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
600 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
601 Metadata metadata = nodeTemplate.getMetaData();
602 String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
603 logger.debug("VF Category is : " + vfCustomizationCategory);
605 // Do not treat Allotted Resources as VNF resources
606 if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){
610 String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
611 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
613 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
615 // Make sure the VF ResourceCustomizationUUID from the notification and tosca
616 // customizations match before comparing their VF Modules UUID's
617 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
618 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
619 + vfCustomizationUUID);
621 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
622 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
623 + " matches vfNotificationResource CustomizationUUID");
625 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, vfCustomizationUUID);
628 logger.debug("Notification VF ResourceCustomizationUUID: "
629 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
630 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
636 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
637 Service service, NodeTemplate nodeTemplate, String vfCustomizationUUID)
639 logger.debug("processVfModules for vfCustomizationUUID: " + vfCustomizationUUID);
641 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
643 if (vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty()) {
644 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>();
645 Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
647 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
649 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
650 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct.getSdcCsarHelper()
651 .getVfModulesByVf(vfCustomizationUUID);
652 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
654 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
656 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
657 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
658 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
660 if (matchingObject.isPresent()) {
661 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct,
662 vfResourceStructure, vfMetadata, vnfResource,service, existingCvnfcSet, existingVnfcSet);
663 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
665 throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
670 vnfResource.setResourceInput(getResourceInput(toscaResourceStruct, vnfResource.getModelCustomizationUUID()));
671 service.getVnfCustomizations().add(vnfResource);
674 public void processWatchdog(String distributionId, String servideUUID) {
675 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
676 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
678 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
679 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
682 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
683 VfResourceStructure vfResourceStructure) {
684 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
686 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
687 case ASDCConfiguration.HEAT:
688 case ASDCConfiguration.HEAT_NESTED:
689 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
692 case ASDCConfiguration.HEAT_VOL:
693 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
695 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
696 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
698 case ASDCConfiguration.HEAT_ENV:
699 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
701 case ASDCConfiguration.HEAT_ARTIFACT:
702 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
703 toscaResourceStruct);
705 case ASDCConfiguration.HEAT_NET:
706 case ASDCConfiguration.OTHER:
707 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
708 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
709 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
710 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
719 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
720 VfModuleArtifact vfModuleArtifact) {
721 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
722 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
723 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
724 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
725 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
726 return moduleArtifact;
732 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
733 List<String> listTypes) {
734 String newFileBody = filebody;
735 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
737 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
739 newFileBody = verifyTheFilePrefixInString(newFileBody,
740 moduleArtifact.getArtifactInfo().getArtifactName());
746 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
748 String needlePrefix = "file:///";
749 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
751 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
755 StringBuilder sb = new StringBuilder(body.length());
757 int currentIndex = 0;
760 while (currentIndex != -1) {
761 startIndex = currentIndex;
762 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
764 if (currentIndex == -1) {
767 // We append from the startIndex up to currentIndex (start of File
769 sb.append(body.substring(startIndex, currentIndex));
770 sb.append(filenameToVerify);
772 currentIndex += prefixedFilenameToVerify.length();
775 sb.append(body.substring(startIndex));
777 return sb.toString();
780 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
781 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
782 HeatTemplate heatTemplate = new HeatTemplate();
783 List<String> typeList = new ArrayList<>();
784 typeList.add(ASDCConfiguration.HEAT_NESTED);
785 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
787 heatTemplate.setTemplateBody(
788 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
789 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
791 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
792 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
794 heatTemplate.setTimeoutMinutes(240);
797 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
798 heatTemplate.setVersion(BigDecimalVersion
799 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
800 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
802 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
803 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
805 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
808 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
809 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
810 heatTemplate.setParameters(heatParam);
811 vfModuleArtifact.setHeatTemplate(heatTemplate);
814 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
815 VfModuleArtifact vfModuleArtifact) {
816 HeatEnvironment heatEnvironment = new HeatEnvironment();
817 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
818 List<String> typeList = new ArrayList<>();
819 typeList.add(ASDCConfiguration.HEAT);
820 typeList.add(ASDCConfiguration.HEAT_VOL);
821 heatEnvironment.setEnvironment(
822 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
823 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
824 heatEnvironment.setVersion(BigDecimalVersion
825 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
826 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
828 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
829 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
831 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
833 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
836 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
837 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
839 HeatFiles heatFile = new HeatFiles();
840 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
841 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
842 heatFile.setFileBody(vfModuleArtifact.getResult());
843 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
844 heatFile.setVersion(BigDecimalVersion
845 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
846 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
847 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
848 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
850 heatFile.setArtifactChecksum(MANUAL_RECORD);
852 vfModuleArtifact.setHeatFiles(heatFile);
855 protected Service createService(ToscaResourceStructure toscaResourceStructure,
856 VfResourceStructure vfResourceStructure) {
858 toscaResourceStructure.getServiceMetadata();
860 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
862 Service service = new Service();
864 if (serviceMetadata != null) {
866 if (toscaResourceStructure.getServiceVersion() != null) {
867 service.setModelVersion(toscaResourceStructure.getServiceVersion());
870 service.setServiceType(serviceMetadata.getValue("serviceType"));
871 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
873 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
874 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
875 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
876 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
878 if (vfResourceStructure != null)
879 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
881 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
882 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
886 toscaResourceStructure.setCatalogService(service);
890 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
892 Metadata spMetadata = nodeTemplate.getMetaData();
894 ServiceProxyResource spResource = new ServiceProxyResource();
896 spResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
897 spResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
898 spResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
899 spResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
900 spResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
902 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
904 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
906 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
907 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
908 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
909 spCustomizationResource.setSourceService(service);
910 spCustomizationResource.setServiceProxyResource(spResource);
911 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
912 spCustomizationResource.setServiceProxyResource(spResource);
913 serviceProxyCustomizationSet.add(spCustomizationResource);
915 toscaResourceStructure.setCatalogServiceProxyResource(spResource);
917 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
919 return spCustomizationResource;
922 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
924 Metadata metadata = nodeTemplate.getMetaData();
926 ConfigurationResource configResource = new ConfigurationResource();
928 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
929 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
930 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
931 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
932 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
933 configResource.setToscaNodeType(nodeTemplate.getType());
935 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
937 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
939 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
940 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
942 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
943 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
944 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
945 configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
946 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
947 configCustomizationResource.setConfigurationResource(configResource);
948 configResourceCustomizationSet.add(configCustomizationResource);
950 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
952 toscaResourceStructure.setCatalogConfigurationResource(configResource);
954 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
956 return configCustomizationResource;
959 protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
961 Metadata fabricMetadata = nodeTemplate.getMetaData();
963 ConfigurationResource configResource = new ConfigurationResource();
965 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
966 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
967 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
968 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
969 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
970 configResource.setToscaNodeType(nodeTemplate.getType());
972 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
974 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
976 configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
977 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
979 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
980 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
981 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
982 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
983 configCustomizationResource.setConfigurationResource(configResource);
984 configResourceCustomizationSet.add(configCustomizationResource);
986 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
988 return configCustomizationResource;
991 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
992 ToscaCsar toscaCsar = new ToscaCsar();
993 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
994 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
996 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
998 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
999 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1000 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1001 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1002 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1004 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1007 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1008 VnfcCustomization vnfcCustomization = null;
1009 for(VnfcCustomization vnfcCustom : vnfcCustomizations){
1010 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1011 vnfcCustomization = vnfcCustom;
1015 if(vnfcCustomization==null)
1016 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1018 return vnfcCustomization;
1021 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
1022 CvnfcCustomization cvnfcCustomization = null;
1023 for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
1024 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1025 cvnfcCustomization = cvnfcCustom;
1029 if(cvnfcCustomization==null)
1030 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1032 return cvnfcCustomization;
1035 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1036 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
1038 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1039 if(networkResourceCustomization==null){
1040 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
1041 toscaResourceStructure);
1043 NetworkResource networkResource = findExistingNetworkResource(service,
1044 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1045 if(networkResource == null)
1046 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1049 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1050 networkResourceCustomization.setNetworkResource(networkResource);
1052 return networkResourceCustomization;
1055 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1056 NetworkResource networkResource = null;
1057 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
1058 if (networkCustom.getNetworkResource() != null
1059 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1060 networkResource = networkCustom.getNetworkResource();
1063 if(networkResource==null)
1064 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1066 return networkResource;
1069 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1070 ToscaResourceStructure toscaResourceStructure) {
1071 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1072 networkResourceCustomization.setModelInstanceName(
1073 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1074 networkResourceCustomization.setModelCustomizationUUID(
1075 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1077 networkResourceCustomization.setNetworkTechnology(
1078 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1079 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1080 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1081 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1082 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1083 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1084 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1085 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1086 return networkResourceCustomization;
1089 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1090 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1091 NetworkResource networkResource = new NetworkResource();
1092 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1093 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1095 if ("true".equalsIgnoreCase(providerNetwork)) {
1096 networkResource.setNeutronNetworkType(PROVIDER);
1098 networkResource.setNeutronNetworkType(BASIC);
1101 networkResource.setModelName(
1102 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1104 networkResource.setModelInvariantUUID(
1105 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1106 networkResource.setModelUUID(
1107 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1108 networkResource.setModelVersion(
1109 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1111 networkResource.setAicVersionMax(aicMax);
1112 networkResource.setAicVersionMin(aicMin);
1113 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1114 networkResource.setDescription(
1115 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1116 networkResource.setOrchestrationMode(HEAT);
1117 networkResource.setHeatTemplate(heatTemplate);
1118 return networkResource;
1121 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1122 ToscaResourceStructure toscaResourceStructure, Service service) {
1124 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
1126 // **** Build Object to populate Collection_Resource table
1127 CollectionResource collectionResource = new CollectionResource();
1130 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1131 collectionResource.setModelInvariantUUID(
1132 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1134 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1136 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1138 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1139 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1141 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1143 // **** Build object to populate Collection_Resource_Customization table
1144 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1146 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1148 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1150 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1153 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1154 ncfc.setModelCustomizationUUID(
1155 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1157 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1158 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1160 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1162 ncfc.setCollectionResource(collectionResource);
1163 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1165 //*** Build object to populate the Instance_Group table
1166 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1167 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
1168 "org.openecomp.groups.NetworkCollection");
1170 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1172 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
1174 for (Group group : groupList) {
1176 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1177 Metadata instanceMetadata = group.getMetadata();
1178 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1179 networkInstanceGroup
1180 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1181 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1182 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1183 networkInstanceGroup.setToscaNodeType(group.getType());
1184 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1186 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1188 networkInstanceGroup.setCollectionResource(collectionResource);
1190 // ****Build object to populate
1191 // Collection_Resource_Instance_Group_Customization table
1192 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
1193 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1194 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1195 crInstanceGroupCustomization.setModelCustomizationUUID(
1196 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1198 String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
1199 String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
1200 if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1201 fixedQuantity + "_quantity") != null) {
1203 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
1204 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1205 fixedQuantity + "_quantity")));
1208 crInstanceGroupCustomization.setDescription(
1209 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1210 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1211 + "_network_collection_description"));
1212 crInstanceGroupCustomization.setFunction(
1213 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1214 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1215 + "_network_collection_function"));
1216 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1217 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1219 networkInstanceGroup
1220 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1222 networkInstanceGroupList.add(networkInstanceGroup);
1226 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1228 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1229 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1231 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1233 //*****Build object to populate the NetworkResource table
1234 NetworkResource networkResource = new NetworkResource();
1236 for(NodeTemplate vlNodeTemplate : vlNodeList){
1238 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1239 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1241 if ("true".equalsIgnoreCase(providerNetwork)) {
1242 networkResource.setNeutronNetworkType(PROVIDER);
1244 networkResource.setNeutronNetworkType(BASIC);
1247 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1249 networkResource.setModelInvariantUUID(
1250 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1251 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1253 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1255 networkResource.setAicVersionMax(
1256 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1258 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1259 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1261 if (tempNetworkLookUp != null ) {
1263 HeatTemplate heatTemplate = heatRepo
1264 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1265 networkResource.setHeatTemplate(heatTemplate);
1267 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1271 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1273 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1274 networkResource.setOrchestrationMode(HEAT);
1276 // Build object to populate the
1277 // Collection_Network_Resource_Customization table
1278 for (NodeTemplate memberNode : group.getMemberNodes()) {
1279 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1282 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1283 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1285 collectionNetworkResourceCustomization.setNetworkTechnology(
1286 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1287 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1288 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1289 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1290 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1291 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1292 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1293 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1294 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1295 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1296 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1298 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1303 return collectionNetworkResourceCustomization;
1306 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1307 VnfResourceCustomization vnfResourceCustomization) {
1309 Metadata instanceMetadata = group.getMetadata();
1310 // Populate InstanceGroup
1311 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1313 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1314 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1315 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1316 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1317 vfcInstanceGroup.setToscaNodeType(group.getType());
1318 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1319 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1321 //Populate VNFCInstanceGroupCustomization
1322 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1324 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1325 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1326 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1327 vfcInstanceGroupCustom.setFunction("FUNCTION");
1328 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1329 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1331 return vfcInstanceGroupCustom;
1335 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1336 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1337 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1339 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1340 vfModuleData.getVfModuleModelCustomizationUUID());
1341 if(vfModuleCustomization == null){
1342 VfModule vfModule = findExistingVfModule(vnfResource,
1343 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1344 Metadata vfMetadata = group.getMetadata();
1346 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1348 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1349 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1351 vfModuleCustomization.setVfModule(vfModule);
1352 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1353 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1355 vfResourceStructure.setAlreadyDeployed(true);
1358 //******************************************************************************************************************
1359 //* Extract VFC's and CVFC's then add them to VFModule
1360 //******************************************************************************************************************
1362 Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();
1363 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
1364 Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
1366 // Extract CVFC lists
1367 List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
1369 for(NodeTemplate cvfcTemplate : cvfcList) {
1371 CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1373 if(existingCvnfcCustomization == null){
1375 //Extract associated VFC - Should always be just one
1376 List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1378 for(NodeTemplate vfcTemplate : vfcList) {
1380 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1381 VnfcCustomization existingVnfcCustomization = null;
1383 existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1385 // Only Add Abstract VNFC's to our DB, ignore all others
1386 if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
1387 vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1388 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1389 vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1390 vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1391 vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1393 vnfcCustomization.setModelVersion(
1394 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1395 vnfcCustomization.setDescription(
1396 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1397 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1399 vnfcCustomizations.add(vnfcCustomization);
1400 existingVnfcSet.add(vnfcCustomization);
1403 // 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.
1404 if(vnfcCustomization.getModelCustomizationUUID() != null){
1406 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
1407 cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1408 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
1409 cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1410 cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1411 cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1413 cvnfcCustomization.setModelVersion(
1414 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1415 cvnfcCustomization.setDescription(
1416 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1417 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
1419 if(existingVnfcCustomization != null){
1420 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
1422 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
1425 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
1426 cvnfcCustomization.setVnfResourceCustomization(vnfResource);
1428 cvnfcCustomizations.add(cvnfcCustomization);
1429 existingCvnfcSet.add(cvnfcCustomization);
1431 //*****************************************************************************************************************************************
1432 //* Extract Fabric Configuration
1433 //*****************************************************************************************************************************************
1435 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
1437 for(NodeTemplate fabricTemplate : fabricConfigList) {
1439 ConfigurationResource fabricConfig = null;
1441 ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1443 if(existingConfig == null){
1445 ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
1447 fabricConfig = fabricConfigCustomization.getConfigurationResource();
1449 service.getConfigurationCustomizations().add(fabricConfigCustomization);
1451 fabricConfig = existingConfig;
1455 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure,
1456 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
1458 vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
1469 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
1470 vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
1472 return vfModuleCustomization;
1475 protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct,
1476 VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
1477 ConfigurationResource configResource) {
1479 Metadata fabricMetadata = fabricTemplate.getMetaData();
1482 VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
1484 vfModuleToCvnfc.setConfigurationResource(configResource);
1485 vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
1486 vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1487 vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
1488 vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
1489 vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
1490 vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
1492 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
1494 if(policyList != null){
1495 for(Policy policy : policyList){
1496 vfModuleToCvnfc.setPolicyName(policy.getName());
1500 vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
1501 vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
1502 vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
1504 return vfModuleToCvnfc;
1507 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
1508 ConfigurationResource configResource = null;
1509 for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
1510 if (configurationResourceCustom.getConfigurationResource() != null
1511 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
1512 configResource = configurationResourceCustom.getConfigurationResource();
1515 if(configResource==null)
1516 configResource = configRepo.findResourceByModelUUID(modelUUID);
1518 return configResource;
1521 protected ServiceProxyResource findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelUUID) {
1522 ServiceProxyResource serviceProxyResource = null;
1523 for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){
1524 if (serviceProxyResourceCustom.getServiceProxyResource() != null
1525 && serviceProxyResourceCustom.getServiceProxyResource().getModelUUID().equals(modelUUID)) {
1526 serviceProxyResource = serviceProxyResourceCustom.getServiceProxyResource();
1529 if(serviceProxyResource==null)
1530 serviceProxyResource = serviceProxyRepo.findResourceByModelUUID(modelUUID);
1532 return serviceProxyResource;
1535 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1536 String vfModuleModelCustomizationUUID) {
1537 VfModuleCustomization vfModuleCustomization = null;
1538 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1539 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1540 vfModuleCustomization = vfModuleCustom;
1543 if(vfModuleCustomization==null)
1544 vfModuleCustomization = vfModuleCustomizationRepo
1545 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1547 return vfModuleCustomization;
1550 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1551 VfModule vfModule = null;
1552 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1553 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1554 vfModule = vfModuleCustom.getVfModule();
1558 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1563 protected VfModuleCustomization createVfModuleCustomization(Group group,
1564 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1565 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1567 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1569 vfModuleCustomization.setVfModule(vfModule);
1571 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1572 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1573 if (initialCount != null && initialCount.length() > 0) {
1574 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1577 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1578 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1580 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1581 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1582 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1583 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1586 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1587 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1589 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1590 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1591 if (maxInstances != null && maxInstances.length() > 0) {
1592 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1595 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1596 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1597 if (minInstances != null && minInstances.length() > 0) {
1598 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1600 return vfModuleCustomization;
1603 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1604 IVfModuleData vfModuleData, Metadata vfMetadata) {
1605 VfModule vfModule = new VfModule();
1606 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1608 if(vfModuleModelUUID == null) {
1609 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1610 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1611 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1612 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1615 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1616 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1617 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1618 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1619 vfModule.setModelUUID(vfModuleModelUUID);
1620 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1621 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1622 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1623 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1625 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1626 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1627 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1628 vfModule.setIsBase(true);
1630 vfModule.setIsBase(false);
1635 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1636 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1637 Metadata vfMetadata) {
1639 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1640 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1641 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1642 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1645 if (matchingObject.isPresent()) {
1646 List<HeatFiles> heatFilesList = new ArrayList<>();
1647 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1648 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1649 HeatTemplate parentHeatTemplate = new HeatTemplate();
1650 String parentArtifactType = null;
1651 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1652 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1654 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1656 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1657 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1658 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1661 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1662 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1664 if(!childNestedHeatTemplates.isEmpty()){
1666 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1667 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1669 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1675 if(!heatFilesList.isEmpty()){
1676 vfModule.setHeatFiles(heatFilesList);
1680 // Set all Child Templates related to HEAT_VOLUME
1681 if(!volumeHeatChildTemplates.isEmpty()){
1682 if(vfModule.getVolumeHeatTemplate() != null){
1683 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1685 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1689 // Set all Child Templates related to HEAT
1690 if(!heatChildTemplates.isEmpty()){
1691 if(vfModule.getModuleHeatTemplate() != null){
1692 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1694 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1700 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1701 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1702 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1703 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1704 vfModuleArtifact.incrementDeployedInDB();
1705 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1706 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1707 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1708 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1709 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1710 vfModuleArtifact.incrementDeployedInDB();
1711 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1712 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1713 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1715 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1717 vfModuleArtifact.incrementDeployedInDB();
1718 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1719 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1720 vfModuleArtifact.incrementDeployedInDB();
1721 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1722 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1723 vfModuleArtifact.incrementDeployedInDB();
1727 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1728 ToscaResourceStructure toscaResourceStructure, Service service) {
1729 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1730 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1731 if(vnfResourceCustomization == null){
1732 VnfResource vnfResource = findExistingVnfResource(service,
1733 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1735 if(vnfResource==null)
1736 vnfResource=createVnfResource(vfNodeTemplate);
1738 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1740 vnfResourceCustomization.setVnfResources(vnfResource);
1741 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1743 // Fetch VNFC Instance Group Info
1744 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1745 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1746 "org.openecomp.groups.VfcInstanceGroup");
1748 for (Group group : groupList) {
1750 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization);
1752 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1755 return vnfResourceCustomization;
1758 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1759 VnfResource vnfResource = null;
1760 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1761 if (vnfResourceCustom.getVnfResources() != null
1762 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1763 vnfResource = vnfResourceCustom.getVnfResources();
1766 if(vnfResource==null)
1767 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1772 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1773 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1774 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1775 vnfResourceCustomization.setModelCustomizationUUID(
1776 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1777 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1779 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1780 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1781 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1782 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1783 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1784 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1785 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1786 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1788 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1789 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1791 vnfResourceCustomization.setVnfResources(vnfResource);
1792 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1793 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1795 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1796 .getCapabilitiesOf(vfNodeTemplate);
1798 if (vnfCustomizationCapability != null) {
1799 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1801 if (capAssign != null) {
1802 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1803 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1804 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1805 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1810 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1812 return vnfResourceCustomization;
1815 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1816 VnfResource vnfResource = new VnfResource();
1817 vnfResource.setModelInvariantUUID(
1818 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1819 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1820 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1822 vnfResource.setModelVersion(
1823 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1824 vnfResource.setDescription(
1825 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1826 vnfResource.setOrchestrationMode(HEAT);
1827 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1828 vnfResource.setAicVersionMax(
1829 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1830 vnfResource.setAicVersionMin(
1831 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1832 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1833 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
1838 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1839 ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException {
1840 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1841 .findOneByModelCustomizationUUID(
1842 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1844 if(allottedResourceCustomization == null){
1845 AllottedResource allottedResource = findExistingAllottedResource(service,
1846 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1848 if(allottedResource==null)
1849 allottedResource=createAR(nodeTemplate);
1851 toscaResourceStructure.setAllottedResource(allottedResource);
1852 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1853 allottedResourceCustomization.setAllottedResource(allottedResource);
1854 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1857 allottedResourceCustomization.setResourceInput(getResourceInput(toscaResourceStructure, allottedResourceCustomization.getModelCustomizationUUID()));
1858 return allottedResourceCustomization;
1861 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1862 AllottedResource allottedResource = null;
1863 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1864 if (allottedResourceCustom.getAllottedResource() != null
1865 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1866 allottedResource = allottedResourceCustom.getAllottedResource();
1869 if(allottedResource==null)
1870 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1872 return allottedResource;
1875 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1876 ToscaResourceStructure toscaResourceStructure) {
1877 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1878 allottedResourceCustomization.setModelCustomizationUUID(
1879 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1880 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1883 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1884 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1885 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1886 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1887 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1888 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1889 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1890 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1892 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1894 if(vfcNodes != null){
1895 for(NodeTemplate vfcNode : vfcNodes){
1897 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1898 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1899 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1904 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1905 .getCapabilitiesOf(nodeTemplate);
1907 if (arCustomizationCapability != null) {
1908 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1910 if (capAssign != null) {
1911 allottedResourceCustomization.setMinInstances(
1912 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1913 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1914 allottedResourceCustomization.setMaxInstances(
1915 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1916 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1919 return allottedResourceCustomization;
1922 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1923 AllottedResource allottedResource = new AllottedResource();
1925 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1926 allottedResource.setModelInvariantUUID(
1927 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1929 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1931 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1932 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1933 allottedResource.setSubcategory(
1934 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1936 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1937 return allottedResource;
1940 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1941 // Scan the payload downloadResult and extract the HeatTemplate
1943 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1944 return yamlEditor.getParameterList(artifactUUID);
1947 protected String testNull(Object object) {
1949 if (object == null) {
1951 } else if (object.equals("NULL")) {
1953 } else if (object instanceof Integer) {
1954 return object.toString();
1955 } else if (object instanceof String) {
1956 return (String) object;
1958 return "Type not recognized";
1962 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1963 VfModuleArtifact heatNestedArtifact) {
1965 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1966 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1967 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1968 .getArtifactInfo().getRelatedArtifacts()) {
1969 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1970 return ASDCConfiguration.HEAT;
1976 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
1977 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
1978 .getRelatedArtifacts() != null) {
1979 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
1980 .get(0).getArtifactInfo().getRelatedArtifacts()) {
1981 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1982 return ASDCConfiguration.HEAT_VOL;
1988 // Does not belong to anything
1993 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
1995 return vfResourceStructure.getNotification().getServiceName() + "/"
1996 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
1999 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2001 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2002 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2006 protected static Timestamp getCurrentTimeStamp() {
2008 return new Timestamp(new Date().getTime());