2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.asdc.installer.heat;
25 import java.sql.Timestamp;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Optional;
33 import org.hibernate.exception.ConstraintViolationException;
34 import org.hibernate.exception.LockAcquisitionException;
35 import org.onap.sdc.api.notification.IArtifactInfo;
36 import org.onap.sdc.api.notification.IStatusData;
37 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
38 import org.onap.sdc.tosca.parser.impl.SdcTypes;
39 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
40 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
41 import org.onap.sdc.toscaparser.api.Group;
42 import org.onap.sdc.toscaparser.api.NodeTemplate;
43 import org.onap.sdc.toscaparser.api.RequirementAssignment;
44 import org.onap.sdc.toscaparser.api.elements.Metadata;
45 import org.onap.sdc.utils.DistributionStatusEnum;
46 import org.onap.so.asdc.client.ASDCConfiguration;
47 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
48 import org.onap.so.asdc.installer.ASDCElementInfo;
49 import org.onap.so.asdc.installer.BigDecimalVersion;
50 import org.onap.so.asdc.installer.IVfModuleData;
51 import org.onap.so.asdc.installer.ToscaResourceStructure;
52 import org.onap.so.asdc.installer.VfModuleArtifact;
53 import org.onap.so.asdc.installer.VfModuleStructure;
54 import org.onap.so.asdc.installer.VfResourceStructure;
55 import org.onap.so.asdc.util.YamlEditor;
56 import org.onap.so.db.catalog.beans.AllottedResource;
57 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
58 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
59 import org.onap.so.db.catalog.beans.CollectionResource;
60 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
61 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
62 import org.onap.so.db.catalog.beans.ConfigurationResource;
63 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
64 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
65 import org.onap.so.db.catalog.beans.HeatEnvironment;
66 import org.onap.so.db.catalog.beans.HeatFiles;
67 import org.onap.so.db.catalog.beans.HeatTemplate;
68 import org.onap.so.db.catalog.beans.HeatTemplateParam;
69 import org.onap.so.db.catalog.beans.InstanceGroupType;
70 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
71 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
72 import org.onap.so.db.catalog.beans.NetworkResource;
73 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
74 import org.onap.so.db.catalog.beans.Service;
75 import org.onap.so.db.catalog.beans.ServiceProxyResource;
76 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
77 import org.onap.so.db.catalog.beans.SubType;
78 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
79 import org.onap.so.db.catalog.beans.ToscaCsar;
80 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
81 import org.onap.so.db.catalog.beans.VfModule;
82 import org.onap.so.db.catalog.beans.VfModuleCustomization;
83 import org.onap.so.db.catalog.beans.VnfResource;
84 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
85 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
86 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
87 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
88 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
89 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
90 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
91 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
92 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
93 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
94 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
95 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
96 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
97 import org.onap.so.db.catalog.data.repository.ServiceRepository;
98 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
99 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
100 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
101 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
102 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
103 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
104 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
105 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
106 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
107 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
108 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
109 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
110 import org.onap.so.logger.MessageEnum;
111 import org.onap.so.logger.MsoLogger;
112 import org.springframework.beans.factory.annotation.Autowired;
113 import org.springframework.stereotype.Component;
114 import org.springframework.transaction.annotation.Transactional;
117 public class ToscaResourceInstaller {
119 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
121 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
123 protected static final String SCALABLE = "scalable";
125 protected static final String BASIC = "BASIC";
127 protected static final String PROVIDER = "PROVIDER";
129 protected static final String HEAT = "HEAT";
131 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
133 protected static final String MSO = "SO";
137 protected ServiceRepository serviceRepo;
140 protected InstanceGroupRepository instanceGroupRepo;
143 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
146 protected CollectionResourceRepository collectionRepo;
149 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
152 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
155 protected VnfResourceRepository vnfRepo;
158 protected VnfCustomizationRepository vnfCustomizationRepo;
161 protected VFModuleRepository vfModuleRepo;
164 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
167 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
170 protected AllottedResourceRepository allottedRepo;
173 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
176 protected NetworkResourceRepository networkRepo;
179 protected HeatTemplateRepository heatRepo;
182 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
185 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
187 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
189 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
192 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
195 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
197 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
199 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
200 boolean status = false;
201 VfResourceStructure vfResourceStructure = vfResourceStruct;
203 status = vfResourceStructure.isDeployedSuccessfully();
204 } catch (RuntimeException e) {
208 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
209 if(existingService != null)
212 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
213 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
214 vfResourceStructure.getNotification().getServiceName(),
215 BigDecimalVersion.castAndCheckNotificationVersionToString(
216 vfResourceStructure.getNotification().getServiceVersion()),
217 vfResourceStructure.getNotification().getServiceUUID(),
218 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
219 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
220 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
221 watchdogCDStatusRepository.saveAndFlush(wdStatus);
223 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
224 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
225 vfResourceStructure.getNotification().getServiceName(),
226 BigDecimalVersion.castAndCheckNotificationVersionToString(
227 vfResourceStructure.getNotification().getServiceVersion()),
228 vfResourceStructure.getNotification().getServiceUUID(),
229 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
232 } catch (Exception e) {
233 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
234 "Exception - isResourceAlreadyDeployed");
235 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
239 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
240 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
241 + " and ComponentName " + iStatus.getComponentName());
244 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
245 iStatus.getComponentName());
246 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
247 watchdogCDStatusRepository.save(cdStatus);
249 } catch (Exception e) {
250 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
251 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
255 @Transactional(rollbackFor = { ArtifactInstallerException.class })
256 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
257 throws ArtifactInstallerException {
258 VfResourceStructure vfResourceStructure = vfResourceStruct;
259 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
261 // PCLO: in case of deployment failure, use a string that will represent
262 // the type of artifact that failed...
263 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
265 createToscaCsar(toscaResourceStruct);
266 createService(toscaResourceStruct, vfResourceStruct);
267 Service service = toscaResourceStruct.getCatalogService();
268 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
271 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
273 Metadata metadata = nodeTemplate.getMetaData();
274 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
275 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
276 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
277 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
278 vfCustomizationCategory);
281 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
282 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
283 processNetworks(toscaResourceStruct, service);
284 // process Network Collections
285 processNetworkCollections(toscaResourceStruct, service);
286 // Process Service Proxy & Configuration
287 processServiceProxyAndConfiguration(toscaResourceStruct, service);
289 serviceRepo.save(service);
291 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
292 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
293 watchdogCDStatusRepository.save(status);
295 toscaResourceStruct.setSuccessfulDeployment();
297 } catch (Exception e) {
298 logger.debug("Exception :", e);
299 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
300 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
301 watchdogCDStatusRepository.save(status);
302 Throwable dbExceptionToCapture = e;
303 while (!(dbExceptionToCapture instanceof ConstraintViolationException
304 || dbExceptionToCapture instanceof LockAcquisitionException)
305 && (dbExceptionToCapture.getCause() != null)) {
306 dbExceptionToCapture = dbExceptionToCapture.getCause();
309 if (dbExceptionToCapture instanceof ConstraintViolationException
310 || dbExceptionToCapture instanceof LockAcquisitionException) {
311 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
312 vfResourceStructure.getResourceInstance().getResourceName(),
313 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
315 String elementToLog = (!artifactListForLogging.isEmpty()
316 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
317 : "No element listed");
318 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
319 "Exception caught during installation of "
320 + vfResourceStructure.getResourceInstance().getResourceName()
321 + ". Transaction rollback",
323 throw new ArtifactInstallerException("Exception caught during installation of "
324 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
329 protected void processNetworks(ToscaResourceStructure toscaResourceStruct, Service service)
330 throws ArtifactInstallerException {
331 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper().getServiceVlList();
333 if (nodeTemplatesVLList != null) {
334 for (NodeTemplate vlNode : nodeTemplatesVLList) {
335 String networkResourceModelName = vlNode.getMetaData()
336 .getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
338 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkResourceModelName);
340 if (tempNetworkLookUp != null ) {
341 HeatTemplate heatTemplate = heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
342 if (heatTemplate != null ) {
343 NetworkResourceCustomization networkCustomization = createNetwork(vlNode, toscaResourceStruct, heatTemplate,tempNetworkLookUp.getAicVersionMax(),
344 tempNetworkLookUp.getAicVersionMin(),service);
345 service.getNetworkCustomizations()
346 .add(networkCustomization);
349 throw new ArtifactInstallerException(
350 "No HeatTemplate found for artifactUUID: "
351 + tempNetworkLookUp.getHeatTemplateArtifactUuid());
354 throw new ArtifactInstallerException(
355 "No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
356 + networkResourceModelName);
363 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
364 List<NodeTemplate> allottedResourceList) {
365 if (allottedResourceList != null) {
366 for (NodeTemplate allottedNode : allottedResourceList) {
367 service.getAllottedCustomizations()
368 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
373 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
375 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
377 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
379 if (serviceProxyResourceList != null) {
380 for (NodeTemplate spNode : serviceProxyResourceList) {
381 createServiceProxy(spNode, service, toscaResourceStruct);
382 serviceProxyCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogServiceProxyResourceCustomization());
384 for (NodeTemplate configNode : configurationNodeTemplatesList) {
386 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
387 for (RequirementAssignment requirement : requirementsList) {
388 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
389 createConfiguration(configNode, toscaResourceStruct, toscaResourceStruct.getCatalogServiceProxyResourceCustomization());
390 configCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogConfigurationResourceCustomization());
400 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
402 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
404 if (networkCollectionList != null) {
405 for (NodeTemplate crNode : networkCollectionList) {
407 createNetworkCollection(crNode, toscaResourceStruct, service);
408 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
410 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
411 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
412 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
417 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
420 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
421 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
422 if (!vfCustomizationCategory.equalsIgnoreCase(ALLOTTED_RESOURCE))
425 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
426 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
427 logger.debug("vfCustomizationUUID=" + vfCustomizationUUID);
429 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
431 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
432 logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
433 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
434 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
435 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
436 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream().
437 filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())).
439 if(matchingObject.isPresent()){
440 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, vfResourceStructure,vfMetadata, vnfResource);
441 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
443 throw (new Exception("Cannot find matching VFModule Customization"));
446 service.getVnfCustomizations().add(vnfResource);
450 protected void processFlexware(ToscaResourceStructure toscaResourceStruct, Service service, NodeTemplate nodeTemplate,
451 String serviceType) {
452 if (serviceType != null && serviceType.equalsIgnoreCase("Flexware")) {
454 createVnfResource(nodeTemplate, toscaResourceStruct, service);
455 String modelName = toscaResourceStruct.getVnfResourceCustomization().getVnfResources().getModelName();
457 String modelVersion = BigDecimalVersion.castAndCheckNotificationVersionToString(
458 toscaResourceStruct.getCatalogVnfResourceCustomization().getVnfResources().getModelVersion());
459 // check for duplicate record already in the database
460 VnfResource vnfResource = vnfRepo.findByModelNameAndModelVersion(modelName, modelVersion);
462 if (vnfResource != null) {
463 toscaResourceStruct.setVnfAlreadyInstalled(true);
466 vnfCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogVnfResourceCustomization());
470 public void processWatchdog(String distributionId, String servideUUID) {
471 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
472 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
474 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
475 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
478 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
479 VfResourceStructure vfResourceStructure) {
480 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
482 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
483 case ASDCConfiguration.HEAT:
484 case ASDCConfiguration.HEAT_NESTED:
485 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
488 case ASDCConfiguration.HEAT_VOL:
489 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
491 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
492 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
494 case ASDCConfiguration.HEAT_ENV:
495 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
497 case ASDCConfiguration.HEAT_ARTIFACT:
498 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
499 toscaResourceStruct);
501 case ASDCConfiguration.HEAT_NET:
502 case ASDCConfiguration.OTHER:
503 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
504 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
505 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
506 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
515 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
516 VfModuleArtifact vfModuleArtifact) {
517 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
518 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
519 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
520 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
521 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
522 return moduleArtifact;
528 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
529 List<String> listTypes) {
530 String newFileBody = filebody;
531 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
533 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
535 newFileBody = verifyTheFilePrefixInString(newFileBody,
536 moduleArtifact.getArtifactInfo().getArtifactName());
542 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
544 String needlePrefix = "file:///";
545 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
547 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
551 StringBuilder sb = new StringBuilder(body.length());
553 int currentIndex = 0;
556 while (currentIndex != -1) {
557 startIndex = currentIndex;
558 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
560 if (currentIndex == -1) {
563 // We append from the startIndex up to currentIndex (start of File
565 sb.append(body.substring(startIndex, currentIndex));
566 sb.append(filenameToVerify);
568 currentIndex += prefixedFilenameToVerify.length();
571 sb.append(body.substring(startIndex));
573 return sb.toString();
576 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
577 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
578 HeatTemplate heatTemplate = new HeatTemplate();
579 List<String> typeList = new ArrayList<>();
580 typeList.add(ASDCConfiguration.HEAT_NESTED);
581 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
583 heatTemplate.setTemplateBody(
584 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
585 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
587 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
588 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
590 heatTemplate.setTimeoutMinutes(240);
593 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
594 heatTemplate.setVersion(BigDecimalVersion
595 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
596 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
598 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
599 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
601 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
604 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
605 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
606 heatTemplate.setParameters(heatParam);
607 vfModuleArtifact.setHeatTemplate(heatTemplate);
610 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
611 VfModuleArtifact vfModuleArtifact) {
612 HeatEnvironment heatEnvironment = new HeatEnvironment();
613 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
614 List<String> typeList = new ArrayList<>();
615 typeList.add(ASDCConfiguration.HEAT);
616 typeList.add(ASDCConfiguration.HEAT_VOL);
617 heatEnvironment.setEnvironment(
618 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
619 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
620 heatEnvironment.setVersion(BigDecimalVersion
621 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
622 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
624 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
625 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
627 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
629 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
632 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
633 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
635 HeatFiles heatFile = new HeatFiles();
636 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
637 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
638 heatFile.setFileBody(vfModuleArtifact.getResult());
639 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
640 heatFile.setVersion(BigDecimalVersion
641 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
642 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
643 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
644 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
646 heatFile.setArtifactChecksum(MANUAL_RECORD);
648 vfModuleArtifact.setHeatFiles(heatFile);
651 protected Service createService(ToscaResourceStructure toscaResourceStructure,
652 VfResourceStructure vfResourceStructure) {
654 toscaResourceStructure.getServiceMetadata();
656 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
658 Service service = new Service();
660 if (serviceMetadata != null) {
662 if (toscaResourceStructure.getServiceVersion() != null) {
663 service.setModelVersion(toscaResourceStructure.getServiceVersion());
666 service.setServiceType(serviceMetadata.getValue("serviceType"));
667 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
669 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
670 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
671 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
672 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
674 if (vfResourceStructure != null)
675 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
677 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
678 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
682 toscaResourceStructure.setCatalogService(service);
686 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
688 Metadata spMetadata = nodeTemplate.getMetaData();
690 ServiceProxyResource spResource = new ServiceProxyResource();
692 spResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
693 spResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
694 spResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
695 spResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
696 spResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
698 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
700 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
702 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
703 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
704 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
705 spCustomizationResource.setSourceService(service);
706 spCustomizationResource.setServiceProxyResource(spResource);
707 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
708 spCustomizationResource.setServiceProxyResource(spResource);
709 serviceProxyCustomizationSet.add(spCustomizationResource);
712 spResource.setServiceProxyCustomization(serviceProxyCustomizationSet);
714 toscaResourceStructure.setCatalogServiceProxyResource(spResource);
716 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
718 return spCustomizationResource;
721 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
723 Metadata metadata = nodeTemplate.getMetaData();
725 ConfigurationResource configResource = new ConfigurationResource();
727 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
728 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
729 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
730 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
731 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
732 configResource.setToscaNodeType(nodeTemplate.getType());
734 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
736 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
738 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
739 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
741 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
742 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
743 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
744 configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
745 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
746 configCustomizationResource.setConfigurationResource(configResource);
747 configResourceCustomizationSet.add(configCustomizationResource);
749 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
751 toscaResourceStructure.setCatalogConfigurationResource(configResource);
753 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
755 return configCustomizationResource;
759 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
760 ToscaCsar toscaCsar = new ToscaCsar();
761 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
762 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
764 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
766 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
767 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
768 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
769 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
770 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
772 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
775 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
776 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
778 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
779 if(networkResourceCustomization==null){
780 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
781 toscaResourceStructure);
783 NetworkResource networkResource = findExistingNetworkResource(service,
784 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
785 if(networkResource == null)
786 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
789 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
790 networkResourceCustomization.setNetworkResource(networkResource);
792 return networkResourceCustomization;
795 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
796 NetworkResource networkResource = null;
797 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
798 if (networkCustom.getNetworkResource() != null
799 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
800 networkResource = networkCustom.getNetworkResource();
803 if(networkResource==null)
804 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
806 return networkResource;
809 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
810 ToscaResourceStructure toscaResourceStructure) {
811 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
812 networkResourceCustomization.setModelInstanceName(
813 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
814 networkResourceCustomization.setModelCustomizationUUID(
815 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
817 networkResourceCustomization.setNetworkTechnology(
818 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
819 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
820 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
821 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
822 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
823 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
824 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
825 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
826 return networkResourceCustomization;
829 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
830 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
831 NetworkResource networkResource = new NetworkResource();
832 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
833 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
835 if ("true".equalsIgnoreCase(providerNetwork)) {
836 networkResource.setNeutronNetworkType(PROVIDER);
838 networkResource.setNeutronNetworkType(BASIC);
841 networkResource.setModelName(
842 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
844 networkResource.setModelInvariantUUID(
845 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
846 networkResource.setModelUUID(
847 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
848 networkResource.setModelVersion(
849 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
851 networkResource.setAicVersionMax(aicMax);
852 networkResource.setAicVersionMin(aicMin);
853 networkResource.setToscaNodeType(networkNodeTemplate.getType());
854 networkResource.setDescription(
855 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
856 networkResource.setOrchestrationMode(HEAT);
857 networkResource.setHeatTemplate(heatTemplate);
858 return networkResource;
861 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
862 ToscaResourceStructure toscaResourceStructure, Service service) {
864 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
866 // **** Build Object to populate Collection_Resource table
867 CollectionResource collectionResource = new CollectionResource();
870 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
871 collectionResource.setModelInvariantUUID(
872 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
874 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
876 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
878 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
879 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
881 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
883 // **** Build object to populate Collection_Resource_Customization table
884 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
886 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
888 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
890 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
893 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
894 ncfc.setModelCustomizationUUID(
895 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
897 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
898 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
900 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
902 ncfc.setCollectionResource(collectionResource);
903 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
905 //*** Build object to populate the Instance_Group table
906 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
907 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
908 "org.openecomp.groups.NetworkCollection");
910 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
912 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
914 for (Group group : groupList) {
916 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
917 Metadata instanceMetadata = group.getMetadata();
918 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
920 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
921 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
922 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
923 networkInstanceGroup.setToscaNodeType(group.getType());
924 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
926 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
928 networkInstanceGroup.setCollectionResource(collectionResource);
930 // ****Build object to populate
931 // Collection_Resource_Instance_Group_Customization table
932 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
933 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
934 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
935 crInstanceGroupCustomization.setModelCustomizationUUID(
936 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
938 String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
939 String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
940 if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
941 fixedQuantity + "_quantity") != null) {
943 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
944 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
945 fixedQuantity + "_quantity")));
948 crInstanceGroupCustomization.setDescription(
949 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
950 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
951 + "_network_collection_description"));
952 crInstanceGroupCustomization.setFunction(
953 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
954 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
955 + "_network_collection_function"));
956 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
957 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
960 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
962 networkInstanceGroupList.add(networkInstanceGroup);
966 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
968 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
969 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
971 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
973 //*****Build object to populate the NetworkResource table
974 NetworkResource networkResource = new NetworkResource();
976 for(NodeTemplate vlNodeTemplate : vlNodeList){
978 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
979 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
981 if ("true".equalsIgnoreCase(providerNetwork)) {
982 networkResource.setNeutronNetworkType(PROVIDER);
984 networkResource.setNeutronNetworkType(BASIC);
987 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
989 networkResource.setModelInvariantUUID(
990 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
991 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
993 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
995 networkResource.setAicVersionMax(
996 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
998 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
999 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1001 if (tempNetworkLookUp != null ) {
1003 HeatTemplate heatTemplate = heatRepo
1004 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
1005 networkResource.setHeatTemplate(heatTemplate);
1007 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1011 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1013 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1014 networkResource.setOrchestrationMode(HEAT);
1016 // Build object to populate the
1017 // Collection_Network_Resource_Customization table
1018 for (NodeTemplate memberNode : group.getMemberNodes()) {
1019 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1022 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1023 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1025 collectionNetworkResourceCustomization.setNetworkTechnology(
1026 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1027 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1028 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1029 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1030 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1031 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1032 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1033 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1034 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1035 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1036 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1038 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1043 return collectionNetworkResourceCustomization;
1046 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1047 VnfResourceCustomization vnfResourceCustomization) {
1049 Metadata instanceMetadata = group.getMetadata();
1050 // Populate InstanceGroup
1051 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1053 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1054 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1055 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1056 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1057 vfcInstanceGroup.setToscaNodeType(group.getType());
1058 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1059 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1061 //Populate VNFCInstanceGroupCustomization
1062 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1064 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1065 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1066 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1067 vfcInstanceGroupCustom.setFunction("FUNCTION");
1068 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1069 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1071 return vfcInstanceGroupCustom;
1075 protected VFCInstanceGroup findExistingVnfcInstanceGroup(VnfResourceCustomization vnfResourceCustomization,
1077 VFCInstanceGroup vfcInstanceGroup = null;
1078 List<VnfcInstanceGroupCustomization> vnfInstanceGroupCustomizations = vnfResourceCustomization
1079 .getVnfcInstanceGroupCustomizations();
1080 if(vnfInstanceGroupCustomizations != null){
1081 for (VnfcInstanceGroupCustomization vnfcInstanceGroupCustom : vnfResourceCustomization
1082 .getVnfcInstanceGroupCustomizations()) {
1083 if (vnfcInstanceGroupCustom.getInstanceGroup() != null
1084 && vnfcInstanceGroupCustom.getInstanceGroup().getModelUUID().equals(modelUUID)) {
1085 vfcInstanceGroup = (VFCInstanceGroup)vnfcInstanceGroupCustom.getInstanceGroup();
1089 if (vfcInstanceGroup == null)
1090 vfcInstanceGroup = (VFCInstanceGroup) instanceGroupRepo.findByModelUUID(modelUUID);
1092 return vfcInstanceGroup;
1095 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1096 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1097 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource) {
1098 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1099 vfModuleData.getVfModuleModelCustomizationUUID());
1100 if(vfModuleCustomization == null){
1101 VfModule vfModule = findExistingVfModule(vnfResource,
1102 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1103 Metadata vfMetadata = group.getMetadata();
1105 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1107 vfModuleCustomization = createVfModuleCustomzation(group, toscaResourceStructure, vfModule, vfModuleData);
1108 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1110 vfModuleCustomization.setVfModule(vfModule);
1111 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1112 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1114 vfResourceStructure.setAlreadyDeployed(true);
1117 return vfModuleCustomization;
1120 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1121 String vfModuleModelCustomizationUUID) {
1122 VfModuleCustomization vfModuleCustomization = null;
1123 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1124 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1125 vfModuleCustomization = vfModuleCustom;
1128 if(vfModuleCustomization==null)
1129 vfModuleCustomization = vfModuleCustomizationRepo
1130 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1132 return vfModuleCustomization;
1135 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1136 VfModule vfModule = null;
1137 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1138 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1139 vfModule = vfModuleCustom.getVfModule();
1143 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1148 protected VfModuleCustomization createVfModuleCustomzation(Group group,
1149 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1150 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1152 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1154 vfModuleCustomization.setVfModule(vfModule);
1156 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1157 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1158 if (initialCount != null && initialCount.length() > 0) {
1159 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1162 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1163 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1165 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1166 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1167 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1168 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1171 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1172 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1174 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1175 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1176 if (maxInstances != null && maxInstances.length() > 0) {
1177 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1180 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1181 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1182 if (minInstances != null && minInstances.length() > 0) {
1183 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1185 return vfModuleCustomization;
1188 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1189 IVfModuleData vfModuleData, Metadata vfMetadata) {
1190 VfModule vfModule = new VfModule();
1191 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1193 if(vfModuleModelUUID == null) {
1194 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1195 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1196 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1197 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1200 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1201 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1202 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1203 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1204 vfModule.setModelUUID(vfModuleModelUUID);
1205 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1206 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1207 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1208 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1210 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1211 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1212 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1213 vfModule.setIsBase(true);
1215 vfModule.setIsBase(false);
1220 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1221 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1222 Metadata vfMetadata) {
1223 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1224 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1225 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1226 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1229 if (matchingObject.isPresent()) {
1230 List<HeatFiles> heatFilesList = new ArrayList<>();
1231 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1232 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1233 HeatTemplate parentHeatTemplate = new HeatTemplate();
1234 String parentArtifactType = null;
1235 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1236 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1238 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1240 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1241 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1242 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1245 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1246 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1248 if(!childNestedHeatTemplates.isEmpty()){
1250 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1251 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1253 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1259 if(!heatFilesList.isEmpty()){
1260 vfModule.setHeatFiles(heatFilesList);
1264 // Set all Child Templates related to HEAT_VOLUME
1265 if(!volumeHeatChildTemplates.isEmpty()){
1266 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1269 // Set all Child Templates related to HEAT
1270 if(!heatChildTemplates.isEmpty()){
1271 vfModule.getVolumeHeatTemplate().setChildTemplates(heatChildTemplates);
1276 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1277 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1278 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1279 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1280 vfModuleArtifact.incrementDeployedInDB();
1281 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1282 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1283 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1284 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1285 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1286 vfModuleArtifact.incrementDeployedInDB();
1287 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1288 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1289 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1291 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1293 vfModuleArtifact.incrementDeployedInDB();
1294 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1295 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1296 vfModuleArtifact.incrementDeployedInDB();
1297 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1298 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1299 vfModuleArtifact.incrementDeployedInDB();
1303 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1304 ToscaResourceStructure toscaResourceStructure, Service service) {
1305 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1306 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1307 if(vnfResourceCustomization == null){
1308 VnfResource vnfResource = findExistingVnfResource(service,
1309 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1311 if(vnfResource==null)
1312 vnfResource=createVnfResource(vfNodeTemplate);
1314 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1316 vnfResourceCustomization.setVnfResources(vnfResource);
1317 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1319 // Fetch VNFC Instance Group Info
1320 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1321 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1322 "org.openecomp.groups.VfcInstanceGroup");
1324 for (Group group : groupList) {
1326 VFCInstanceGroup vfcInstanceGroup = findExistingVnfcInstanceGroup(vnfResourceCustomization,
1327 group.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1328 if(vfcInstanceGroup == null){
1329 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(
1330 vfNodeTemplate, group, vnfResourceCustomization);
1332 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1337 return vnfResourceCustomization;
1340 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1341 VnfResource vnfResource = null;
1342 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1343 if (vnfResourceCustom.getVnfResources() != null
1344 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1345 vnfResource = vnfResourceCustom.getVnfResources();
1348 if(vnfResource==null)
1349 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1354 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1355 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1356 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1357 vnfResourceCustomization.setModelCustomizationUUID(
1358 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1359 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1361 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1362 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1363 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1364 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1365 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1366 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1367 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1368 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1370 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1371 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1373 vnfResourceCustomization.setVnfResources(vnfResource);
1374 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1375 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1377 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1378 .getCapabilitiesOf(vfNodeTemplate);
1380 if (vnfCustomizationCapability != null) {
1381 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1383 if (capAssign != null) {
1384 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1385 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1386 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1387 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1392 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1394 return vnfResourceCustomization;
1397 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1398 VnfResource vnfResource = new VnfResource();
1399 vnfResource.setModelInvariantUUID(
1400 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1401 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1402 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1404 vnfResource.setModelVersion(
1405 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1406 vnfResource.setDescription(
1407 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1408 vnfResource.setOrchestrationMode(HEAT);
1409 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1410 vnfResource.setAicVersionMax(
1411 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1412 vnfResource.setAicVersionMin(
1413 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1418 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1419 ToscaResourceStructure toscaResourceStructure, Service service) {
1420 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1421 .findOneByModelCustomizationUUID(
1422 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1424 if(allottedResourceCustomization == null){
1425 AllottedResource allottedResource = findExistingAllottedResource(service,
1426 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1428 if(allottedResource==null)
1429 allottedResource=createAR(nodeTemplate);
1431 toscaResourceStructure.setAllottedResource(allottedResource);
1432 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1433 allottedResourceCustomization.setAllottedResource(allottedResource);
1434 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1436 return allottedResourceCustomization;
1439 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1440 AllottedResource allottedResource = null;
1441 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1442 if (allottedResourceCustom.getAllottedResource() != null
1443 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1444 allottedResource = allottedResourceCustom.getAllottedResource();
1447 if(allottedResource==null)
1448 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1450 return allottedResource;
1453 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1454 ToscaResourceStructure toscaResourceStructure) {
1455 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1456 allottedResourceCustomization.setModelCustomizationUUID(
1457 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1458 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1461 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1462 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1463 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1464 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1465 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1466 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1467 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1468 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1470 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1472 if(vfcNodes != null){
1473 for(NodeTemplate vfcNode : vfcNodes){
1475 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1476 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1477 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1482 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1483 .getCapabilitiesOf(nodeTemplate);
1485 if (arCustomizationCapability != null) {
1486 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1488 if (capAssign != null) {
1489 allottedResourceCustomization.setMinInstances(
1490 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1491 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1492 allottedResourceCustomization.setMaxInstances(
1493 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1494 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1497 return allottedResourceCustomization;
1500 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1501 AllottedResource allottedResource = new AllottedResource();
1503 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1504 allottedResource.setModelInvariantUUID(
1505 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1507 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1509 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1510 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1511 allottedResource.setSubcategory(
1512 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1514 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1515 return allottedResource;
1518 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1519 // Scan the payload downloadResult and extract the HeatTemplate
1521 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1522 return yamlEditor.getParameterList(artifactUUID);
1525 protected String testNull(Object object) {
1527 if (object == null) {
1529 } else if (object.equals("NULL")) {
1531 } else if (object instanceof Integer) {
1532 return object.toString();
1533 } else if (object instanceof String) {
1534 return (String) object;
1536 return "Type not recognized";
1540 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1541 VfModuleArtifact heatNestedArtifact) {
1543 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1544 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1545 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1546 .getArtifactInfo().getRelatedArtifacts()) {
1547 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1548 return ASDCConfiguration.HEAT;
1554 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
1555 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
1556 .getRelatedArtifacts() != null) {
1557 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
1558 .get(0).getArtifactInfo().getRelatedArtifacts()) {
1559 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1560 return ASDCConfiguration.HEAT_VOL;
1566 // Does not belong to anything
1571 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
1573 return vfResourceStructure.getNotification().getServiceName() + "/"
1574 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
1577 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
1579 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
1580 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
1584 protected static Timestamp getCurrentTimeStamp() {
1586 return new Timestamp(new Date().getTime());