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 org.onap.so.logger.LoggingAnchor;
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.elements.queries.TopologyTemplateQuery.TopologyTemplateQueryBuilder;
52 import org.onap.sdc.tosca.parser.enums.SdcTypes;
53 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
54 import org.onap.sdc.toscaparser.api.*;
55 import org.onap.sdc.toscaparser.api.elements.Metadata;
56 import org.onap.sdc.toscaparser.api.functions.GetInput;
57 import org.onap.sdc.toscaparser.api.parameters.Input;
58 import org.onap.sdc.utils.DistributionStatusEnum;
59 import org.onap.so.asdc.client.ASDCConfiguration;
60 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
61 import org.onap.so.asdc.installer.ASDCElementInfo;
62 import org.onap.so.asdc.installer.BigDecimalVersion;
63 import org.onap.so.asdc.installer.IVfModuleData;
64 import org.onap.so.asdc.installer.PnfResourceStructure;
65 import org.onap.so.asdc.installer.ResourceStructure;
66 import org.onap.so.asdc.installer.ToscaResourceStructure;
67 import org.onap.so.asdc.installer.VfModuleArtifact;
68 import org.onap.so.asdc.installer.VfModuleStructure;
69 import org.onap.so.asdc.installer.VfResourceStructure;
70 import org.onap.so.asdc.installer.bpmn.WorkflowResource;
71 import org.onap.so.asdc.util.YamlEditor;
72 import org.onap.so.db.catalog.beans.AllottedResource;
73 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
74 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
75 import org.onap.so.db.catalog.beans.CollectionResource;
76 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
77 import org.onap.so.db.catalog.beans.ConfigurationResource;
78 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
79 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
80 import org.onap.so.db.catalog.beans.CvnfcCustomization;
81 import org.onap.so.db.catalog.beans.HeatEnvironment;
82 import org.onap.so.db.catalog.beans.HeatFiles;
83 import org.onap.so.db.catalog.beans.HeatTemplate;
84 import org.onap.so.db.catalog.beans.HeatTemplateParam;
85 import org.onap.so.db.catalog.beans.InstanceGroup;
86 import org.onap.so.db.catalog.beans.InstanceGroupType;
87 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
88 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
89 import org.onap.so.db.catalog.beans.NetworkResource;
90 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
91 import org.onap.so.db.catalog.beans.PnfResource;
92 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
93 import org.onap.so.db.catalog.beans.Service;
94 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
95 import org.onap.so.db.catalog.beans.SubType;
96 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
97 import org.onap.so.db.catalog.beans.ToscaCsar;
98 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
99 import org.onap.so.db.catalog.beans.VfModule;
100 import org.onap.so.db.catalog.beans.VfModuleCustomization;
101 import org.onap.so.db.catalog.beans.VnfResource;
102 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
103 import org.onap.so.db.catalog.beans.VnfcCustomization;
104 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
105 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
106 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
107 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
108 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
109 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
110 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
111 import org.onap.so.db.catalog.data.repository.CvnfcConfigurationCustomizationRepository;
112 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
113 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
114 import org.onap.so.db.catalog.data.repository.HeatEnvironmentRepository;
115 import org.onap.so.db.catalog.data.repository.HeatFilesRepository;
116 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
117 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
118 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
119 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
120 import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
121 import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
122 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
123 import org.onap.so.db.catalog.data.repository.ServiceRepository;
124 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
125 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
126 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
127 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
128 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
129 import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
130 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
131 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
132 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
133 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
134 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
135 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
136 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
137 import org.onap.so.logger.ErrorCode;
138 import org.onap.so.logger.MessageEnum;
139 import org.slf4j.Logger;
140 import org.slf4j.LoggerFactory;
141 import org.springframework.beans.factory.annotation.Autowired;
142 import org.springframework.orm.ObjectOptimisticLockingFailureException;
143 import org.springframework.stereotype.Component;
144 import org.springframework.transaction.annotation.Transactional;
145 import com.fasterxml.jackson.core.JsonProcessingException;
146 import com.fasterxml.jackson.databind.ObjectMapper;
147 import org.springframework.util.CollectionUtils;
150 public class ToscaResourceInstaller {
152 protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry";
154 protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor";
156 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
158 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
160 protected static final String SCALABLE = "scalable";
162 protected static final String BASIC = "BASIC";
164 protected static final String PROVIDER = "PROVIDER";
166 protected static final String HEAT = "HEAT";
168 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
170 protected static final String MSO = "SO";
172 protected static final String SDNC_MODEL_NAME = "sdnc_model_name";
174 protected static final String SDNC_MODEL_VERSION = "sdnc_model_version";
176 private static String CUSTOMIZATION_UUID = "customizationUUID";
178 protected static final String SKIP_POST_INST_CONF = "skip_post_instantiation_configuration";
181 protected ServiceRepository serviceRepo;
184 protected InstanceGroupRepository instanceGroupRepo;
187 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
190 protected CollectionResourceRepository collectionRepo;
193 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
196 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
199 protected ConfigurationResourceRepository configRepo;
202 protected VnfResourceRepository vnfRepo;
205 protected VFModuleRepository vfModuleRepo;
208 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
211 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
214 protected VnfcCustomizationRepository vnfcCustomizationRepo;
217 protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
220 protected AllottedResourceRepository allottedRepo;
223 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
226 protected NetworkResourceRepository networkRepo;
229 protected HeatTemplateRepository heatRepo;
232 protected HeatEnvironmentRepository heatEnvRepo;
235 protected HeatFilesRepository heatFilesRepo;
238 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
241 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
243 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
245 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
248 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
251 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
254 protected ToscaCsarRepository toscaCsarRepo;
257 protected PnfResourceRepository pnfResourceRepository;
260 protected PnfCustomizationRepository pnfCustomizationRepository;
263 protected WorkflowResource workflowResource;
265 protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
267 public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure)
268 throws ArtifactInstallerException {
269 boolean deployed = false;
270 if (toscaResourceStructure == null) {
274 IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
275 String checkSum = inputToscaCsar.getArtifactChecksum();
276 String artifactUuid = inputToscaCsar.getArtifactUUID();
278 Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
279 if (toscaCsarObj.isPresent()) {
280 ToscaCsar toscaCsar = toscaCsarObj.get();
281 if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
282 String errorMessage =
283 String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
284 throw new ArtifactInstallerException(errorMessage);
285 } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
292 public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed)
293 throws ArtifactInstallerException {
294 boolean status = false;
295 ResourceStructure vfResourceStructure = vfResourceStruct;
297 status = vfResourceStructure.isDeployedSuccessfully();
298 } catch (RuntimeException e) {
300 logger.debug("Exception :", e);
303 Service existingService =
304 serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
305 if (existingService != null && !serviceDeployed)
308 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
309 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
310 vfResourceStructure.getNotification().getServiceName(),
311 BigDecimalVersion.castAndCheckNotificationVersionToString(
312 vfResourceStructure.getNotification().getServiceVersion()),
313 vfResourceStructure.getNotification().getServiceUUID(),
314 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
315 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(
316 vfResourceStruct.getNotification().getDistributionID(), MSO);
317 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
318 watchdogCDStatusRepository.saveAndFlush(wdStatus);
320 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
321 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
322 vfResourceStructure.getNotification().getServiceName(),
323 BigDecimalVersion.castAndCheckNotificationVersionToString(
324 vfResourceStructure.getNotification().getServiceVersion()),
325 vfResourceStructure.getNotification().getServiceUUID(),
326 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
329 } catch (Exception e) {
330 logger.error(LoggingAnchor.THREE, MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(),
331 ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed");
332 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
336 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
337 logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}",
338 iStatus.getDistributionID(), iStatus.getComponentName());
341 WatchdogComponentDistributionStatus cdStatus =
342 new WatchdogComponentDistributionStatus(iStatus.getDistributionID(), iStatus.getComponentName());
343 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
344 watchdogCDStatusRepository.save(cdStatus);
346 } catch (Exception e) {
347 logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
348 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
353 @Transactional(rollbackFor = {ArtifactInstallerException.class})
354 public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct)
355 throws ArtifactInstallerException {
356 if (resourceStruct instanceof VfResourceStructure) {
357 installTheVfResource(toscaResourceStruct, (VfResourceStructure) resourceStruct);
358 } else if (resourceStruct instanceof PnfResourceStructure) {
359 installPnfResource(toscaResourceStruct, (PnfResourceStructure) resourceStruct);
361 logger.warn("Unrecognized resource type");
365 private void installPnfResource(ToscaResourceStructure toscaResourceStruct, PnfResourceStructure resourceStruct)
366 throws ArtifactInstallerException {
368 // PCLO: in case of deployment failure, use a string that will represent
369 // the type of artifact that failed...
370 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
372 createToscaCsar(toscaResourceStruct);
373 Service service = createService(toscaResourceStruct, resourceStruct);
375 processResourceSequence(toscaResourceStruct, service);
376 processPnfResources(toscaResourceStruct, service, resourceStruct);
377 serviceRepo.save(service);
379 WatchdogComponentDistributionStatus status =
380 new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
381 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
382 watchdogCDStatusRepository.save(status);
384 toscaResourceStruct.setSuccessfulDeployment();
386 } catch (Exception e) {
387 logger.debug("Exception :", e);
388 WatchdogComponentDistributionStatus status =
389 new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
390 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
391 watchdogCDStatusRepository.save(status);
392 Throwable dbExceptionToCapture = e;
393 while (!(dbExceptionToCapture instanceof ConstraintViolationException
394 || dbExceptionToCapture instanceof LockAcquisitionException)
395 && (dbExceptionToCapture.getCause() != null)) {
396 dbExceptionToCapture = dbExceptionToCapture.getCause();
399 if (dbExceptionToCapture instanceof ConstraintViolationException
400 || dbExceptionToCapture instanceof LockAcquisitionException) {
401 logger.warn(LoggingAnchor.FIVE, MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
402 resourceStruct.getResourceInstance().getResourceName(),
403 resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
404 "Exception - ASCDC Artifact already deployed", e);
406 String elementToLog = (!artifactListForLogging.isEmpty()
407 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
408 : "No element listed");
409 logger.error(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
410 ErrorCode.DataError.getValue(), "Exception caught during installation of "
411 + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback",
413 throw new ArtifactInstallerException(
414 "Exception caught during installation of "
415 + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback.",
421 @Transactional(rollbackFor = {ArtifactInstallerException.class})
422 public void installTheVfResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
423 throws ArtifactInstallerException {
424 VfResourceStructure vfResourceStructure = vfResourceStruct;
425 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
427 // PCLO: in case of deployment failure, use a string that will represent
428 // the type of artifact that failed...
429 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
431 createToscaCsar(toscaResourceStruct);
432 createService(toscaResourceStruct, vfResourceStruct);
433 Service service = toscaResourceStruct.getCatalogService();
434 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
436 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
437 Metadata metadata = nodeTemplate.getMetaData();
438 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
439 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
440 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
441 vfCustomizationCategory);
444 processResourceSequence(toscaResourceStruct, service);
445 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
446 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
447 processNetworks(toscaResourceStruct, service);
448 // process Network Collections
449 processNetworkCollections(toscaResourceStruct, service);
450 // Process Service Proxy & Configuration
451 processServiceProxyAndConfiguration(toscaResourceStruct, service);
453 logger.info("Saving Service: {} ", service.getModelName());
454 service = serviceRepo.save(service);
455 correlateConfigCustomResources(service);
457 workflowResource.processWorkflows(vfResourceStructure);
459 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
460 vfResourceStruct.getNotification().getDistributionID(), MSO);
461 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
462 watchdogCDStatusRepository.save(status);
464 toscaResourceStruct.setSuccessfulDeployment();
466 } catch (Exception e) {
467 logger.debug("Exception :", e);
468 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
469 vfResourceStruct.getNotification().getDistributionID(), MSO);
470 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
471 watchdogCDStatusRepository.save(status);
472 Throwable dbExceptionToCapture = e;
473 while (!(dbExceptionToCapture instanceof ConstraintViolationException
474 || dbExceptionToCapture instanceof LockAcquisitionException)
475 && (dbExceptionToCapture.getCause() != null)) {
476 dbExceptionToCapture = dbExceptionToCapture.getCause();
479 if (dbExceptionToCapture instanceof ConstraintViolationException
480 || dbExceptionToCapture instanceof LockAcquisitionException) {
481 logger.warn(LoggingAnchor.FIVE, MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
482 vfResourceStructure.getResourceInstance().getResourceName(),
483 vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
484 "Exception - ASCDC Artifact already deployed", e);
486 String elementToLog = (!artifactListForLogging.isEmpty()
487 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
488 : "No element listed");
489 logger.error(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
490 ErrorCode.DataError.getValue(),
491 "Exception caught during installation of "
492 + vfResourceStructure.getResourceInstance().getResourceName()
493 + ". Transaction rollback",
495 throw new ArtifactInstallerException("Exception caught during installation of "
496 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
502 List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
503 ISdcCsarHelper iSdcCsarHelper) {
505 List<NodeTemplate> nodes = new ArrayList<>();
506 nodes.addAll(nodeTemplates);
508 for (NodeTemplate nodeTemplate : nodeTemplates) {
509 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
510 List<RequirementAssignment> reqAs = requirement.getAll();
511 for (RequirementAssignment ra : reqAs) {
512 String reqNode = ra.getNodeTemplateName();
513 for (NodeTemplate rNode : resultList) {
514 if (rNode.getName().equals(reqNode)) {
515 if (!resultList.contains(nodeTemplate)) {
516 resultList.add(nodeTemplate);
518 if (nodes.contains(nodeTemplate)) {
519 nodes.remove(nodeTemplate);
527 if (!nodes.isEmpty()) {
528 getRequirementList(resultList, nodes, iSdcCsarHelper);
534 // This method retrieve resource sequence from csar file
535 void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
536 List<String> resouceSequence = new ArrayList<>();
537 List<NodeTemplate> resultList = new ArrayList<>();
539 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
540 List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
541 List<NodeTemplate> nodes = new ArrayList<>();
542 nodes.addAll(nodeTemplates);
544 for (NodeTemplate nodeTemplate : nodeTemplates) {
545 RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
547 if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
548 resultList.add(nodeTemplate);
549 nodes.remove(nodeTemplate);
553 resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
555 for (NodeTemplate node : resultList) {
556 String templateName = node.getMetaData().getValue("name");
557 if (!resouceSequence.contains(templateName)) {
558 resouceSequence.add(templateName);
562 String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
563 service.setResourceOrder(resourceSeqStr);
564 logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
568 // this of temporary solution
569 private static String getValue(Object value, List<Input> inputs) {
571 String defaultValue = null;
572 if (value instanceof Map) {
573 outInput = ((LinkedHashMap) value).values().toArray()[0].toString();
574 } else if (value instanceof GetInput) {
575 String inputName = ((GetInput) value).getInputName();
576 Optional<Input> inputOptional =
577 inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst();
578 if (inputOptional.isPresent()) {
579 Input input = inputOptional.get();
580 defaultValue = input.getDefault() != null ? input.getDefault().toString() : "";
582 // Gets a value between [ and ]
583 String regex = "\\[.*?\\]";
584 Pattern pattern = Pattern.compile(regex);
585 Matcher matcher = pattern.matcher(value.toString());
586 String valueStr = matcher.find() ? matcher.group() : inputName;
587 outInput = valueStr + "|" + defaultValue;
589 outInput = value != null ? value.toString() : "";
594 String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid)
595 throws ArtifactInstallerException {
596 Map<String, String> resouceRequest = new HashMap<>();
597 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
599 List<Input> serInput = iSdcCsarHelper.getServiceInputs();
600 Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
601 .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid))
603 if (nodeTemplateOpt.isPresent()) {
604 NodeTemplate nodeTemplate = nodeTemplateOpt.get();
605 LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
607 for (String key : resourceProperties.keySet()) {
608 Property property = resourceProperties.get(key);
610 String value = getValue(property.getValue(), serInput);
611 resouceRequest.put(key, value);
616 ObjectMapper objectMapper = new ObjectMapper();
617 String jsonStr = objectMapper.writeValueAsString(resouceRequest);
619 jsonStr = jsonStr.replace("\"", "\\\"");
621 "resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
623 } catch (JsonProcessingException e) {
624 logger.error("resource input could not be deserialized for resource customization id ("
625 + resourceCustomizationUuid + ")");
626 throw new ArtifactInstallerException("resource input could not be parsed", e);
630 protected void processNetworks(ToscaResourceStructure toscaResourceStruct, Service service)
631 throws ArtifactInstallerException {
633 List<IEntityDetails> vlEntityList = getEntityDetails(toscaResourceStruct, SdcTypes.VL, SdcTypes.SERVICE, false);
635 if (vlEntityList != null) {
636 for (IEntityDetails vlEntity : vlEntityList) {
637 String networkResourceModelName = vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
639 TempNetworkHeatTemplateLookup tempNetworkLookUp =
640 tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkResourceModelName);
642 if (tempNetworkLookUp != null) {
643 HeatTemplate heatTemplate =
644 heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
645 if (heatTemplate != null) {
646 NetworkResourceCustomization networkCustomization = createNetwork(vlEntity, toscaResourceStruct,
647 heatTemplate, tempNetworkLookUp.getAicVersionMax(),
648 tempNetworkLookUp.getAicVersionMin(), service);
649 service.getNetworkCustomizations().add(networkCustomization);
651 throw new ArtifactInstallerException("No HeatTemplate found for artifactUUID: "
652 + tempNetworkLookUp.getHeatTemplateArtifactUuid());
655 NetworkResourceCustomization networkCustomization =
656 createNetwork(vlEntity, toscaResourceStruct, null, null, null, service);
657 service.getNetworkCustomizations().add(networkCustomization);
658 logger.debug("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
659 + networkResourceModelName);
666 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
667 List<NodeTemplate> allottedResourceList) {
668 if (allottedResourceList != null) {
669 for (NodeTemplate allottedNode : allottedResourceList) {
670 service.getAllottedCustomizations()
671 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
677 protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) {
678 Metadata metadata = nodeTemplate.getMetaData();
679 ConfigurationResource configResource = new ConfigurationResource();
680 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
681 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
682 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
683 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
684 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
685 configResource.setToscaNodeType(nodeTemplate.getType());
686 return configResource;
689 protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate,
690 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
692 Metadata metadata = nodeTemplate.getMetaData();
694 ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
696 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
698 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
700 configCustomizationResource
701 .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
702 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
704 configCustomizationResource.setFunction(
705 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
706 configCustomizationResource.setRole(
707 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
708 configCustomizationResource.setType(
709 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
710 configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
712 configCustomizationResource.setConfigurationResource(configResource);
713 configCustomizationResource.setService(service);
714 configResourceCustomizationSet.add(configCustomizationResource);
716 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
718 return configCustomizationResource;
722 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
724 List<NodeTemplate> serviceProxyResourceList =
725 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
727 List<NodeTemplate> configurationNodeTemplatesList =
728 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
730 List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<>();
731 List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<>();
733 ServiceProxyResourceCustomization serviceProxy = null;
735 if (serviceProxyResourceList != null) {
736 for (NodeTemplate spNode : serviceProxyResourceList) {
737 serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
738 serviceProxyList.add(serviceProxy);
740 for (NodeTemplate configNode : configurationNodeTemplatesList) {
742 List<RequirementAssignment> requirementsList =
743 toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
744 for (RequirementAssignment requirement : requirementsList) {
745 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
746 ConfigurationResourceCustomization configurationResource = createConfiguration(configNode,
747 toscaResourceStruct, serviceProxy, service, configurationResourceList);
749 Optional<ConfigurationResourceCustomization> matchingObject =
750 configurationResourceList.stream()
751 .filter(configurationResourceCustomization -> configNode.getMetaData()
752 .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)
753 .equals(configurationResource.getModelCustomizationUUID()))
754 .filter(configurationResourceCustomization -> configurationResourceCustomization
755 .getModelInstanceName()
756 .equals(configurationResource.getModelInstanceName()))
758 if (!matchingObject.isPresent()) {
759 configurationResourceList.add(configurationResource);
769 service.setConfigurationCustomizations(configurationResourceList);
770 service.setServiceProxyCustomizations(serviceProxyList);
774 * ConfigurationResourceCustomization objects have their IDs auto incremented in the database. Unless we know their
775 * IDs we cannot possibly associate their related records. So these ConfigResourceCustomizations are persisted first
776 * and subsequently correlated.
779 protected void correlateConfigCustomResources(Service service) {
780 /* Assuming that we have only one pair of VRF-VNR */
781 ConfigurationResourceCustomization vrfConfigCustomResource = null;
782 ConfigurationResourceCustomization vnrConfigCustomResource = null;
783 List<ConfigurationResourceCustomization> configCustomList = service.getConfigurationCustomizations();
784 for (ConfigurationResourceCustomization configResource : configCustomList) {
785 String nodeType = configResource.getConfigurationResource().getToscaNodeType();
786 if (NODES_VRF_ENTRY.equalsIgnoreCase(nodeType)) {
787 vrfConfigCustomResource = configResource;
788 } else if (VLAN_NETWORK_RECEPTOR.equalsIgnoreCase(nodeType)) {
789 vnrConfigCustomResource = configResource;
793 if (vrfConfigCustomResource != null) {
794 vrfConfigCustomResource.setConfigResourceCustomization(vnrConfigCustomResource);
795 configCustomizationRepo.save(vrfConfigCustomResource);
798 if (vnrConfigCustomResource != null) {
799 vnrConfigCustomResource.setConfigResourceCustomization(vrfConfigCustomResource);
800 configCustomizationRepo.save(vnrConfigCustomResource);
804 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
806 List<NodeTemplate> networkCollectionList =
807 toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
809 if (networkCollectionList != null) {
810 for (NodeTemplate crNode : networkCollectionList) {
812 createNetworkCollection(crNode, toscaResourceStruct, service);
813 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
815 List<NetworkInstanceGroup> networkInstanceGroupList =
816 toscaResourceStruct.getCatalogNetworkInstanceGroup();
817 for (NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList) {
818 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
823 service.getCollectionResourceCustomizations()
824 .add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
830 * This is used to process the PNF specific resource, including resource and resource_customization.
831 * {@link IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for
834 protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service,
835 PnfResourceStructure resourceStructure) throws Exception {
836 logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
838 ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
839 EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
840 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
842 List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
843 for (IEntityDetails entityDetails : entityDetailsList) {
844 Metadata metadata = entityDetails.getMetadata();
845 String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
846 String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
847 String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
848 if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
849 logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}",
850 customizationUUID, notifCustomizationUUID);
852 if (checkExistingPnfResourceCutomization(customizationUUID)) {
853 logger.info("Resource customization UUID: {} already deployed", customizationUUID);
855 PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
856 if (pnfResource == null) {
857 pnfResource = createPnfResource(entityDetails);
859 PnfResourceCustomization pnfResourceCustomization =
860 createPnfResourceCustomization(entityDetails, pnfResource);
861 pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
862 toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
863 service.getPnfCustomizations().add(pnfResourceCustomization);
867 "Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}",
868 customizationUUID, notifCustomizationUUID);
873 private PnfResource findExistingPnfResource(Service service, String modelUuid) {
874 PnfResource pnfResource = null;
875 for (PnfResourceCustomization pnfResourceCustomization : service.getPnfCustomizations()) {
876 if (pnfResourceCustomization.getPnfResources() != null
877 && pnfResourceCustomization.getPnfResources().getModelUUID().equals(modelUuid)) {
878 pnfResource = pnfResourceCustomization.getPnfResources();
881 if (pnfResource == null) {
882 pnfResource = pnfResourceRepository.findById(modelUuid).orElse(pnfResource);
887 private boolean checkExistingPnfResourceCutomization(String customizationUUID) {
888 return pnfCustomizationRepository.findById(customizationUUID).isPresent();
892 * Construct the {@link PnfResource} from {@link IEntityDetails} object.
894 private PnfResource createPnfResource(IEntityDetails entity) {
895 PnfResource pnfResource = new PnfResource();
896 Metadata metadata = entity.getMetadata();
897 pnfResource.setModelInvariantUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
898 pnfResource.setModelName(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
899 pnfResource.setModelUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
900 pnfResource.setModelVersion(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
901 pnfResource.setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
902 pnfResource.setCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)));
903 pnfResource.setSubCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
904 pnfResource.setToscaNodeType(entity.getToscaType());
909 * Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object.
911 private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails,
912 PnfResource pnfResource) {
914 PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization();
915 Metadata metadata = entityDetails.getMetadata();
916 Map<String, Property> properties = entityDetails.getProperties();
917 pnfResourceCustomization.setModelCustomizationUUID(
918 testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
919 pnfResourceCustomization.setModelInstanceName(entityDetails.getName());
920 pnfResourceCustomization
921 .setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
922 pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE)));
923 pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE)));
924 pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
925 pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN)));
926 pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME)));
927 pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION)));
928 pnfResourceCustomization.setSkipPostInstConf(getBooleanValue(properties.get(SKIP_POST_INST_CONF)));
929 pnfResourceCustomization.setPnfResources(pnfResource);
931 return pnfResourceCustomization;
935 * Get value from {@link Property} and cast to boolean value. Return true if property is null.
937 private boolean getBooleanValue(Property property) {
938 if (null == property) {
941 Object value = property.getValue();
942 return new Boolean(String.valueOf(value));
946 * Get value from {@link Property} and cast to String value. Return empty String if property is null value.
948 private String getStringValue(Property property) {
949 if (null == property) {
952 Object value = property.getValue();
953 return String.valueOf(value);
956 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
957 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory)
960 logger.debug("VF Category is : " + vfCustomizationCategory);
962 if (vfResourceStructure.getVfModuleStructure() != null
963 && !vfResourceStructure.getVfModuleStructure().isEmpty()) {
965 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper().getMetadataPropertyValue(metadata,
966 SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
967 logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);
969 IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
971 // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before
972 // comparing their VF Modules UUID's
973 logger.debug("Checking if Notification VF ResourceCustomizationUUID: "
974 + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: "
975 + vfCustomizationUUID);
977 if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
979 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID
980 + " matches vfNotificationResource CustomizationUUID");
982 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
984 Set<CvnfcCustomization> existingCvnfcSet = new HashSet<>();
985 Set<VnfcCustomization> existingVnfcSet = new HashSet<>();
986 List<CvnfcConfigurationCustomization> existingCvnfcConfigurationCustom = new ArrayList<>();
988 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
990 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
991 List<org.onap.sdc.toscaparser.api.Group> vfGroups =
992 toscaResourceStruct.getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
993 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
995 logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : "
996 + vfMetadata.getVfModuleModelCustomizationUUID());
998 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
999 .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID "
1000 + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
1001 .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID")
1002 .equals(vfMetadata.getVfModuleModelCustomizationUUID()))
1004 if (matchingObject.isPresent()) {
1005 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(),
1006 nodeTemplate, toscaResourceStruct, vfResourceStructure, vfMetadata, vnfResource,
1007 existingCvnfcSet, existingVnfcSet, existingCvnfcConfigurationCustom);
1008 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
1010 throw new Exception(
1011 "Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: "
1012 + vfMetadata.getVfModuleModelCustomizationUUID());
1017 // Check for VNFC Instance Group info and add it if there is
1018 List<Group> groupList =
1019 toscaResourceStruct.getSdcCsarHelper().getGroupsOfOriginOfNodeTemplateByToscaGroupType(
1020 nodeTemplate, "org.openecomp.groups.VfcInstanceGroup");
1022 for (Group group : groupList) {
1023 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization =
1024 createVNFCInstanceGroup(nodeTemplate, group, vnfResource, toscaResourceStruct);
1025 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1028 List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList);
1029 if (!CollectionUtils.isEmpty(seqResult)) {
1030 String resultStr = seqResult.stream().collect(Collectors.joining(","));
1031 vnfResource.setVnfcInstanceGroupOrder(resultStr);
1033 "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr);
1035 // add this vnfResource with existing vnfResource for this service
1036 addVnfCustomization(service, vnfResource);
1038 logger.debug("Notification VF ResourceCustomizationUUID: "
1039 + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match "
1040 + "Tosca VF Customization UUID: " + vfCustomizationUUID);
1045 private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure,
1046 List<Group> groupList) {
1047 if (CollectionUtils.isEmpty(groupList)) {
1048 return Collections.emptyList();
1051 ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
1052 List<String> strSequence = new ArrayList<>(groupList.size());
1053 List<Group> tempGroupList = new ArrayList<>(groupList.size());
1054 List<NodeTemplate> nodes = new ArrayList<>();
1055 tempGroupList.addAll(groupList);
1057 for (Group group : groupList) {
1058 List<NodeTemplate> nodeList = group.getMemberNodes();
1059 boolean hasRequirements = false;
1060 for (NodeTemplate node : nodeList) {
1061 RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node);
1062 if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) {
1063 hasRequirements = true;
1068 if (!hasRequirements) {
1069 strSequence.add(group.getName());
1070 tempGroupList.remove(group);
1071 nodes.addAll(nodeList);
1075 getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
1081 private void getVNFCGroupSequenceList(List<String> strSequence, List<Group> groupList, List<NodeTemplate> nodes,
1082 ISdcCsarHelper iSdcCsarHelper) {
1083 if (CollectionUtils.isEmpty(groupList)) {
1087 List<Group> tempGroupList = new ArrayList<>();
1088 tempGroupList.addAll(groupList);
1090 for (Group group : groupList) {
1091 boolean isAllExists = true;
1092 ArrayList<NodeTemplate> members = group.getMemberNodes();
1093 for (NodeTemplate memberNode : members) {
1094 RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode);
1095 if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) {
1098 List<RequirementAssignment> rqaList = requirements.getAll();
1099 for (RequirementAssignment rqa : rqaList) {
1100 String name = rqa.getNodeTemplateName();
1101 Optional<NodeTemplate> findNode =
1102 nodes.stream().filter(node -> node.getName().equals(name)).findFirst();
1103 if (!findNode.isPresent()) {
1104 isAllExists = false;
1114 strSequence.add(group.getName());
1115 tempGroupList.remove(group);
1116 nodes.addAll(group.getMemberNodes());
1120 if (tempGroupList.size() != 0 && tempGroupList.size() < groupList.size()) {
1121 getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
1125 public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
1126 String consumerId) {
1127 WatchdogServiceModVerIdLookup modVerIdLookup =
1128 new WatchdogServiceModVerIdLookup(distributionId, servideUUID, distributionNotification, consumerId);
1129 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
1133 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
1134 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
1136 } catch (ObjectOptimisticLockingFailureException e) {
1137 logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
1142 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
1143 VfResourceStructure vfResourceStructure) {
1144 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1146 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
1147 case ASDCConfiguration.HEAT:
1148 case ASDCConfiguration.HEAT_NESTED:
1149 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, vfModuleArtifact);
1151 case ASDCConfiguration.HEAT_VOL:
1152 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, vfModuleArtifact);
1153 VfModuleArtifact envModuleArtifact =
1154 getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1155 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
1157 case ASDCConfiguration.HEAT_ENV:
1158 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
1160 case ASDCConfiguration.HEAT_ARTIFACT:
1161 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact, toscaResourceStruct);
1163 case ASDCConfiguration.HEAT_NET:
1164 case ASDCConfiguration.OTHER:
1165 case ASDCConfiguration.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT:
1166 logger.warn(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(),
1167 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
1168 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
1169 ErrorCode.DataError.getValue(), "Artifact type not supported");
1178 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
1179 VfModuleArtifact vfModuleArtifact) {
1180 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
1181 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
1182 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1183 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
1184 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1185 return moduleArtifact;
1191 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
1192 List<String> listTypes) {
1193 String newFileBody = filebody;
1194 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1196 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
1199 verifyTheFilePrefixInString(newFileBody, moduleArtifact.getArtifactInfo().getArtifactName());
1205 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
1207 String needlePrefix = "file:///";
1208 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
1210 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
1214 StringBuilder sb = new StringBuilder(body.length());
1216 int currentIndex = 0;
1219 while (currentIndex != -1) {
1220 startIndex = currentIndex;
1221 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
1223 if (currentIndex == -1) {
1226 // We append from the startIndex up to currentIndex (start of File
1228 sb.append(body.substring(startIndex, currentIndex));
1229 sb.append(filenameToVerify);
1231 currentIndex += prefixedFilenameToVerify.length();
1234 sb.append(body.substring(startIndex));
1236 return sb.toString();
1239 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
1240 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
1242 HeatTemplate existingHeatTemplate =
1243 heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1245 if (existingHeatTemplate == null) {
1246 HeatTemplate heatTemplate = new HeatTemplate();
1247 List<String> typeList = new ArrayList<>();
1248 typeList.add(ASDCConfiguration.HEAT_NESTED);
1249 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
1251 heatTemplate.setTemplateBody(
1252 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
1253 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1255 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
1256 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
1258 heatTemplate.setTimeoutMinutes(240);
1261 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1262 heatTemplate.setVersion(BigDecimalVersion
1263 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1264 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1266 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1267 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1269 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
1272 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
1273 vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1274 heatTemplate.setParameters(heatParam);
1275 vfModuleArtifact.setHeatTemplate(heatTemplate);
1277 vfModuleArtifact.setHeatTemplate(existingHeatTemplate);
1281 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
1282 VfModuleArtifact vfModuleArtifact) {
1284 HeatEnvironment existingHeatEnvironment =
1285 heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1287 if (existingHeatEnvironment == null) {
1288 HeatEnvironment heatEnvironment = new HeatEnvironment();
1289 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1290 List<String> typeList = new ArrayList<>();
1291 typeList.add(ASDCConfiguration.HEAT);
1292 typeList.add(ASDCConfiguration.HEAT_VOL);
1293 heatEnvironment.setEnvironment(
1294 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
1295 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1296 heatEnvironment.setVersion(BigDecimalVersion
1297 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1298 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1300 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1301 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1303 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
1305 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
1307 vfModuleArtifact.setHeatEnvironment(existingHeatEnvironment);
1311 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
1312 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
1314 HeatFiles existingHeatFiles =
1315 heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1317 if (existingHeatFiles == null) {
1318 HeatFiles heatFile = new HeatFiles();
1319 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1320 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
1321 heatFile.setFileBody(vfModuleArtifact.getResult());
1322 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
1323 heatFile.setVersion(BigDecimalVersion
1324 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
1325 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
1326 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
1327 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
1329 heatFile.setArtifactChecksum(MANUAL_RECORD);
1331 vfModuleArtifact.setHeatFiles(heatFile);
1333 vfModuleArtifact.setHeatFiles(existingHeatFiles);
1337 protected Service createService(ToscaResourceStructure toscaResourceStructure,
1338 ResourceStructure resourceStructure) {
1340 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
1342 Service service = new Service();
1344 if (serviceMetadata != null) {
1346 if (toscaResourceStructure.getServiceVersion() != null) {
1347 service.setModelVersion(toscaResourceStructure.getServiceVersion());
1350 service.setServiceType(serviceMetadata.getValue("serviceType"));
1351 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
1352 service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
1354 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1355 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1356 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1357 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
1359 if (resourceStructure != null)
1360 service.setWorkloadContext(resourceStructure.getNotification().getWorkloadContext());
1362 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1363 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
1364 service.setNamingPolicy(serviceMetadata.getValue("namingPolicy"));
1365 String generateNaming = serviceMetadata.getValue("ecompGeneratedNaming");
1366 Boolean generateNamingValue = null;
1367 if (generateNaming != null) {
1368 generateNamingValue = "true".equalsIgnoreCase(generateNaming);
1370 service.setOnapGeneratedNaming(generateNamingValue);
1374 toscaResourceStructure.setCatalogService(service);
1378 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service,
1379 ToscaResourceStructure toscaResourceStructure) {
1381 Metadata spMetadata = nodeTemplate.getMetaData();
1383 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
1385 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
1387 spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1388 spCustomizationResource
1389 .setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1390 spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1391 spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1392 spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1394 spCustomizationResource
1395 .setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1396 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
1397 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
1399 String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
1401 Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);
1403 spCustomizationResource.setSourceService(sourceService);
1404 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
1405 serviceProxyCustomizationSet.add(spCustomizationResource);
1408 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
1410 return spCustomizationResource;
1413 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate,
1414 ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
1415 Service service, List<ConfigurationResourceCustomization> configurationResourceList) {
1417 ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(
1418 nodeTemplate, toscaResourceStructure, spResourceCustomization, service);
1420 ConfigurationResource configResource = null;
1422 ConfigurationResource existingConfigResource = findExistingConfiguration(service,
1423 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID), configurationResourceList);
1425 if (existingConfigResource == null) {
1426 configResource = getConfigurationResource(nodeTemplate);
1428 configResource = existingConfigResource;
1431 configCustomizationResource.setConfigurationResource(configResource);
1433 return configCustomizationResource;
1436 protected ConfigurationResource createFabricConfiguration(IEntityDetails fabricEntity,
1437 ToscaResourceStructure toscaResourceStructure) {
1439 Metadata fabricMetadata = fabricEntity.getMetadata();
1441 ConfigurationResource configResource = new ConfigurationResource();
1443 configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1444 configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1445 configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1446 configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1447 configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1448 configResource.setToscaNodeType(fabricEntity.getToscaType());
1450 return configResource;
1453 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
1454 ToscaCsar toscaCsar = new ToscaCsar();
1455 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
1456 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
1458 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
1460 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
1461 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
1462 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
1463 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
1464 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
1466 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
1469 protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
1470 VnfcCustomization vnfcCustomization = null;
1471 for (VnfcCustomization vnfcCustom : vnfcCustomizations) {
1472 if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1473 vnfcCustomization = vnfcCustom;
1477 if (vnfcCustomization == null)
1478 vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1480 return vnfcCustomization;
1483 protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations,
1484 String customizationUUID) {
1485 CvnfcCustomization cvnfcCustomization = null;
1486 for (CvnfcCustomization cvnfcCustom : cvnfcCustomizations) {
1487 if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
1488 cvnfcCustomization = cvnfcCustom;
1492 if (cvnfcCustomization == null)
1493 cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
1495 return cvnfcCustomization;
1498 protected NetworkResourceCustomization createNetwork(IEntityDetails networkEntity,
1499 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,
1502 NetworkResourceCustomization networkResourceCustomization =
1503 networkCustomizationRepo.findOneByModelCustomizationUUID(
1504 networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1506 boolean networkUUIDsMatch = true;
1507 // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from
1508 // the distribution.
1509 // If not we'll update the Customization record with latest from the distribution
1510 if (networkResourceCustomization != null) {
1511 String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
1512 String latestNetworkModelUUID = networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
1514 if (!existingNetworkModelUUID.equals(latestNetworkModelUUID)) {
1515 networkUUIDsMatch = false;
1520 if (networkResourceCustomization != null && !networkUUIDsMatch) {
1522 NetworkResource networkResource =
1523 createNetworkResource(networkEntity, toscaResourceStructure, heatTemplate, aicMax, aicMin);
1525 networkResourceCustomization.setNetworkResource(networkResource);
1527 networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
1530 } else if (networkResourceCustomization == null) {
1531 networkResourceCustomization = createNetworkResourceCustomization(networkEntity, toscaResourceStructure);
1533 NetworkResource networkResource = findExistingNetworkResource(service,
1534 networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1535 if (networkResource == null)
1537 createNetworkResource(networkEntity, toscaResourceStructure, heatTemplate, aicMax, aicMin);
1539 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
1540 networkResourceCustomization.setNetworkResource(networkResource);
1543 return networkResourceCustomization;
1546 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
1547 NetworkResource networkResource = null;
1548 for (NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()) {
1549 if (networkCustom.getNetworkResource() != null
1550 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
1551 networkResource = networkCustom.getNetworkResource();
1554 if (networkResource == null)
1555 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
1557 return networkResource;
1560 protected NetworkResourceCustomization createNetworkResourceCustomization(IEntityDetails networkEntity,
1561 ToscaResourceStructure toscaResourceStructure) {
1562 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
1563 networkResourceCustomization.setModelInstanceName(
1564 testNull(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1565 networkResourceCustomization.setModelCustomizationUUID(
1566 testNull(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1568 networkResourceCustomization.setNetworkTechnology(
1569 getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1571 networkResourceCustomization
1572 .setNetworkType(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1574 networkResourceCustomization
1575 .setNetworkRole(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1577 networkResourceCustomization
1578 .setNetworkScope(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1580 return networkResourceCustomization;
1583 protected NetworkResource createNetworkResource(IEntityDetails vlEntity,
1584 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
1585 NetworkResource networkResource = new NetworkResource();
1586 String providerNetwork =
1587 getLeafPropertyValue(vlEntity, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1589 if ("true".equalsIgnoreCase(providerNetwork)) {
1590 networkResource.setNeutronNetworkType(PROVIDER);
1592 networkResource.setNeutronNetworkType(BASIC);
1595 networkResource.setModelName(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1597 networkResource.setModelInvariantUUID(
1598 testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1599 networkResource.setModelUUID(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1601 .setModelVersion(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1603 networkResource.setAicVersionMax(aicMax);
1604 networkResource.setAicVersionMin(aicMin);
1605 networkResource.setToscaNodeType(vlEntity.getToscaType());
1607 .setDescription(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1608 networkResource.setOrchestrationMode(HEAT);
1609 networkResource.setHeatTemplate(heatTemplate);
1610 return networkResource;
1613 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
1614 ToscaResourceStructure toscaResourceStructure, Service service) {
1616 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
1617 new CollectionNetworkResourceCustomization();
1619 // **** Build Object to populate Collection_Resource table
1620 CollectionResource collectionResource = new CollectionResource();
1623 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1624 collectionResource.setModelInvariantUUID(
1625 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1627 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1629 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1631 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1632 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
1634 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
1636 // **** Build object to populate Collection_Resource_Customization table
1637 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
1639 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1641 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1643 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1646 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1647 ncfc.setModelCustomizationUUID(
1648 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1650 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
1651 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
1653 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
1655 ncfc.setCollectionResource(collectionResource);
1656 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
1658 // *** Build object to populate the Instance_Group table
1659 List<Group> groupList =
1660 toscaResourceStructure.getSdcCsarHelper().getGroupsOfOriginOfNodeTemplateByToscaGroupType(
1661 networkNodeTemplate, "org.openecomp.groups.NetworkCollection");
1663 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
1665 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList =
1668 for (Group group : groupList) {
1670 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
1671 Metadata instanceMetadata = group.getMetadata();
1672 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1673 networkInstanceGroup
1674 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1675 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1676 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1677 networkInstanceGroup.setToscaNodeType(group.getType());
1678 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
1680 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
1682 networkInstanceGroup.setCollectionResource(collectionResource);
1684 // ****Build object to populate
1685 // Collection_Resource_Instance_Group_Customization table
1686 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization =
1687 new CollectionResourceInstanceGroupCustomization();
1688 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
1689 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1690 crInstanceGroupCustomization.setModelCustomizationUUID(
1691 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1693 // Loop through the template policy to find the subinterface_network_quantity property name. Then extract
1694 // the value for it.
1695 List<Policy> policyList =
1696 toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(
1697 networkNodeTemplate, "org.openecomp.policies.scaling.Fixed");
1699 if (policyList != null) {
1700 for (Policy policy : policyList) {
1701 for (String policyNetworkCollection : policy.getTargets()) {
1703 if (policyNetworkCollection.equalsIgnoreCase(group.getName())) {
1705 Map<String, Object> propMap = policy.getPolicyProperties();
1707 if (propMap.get("quantity") != null) {
1709 String quantity = toscaResourceStructure.getSdcCsarHelper()
1710 .getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1711 getPropertyInput(propMap.get("quantity").toString()));
1713 if (quantity != null) {
1714 crInstanceGroupCustomization
1715 .setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
1725 crInstanceGroupCustomization.setDescription(
1726 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1727 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1728 + "_network_collection_description"));
1729 crInstanceGroupCustomization.setFunction(
1730 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
1731 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
1732 + "_network_collection_function"));
1733 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
1734 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
1736 networkInstanceGroup
1737 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
1739 networkInstanceGroupList.add(networkInstanceGroup);
1742 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
1744 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
1745 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
1747 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
1749 // *****Build object to populate the NetworkResource table
1750 NetworkResource networkResource = new NetworkResource();
1752 for (NodeTemplate vlNodeTemplate : vlNodeList) {
1754 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
1755 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
1757 if ("true".equalsIgnoreCase(providerNetwork)) {
1758 networkResource.setNeutronNetworkType(PROVIDER);
1760 networkResource.setNeutronNetworkType(BASIC);
1764 .setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1766 networkResource.setModelInvariantUUID(
1767 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1769 .setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1771 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1773 networkResource.setAicVersionMax(
1774 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
1776 TempNetworkHeatTemplateLookup tempNetworkLookUp =
1777 tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
1778 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1780 if (tempNetworkLookUp != null) {
1782 HeatTemplate heatTemplate =
1783 heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1784 networkResource.setHeatTemplate(heatTemplate);
1786 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1790 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1791 networkResource.setDescription(
1792 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1793 networkResource.setOrchestrationMode(HEAT);
1795 // Build object to populate the
1796 // Collection_Network_Resource_Customization table
1797 for (NodeTemplate memberNode : group.getMemberNodes()) {
1798 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1801 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1802 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1804 collectionNetworkResourceCustomization.setNetworkTechnology(
1805 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1806 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1807 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1808 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1809 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1810 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1811 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1812 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1813 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1814 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1815 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1817 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1822 return collectionNetworkResourceCustomization;
1825 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1826 VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) {
1828 Metadata instanceMetadata = group.getMetadata();
1830 InstanceGroup existingInstanceGroup =
1831 instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1833 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1835 if (existingInstanceGroup == null) {
1836 // Populate InstanceGroup
1837 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1839 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1840 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1841 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1842 vfcInstanceGroup.setToscaNodeType(group.getType());
1843 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1844 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1846 vfcInstanceGroup = (VFCInstanceGroup) existingInstanceGroup;
1849 // Populate VNFCInstanceGroupCustomization
1850 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1852 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1853 vnfResourceCustomization.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
1855 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1856 vfcInstanceGroup.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
1858 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1860 String getInputName = null;
1861 String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1862 "vfc_instance_group_function");
1863 if (groupProperty != null) {
1864 int getInputIndex = groupProperty.indexOf("{get_input=");
1865 if (getInputIndex > -1) {
1866 getInputName = groupProperty.substring(getInputIndex + 11, groupProperty.length() - 1);
1869 vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper()
1870 .getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
1871 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1873 ArrayList<Input> inputs = vnfcNodeTemplate.getSubMappingToscaTemplate().getInputs();
1874 createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group, inputs);
1876 return vfcInstanceGroupCustom;
1880 private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group,
1881 List<Input> inputList) {
1882 List<NodeTemplate> members = group.getMemberNodes();
1883 if (!CollectionUtils.isEmpty(members)) {
1884 for (NodeTemplate vfcTemplate : members) {
1885 VnfcCustomization vnfcCustomization = new VnfcCustomization();
1887 Metadata metadata = vfcTemplate.getMetaData();
1889 .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1890 vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
1891 vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1893 .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1894 vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1895 vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1896 vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
1898 .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1899 vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcTemplate, inputList));
1900 List<VnfcCustomization> vnfcCustomizations = vfcInstanceGroupCustom.getVnfcCustomizations();
1902 if (vnfcCustomizations == null) {
1903 vnfcCustomizations = new ArrayList<>();
1904 vfcInstanceGroupCustom.setVnfcCustomizations(vnfcCustomizations);
1906 vnfcCustomizations.add(vnfcCustomization);
1911 public String getVnfcResourceInput(NodeTemplate vfcTemplate, List<Input> inputList) {
1912 Map<String, String> resouceRequest = new HashMap<>();
1913 LinkedHashMap<String, Property> vfcTemplateProperties = vfcTemplate.getProperties();
1914 for (String key : vfcTemplateProperties.keySet()) {
1915 Property property = vfcTemplateProperties.get(key);
1916 String resourceValue = getValue(property.getValue(), inputList);
1917 resouceRequest.put(key, resourceValue);
1920 String resourceCustomizationUuid =
1921 vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
1923 String jsonStr = null;
1925 ObjectMapper objectMapper = new ObjectMapper();
1926 jsonStr = objectMapper.writeValueAsString(resouceRequest);
1927 jsonStr = jsonStr.replace("\"", "\\\"");
1928 logger.debug("vfcResource request for resource customization id (" + resourceCustomizationUuid + ") : "
1930 } catch (JsonProcessingException e) {
1931 logger.debug("Json Exception: {}", e.getMessage());
1932 logger.error("Exception occurred", e);
1938 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
1939 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1940 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Set<CvnfcCustomization> existingCvnfcSet,
1941 Set<VnfcCustomization> existingVnfcSet,
1942 List<CvnfcConfigurationCustomization> existingCvnfcConfigurationCustom) {
1944 VfModuleCustomization vfModuleCustomization =
1945 findExistingVfModuleCustomization(vnfResource, vfModuleData.getVfModuleModelCustomizationUUID());
1946 if (vfModuleCustomization == null) {
1947 VfModule vfModule = findExistingVfModule(vnfResource,
1948 vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1949 Metadata vfMetadata = group.getMetadata();
1950 if (vfModule == null)
1951 vfModule = createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1953 vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
1954 vfModuleCustomization.setVnfCustomization(vnfResource);
1955 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1957 vfModuleCustomization.setVfModule(vfModule);
1958 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1959 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1961 vfResourceStructure.setAlreadyDeployed(true);
1964 // ******************************************************************************************************************
1965 // * Extract VFC's and CVFC's then add them to VFModule
1966 // ******************************************************************************************************************
1968 List<CvnfcConfigurationCustomization> cvnfcConfigurationCustomizations = new ArrayList<>();
1969 Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<>();
1970 Set<VnfcCustomization> vnfcCustomizations = new HashSet<>();
1972 // Only set the CVNFC if this vfModule group is a member of it.
1973 List<NodeTemplate> groupMembers =
1974 toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group);
1975 String vfModuleMemberName = null;
1977 for (NodeTemplate node : groupMembers) {
1978 vfModuleMemberName = node.getName();
1981 // Extract CVFC lists
1982 List<IEntityDetails> cvnfcEntityList =
1983 getEntityDetails(toscaResourceStructure, SdcTypes.CVFC, SdcTypes.VF, false);
1985 for (IEntityDetails cvfcEntity : cvnfcEntityList) {
1986 boolean cvnfcVfModuleNameMatch = false;
1988 for (NodeTemplate node : groupMembers) {
1989 vfModuleMemberName = node.getName();
1991 if (vfModuleMemberName.equalsIgnoreCase(cvfcEntity.getName())) {
1992 cvnfcVfModuleNameMatch = true;
1997 if (vfModuleMemberName != null && cvnfcVfModuleNameMatch) {
1999 // Extract associated VFC - Should always be just one
2000 List<IEntityDetails> vfcEntityList = getEntityDetails(toscaResourceStructure, SdcTypes.VFC,
2001 TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(
2002 cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)),
2005 for (IEntityDetails vfcEntity : vfcEntityList) {
2007 VnfcCustomization vnfcCustomization = new VnfcCustomization();
2008 VnfcCustomization existingVnfcCustomization = null;
2010 existingVnfcCustomization = findExistingVfc(existingVnfcSet,
2011 vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2013 if (existingVnfcCustomization == null) {
2014 vnfcCustomization = new VnfcCustomization();
2016 vnfcCustomization = existingVnfcCustomization;
2019 // Only Add Abstract VNFC's to our DB, ignore all others
2020 if (existingVnfcCustomization == null && vfcEntity.getMetadata()
2021 .getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")) {
2023 vnfcCustomization.setModelCustomizationUUID(
2024 vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2025 vnfcCustomization.setModelInstanceName(vfcEntity.getName());
2026 vnfcCustomization.setModelInvariantUUID(
2027 vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
2029 .setModelName(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
2031 .setModelUUID(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2033 vnfcCustomization.setModelVersion(
2034 testNull(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2035 vnfcCustomization.setDescription(
2036 testNull(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2037 vnfcCustomization.setToscaNodeType(testNull(vfcEntity.getToscaType()));
2039 vnfcCustomizations.add(vnfcCustomization);
2040 existingVnfcSet.add(vnfcCustomization);
2043 // This check is needed incase the VFC subcategory is
2044 // something other than Abstract. In that case we want to
2045 // skip adding that record to our DB.
2046 if (vnfcCustomization.getModelCustomizationUUID() != null) {
2047 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
2048 cvnfcCustomization.setModelCustomizationUUID(
2049 cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2050 cvnfcCustomization.setModelInstanceName(cvfcEntity.getName());
2051 cvnfcCustomization.setModelInvariantUUID(
2052 cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
2054 .setModelName(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
2056 .setModelUUID(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2058 cvnfcCustomization.setModelVersion(
2059 testNull(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2060 cvnfcCustomization.setDescription(testNull(
2061 cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2062 cvnfcCustomization.setToscaNodeType(testNull(cvfcEntity.getToscaType()));
2064 if (existingVnfcCustomization != null) {
2065 cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
2067 cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
2070 cvnfcCustomization.setNfcFunction(getLeafPropertyValue(cvfcEntity, "nfc_function"));
2071 cvnfcCustomization.setNfcNamingCode(getLeafPropertyValue(cvfcEntity, "nfc_naming_code"));
2073 cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
2074 // *****************************************************************************************************************************************
2075 // * Extract Fabric Configuration
2076 // *****************************************************************************************************************************************
2078 List<IEntityDetails> fabricEntityList =
2079 getEntityDetails(toscaResourceStructure, SdcTypes.CONFIGURATION, SdcTypes.VF, false);
2081 for (IEntityDetails fabricEntity : fabricEntityList) {
2083 ConfigurationResource fabricConfig = null;
2085 ConfigurationResource existingConfig =
2086 findExistingConfiguration(existingCvnfcConfigurationCustom,
2087 fabricEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2089 if (existingConfig == null) {
2091 fabricConfig = createFabricConfiguration(fabricEntity, toscaResourceStructure);
2094 fabricConfig = existingConfig;
2097 CvnfcConfigurationCustomization cvnfcConfigurationCustomization =
2098 createCvnfcConfigurationCustomization(fabricEntity, toscaResourceStructure,
2099 vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig,
2100 vfTemplate, vfModuleMemberName);
2102 cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization);
2104 existingCvnfcConfigurationCustom.add(cvnfcConfigurationCustomization);
2107 cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations);
2108 cvnfcCustomizations.add(cvnfcCustomization);
2109 existingCvnfcSet.add(cvnfcCustomization);
2117 vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
2119 return vfModuleCustomization;
2122 protected CvnfcConfigurationCustomization createCvnfcConfigurationCustomization(IEntityDetails fabricEntity,
2123 ToscaResourceStructure toscaResourceStruct, VnfResourceCustomization vnfResource,
2124 VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
2125 ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) {
2127 Metadata fabricMetadata = fabricEntity.getMetadata();
2129 CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization();
2131 cvnfcConfigurationCustomization.setConfigurationResource(configResource);
2133 cvnfcConfigurationCustomization.setCvnfcCustomization(cvnfcCustomization);
2135 cvnfcConfigurationCustomization
2136 .setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2137 cvnfcConfigurationCustomization.setModelInstanceName(fabricEntity.getName());
2139 List<IEntityDetails> policyList =
2140 getEntityDetails(toscaResourceStruct, "org.openecomp.policies.External", SdcTypes.VF, true);
2142 if (policyList != null) {
2143 for (IEntityDetails policyEntity : policyList) {
2145 for (String policyCvfcTarget : policyEntity.getTargets()) {
2147 if (policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)) {
2149 String policyType = getLeafPropertyValue(policyEntity, "type");
2151 if (policyType != null && policyType.equalsIgnoreCase("Fabric Policy")) {
2152 cvnfcConfigurationCustomization.setPolicyName(getLeafPropertyValue(policyEntity, "name"));
2159 cvnfcConfigurationCustomization.setConfigurationFunction(getLeafPropertyValue(fabricEntity, "function"));
2160 cvnfcConfigurationCustomization.setConfigurationRole(getLeafPropertyValue(fabricEntity, "role"));
2161 cvnfcConfigurationCustomization.setConfigurationType(getLeafPropertyValue(fabricEntity, "type"));
2163 return cvnfcConfigurationCustomization;
2166 protected ConfigurationResource findExistingConfiguration(
2167 List<CvnfcConfigurationCustomization> existingCvnfcConfigurationCustom, String modelUUID) {
2168 ConfigurationResource configResource = null;
2169 for (CvnfcConfigurationCustomization cvnfcConfigCustom : existingCvnfcConfigurationCustom) {
2170 if (cvnfcConfigCustom != null) {
2171 if (cvnfcConfigCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
2172 configResource = cvnfcConfigCustom.getConfigurationResource();
2177 return configResource;
2180 protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID,
2181 List<ConfigurationResourceCustomization> configurationResourceList) {
2182 ConfigurationResource configResource = null;
2183 for (ConfigurationResourceCustomization configurationResourceCustom : configurationResourceList) {
2184 if (configurationResourceCustom.getConfigurationResource() != null
2185 && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
2186 configResource = configurationResourceCustom.getConfigurationResource();
2190 return configResource;
2193 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
2194 String vfModuleModelCustomizationUUID) {
2195 VfModuleCustomization vfModuleCustomization = null;
2196 for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) {
2197 if (vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)) {
2198 vfModuleCustomization = vfModuleCustom;
2201 return vfModuleCustomization;
2204 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
2205 VfModule vfModule = null;
2206 for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) {
2207 if (vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)) {
2208 vfModule = vfModuleCustom.getVfModule();
2211 if (vfModule == null)
2212 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
2217 protected VfModuleCustomization createVfModuleCustomization(Group group,
2218 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
2219 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
2221 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
2223 vfModuleCustomization.setVfModule(vfModule);
2225 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2226 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
2227 if (initialCount != null && initialCount.length() > 0) {
2228 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
2231 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
2232 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
2234 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2235 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
2236 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
2237 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
2240 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2241 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
2243 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2244 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
2245 if (maxInstances != null && maxInstances.length() > 0) {
2246 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
2249 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2250 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
2251 if (minInstances != null && minInstances.length() > 0) {
2252 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
2254 return vfModuleCustomization;
2257 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
2258 IVfModuleData vfModuleData, Metadata vfMetadata) {
2259 VfModule vfModule = new VfModule();
2260 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
2262 if (vfModuleModelUUID == null) {
2263 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2264 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
2265 } else if (vfModuleModelUUID.indexOf('.') > -1) {
2266 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
2269 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
2270 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
2271 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2272 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
2273 vfModule.setModelUUID(vfModuleModelUUID);
2274 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2275 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
2276 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2277 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2279 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
2280 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
2281 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
2282 vfModule.setIsBase(true);
2284 vfModule.setIsBase(false);
2289 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
2290 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
2291 Metadata vfMetadata) {
2293 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
2294 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
2295 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
2296 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
2299 if (matchingObject.isPresent()) {
2300 List<HeatFiles> heatFilesList = new ArrayList<>();
2301 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<>();
2302 List<HeatTemplate> heatChildTemplates = new ArrayList<>();
2303 HeatTemplate parentHeatTemplate = new HeatTemplate();
2304 String parentArtifactType = null;
2305 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
2306 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
2308 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<>();
2310 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
2311 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
2312 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
2315 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
2316 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
2318 if (!childNestedHeatTemplates.isEmpty()) {
2320 if (parentArtifactType != null
2321 && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
2322 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
2324 heatChildTemplates.add(childNestedHeatTemplates.get(0));
2330 if (!heatFilesList.isEmpty()) {
2331 vfModule.setHeatFiles(heatFilesList);
2335 // Set all Child Templates related to HEAT_VOLUME
2336 if (!volumeHeatChildTemplates.isEmpty()) {
2337 if (vfModule.getVolumeHeatTemplate() != null) {
2338 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
2340 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
2344 // Set all Child Templates related to HEAT
2345 if (!heatChildTemplates.isEmpty()) {
2346 if (vfModule.getModuleHeatTemplate() != null) {
2347 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
2349 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
2355 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
2356 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
2357 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
2358 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
2359 vfModuleArtifact.incrementDeployedInDB();
2360 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
2361 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
2362 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
2363 VfModuleArtifact volVfModuleArtifact =
2364 this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
2365 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
2366 vfModuleArtifact.incrementDeployedInDB();
2367 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
2368 if (vfModuleArtifact.getHeatEnvironment() != null) {
2369 if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
2370 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
2372 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
2375 vfModuleArtifact.incrementDeployedInDB();
2376 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
2377 heatFilesList.add(vfModuleArtifact.getHeatFiles());
2378 vfModuleArtifact.incrementDeployedInDB();
2379 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
2380 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
2381 vfModuleArtifact.incrementDeployedInDB();
2385 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
2386 ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException {
2387 VnfResourceCustomization vnfResourceCustomization = null;
2388 if (vnfResourceCustomization == null) {
2389 VnfResource vnfResource = findExistingVnfResource(service,
2390 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2392 if (vnfResource == null) {
2393 vnfResource = createVnfResource(vfNodeTemplate);
2396 vnfResourceCustomization =
2397 createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, vnfResource);
2398 vnfResourceCustomization.setVnfResources(vnfResource);
2399 vnfResourceCustomization.setService(service);
2401 // setting resource input for vnf customization
2402 vnfResourceCustomization.setResourceInput(
2403 getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID()));
2404 service.getVnfCustomizations().add(vnfResourceCustomization);
2407 return vnfResourceCustomization;
2410 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
2411 VnfResource vnfResource = null;
2412 for (VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()) {
2413 if (vnfResourceCustom.getVnfResources() != null
2414 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
2415 vnfResource = vnfResourceCustom.getVnfResources();
2418 if (vnfResource == null)
2419 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
2424 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
2425 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
2426 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
2427 vnfResourceCustomization.setModelCustomizationUUID(
2428 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
2429 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
2431 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
2432 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
2433 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
2434 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
2435 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
2436 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
2437 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
2438 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
2440 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
2441 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
2443 vnfResourceCustomization.setBlueprintName(testNull(toscaResourceStructure.getSdcCsarHelper()
2444 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_NAME)));
2446 vnfResourceCustomization.setBlueprintVersion(testNull(toscaResourceStructure.getSdcCsarHelper()
2447 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_VERSION)));
2449 String skipPostInstConfText = toscaResourceStructure.getSdcCsarHelper()
2450 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SKIP_POST_INST_CONF);
2451 if (skipPostInstConfText != null) {
2452 vnfResourceCustomization.setSkipPostInstConf(Boolean.parseBoolean(skipPostInstConfText));
2455 vnfResourceCustomization.setVnfResources(vnfResource);
2456 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
2457 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
2459 CapabilityAssignments vnfCustomizationCapability =
2460 toscaResourceStructure.getSdcCsarHelper().getCapabilitiesOf(vfNodeTemplate);
2462 if (vnfCustomizationCapability != null) {
2463 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
2465 if (capAssign != null) {
2466 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2467 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2468 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2469 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2474 if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) {
2475 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2476 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2477 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
2478 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2481 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
2483 return vnfResourceCustomization;
2486 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
2487 VnfResource vnfResource = new VnfResource();
2488 vnfResource.setModelInvariantUUID(
2489 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
2490 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2491 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
2493 vnfResource.setModelVersion(
2494 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2495 vnfResource.setDescription(
2496 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
2497 vnfResource.setOrchestrationMode(HEAT);
2498 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
2499 vnfResource.setAicVersionMax(
2500 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2501 vnfResource.setAicVersionMin(
2502 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2503 vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
2504 vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
2509 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
2510 ToscaResourceStructure toscaResourceStructure, Service service) {
2511 AllottedResourceCustomization allottedResourceCustomization =
2512 allottedCustomizationRepo.findOneByModelCustomizationUUID(
2513 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
2515 if (allottedResourceCustomization == null) {
2516 AllottedResource allottedResource = findExistingAllottedResource(service,
2517 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
2519 if (allottedResource == null)
2520 allottedResource = createAR(nodeTemplate);
2522 toscaResourceStructure.setAllottedResource(allottedResource);
2523 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
2524 allottedResourceCustomization.setAllottedResource(allottedResource);
2525 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
2527 return allottedResourceCustomization;
2530 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
2531 AllottedResource allottedResource = null;
2532 for (AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()) {
2533 if (allottedResourceCustom.getAllottedResource() != null
2534 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
2535 allottedResource = allottedResourceCustom.getAllottedResource();
2538 if (allottedResource == null)
2539 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
2541 return allottedResource;
2544 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
2545 ToscaResourceStructure toscaResourceStructure) {
2546 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
2547 allottedResourceCustomization.setModelCustomizationUUID(
2548 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
2549 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
2552 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
2553 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
2554 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
2555 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
2556 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
2557 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
2558 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
2559 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
2561 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper()
2562 .getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
2564 if (vfcNodes != null) {
2565 for (NodeTemplate vfcNode : vfcNodes) {
2567 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper()
2568 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
2569 allottedResourceCustomization
2570 .setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper()
2571 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
2572 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper()
2573 .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
2578 CapabilityAssignments arCustomizationCapability =
2579 toscaResourceStructure.getSdcCsarHelper().getCapabilitiesOf(nodeTemplate);
2581 if (arCustomizationCapability != null) {
2582 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
2584 if (capAssign != null) {
2585 allottedResourceCustomization.setMinInstances(
2586 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2587 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
2588 allottedResourceCustomization.setMaxInstances(
2589 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
2590 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
2593 return allottedResourceCustomization;
2596 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
2597 AllottedResource allottedResource = new AllottedResource();
2599 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
2600 allottedResource.setModelInvariantUUID(
2601 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
2603 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
2605 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
2606 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
2607 allottedResource.setSubcategory(
2608 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
2610 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
2611 return allottedResource;
2614 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
2615 // Scan the payload downloadResult and extract the HeatTemplate
2617 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
2618 return yamlEditor.getParameterList(artifactUUID);
2621 protected String testNull(Object object) {
2623 if (object == null) {
2625 } else if ("NULL".equals(object)) {
2627 } else if (object instanceof Integer) {
2628 return object.toString();
2629 } else if (object instanceof String) {
2630 return (String) object;
2632 return "Type not recognized";
2636 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
2637 VfModuleArtifact heatNestedArtifact) {
2639 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
2640 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
2641 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
2642 .getArtifactInfo().getRelatedArtifacts()) {
2643 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2644 return ASDCConfiguration.HEAT;
2650 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
2651 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
2652 .getRelatedArtifacts() != null) {
2653 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
2654 .get(0).getArtifactInfo().getRelatedArtifacts()) {
2655 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
2656 return ASDCConfiguration.HEAT_VOL;
2662 // Does not belong to anything
2667 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
2669 return vfResourceStructure.getNotification().getServiceName() + "/"
2670 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
2673 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
2675 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
2676 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
2679 protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, SdcTypes entityType,
2680 SdcTypes topologyTemplate, boolean nestedSearch) {
2682 EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build();
2683 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(topologyTemplate).build();
2684 List<IEntityDetails> entityDetails =
2685 toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch);
2687 return entityDetails;
2691 protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, String entityType,
2692 SdcTypes topologyTemplate, boolean nestedSearch) {
2694 EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build();
2695 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(topologyTemplate).build();
2696 List<IEntityDetails> entityDetails =
2697 toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch);
2699 return entityDetails;
2703 protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, SdcTypes entityType,
2704 TopologyTemplateQueryBuilder topologyTemplateBuilder, boolean nestedSearch) {
2706 EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build();
2707 TopologyTemplateQuery topologyTemplateQuery = topologyTemplateBuilder.build();
2708 List<IEntityDetails> entityDetails =
2709 toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch);
2711 return entityDetails;
2715 protected String getLeafPropertyValue(IEntityDetails entityDetails, String propName) {
2717 Property leafProperty = entityDetails.getProperties().get(propName);
2719 if (leafProperty != null && leafProperty.getValue() != null) {
2720 return leafProperty.getValue().toString();
2726 protected String getPropertyInput(String propertyName) {
2728 String inputName = new String();
2730 if (propertyName != null) {
2731 int getInputIndex = propertyName.indexOf("{get_input=");
2732 if (getInputIndex > -1) {
2733 inputName = propertyName.substring(getInputIndex + 11, propertyName.length() - 1);
2740 // this method add provided vnfCustomization to service with
2741 // existing customization available in db.
2742 private void addVnfCustomization(Service service, VnfResourceCustomization vnfResourceCustomization) {
2743 List<Service> services = serviceRepo.findByModelUUID(service.getModelUUID());
2744 if (!services.isEmpty()) {
2745 // service exist in db
2746 Service existingService = services.get(0);
2747 List<VnfResourceCustomization> vnfCustomizations = existingService.getVnfCustomizations();
2748 vnfCustomizations.forEach(e -> service.getVnfCustomizations().add(e));
2750 service.getVnfCustomizations().add(vnfResourceCustomization);
2754 protected static Timestamp getCurrentTimeStamp() {
2756 return new Timestamp(new Date().getTime());