2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.asdc.installer.heat;
27 import java.sql.Timestamp;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.Date;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.LinkedHashMap;
34 import java.util.List;
36 import java.util.Optional;
38 import java.util.regex.Matcher;
39 import java.util.regex.Pattern;
40 import java.util.stream.Collectors;
41 import com.google.common.base.Strings;
42 import org.hibernate.exception.ConstraintViolationException;
43 import org.hibernate.exception.LockAcquisitionException;
44 import org.onap.sdc.api.notification.IArtifactInfo;
45 import org.onap.sdc.api.notification.IResourceInstance;
46 import org.onap.sdc.api.notification.IStatusData;
47 import org.onap.sdc.tosca.parser.api.IEntityDetails;
48 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
49 import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
50 import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
51 import org.onap.sdc.tosca.parser.enums.SdcTypes;
52 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
53 import org.onap.sdc.toscaparser.api.*;
54 import org.onap.sdc.toscaparser.api.elements.Metadata;
55 import org.onap.sdc.toscaparser.api.functions.GetInput;
56 import org.onap.sdc.toscaparser.api.parameters.Input;
57 import org.onap.sdc.utils.DistributionStatusEnum;
58 import org.onap.so.asdc.client.ASDCConfiguration;
59 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
60 import org.onap.so.asdc.installer.ASDCElementInfo;
61 import org.onap.so.asdc.installer.BigDecimalVersion;
62 import org.onap.so.asdc.installer.IVfModuleData;
63 import org.onap.so.asdc.installer.PnfResourceStructure;
64 import org.onap.so.asdc.installer.ResourceStructure;
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.installer.bpmn.WorkflowResource;
70 import org.onap.so.asdc.util.YamlEditor;
71 import org.onap.so.db.catalog.beans.AllottedResource;
72 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
73 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
74 import org.onap.so.db.catalog.beans.CollectionResource;
75 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
76 import org.onap.so.db.catalog.beans.ConfigurationResource;
77 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
78 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
79 import org.onap.so.db.catalog.beans.CvnfcCustomization;
80 import org.onap.so.db.catalog.beans.HeatEnvironment;
81 import org.onap.so.db.catalog.beans.HeatFiles;
82 import org.onap.so.db.catalog.beans.HeatTemplate;
83 import org.onap.so.db.catalog.beans.HeatTemplateParam;
84 import org.onap.so.db.catalog.beans.InstanceGroup;
85 import org.onap.so.db.catalog.beans.InstanceGroupType;
86 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
87 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
88 import org.onap.so.db.catalog.beans.NetworkResource;
89 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
90 import org.onap.so.db.catalog.beans.PnfResource;
91 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
92 import org.onap.so.db.catalog.beans.Service;
93 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
94 import org.onap.so.db.catalog.beans.SubType;
95 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
96 import org.onap.so.db.catalog.beans.ToscaCsar;
97 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
98 import org.onap.so.db.catalog.beans.VfModule;
99 import org.onap.so.db.catalog.beans.VfModuleCustomization;
100 import org.onap.so.db.catalog.beans.VnfResource;
101 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
102 import org.onap.so.db.catalog.beans.VnfcCustomization;
103 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
104 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
105 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
106 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
107 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
108 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
109 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
110 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
111 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
112 import org.onap.so.db.catalog.data.repository.HeatEnvironmentRepository;
113 import org.onap.so.db.catalog.data.repository.HeatFilesRepository;
114 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
115 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
116 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
117 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
118 import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
119 import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
120 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
121 import org.onap.so.db.catalog.data.repository.ServiceRepository;
122 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
123 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
124 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
125 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
126 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
127 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
128 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
129 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
130 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
131 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
132 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
133 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
134 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
135 import org.onap.so.logger.ErrorCode;
136 import org.onap.so.logger.MessageEnum;
137 import org.slf4j.Logger;
138 import org.slf4j.LoggerFactory;
139 import org.springframework.beans.factory.annotation.Autowired;
140 import org.springframework.orm.ObjectOptimisticLockingFailureException;
141 import org.springframework.stereotype.Component;
142 import org.springframework.transaction.annotation.Transactional;
143 import com.fasterxml.jackson.core.JsonProcessingException;
144 import com.fasterxml.jackson.databind.ObjectMapper;
145 import org.springframework.util.CollectionUtils;
148 public class ToscaResourceInstaller {
150 protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry";
152 protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor";
154 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
156 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
158 protected static final String SCALABLE = "scalable";
160 protected static final String BASIC = "BASIC";
162 protected static final String PROVIDER = "PROVIDER";
164 protected static final String HEAT = "HEAT";
166 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
168 protected static final String MSO = "SO";
170 protected static final String SDNC_MODEL_NAME = "sdnc_model_name";
172 protected static final String SDNC_MODEL_VERSION = "sdnc_model_version";
174 private static String CUSTOMIZATION_UUID = "customizationUUID";
176 protected static final String SKIP_POST_INST_CONF = "skip_post_instantiation_configuration";
179 protected ServiceRepository serviceRepo;
182 protected InstanceGroupRepository instanceGroupRepo;
185 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
188 protected CollectionResourceRepository collectionRepo;
191 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
194 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
197 protected ConfigurationResourceRepository configRepo;
200 protected VnfResourceRepository vnfRepo;
203 protected VFModuleRepository vfModuleRepo;
206 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
209 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
212 protected VnfcCustomizationRepository vnfcCustomizationRepo;
215 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
218 protected AllottedResourceRepository allottedRepo;
221 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
224 protected NetworkResourceRepository networkRepo;
227 protected HeatTemplateRepository heatRepo;
230 protected HeatEnvironmentRepository heatEnvRepo;
233 protected HeatFilesRepository heatFilesRepo;
236 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
239 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
241 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
243 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
246 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
249 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
252 protected ToscaCsarRepository toscaCsarRepo;
255 protected PnfResourceRepository pnfResourceRepository;
258 protected PnfCustomizationRepository pnfCustomizationRepository;
261 protected WorkflowResource workflowResource;
263 protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
265 public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure)
266 throws ArtifactInstallerException {
267 boolean deployed = false;
268 if (toscaResourceStructure == null) {
272 IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
273 String checkSum = inputToscaCsar.getArtifactChecksum();
274 String artifactUuid = inputToscaCsar.getArtifactUUID();
276 Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
277 if (toscaCsarObj.isPresent()) {
278 ToscaCsar toscaCsar = toscaCsarObj.get();
279 if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
280 String errorMessage =
281 String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
282 throw new ArtifactInstallerException(errorMessage);
283 } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
290 public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed)
291 throws ArtifactInstallerException {
292 boolean status = false;
293 ResourceStructure vfResourceStructure = vfResourceStruct;
295 status = vfResourceStructure.isDeployedSuccessfully();
296 } catch (RuntimeException e) {
298 logger.debug("Exception :", e);
301 Service existingService =
302 serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
303 if (existingService != null && !serviceDeployed)
306 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
307 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
308 vfResourceStructure.getNotification().getServiceName(),
309 BigDecimalVersion.castAndCheckNotificationVersionToString(
310 vfResourceStructure.getNotification().getServiceVersion()),
311 vfResourceStructure.getNotification().getServiceUUID(),
312 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
313 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(
314 vfResourceStruct.getNotification().getDistributionID(), MSO);
315 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
316 watchdogCDStatusRepository.saveAndFlush(wdStatus);
318 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
319 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
320 vfResourceStructure.getNotification().getServiceName(),
321 BigDecimalVersion.castAndCheckNotificationVersionToString(
322 vfResourceStructure.getNotification().getServiceVersion()),
323 vfResourceStructure.getNotification().getServiceUUID(),
324 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
327 } catch (Exception e) {
328 logger.error(Strings.repeat("{} ", 3), MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(),
329 ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed");
330 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
334 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
335 logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}",
336 iStatus.getDistributionID(), iStatus.getComponentName());
339 WatchdogComponentDistributionStatus cdStatus =
340 new WatchdogComponentDistributionStatus(iStatus.getDistributionID(), iStatus.getComponentName());
341 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
342 watchdogCDStatusRepository.save(cdStatus);
344 } catch (Exception e) {
345 logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
346 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
351 @Transactional(rollbackFor = {ArtifactInstallerException.class})
352 public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct)
353 throws ArtifactInstallerException {
354 if (resourceStruct instanceof VfResourceStructure) {
355 installTheVfResource(toscaResourceStruct, (VfResourceStructure) resourceStruct);
356 } else if (resourceStruct instanceof PnfResourceStructure) {
357 installPnfResource(toscaResourceStruct, (PnfResourceStructure) resourceStruct);
359 logger.warn("Unrecognized resource type");
363 private void installPnfResource(ToscaResourceStructure toscaResourceStruct, PnfResourceStructure resourceStruct)
364 throws ArtifactInstallerException {
366 // PCLO: in case of deployment failure, use a string that will represent
367 // the type of artifact that failed...
368 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
370 createToscaCsar(toscaResourceStruct);
371 Service service = createService(toscaResourceStruct, resourceStruct);
373 processResourceSequence(toscaResourceStruct, service);
374 processPnfResources(toscaResourceStruct, service, resourceStruct);
375 serviceRepo.save(service);
377 WatchdogComponentDistributionStatus status =
378 new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
379 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
380 watchdogCDStatusRepository.save(status);
382 toscaResourceStruct.setSuccessfulDeployment();
384 } catch (Exception e) {
385 logger.debug("Exception :", e);
386 WatchdogComponentDistributionStatus status =
387 new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
388 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
389 watchdogCDStatusRepository.save(status);
390 Throwable dbExceptionToCapture = e;
391 while (!(dbExceptionToCapture instanceof ConstraintViolationException
392 || dbExceptionToCapture instanceof LockAcquisitionException)
393 && (dbExceptionToCapture.getCause() != null)) {
394 dbExceptionToCapture = dbExceptionToCapture.getCause();
397 if (dbExceptionToCapture instanceof ConstraintViolationException
398 || dbExceptionToCapture instanceof LockAcquisitionException) {
399 logger.warn(Strings.repeat("{} ", 5), MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
400 resourceStruct.getResourceInstance().getResourceName(),
401 resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
402 "Exception - ASCDC Artifact already deployed", e);
404 String elementToLog = (!artifactListForLogging.isEmpty()
405 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
406 : "No element listed");
407 logger.error(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
408 ErrorCode.DataError.getValue(), "Exception caught during installation of "
409 + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback",
411 throw new ArtifactInstallerException(
412 "Exception caught during installation of "
413 + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback.",
419 @Transactional(rollbackFor = {ArtifactInstallerException.class})
420 public void installTheVfResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
421 throws ArtifactInstallerException {
422 VfResourceStructure vfResourceStructure = vfResourceStruct;
423 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
425 // PCLO: in case of deployment failure, use a string that will represent
426 // the type of artifact that failed...
427 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
429 createToscaCsar(toscaResourceStruct);
430 createService(toscaResourceStruct, vfResourceStruct);
431 Service service = toscaResourceStruct.getCatalogService();
432 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
434 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
435 Metadata metadata = nodeTemplate.getMetaData();
436 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
437 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
438 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
439 vfCustomizationCategory);
442 workflowResource.processWorkflows(vfResourceStructure);
443 processResourceSequence(toscaResourceStruct, service);
444 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
445 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
446 processNetworks(toscaResourceStruct, service);
447 // process Network Collections
448 processNetworkCollections(toscaResourceStruct, service);
449 // Process Service Proxy & Configuration
450 processServiceProxyAndConfiguration(toscaResourceStruct, service);
452 logger.info("Saving Service: {} ", service.getModelName());
453 service = serviceRepo.save(service);
454 correlateConfigCustomResources(service);
456 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
457 vfResourceStruct.getNotification().getDistributionID(), MSO);
458 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
459 watchdogCDStatusRepository.save(status);
461 toscaResourceStruct.setSuccessfulDeployment();
463 } catch (Exception e) {
464 logger.debug("Exception :", e);
465 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
466 vfResourceStruct.getNotification().getDistributionID(), MSO);
467 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
468 watchdogCDStatusRepository.save(status);
469 Throwable dbExceptionToCapture = e;
470 while (!(dbExceptionToCapture instanceof ConstraintViolationException
471 || dbExceptionToCapture instanceof LockAcquisitionException)
472 && (dbExceptionToCapture.getCause() != null)) {
473 dbExceptionToCapture = dbExceptionToCapture.getCause();
476 if (dbExceptionToCapture instanceof ConstraintViolationException
477 || dbExceptionToCapture instanceof LockAcquisitionException) {
478 logger.warn(Strings.repeat("{} ", 5), MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
479 vfResourceStructure.getResourceInstance().getResourceName(),
480 vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
481 "Exception - ASCDC Artifact already deployed", e);
483 String elementToLog = (!artifactListForLogging.isEmpty()
484 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
485 : "No element listed");
486 logger.error(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
487 ErrorCode.DataError.getValue(),
488 "Exception caught during installation of "
489 + vfResourceStructure.getResourceInstance().getResourceName()
490 + ". Transaction rollback",
492 throw new ArtifactInstallerException("Exception caught during installation of "
493 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
499 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
500 ISdcCsarHelper iSdcCsarHelper) {
502 List<NodeTemplate> nodes = new ArrayList<>();
503 nodes.addAll(nodeTemplates);
505 for (NodeTemplate nodeTemplate : nodeTemplates) {
506 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
507 List<RequirementAssignment> reqAs = requirement.getAll();
508 for (RequirementAssignment ra : reqAs) {
509 String reqNode = ra.getNodeTemplateName();
510 for (NodeTemplate rNode : resultList) {
511 if (rNode.getName().equals(reqNode)) {
512 if (!resultList.contains(nodeTemplate)) {
513 resultList.add(nodeTemplate);
515 if (nodes.contains(nodeTemplate)) {
516 nodes.remove(nodeTemplate);
524 if (!nodes.isEmpty()) {
525 getRequirementList(resultList, nodes, iSdcCsarHelper);
531 // This method retrieve resource sequence from csar file
532 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
533 List<String> resouceSequence = new ArrayList<>();
534 List<NodeTemplate> resultList = new ArrayList<>();
536 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
537 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
538 List<NodeTemplate> nodes = new ArrayList<>();
539 nodes.addAll(nodeTemplates);
541 for (NodeTemplate nodeTemplate : nodeTemplates) {
542 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
544 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
545 resultList.add(nodeTemplate);
546 nodes.remove(nodeTemplate);
550 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
552 for (NodeTemplate node : resultList) {
553 String templateName = node.getMetaData().getValue("name");
554 if (!resouceSequence.contains(templateName)) {
555 resouceSequence.add(templateName);
559 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
560 service.setResourceOrder(resourceSeqStr);
561 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
565 // this of temporary solution
566 private static String getValue(Object value, List<Input> inputs) {
568 String defaultValue = null;
569 if (value instanceof Map) {
570 outInput = ((LinkedHashMap) value).values().toArray()[0].toString();
571 } else if (value instanceof GetInput) {
572 String inputName = ((GetInput) value).getInputName();
573 Optional<Input> inputOptional =
574 inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst();
575 if (inputOptional.isPresent()) {
576 Input input = inputOptional.get();
577 defaultValue = input.getDefault() != null ? input.getDefault().toString() : "";
579 // Gets a value between [ and ]
580 String regex = "\\[.*?\\]";
581 Pattern pattern = Pattern.compile(regex);
582 Matcher matcher = pattern.matcher(value.toString());
583 String valueStr = matcher.find() ? matcher.group() : inputName;
584 outInput = valueStr + "|" + defaultValue;
586 outInput = value != null ? value.toString() : "";
591 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid)
592 throws ArtifactInstallerException {
593 Map<String, String> resouceRequest = new HashMap<>();
594 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
596 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
597 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
598 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid))
600 if (nodeTemplateOpt.isPresent()) {
601 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
602 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
604 for (String key : resourceProperties.keySet()) {
605 Property property = resourceProperties.get(key);
607 String value = getValue(property.getValue(), serInput);
608 resouceRequest.put(key, value);
613 ObjectMapper objectMapper = new ObjectMapper();
614 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
616 jsonStr = jsonStr.replace("\"", "\\\"");
618 "resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
620 } catch (JsonProcessingException e) {
621 logger.error("resource input could not be deserialized for resource customization id ("
622 + resourceCustomizationUuid + ")");
623 throw new ArtifactInstallerException("resource input could not be parsed", e);
627 protected void processNetworks(ToscaResourceStructure toscaResourceStruct, Service service)
628 throws ArtifactInstallerException {
629 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper().getServiceVlList();
631 if (nodeTemplatesVLList != null) {
632 for (NodeTemplate vlNode : nodeTemplatesVLList) {
633 String networkResourceModelName = vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
635 TempNetworkHeatTemplateLookup tempNetworkLookUp =
636 tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkResourceModelName);
638 if (tempNetworkLookUp != null) {
639 HeatTemplate heatTemplate =
640 heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
641 if (heatTemplate != null) {
642 NetworkResourceCustomization networkCustomization = createNetwork(vlNode, toscaResourceStruct,
643 heatTemplate, tempNetworkLookUp.getAicVersionMax(),
644 tempNetworkLookUp.getAicVersionMin(), service);
645 service.getNetworkCustomizations().add(networkCustomization);
647 throw new ArtifactInstallerException("No HeatTemplate found for artifactUUID: "
648 + tempNetworkLookUp.getHeatTemplateArtifactUuid());
651 NetworkResourceCustomization networkCustomization =
652 createNetwork(vlNode, toscaResourceStruct, null, null, null, service);
653 service.getNetworkCustomizations().add(networkCustomization);
654 logger.debug("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
655 + networkResourceModelName);
662 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
663 List<NodeTemplate> allottedResourceList) {
664 if (allottedResourceList != null) {
665 for (NodeTemplate allottedNode : allottedResourceList) {
666 service.getAllottedCustomizations()
667 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
673 protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) {
674 Metadata metadata = nodeTemplate.getMetaData();
675 ConfigurationResource configResource = new ConfigurationResource();
676 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
677 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
678 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
679 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
680 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
681 configResource.setToscaNodeType(nodeTemplate.getType());
682 return configResource;
685 protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate,
686 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
688 Metadata metadata = nodeTemplate.getMetaData();
690 ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
692 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
694 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
696 configCustomizationResource
697 .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
698 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
700 configCustomizationResource.setFunction(
701 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
702 configCustomizationResource.setRole(
703 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
704 configCustomizationResource.setType(
705 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
706 configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
708 configCustomizationResource.setConfigurationResource(configResource);
709 configCustomizationResource.setService(service);
710 configResourceCustomizationSet.add(configCustomizationResource);
712 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
714 return configCustomizationResource;
718 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
720 List<NodeTemplate> serviceProxyResourceList =
721 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
723 List<NodeTemplate> configurationNodeTemplatesList =
724 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
726 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<>();
727 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<>();
729 ServiceProxyResourceCustomization serviceProxy = null;
731 if (serviceProxyResourceList != null) {
732 for (NodeTemplate spNode : serviceProxyResourceList) {
733 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
734 serviceProxyList.add(serviceProxy);
736 for (NodeTemplate configNode : configurationNodeTemplatesList) {
738 List<RequirementAssignment> requirementsList =
739 toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
740 for (RequirementAssignment requirement : requirementsList) {
741 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
742 ConfigurationResourceCustomization configurationResource =
743 createConfiguration(configNode, toscaResourceStruct, serviceProxy, service);
745 Optional<ConfigurationResourceCustomization> matchingObject =
746 configurationResourceList.stream()
747 .filter(configurationResourceCustomization -> configNode.getMetaData()
748 .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)
749 .equals(configurationResource.getModelCustomizationUUID()))
750 .filter(configurationResourceCustomization -> configurationResourceCustomization
751 .getModelInstanceName()
752 .equals(configurationResource.getModelInstanceName()))
754 if (!matchingObject.isPresent()) {
755 configurationResourceList.add(configurationResource);
765 service.setConfigurationCustomizations(configurationResourceList);
766 service.setServiceProxyCustomizations(serviceProxyList);
770 * ConfigurationResourceCustomization objects have their IDs auto incremented in the database. Unless we know their
771 * IDs we cannot possibly associate their related records. So these ConfigResourceCustomizations are persisted first
772 * and subsequently correlated.
775 protected void correlateConfigCustomResources(Service service) {
776 /* Assuming that we have only one pair of VRF-VNR */
777 ConfigurationResourceCustomization vrfConfigCustomResource = null;
778 ConfigurationResourceCustomization vnrConfigCustomResource = null;
779 List<ConfigurationResourceCustomization> configCustomList = service.getConfigurationCustomizations();
780 for (ConfigurationResourceCustomization configResource : configCustomList) {
781 String nodeType = configResource.getConfigurationResource().getToscaNodeType();
782 if (NODES_VRF_ENTRY.equalsIgnoreCase(nodeType)) {
783 vrfConfigCustomResource = configResource;
784 } else if (VLAN_NETWORK_RECEPTOR.equalsIgnoreCase(nodeType)) {
785 vnrConfigCustomResource = configResource;
789 if (vrfConfigCustomResource != null) {
790 vrfConfigCustomResource.setConfigResourceCustomization(vnrConfigCustomResource);
791 configCustomizationRepo.save(vrfConfigCustomResource);
794 if (vnrConfigCustomResource != null) {
795 vnrConfigCustomResource.setConfigResourceCustomization(vrfConfigCustomResource);
796 configCustomizationRepo.save(vnrConfigCustomResource);
800 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
802 List<NodeTemplate> networkCollectionList =
803 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
805 if (networkCollectionList != null) {
806 for (NodeTemplate crNode : networkCollectionList) {
808 createNetworkCollection(crNode, toscaResourceStruct, service);
809 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
811 List<NetworkInstanceGroup> networkInstanceGroupList =
812 toscaResourceStruct.getCatalogNetworkInstanceGroup();
813 for (NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList) {
814 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
819 service.getCollectionResourceCustomizations()
820 .add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
826 * This is used to process the PNF specific resource, including resource and resource_customization.
827 * {@link IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for
830 protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service,
831 PnfResourceStructure resourceStructure) throws Exception {
832 logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
834 ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
835 EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
836 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
838 List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
839 for (IEntityDetails entityDetails : entityDetailsList) {
840 Metadata metadata = entityDetails.getMetadata();
841 String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
842 String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
843 String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
844 if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
845 logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}",
846 customizationUUID, notifCustomizationUUID);
848 if (checkExistingPnfResourceCutomization(customizationUUID)) {
849 logger.info("Resource customization UUID: {} already deployed", customizationUUID);
851 PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
852 if (pnfResource == null) {
853 pnfResource = createPnfResource(entityDetails);
855 PnfResourceCustomization pnfResourceCustomization =
856 createPnfResourceCustomization(entityDetails, pnfResource);
857 pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
858 toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
859 service.getPnfCustomizations().add(pnfResourceCustomization);
863 "Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}",
864 customizationUUID, notifCustomizationUUID);
869 private PnfResource findExistingPnfResource(Service service, String modelUuid) {
870 PnfResource pnfResource = null;
871 for (PnfResourceCustomization pnfResourceCustomization : service.getPnfCustomizations()) {
872 if (pnfResourceCustomization.getPnfResources() != null
873 && pnfResourceCustomization.getPnfResources().getModelUUID().equals(modelUuid)) {
874 pnfResource = pnfResourceCustomization.getPnfResources();
877 if (pnfResource == null) {
878 pnfResource = pnfResourceRepository.findById(modelUuid).orElse(pnfResource);
883 private boolean checkExistingPnfResourceCutomization(String customizationUUID) {
884 return pnfCustomizationRepository.findById(customizationUUID).isPresent();
888 * Construct the {@link PnfResource} from {@link IEntityDetails} object.
890 private PnfResource createPnfResource(IEntityDetails entity) {
891 PnfResource pnfResource = new PnfResource();
892 Metadata metadata = entity.getMetadata();
893 pnfResource.setModelInvariantUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
894 pnfResource.setModelName(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
895 pnfResource.setModelUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
896 pnfResource.setModelVersion(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
897 pnfResource.setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
898 pnfResource.setCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)));
899 pnfResource.setSubCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
900 pnfResource.setToscaNodeType(entity.getToscaType());
905 * Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object.
907 private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails,
908 PnfResource pnfResource) {
910 PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization();
911 Metadata metadata = entityDetails.getMetadata();
912 Map<String, Property> properties = entityDetails.getProperties();
913 pnfResourceCustomization.setModelCustomizationUUID(
914 testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
915 pnfResourceCustomization.setModelInstanceName(entityDetails.getName());
916 pnfResourceCustomization
917 .setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
918 pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE)));
919 pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE)));
920 pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
921 pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN)));
922 pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME)));
923 pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION)));
924 pnfResourceCustomization.setSkipPostInstConf(getBooleanValue(properties.get(SKIP_POST_INST_CONF)));
925 pnfResourceCustomization.setPnfResources(pnfResource);
927 return pnfResourceCustomization;
931 * Get value from {@link Property} and cast to boolean value. Return true if property is null.
933 private boolean getBooleanValue(Property property) {
934 if (null == property) {
937 Object value = property.getValue();
938 return new Boolean(String.valueOf(value));
942 * Get value from {@link Property} and cast to String value. Return empty String if property is null value.
944 private String getStringValue(Property property) {
945 if (null == property) {
948 Object value = property.getValue();
949 return String.valueOf(value);
952 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
953 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory)
956 logger.debug("VF Category is : " + vfCustomizationCategory);
958 if (vfResourceStructure.getVfModuleStructure() != null
959 && !vfResourceStructure.getVfModuleStructure().isEmpty()) {
961 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper().getMetadataPropertyValue(metadata,
962 SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
963 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
965 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
967 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before
968 // comparing their VF Modules UUID's
969 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
970 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
971 + vfCustomizationUUID);
973 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
975 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
976 + " matches vfNotificationResource CustomizationUUID");
978 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
980 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<>();
981 Set<VnfcCustomization> existingVnfcSet = new HashSet<>();
983 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
985 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
986 List<org.onap.sdc.toscaparser.api.Group> vfGroups =
987 toscaResourceStruct.getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
988 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
990 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : "
991 + vfMetadata.getVfModuleModelCustomizationUUID());
993 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
994 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID "
995 + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
996 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID")
997 .equals(vfMetadata.getVfModuleModelCustomizationUUID()))
999 if (matchingObject.isPresent()) {
1000 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(),
1001 nodeTemplate, toscaResourceStruct, vfResourceStructure, vfMetadata, vnfResource,
1002 service, existingCvnfcSet, existingVnfcSet);
1003 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
1005 throw new Exception(
1006 "Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: "
1007 + vfMetadata.getVfModuleModelCustomizationUUID());
1012 // Check for VNFC Instance Group info and add it if there is
1013 List<Group> groupList =
1014 toscaResourceStruct.getSdcCsarHelper().getGroupsOfOriginOfNodeTemplateByToscaGroupType(
1015 nodeTemplate, "org.openecomp.groups.VfcInstanceGroup");
1017 for (Group group : groupList) {
1018 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization =
1019 createVNFCInstanceGroup(nodeTemplate, group, vnfResource, toscaResourceStruct);
1020 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1023 List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList);
1024 if (!CollectionUtils.isEmpty(seqResult)) {
1025 String resultStr = seqResult.stream().collect(Collectors.joining(","));
1026 vnfResource.setVnfcInstanceGroupOrder(resultStr);
1028 "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr);
1030 // add this vnfResource with existing vnfResource for this service
1031 addVnfCustomization(service, vnfResource);
1033 logger.debug("Notification VF ResourceCustomizationUUID: "
1034 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
1035 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
1040 private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure,
1041 List<Group> groupList) {
1042 if (CollectionUtils.isEmpty(groupList)) {
1043 return Collections.emptyList();
1046 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
1047 List<String> strSequence = new ArrayList<>(groupList.size());
1048 List<Group> tempGroupList = new ArrayList<>(groupList.size());
1049 List<NodeTemplate> nodes = new ArrayList<>();
1050 tempGroupList.addAll(groupList);
1052 for (Group group : groupList) {
1053 List<NodeTemplate> nodeList = group.getMemberNodes();
1054 boolean hasRequirements = false;
1055 for (NodeTemplate node : nodeList) {
1056 RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node);
1057 if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) {
1058 hasRequirements = true;
1063 if (!hasRequirements) {
1064 strSequence.add(group.getName());
1065 tempGroupList.remove(group);
1066 nodes.addAll(nodeList);
1070 getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
1076 private void getVNFCGroupSequenceList(List<String> strSequence, List<Group> groupList, List<NodeTemplate> nodes,
1077 ISdcCsarHelper iSdcCsarHelper) {
1078 if (CollectionUtils.isEmpty(groupList)) {
1082 List<Group> tempGroupList = new ArrayList<>();
1083 tempGroupList.addAll(groupList);
1085 for (Group group : groupList) {
1086 ArrayList<NodeTemplate> members = group.getMemberNodes();
1087 for (NodeTemplate memberNode : members) {
1088 boolean isAllExists = true;
1089 RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode);
1090 if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) {
1093 List<RequirementAssignment> rqaList = requirements.getAll();
1094 for (RequirementAssignment rqa : rqaList) {
1095 String name = rqa.getNodeTemplateName();
1096 for (NodeTemplate node : nodes) {
1097 if (name.equals(node.getName())) {
1102 isAllExists = false;
1107 strSequence.add(group.getName());
1108 tempGroupList.remove(group);
1109 nodes.addAll(group.getMemberNodes());
1113 if (!tempGroupList.isEmpty() && tempGroupList.size() < groupList.size()) {
1114 getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
1119 public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
1120 String consumerId) {
1121 WatchdogServiceModVerIdLookup modVerIdLookup =
1122 new WatchdogServiceModVerIdLookup(distributionId, servideUUID, distributionNotification, consumerId);
1123 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
1127 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
1128 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
1130 } catch (ObjectOptimisticLockingFailureException e) {
1131 logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
1136 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
1137 VfResourceStructure vfResourceStructure) {
1138 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1140 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
1141 case ASDCConfiguration.HEAT:
1142 case ASDCConfiguration.HEAT_NESTED:
1143 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, vfModuleArtifact);
1145 case ASDCConfiguration.HEAT_VOL:
1146 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, vfModuleArtifact);
1147 VfModuleArtifact envModuleArtifact =
1148 getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1149 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
1151 case ASDCConfiguration.HEAT_ENV:
1152 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
1154 case ASDCConfiguration.HEAT_ARTIFACT:
1155 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact, toscaResourceStruct);
1157 case ASDCConfiguration.HEAT_NET:
1158 case ASDCConfiguration.OTHER:
1159 case ASDCConfiguration.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT:
1160 logger.warn(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(),
1161 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
1162 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
1163 ErrorCode.DataError.getValue(), "Artifact type not supported");
1172 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
1173 VfModuleArtifact vfModuleArtifact) {
1174 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
1175 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
1176 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1177 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
1178 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1179 return moduleArtifact;
1185 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
1186 List<String> listTypes) {
1187 String newFileBody = filebody;
1188 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1190 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
1193 verifyTheFilePrefixInString(newFileBody, moduleArtifact.getArtifactInfo().getArtifactName());
1199 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
1201 String needlePrefix = "file:///";
1202 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
1204 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
1208 StringBuilder sb = new StringBuilder(body.length());
1210 int currentIndex = 0;
1213 while (currentIndex != -1) {
1214 startIndex = currentIndex;
1215 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
1217 if (currentIndex == -1) {
1220 // We append from the startIndex up to currentIndex (start of File
1222 sb.append(body.substring(startIndex, currentIndex));
1223 sb.append(filenameToVerify);
1225 currentIndex += prefixedFilenameToVerify.length();
1228 sb.append(body.substring(startIndex));
1230 return sb.toString();
1233 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
1234 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
1236 HeatTemplate existingHeatTemplate =
1237 heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1239 if (existingHeatTemplate == null) {
1240 HeatTemplate heatTemplate = new HeatTemplate();
1241 List<String> typeList = new ArrayList<>();
1242 typeList.add(ASDCConfiguration.HEAT_NESTED);
1243 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
1245 heatTemplate.setTemplateBody(
1246 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
1247 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1249 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
1250 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
1252 heatTemplate.setTimeoutMinutes(240);
1255 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1256 heatTemplate.setVersion(BigDecimalVersion
1257 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1258 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1260 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1261 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1263 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
1266 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
1267 vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1268 heatTemplate.setParameters(heatParam);
1269 vfModuleArtifact.setHeatTemplate(heatTemplate);
1271 vfModuleArtifact.setHeatTemplate(existingHeatTemplate);
1275 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
1276 VfModuleArtifact vfModuleArtifact) {
1278 HeatEnvironment existingHeatEnvironment =
1279 heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1281 if (existingHeatEnvironment == null) {
1282 HeatEnvironment heatEnvironment = new HeatEnvironment();
1283 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1284 List<String> typeList = new ArrayList<>();
1285 typeList.add(ASDCConfiguration.HEAT);
1286 typeList.add(ASDCConfiguration.HEAT_VOL);
1287 heatEnvironment.setEnvironment(
1288 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
1289 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1290 heatEnvironment.setVersion(BigDecimalVersion
1291 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1292 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1294 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1295 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1297 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
1299 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
1301 vfModuleArtifact.setHeatEnvironment(existingHeatEnvironment);
1305 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
1306 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
1308 HeatFiles existingHeatFiles =
1309 heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1311 if (existingHeatFiles == null) {
1312 HeatFiles heatFile = new HeatFiles();
1313 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1314 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1315 heatFile.setFileBody(vfModuleArtifact.getResult());
1316 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1317 heatFile.setVersion(BigDecimalVersion
1318 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1319 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1320 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1321 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1323 heatFile.setArtifactChecksum(MANUAL_RECORD);
1325 vfModuleArtifact.setHeatFiles(heatFile);
1327 vfModuleArtifact.setHeatFiles(existingHeatFiles);
1331 protected Service createService(ToscaResourceStructure toscaResourceStructure,
1332 ResourceStructure resourceStructure) {
1334 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
1336 Service service = new Service();
1338 if (serviceMetadata != null) {
1340 if (toscaResourceStructure.getServiceVersion() != null) {
1341 service.setModelVersion(toscaResourceStructure.getServiceVersion());
1344 service.setServiceType(serviceMetadata.getValue("serviceType"));
1345 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
1346 service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1348 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1349 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1350 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1351 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
1353 if (resourceStructure != null)
1354 service.setWorkloadContext(resourceStructure.getNotification().getWorkloadContext());
1356 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1357 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
1358 service.setNamingPolicy(serviceMetadata.getValue("namingPolicy"));
1359 String generateNaming = serviceMetadata.getValue("ecompGeneratedNaming");
1360 Boolean generateNamingValue = null;
1361 if (generateNaming != null) {
1362 generateNamingValue = "true".equalsIgnoreCase(generateNaming);
1364 service.setOnapGeneratedNaming(generateNamingValue);
1368 toscaResourceStructure.setCatalogService(service);
1372 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service,
1373 ToscaResourceStructure toscaResourceStructure) {
1375 Metadata spMetadata = nodeTemplate.getMetaData();
1377 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
1379 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
1381 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1382 spCustomizationResource
1383 .setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1384 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1385 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1386 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1388 spCustomizationResource
1389 .setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1390 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
1391 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
1393 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
1395 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);
1397 spCustomizationResource.setSourceService(sourceService);
1398 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
1399 serviceProxyCustomizationSet.add(spCustomizationResource);
1402 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
1404 return spCustomizationResource;
1407 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate,
1408 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
1411 ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(
1412 nodeTemplate, toscaResourceStructure, spResourceCustomization, service);
1414 ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
1416 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
1418 configCustomizationResource.setConfigurationResource(configResource);
1420 configResourceCustomizationSet.add(configCustomizationResource);
1422 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
1424 toscaResourceStructure.setCatalogConfigurationResource(configResource);
1426 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
1428 return configCustomizationResource;
1431 protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate,
1432 ToscaResourceStructure toscaResourceStructure) {
1434 Metadata fabricMetadata = nodeTemplate.getMetaData();
1436 ConfigurationResource configResource = new ConfigurationResource();
1438 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1439 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1440 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1441 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1442 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1443 configResource.setToscaNodeType(nodeTemplate.getType());
1445 return configResource;
1448 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1449 ToscaCsar toscaCsar = new ToscaCsar();
1450 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1451 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1453 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1455 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1456 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1457 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1458 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1459 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1461 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1464 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1465 VnfcCustomization vnfcCustomization = null;
1466 for (VnfcCustomization vnfcCustom : vnfcCustomizations) {
1467 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1468 vnfcCustomization = vnfcCustom;
1472 if (vnfcCustomization == null)
1473 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1474 // vnfcCustomization = new VnfcCustomization();
1476 return vnfcCustomization;
1479 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations,
1480 String customizationUUID) {
1481 CvnfcCustomization cvnfcCustomization = null;
1482 for (CvnfcCustomization cvnfcCustom : cvnfcCustomizations) {
1483 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1484 cvnfcCustomization = cvnfcCustom;
1488 if (cvnfcCustomization == null)
1489 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1491 return cvnfcCustomization;
1494 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
1495 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,
1498 NetworkResourceCustomization networkResourceCustomization =
1499 networkCustomizationRepo.findOneByModelCustomizationUUID(
1500 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1502 boolean networkUUIDsMatch = true;
1503 // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from
1504 // the distribution.
1505 // If not we'll update the Customization record with latest from the distribution
1506 if (networkResourceCustomization != null) {
1507 String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
1508 String latestNetworkModelUUID =
1509 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
1511 if (!existingNetworkModelUUID.equals(latestNetworkModelUUID)) {
1512 networkUUIDsMatch = false;
1517 if (networkResourceCustomization != null && !networkUUIDsMatch) {
1519 NetworkResource networkResource =
1520 createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate, aicMax, aicMin);
1522 networkResourceCustomization.setNetworkResource(networkResource);
1524 networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
1527 } else if (networkResourceCustomization == null) {
1528 networkResourceCustomization =
1529 createNetworkResourceCustomization(networkNodeTemplate, toscaResourceStructure);
1531 NetworkResource networkResource = findExistingNetworkResource(service,
1532 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1533 if (networkResource == null)
1534 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
1537 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1538 networkResourceCustomization.setNetworkResource(networkResource);
1541 return networkResourceCustomization;
1544 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1545 NetworkResource networkResource = null;
1546 for (NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()) {
1547 if (networkCustom.getNetworkResource() != null
1548 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1549 networkResource = networkCustom.getNetworkResource();
1552 if (networkResource == null)
1553 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1555 return networkResource;
1558 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
1559 ToscaResourceStructure toscaResourceStructure) {
1560 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1561 networkResourceCustomization.setModelInstanceName(
1562 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1563 networkResourceCustomization.setModelCustomizationUUID(
1564 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1566 networkResourceCustomization.setNetworkTechnology(
1567 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1568 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
1569 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
1570 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
1571 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1572 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
1573 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
1574 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
1575 return networkResourceCustomization;
1578 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
1579 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1580 NetworkResource networkResource = new NetworkResource();
1581 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1582 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1584 if ("true".equalsIgnoreCase(providerNetwork)) {
1585 networkResource.setNeutronNetworkType(PROVIDER);
1587 networkResource.setNeutronNetworkType(BASIC);
1590 networkResource.setModelName(
1591 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1593 networkResource.setModelInvariantUUID(
1594 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1595 networkResource.setModelUUID(
1596 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1597 networkResource.setModelVersion(
1598 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1600 networkResource.setAicVersionMax(aicMax);
1601 networkResource.setAicVersionMin(aicMin);
1602 networkResource.setToscaNodeType(networkNodeTemplate.getType());
1603 networkResource.setDescription(
1604 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1605 networkResource.setOrchestrationMode(HEAT);
1606 networkResource.setHeatTemplate(heatTemplate);
1607 return networkResource;
1610 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1611 ToscaResourceStructure toscaResourceStructure, Service service) {
1613 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
1614 new CollectionNetworkResourceCustomization();
1616 // **** Build Object to populate Collection_Resource table
1617 CollectionResource collectionResource = new CollectionResource();
1620 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1621 collectionResource.setModelInvariantUUID(
1622 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1624 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1626 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1628 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1629 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1631 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1633 // **** Build object to populate Collection_Resource_Customization table
1634 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1636 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1638 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1640 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1643 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1644 ncfc.setModelCustomizationUUID(
1645 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1647 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1648 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1650 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1652 ncfc.setCollectionResource(collectionResource);
1653 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1655 // *** Build object to populate the Instance_Group table
1656 List<Group> groupList =
1657 toscaResourceStructure.getSdcCsarHelper().getGroupsOfOriginOfNodeTemplateByToscaGroupType(
1658 networkNodeTemplate, "org.openecomp.groups.NetworkCollection");
1660 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1662 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList =
1665 for (Group group : groupList) {
1667 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1668 Metadata instanceMetadata = group.getMetadata();
1669 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1670 networkInstanceGroup
1671 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1672 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1673 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1674 networkInstanceGroup.setToscaNodeType(group.getType());
1675 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1677 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1679 networkInstanceGroup.setCollectionResource(collectionResource);
1681 // ****Build object to populate
1682 // Collection_Resource_Instance_Group_Customization table
1683 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization =
1684 new CollectionResourceInstanceGroupCustomization();
1685 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1686 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1687 crInstanceGroupCustomization.setModelCustomizationUUID(
1688 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1690 // Loop through the template policy to find the subinterface_network_quantity property name. Then extract
1691 // the value for it.
1692 List<Policy> policyList =
1693 toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(
1694 networkNodeTemplate, "org.openecomp.policies.scaling.Fixed");
1696 if (policyList != null) {
1697 for (Policy policy : policyList) {
1698 for (String policyNetworkCollection : policy.getTargets()) {
1700 if (policyNetworkCollection.equalsIgnoreCase(group.getName())) {
1702 Map<String, Object> propMap = policy.getPolicyProperties();
1704 if (propMap.get("quantity") != null) {
1706 String quantity = toscaResourceStructure.getSdcCsarHelper()
1707 .getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1708 getPropertyInput(propMap.get("quantity").toString()));
1710 if (quantity != null) {
1711 crInstanceGroupCustomization
1712 .setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
1722 crInstanceGroupCustomization.setDescription(
1723 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1724 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1725 + "_network_collection_description"));
1726 crInstanceGroupCustomization.setFunction(
1727 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1728 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1729 + "_network_collection_function"));
1730 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1731 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1733 networkInstanceGroup
1734 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1736 networkInstanceGroupList.add(networkInstanceGroup);
1739 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1741 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1742 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1744 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1746 // *****Build object to populate the NetworkResource table
1747 NetworkResource networkResource = new NetworkResource();
1749 for (NodeTemplate vlNodeTemplate : vlNodeList) {
1751 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1752 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1754 if ("true".equalsIgnoreCase(providerNetwork)) {
1755 networkResource.setNeutronNetworkType(PROVIDER);
1757 networkResource.setNeutronNetworkType(BASIC);
1761 .setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1763 networkResource.setModelInvariantUUID(
1764 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1766 .setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1768 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1770 networkResource.setAicVersionMax(
1771 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1773 TempNetworkHeatTemplateLookup tempNetworkLookUp =
1774 tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1775 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1777 if (tempNetworkLookUp != null) {
1779 HeatTemplate heatTemplate =
1780 heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1781 networkResource.setHeatTemplate(heatTemplate);
1783 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1787 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1788 networkResource.setDescription(
1789 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1790 networkResource.setOrchestrationMode(HEAT);
1792 // Build object to populate the
1793 // Collection_Network_Resource_Customization table
1794 for (NodeTemplate memberNode : group.getMemberNodes()) {
1795 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1798 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1799 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1801 collectionNetworkResourceCustomization.setNetworkTechnology(
1802 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1803 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1804 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1805 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1806 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1807 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1808 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1809 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1810 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1811 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1812 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1814 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1819 return collectionNetworkResourceCustomization;
1822 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1823 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1825 Metadata instanceMetadata = group.getMetadata();
1827 InstanceGroup existingInstanceGroup =
1828 instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1830 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1832 if (existingInstanceGroup == null) {
1833 // Populate InstanceGroup
1834 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1836 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1837 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1838 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1839 vfcInstanceGroup.setToscaNodeType(group.getType());
1840 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1841 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1843 vfcInstanceGroup = (VFCInstanceGroup) existingInstanceGroup;
1846 // Populate VNFCInstanceGroupCustomization
1847 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1849 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1850 vnfResourceCustomization.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
1852 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1853 vfcInstanceGroup.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
1855 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1857 String getInputName = null;
1858 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1859 "vfc_instance_group_function");
1860 if (groupProperty != null) {
1861 int getInputIndex = groupProperty.indexOf("{get_input=");
1862 if (getInputIndex > -1) {
1863 getInputName = groupProperty.substring(getInputIndex + 11, groupProperty.length() - 1);
1866 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper()
1867 .getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1868 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1870 ArrayList<Input> inputs = vnfcNodeTemplate.getSubMappingToscaTemplate().getInputs();
1871 createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group, inputs);
1873 return vfcInstanceGroupCustom;
1877 private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group,
1878 List<Input> inputList) {
1879 List<NodeTemplate> members = group.getMemberNodes();
1880 if (!CollectionUtils.isEmpty(members)) {
1881 for (NodeTemplate vfcTemplate : members) {
1882 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1884 Metadata metadata = vfcTemplate.getMetaData();
1886 .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1887 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1888 vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1890 .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1891 vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1892 vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1893 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1895 .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1896 vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcTemplate, inputList));
1897 vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization);
1902 public String getVnfcResourceInput(NodeTemplate vfcTemplate, List<Input> inputList) {
1903 Map<String, String> resouceRequest = new HashMap<>();
1904 LinkedHashMap<String, Property> vfcTemplateProperties = vfcTemplate.getProperties();
1905 for (String key : vfcTemplateProperties.keySet()) {
1906 Property property = vfcTemplateProperties.get(key);
1907 String resourceValue = getValue(property.getValue(), inputList);
1908 resouceRequest.put(key, resourceValue);
1911 String resourceCustomizationUuid =
1912 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
1914 String jsonStr = null;
1916 ObjectMapper objectMapper = new ObjectMapper();
1917 jsonStr = objectMapper.writeValueAsString(resouceRequest);
1918 jsonStr = jsonStr.replace("\"", "\\\"");
1919 logger.debug("vfcResource request for resource customization id (" + resourceCustomizationUuid + ") : "
1921 } catch (JsonProcessingException e) {
1922 logger.debug("Json Exception: {}", e.getMessage());
1923 logger.error("Exception occurred", e);
1929 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
1930 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1931 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service,
1932 Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
1934 VfModuleCustomization vfModuleCustomization =
1935 findExistingVfModuleCustomization(vnfResource, vfModuleData.getVfModuleModelCustomizationUUID());
1936 if (vfModuleCustomization == null) {
1937 VfModule vfModule = findExistingVfModule(vnfResource,
1938 vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1939 Metadata vfMetadata = group.getMetadata();
1940 if (vfModule == null)
1941 vfModule = createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1943 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1944 vfModuleCustomization.setVnfCustomization(vnfResource);
1945 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1947 vfModuleCustomization.setVfModule(vfModule);
1948 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1949 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1951 vfResourceStructure.setAlreadyDeployed(true);
1954 // ******************************************************************************************************************
1955 // * Extract VFC's and CVFC's then add them to VFModule
1956 // ******************************************************************************************************************
1958 Set<CvnfcConfigurationCustomization> cvnfcConfigurationCustomizations = new HashSet<>();
1959 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<>();
1960 Set<VnfcCustomization> vnfcCustomizations = new HashSet<>();
1962 // Only set the CVNFC if this vfModule group is a member of it.
1963 List<NodeTemplate> groupMembers =
1964 toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group);
1965 String vfModuleMemberName = null;
1967 for (NodeTemplate node : groupMembers) {
1968 vfModuleMemberName = node.getName();
1971 // Extract CVFC lists
1972 List<NodeTemplate> cvfcList =
1973 toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC);
1975 for (NodeTemplate cvfcTemplate : cvfcList) {
1976 boolean cvnfcVfModuleNameMatch = false;
1978 for (NodeTemplate node : groupMembers) {
1979 vfModuleMemberName = node.getName();
1981 if (vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())) {
1982 cvnfcVfModuleNameMatch = true;
1987 if (vfModuleMemberName != null && cvnfcVfModuleNameMatch) {
1989 // Extract associated VFC - Should always be just one
1990 List<NodeTemplate> vfcList =
1991 toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
1993 for (NodeTemplate vfcTemplate : vfcList) {
1995 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1996 VnfcCustomization existingVnfcCustomization = null;
1998 existingVnfcCustomization = findExistingVfc(existingVnfcSet,
1999 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2001 if (existingVnfcCustomization == null) {
2002 vnfcCustomization = new VnfcCustomization();
2004 vnfcCustomization = existingVnfcCustomization;
2007 // Only Add Abstract VNFC's to our DB, ignore all others
2008 if (existingVnfcCustomization == null && vfcTemplate.getMetaData()
2009 .getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")) {
2010 vnfcCustomization.setModelCustomizationUUID(
2011 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2012 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
2013 vnfcCustomization.setModelInvariantUUID(
2014 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
2016 .setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
2018 .setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2020 vnfcCustomization.setModelVersion(
2021 testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2022 vnfcCustomization.setDescription(testNull(
2023 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2024 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
2026 vnfcCustomizations.add(vnfcCustomization);
2027 existingVnfcSet.add(vnfcCustomization);
2030 // This check is needed incase the VFC subcategory is
2031 // something other than Abstract. In that case we want to
2032 // skip adding that record to our DB.
2033 if (vnfcCustomization.getModelCustomizationUUID() != null) {
2034 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
2035 cvnfcCustomization.setModelCustomizationUUID(
2036 cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2037 cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
2038 cvnfcCustomization.setModelInvariantUUID(
2039 cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
2041 .setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
2043 .setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2045 cvnfcCustomization.setModelVersion(
2046 testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2047 cvnfcCustomization.setDescription(testNull(
2048 cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2049 cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
2051 if (existingVnfcCustomization != null) {
2052 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
2054 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
2057 cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper()
2058 .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function"));
2059 cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper()
2060 .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code"));
2061 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
2063 cvnfcCustomizations.add(cvnfcCustomization);
2064 existingCvnfcSet.add(cvnfcCustomization);
2066 // *****************************************************************************************************************************************
2067 // * Extract Fabric Configuration
2068 // *****************************************************************************************************************************************
2070 List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper()
2071 .getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION);
2073 for (NodeTemplate fabricTemplate : fabricConfigList) {
2075 ConfigurationResource fabricConfig = null;
2077 ConfigurationResource existingConfig = findExistingConfiguration(service,
2078 fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2080 if (existingConfig == null) {
2082 fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
2085 fabricConfig = existingConfig;
2088 CvnfcConfigurationCustomization cvnfcConfigurationCustomization =
2089 createCvnfcConfigurationCustomization(fabricTemplate, toscaResourceStructure,
2090 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig,
2091 vfTemplate, vfModuleMemberName);
2092 cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization);
2094 fabricConfig.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations);
2096 cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations);
2103 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
2105 return vfModuleCustomization;
2108 protected CvnfcConfigurationCustomization createCvnfcConfigurationCustomization(NodeTemplate fabricTemplate,
2109 ToscaResourceStructure toscaResourceStruct, VnfResourceCustomization vnfResource,
2110 VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
2111 ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) {
2113 Metadata fabricMetadata = fabricTemplate.getMetaData();
2115 CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization();
2117 cvnfcConfigurationCustomization.setConfigurationResource(configResource);
2119 cvnfcConfigurationCustomization.setCvnfcCustomization(cvnfcCustomization);
2121 cvnfcConfigurationCustomization
2122 .setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2123 cvnfcConfigurationCustomization.setModelInstanceName(fabricTemplate.getName());
2125 List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper()
2126 .getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External");
2128 if (policyList != null) {
2129 for (Policy policy : policyList) {
2131 for (String policyCvfcTarget : policy.getTargets()) {
2133 if (policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)) {
2135 Map<String, Object> propMap = policy.getPolicyProperties();
2137 if (propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")) {
2138 cvnfcConfigurationCustomization.setPolicyName(propMap.get("name").toString());
2145 cvnfcConfigurationCustomization.setConfigurationFunction(
2146 toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function"));
2147 cvnfcConfigurationCustomization.setConfigurationRole(
2148 toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role"));
2149 cvnfcConfigurationCustomization.setConfigurationType(
2150 toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type"));
2152 return cvnfcConfigurationCustomization;
2155 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
2156 ConfigurationResource configResource = null;
2157 for (ConfigurationResourceCustomization configurationResourceCustom : service
2158 .getConfigurationCustomizations()) {
2159 if (configurationResourceCustom.getConfigurationResource() != null
2160 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
2161 configResource = configurationResourceCustom.getConfigurationResource();
2165 return configResource;
2168 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
2169 String vfModuleModelCustomizationUUID) {
2170 VfModuleCustomization vfModuleCustomization = null;
2171 for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) {
2172 if (vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)) {
2173 vfModuleCustomization = vfModuleCustom;
2176 return vfModuleCustomization;
2179 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
2180 VfModule vfModule = null;
2181 for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) {
2182 if (vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)) {
2183 vfModule = vfModuleCustom.getVfModule();
2186 if (vfModule == null)
2187 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
2192 protected VfModuleCustomization createVfModuleCustomization(Group group,
2193 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
2194 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
2196 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
2198 vfModuleCustomization.setVfModule(vfModule);
2200 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2201 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
2202 if (initialCount != null && initialCount.length() > 0) {
2203 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
2206 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
2207 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
2209 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2210 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
2211 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
2212 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
2215 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2216 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
2218 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2219 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
2220 if (maxInstances != null && maxInstances.length() > 0) {
2221 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
2224 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2225 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
2226 if (minInstances != null && minInstances.length() > 0) {
2227 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
2229 return vfModuleCustomization;
2232 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
2233 IVfModuleData vfModuleData, Metadata vfMetadata) {
2234 VfModule vfModule = new VfModule();
2235 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
2237 if (vfModuleModelUUID == null) {
2238 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2239 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
2240 } else if (vfModuleModelUUID.indexOf('.') > -1) {
2241 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
2244 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
2245 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
2246 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2247 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
2248 vfModule.setModelUUID(vfModuleModelUUID);
2249 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2250 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
2251 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2252 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2254 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2255 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
2256 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
2257 vfModule.setIsBase(true);
2259 vfModule.setIsBase(false);
2264 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
2265 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
2266 Metadata vfMetadata) {
2268 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
2269 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
2270 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2271 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
2274 if (matchingObject.isPresent()) {
2275 List<HeatFiles> heatFilesList = new ArrayList<>();
2276 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<>();
2277 List<HeatTemplate> heatChildTemplates = new ArrayList<>();
2278 HeatTemplate parentHeatTemplate = new HeatTemplate();
2279 String parentArtifactType = null;
2280 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
2281 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
2283 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<>();
2285 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
2286 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
2287 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
2290 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
2291 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
2293 if (!childNestedHeatTemplates.isEmpty()) {
2295 if (parentArtifactType != null
2296 && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
2297 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
2299 heatChildTemplates.add(childNestedHeatTemplates.get(0));
2305 if (!heatFilesList.isEmpty()) {
2306 vfModule.setHeatFiles(heatFilesList);
2310 // Set all Child Templates related to HEAT_VOLUME
2311 if (!volumeHeatChildTemplates.isEmpty()) {
2312 if (vfModule.getVolumeHeatTemplate() != null) {
2313 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
2315 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
2319 // Set all Child Templates related to HEAT
2320 if (!heatChildTemplates.isEmpty()) {
2321 if (vfModule.getModuleHeatTemplate() != null) {
2322 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
2324 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
2330 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
2331 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
2332 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
2333 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
2334 vfModuleArtifact.incrementDeployedInDB();
2335 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
2336 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
2337 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
2338 VfModuleArtifact volVfModuleArtifact =
2339 this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
2340 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
2341 vfModuleArtifact.incrementDeployedInDB();
2342 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
2343 if (vfModuleArtifact.getHeatEnvironment() != null) {
2344 if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
2345 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
2347 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
2350 vfModuleArtifact.incrementDeployedInDB();
2351 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
2352 heatFilesList.add(vfModuleArtifact.getHeatFiles());
2353 vfModuleArtifact.incrementDeployedInDB();
2354 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
2355 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
2356 vfModuleArtifact.incrementDeployedInDB();
2360 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
2361 ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException {
2362 VnfResourceCustomization vnfResourceCustomization = null;
2363 if (vnfResourceCustomization == null) {
2364 VnfResource vnfResource = findExistingVnfResource(service,
2365 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2367 if (vnfResource == null) {
2368 vnfResource = createVnfResource(vfNodeTemplate);
2371 vnfResourceCustomization =
2372 createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, vnfResource);
2373 vnfResourceCustomization.setVnfResources(vnfResource);
2374 vnfResourceCustomization.setService(service);
2376 // setting resource input for vnf customization
2377 vnfResourceCustomization.setResourceInput(
2378 getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID()));
2379 service.getVnfCustomizations().add(vnfResourceCustomization);
2382 return vnfResourceCustomization;
2385 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
2386 VnfResource vnfResource = null;
2387 for (VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()) {
2388 if (vnfResourceCustom.getVnfResources() != null
2389 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
2390 vnfResource = vnfResourceCustom.getVnfResources();
2393 if (vnfResource == null)
2394 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
2399 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
2400 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
2401 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
2402 vnfResourceCustomization.setModelCustomizationUUID(
2403 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
2404 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
2406 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
2407 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
2408 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
2409 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
2410 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
2411 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
2412 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
2413 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
2415 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
2416 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
2418 vnfResourceCustomization.setBlueprintName(testNull(toscaResourceStructure.getSdcCsarHelper()
2419 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_NAME)));
2421 vnfResourceCustomization.setBlueprintVersion(testNull(toscaResourceStructure.getSdcCsarHelper()
2422 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_VERSION)));
2424 String skipPostInstConfText = toscaResourceStructure.getSdcCsarHelper()
2425 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SKIP_POST_INST_CONF);
2426 if (skipPostInstConfText != null) {
2427 vnfResourceCustomization.setSkipPostInstConf(Boolean.parseBoolean(skipPostInstConfText));
2430 vnfResourceCustomization.setVnfResources(vnfResource);
2431 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
2432 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
2434 CapabilityAssignments vnfCustomizationCapability =
2435 toscaResourceStructure.getSdcCsarHelper().getCapabilitiesOf(vfNodeTemplate);
2437 if (vnfCustomizationCapability != null) {
2438 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
2440 if (capAssign != null) {
2441 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2442 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2443 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2444 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2449 if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) {
2450 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2451 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2452 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2453 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2456 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
2458 return vnfResourceCustomization;
2461 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
2462 VnfResource vnfResource = new VnfResource();
2463 vnfResource.setModelInvariantUUID(
2464 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
2465 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2466 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
2468 vnfResource.setModelVersion(
2469 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2470 vnfResource.setDescription(
2471 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2472 vnfResource.setOrchestrationMode(HEAT);
2473 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
2474 vnfResource.setAicVersionMax(
2475 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2476 vnfResource.setAicVersionMin(
2477 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2478 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
2479 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
2484 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
2485 ToscaResourceStructure toscaResourceStructure, Service service) {
2486 AllottedResourceCustomization allottedResourceCustomization =
2487 allottedCustomizationRepo.findOneByModelCustomizationUUID(
2488 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2490 if (allottedResourceCustomization == null) {
2491 AllottedResource allottedResource = findExistingAllottedResource(service,
2492 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2494 if (allottedResource == null)
2495 allottedResource = createAR(nodeTemplate);
2497 toscaResourceStructure.setAllottedResource(allottedResource);
2498 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
2499 allottedResourceCustomization.setAllottedResource(allottedResource);
2500 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
2502 return allottedResourceCustomization;
2505 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
2506 AllottedResource allottedResource = null;
2507 for (AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()) {
2508 if (allottedResourceCustom.getAllottedResource() != null
2509 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
2510 allottedResource = allottedResourceCustom.getAllottedResource();
2513 if (allottedResource == null)
2514 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
2516 return allottedResource;
2519 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
2520 ToscaResourceStructure toscaResourceStructure) {
2521 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
2522 allottedResourceCustomization.setModelCustomizationUUID(
2523 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
2524 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
2527 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
2528 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
2529 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
2530 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
2531 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
2532 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
2533 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
2534 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
2536 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper()
2537 .getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
2539 if (vfcNodes != null) {
2540 for (NodeTemplate vfcNode : vfcNodes) {
2542 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper()
2543 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
2544 allottedResourceCustomization
2545 .setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper()
2546 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
2547 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper()
2548 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
2553 CapabilityAssignments arCustomizationCapability =
2554 toscaResourceStructure.getSdcCsarHelper().getCapabilitiesOf(nodeTemplate);
2556 if (arCustomizationCapability != null) {
2557 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
2559 if (capAssign != null) {
2560 allottedResourceCustomization.setMinInstances(
2561 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2562 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2563 allottedResourceCustomization.setMaxInstances(
2564 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2565 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2568 return allottedResourceCustomization;
2571 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
2572 AllottedResource allottedResource = new AllottedResource();
2574 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
2575 allottedResource.setModelInvariantUUID(
2576 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
2578 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2580 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2581 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
2582 allottedResource.setSubcategory(
2583 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
2585 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
2586 return allottedResource;
2589 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
2590 // Scan the payload downloadResult and extract the HeatTemplate
2592 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
2593 return yamlEditor.getParameterList(artifactUUID);
2596 protected String testNull(Object object) {
2598 if (object == null) {
2600 } else if ("NULL".equals(object)) {
2602 } else if (object instanceof Integer) {
2603 return object.toString();
2604 } else if (object instanceof String) {
2605 return (String) object;
2607 return "Type not recognized";
2611 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
2612 VfModuleArtifact heatNestedArtifact) {
2614 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
2615 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
2616 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
2617 .getArtifactInfo().getRelatedArtifacts()) {
2618 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2619 return ASDCConfiguration.HEAT;
2625 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
2626 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2627 .getRelatedArtifacts() != null) {
2628 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2629 .get(0).getArtifactInfo().getRelatedArtifacts()) {
2630 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2631 return ASDCConfiguration.HEAT_VOL;
2637 // Does not belong to anything
2642 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2644 return vfResourceStructure.getNotification().getServiceName() + "/"
2645 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2648 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2650 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2651 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2654 protected String getPropertyInput(String propertyName) {
2656 String inputName = new String();
2658 if (propertyName != null) {
2659 int getInputIndex = propertyName.indexOf("{get_input=");
2660 if (getInputIndex > -1) {
2661 inputName = propertyName.substring(getInputIndex + 11, propertyName.length() - 1);
2668 // this method add provided vnfCustomization to service with
2669 // existing customization available in db.
2670 private void addVnfCustomization(Service service, VnfResourceCustomization vnfResourceCustomization) {
2671 List<Service> services = serviceRepo.findByModelUUID(service.getModelUUID());
2672 if (!services.isEmpty()) {
2673 // service exist in db
2674 Service existingService = services.get(0);
2675 List<VnfResourceCustomization> vnfCustomizations = existingService.getVnfCustomizations();
2676 vnfCustomizations.forEach(e -> service.getVnfCustomizations().add(e));
2678 service.getVnfCustomizations().add(vnfResourceCustomization);
2682 protected static Timestamp getCurrentTimeStamp() {
2684 return new Timestamp(new Date().getTime());