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.IResourceInstance;
37 import org.onap.sdc.api.notification.IStatusData;
38 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
39 import org.onap.sdc.tosca.parser.impl.SdcTypes;
40 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
41 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
42 import org.onap.sdc.toscaparser.api.Group;
43 import org.onap.sdc.toscaparser.api.NodeTemplate;
44 import org.onap.sdc.toscaparser.api.RequirementAssignment;
45 import org.onap.sdc.toscaparser.api.elements.Metadata;
46 import org.onap.sdc.utils.DistributionStatusEnum;
47 import org.onap.so.asdc.client.ASDCConfiguration;
48 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
49 import org.onap.so.asdc.installer.ASDCElementInfo;
50 import org.onap.so.asdc.installer.BigDecimalVersion;
51 import org.onap.so.asdc.installer.IVfModuleData;
52 import org.onap.so.asdc.installer.ToscaResourceStructure;
53 import org.onap.so.asdc.installer.VfModuleArtifact;
54 import org.onap.so.asdc.installer.VfModuleStructure;
55 import org.onap.so.asdc.installer.VfResourceStructure;
56 import org.onap.so.asdc.util.YamlEditor;
57 import org.onap.so.db.catalog.beans.AllottedResource;
58 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
59 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
60 import org.onap.so.db.catalog.beans.CollectionResource;
61 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
62 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
63 import org.onap.so.db.catalog.beans.ConfigurationResource;
64 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
65 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
66 import org.onap.so.db.catalog.beans.HeatEnvironment;
67 import org.onap.so.db.catalog.beans.HeatFiles;
68 import org.onap.so.db.catalog.beans.HeatTemplate;
69 import org.onap.so.db.catalog.beans.HeatTemplateParam;
70 import org.onap.so.db.catalog.beans.InstanceGroupType;
71 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
72 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
73 import org.onap.so.db.catalog.beans.NetworkResource;
74 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
75 import org.onap.so.db.catalog.beans.Service;
76 import org.onap.so.db.catalog.beans.ServiceProxyResource;
77 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
78 import org.onap.so.db.catalog.beans.SubType;
79 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
80 import org.onap.so.db.catalog.beans.ToscaCsar;
81 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
82 import org.onap.so.db.catalog.beans.VfModule;
83 import org.onap.so.db.catalog.beans.VfModuleCustomization;
84 import org.onap.so.db.catalog.beans.VnfResource;
85 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
86 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
87 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
88 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
89 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
90 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
91 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
92 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
93 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
94 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
95 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
96 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
97 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
98 import org.onap.so.db.catalog.data.repository.ServiceRepository;
99 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
100 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
101 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
102 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
103 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
104 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
105 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
106 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
107 import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
108 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
109 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
110 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
111 import org.onap.so.logger.MessageEnum;
112 import org.onap.so.logger.MsoLogger;
113 import org.springframework.beans.factory.annotation.Autowired;
114 import org.springframework.stereotype.Component;
115 import org.springframework.transaction.annotation.Transactional;
118 public class ToscaResourceInstaller {
120 protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
122 protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
124 protected static final String SCALABLE = "scalable";
126 protected static final String BASIC = "BASIC";
128 protected static final String PROVIDER = "PROVIDER";
130 protected static final String HEAT = "HEAT";
132 protected static final String MANUAL_RECORD = "MANUAL_RECORD";
134 protected static final String MSO = "SO";
138 protected ServiceRepository serviceRepo;
141 protected InstanceGroupRepository instanceGroupRepo;
144 protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
147 protected CollectionResourceRepository collectionRepo;
150 protected CollectionResourceCustomizationRepository collectionCustomizationRepo;
153 protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
156 protected VnfResourceRepository vnfRepo;
159 protected VnfCustomizationRepository vnfCustomizationRepo;
162 protected VFModuleRepository vfModuleRepo;
165 protected VFModuleCustomizationRepository vfModuleCustomizationRepo;
168 protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;
171 protected AllottedResourceRepository allottedRepo;
174 protected AllottedResourceCustomizationRepository allottedCustomizationRepo;
177 protected NetworkResourceRepository networkRepo;
180 protected HeatTemplateRepository heatRepo;
183 protected NetworkResourceCustomizationRepository networkCustomizationRepo;
186 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
188 protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository;
190 protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository;
193 protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo;
196 protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
198 protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
200 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
201 boolean status = false;
202 VfResourceStructure vfResourceStructure = vfResourceStruct;
204 status = vfResourceStructure.isDeployedSuccessfully();
205 } catch (RuntimeException e) {
209 Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
210 if(existingService != null)
213 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
214 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
215 vfResourceStructure.getNotification().getServiceName(),
216 BigDecimalVersion.castAndCheckNotificationVersionToString(
217 vfResourceStructure.getNotification().getServiceVersion()),
218 vfResourceStructure.getNotification().getServiceUUID(),
219 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
220 WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
221 wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
222 watchdogCDStatusRepository.saveAndFlush(wdStatus);
224 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
225 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
226 vfResourceStructure.getNotification().getServiceName(),
227 BigDecimalVersion.castAndCheckNotificationVersionToString(
228 vfResourceStructure.getNotification().getServiceVersion()),
229 vfResourceStructure.getNotification().getServiceUUID(),
230 vfResourceStructure.getResourceInstance().getResourceName(), "", "");
233 } catch (Exception e) {
234 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
235 "Exception - isResourceAlreadyDeployed");
236 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
240 public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
241 logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
242 + " and ComponentName " + iStatus.getComponentName());
245 WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
246 iStatus.getComponentName());
247 cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
248 watchdogCDStatusRepository.save(cdStatus);
250 } catch (Exception e) {
251 logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
252 throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
256 @Transactional(rollbackFor = { ArtifactInstallerException.class })
257 public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
258 throws ArtifactInstallerException {
259 VfResourceStructure vfResourceStructure = vfResourceStruct;
260 extractHeatInformation(toscaResourceStruct, vfResourceStructure);
262 // PCLO: in case of deployment failure, use a string that will represent
263 // the type of artifact that failed...
264 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
266 createToscaCsar(toscaResourceStruct);
267 createService(toscaResourceStruct, vfResourceStruct);
268 Service service = toscaResourceStruct.getCatalogService();
269 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
272 for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
274 Metadata metadata = nodeTemplate.getMetaData();
275 String serviceType = toscaResourceStruct.getCatalogService().getServiceType();
276 String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper()
277 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY);
278 processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata,
279 vfCustomizationCategory);
282 List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();
283 processAllottedResources(toscaResourceStruct, service, allottedResourceList);
284 processNetworks(toscaResourceStruct, service);
285 // process Network Collections
286 processNetworkCollections(toscaResourceStruct, service);
287 // Process Service Proxy & Configuration
288 processServiceProxyAndConfiguration(toscaResourceStruct, service);
290 serviceRepo.save(service);
292 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
293 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
294 watchdogCDStatusRepository.save(status);
296 toscaResourceStruct.setSuccessfulDeployment();
298 } catch (Exception e) {
299 logger.debug("Exception :", e);
300 WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
301 status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
302 watchdogCDStatusRepository.save(status);
303 Throwable dbExceptionToCapture = e;
304 while (!(dbExceptionToCapture instanceof ConstraintViolationException
305 || dbExceptionToCapture instanceof LockAcquisitionException)
306 && (dbExceptionToCapture.getCause() != null)) {
307 dbExceptionToCapture = dbExceptionToCapture.getCause();
310 if (dbExceptionToCapture instanceof ConstraintViolationException
311 || dbExceptionToCapture instanceof LockAcquisitionException) {
312 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
313 vfResourceStructure.getResourceInstance().getResourceName(),
314 vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
316 String elementToLog = (!artifactListForLogging.isEmpty()
317 ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
318 : "No element listed");
319 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
320 "Exception caught during installation of "
321 + vfResourceStructure.getResourceInstance().getResourceName()
322 + ". Transaction rollback",
324 throw new ArtifactInstallerException("Exception caught during installation of "
325 + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
330 protected void processNetworks(ToscaResourceStructure toscaResourceStruct, Service service)
331 throws ArtifactInstallerException {
332 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper().getServiceVlList();
334 if (nodeTemplatesVLList != null) {
335 for (NodeTemplate vlNode : nodeTemplatesVLList) {
336 String networkResourceModelName = vlNode.getMetaData()
337 .getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
339 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkResourceModelName);
341 if (tempNetworkLookUp != null ) {
342 HeatTemplate heatTemplate = heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
343 if (heatTemplate != null ) {
344 NetworkResourceCustomization networkCustomization = createNetwork(vlNode, toscaResourceStruct, heatTemplate,tempNetworkLookUp.getAicVersionMax(),
345 tempNetworkLookUp.getAicVersionMin(),service);
346 service.getNetworkCustomizations()
347 .add(networkCustomization);
350 throw new ArtifactInstallerException(
351 "No HeatTemplate found for artifactUUID: "
352 + tempNetworkLookUp.getHeatTemplateArtifactUuid());
355 throw new ArtifactInstallerException(
356 "No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
357 + networkResourceModelName);
364 protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
365 List<NodeTemplate> allottedResourceList) {
366 if (allottedResourceList != null) {
367 for (NodeTemplate allottedNode : allottedResourceList) {
368 service.getAllottedCustomizations()
369 .add(createAllottedResource(allottedNode, toscaResourceStruct, service));
374 protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
376 List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
378 List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
380 if (serviceProxyResourceList != null) {
381 for (NodeTemplate spNode : serviceProxyResourceList) {
382 createServiceProxy(spNode, service, toscaResourceStruct);
383 serviceProxyCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogServiceProxyResourceCustomization());
385 for (NodeTemplate configNode : configurationNodeTemplatesList) {
387 List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
388 for (RequirementAssignment requirement : requirementsList) {
389 if (requirement.getNodeTemplateName().equals(spNode.getName())) {
390 createConfiguration(configNode, toscaResourceStruct, toscaResourceStruct.getCatalogServiceProxyResourceCustomization());
391 configCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogConfigurationResourceCustomization());
401 protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
403 List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR);
405 if (networkCollectionList != null) {
406 for (NodeTemplate crNode : networkCollectionList) {
408 createNetworkCollection(crNode, toscaResourceStruct, service);
409 collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource());
411 List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup();
412 for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){
413 instanceGroupRepo.saveAndFlush(networkInstanceGroup);
418 service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization());
421 protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
422 Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
423 if (!vfCustomizationCategory.equalsIgnoreCase(ALLOTTED_RESOURCE))
426 String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
427 .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
428 logger.debug("vfCustomizationUUID=" + vfCustomizationUUID);
430 IResourceInstance vfMetaDataResource = vfResourceStructure.getResourceInstance();
432 // Make sure the vfMetadata and tosca customizations match before comparing their VF Modules UUID's
433 if(vfCustomizationUUID.equals(vfMetaDataResource.getResourceCustomizationUUID())){
435 logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfMetaData CustomizationUUID");
437 VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
439 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
440 logger.debug("vfModuleStructure ModelUUID: " + vfModuleStructure.toString());
441 List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
442 .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
443 IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
445 Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream().
446 filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())).
448 if(matchingObject.isPresent()){
449 VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, vfResourceStructure,vfMetadata, vnfResource);
450 vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
452 throw new Exception("Cannot find matching VFModule Customization for VF Module Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
455 service.getVnfCustomizations().add(vnfResource);
460 public void processWatchdog(String distributionId, String servideUUID) {
461 WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
462 watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
464 WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
465 watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
468 protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
469 VfResourceStructure vfResourceStructure) {
470 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
472 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
473 case ASDCConfiguration.HEAT:
474 case ASDCConfiguration.HEAT_NESTED:
475 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
478 case ASDCConfiguration.HEAT_VOL:
479 createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct,
481 VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
482 createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact);
484 case ASDCConfiguration.HEAT_ENV:
485 createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
487 case ASDCConfiguration.HEAT_ARTIFACT:
488 createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact,
489 toscaResourceStruct);
491 case ASDCConfiguration.HEAT_NET:
492 case ASDCConfiguration.OTHER:
493 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
494 vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
495 + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
496 "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
505 protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure,
506 VfModuleArtifact vfModuleArtifact) {
507 String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName();
508 artifactName = artifactName.substring(0, artifactName.indexOf('.'));
509 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
510 if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName)
511 && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
512 return moduleArtifact;
518 public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure,
519 List<String> listTypes) {
520 String newFileBody = filebody;
521 for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
523 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
525 newFileBody = verifyTheFilePrefixInString(newFileBody,
526 moduleArtifact.getArtifactInfo().getArtifactName());
532 public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
534 String needlePrefix = "file:///";
535 String prefixedFilenameToVerify = needlePrefix + filenameToVerify;
537 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
541 StringBuilder sb = new StringBuilder(body.length());
543 int currentIndex = 0;
546 while (currentIndex != -1) {
547 startIndex = currentIndex;
548 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
550 if (currentIndex == -1) {
553 // We append from the startIndex up to currentIndex (start of File
555 sb.append(body.substring(startIndex, currentIndex));
556 sb.append(filenameToVerify);
558 currentIndex += prefixedFilenameToVerify.length();
561 sb.append(body.substring(startIndex));
563 return sb.toString();
566 protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
567 ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
568 HeatTemplate heatTemplate = new HeatTemplate();
569 List<String> typeList = new ArrayList<>();
570 typeList.add(ASDCConfiguration.HEAT_NESTED);
571 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
573 heatTemplate.setTemplateBody(
574 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
575 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
577 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
578 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
580 heatTemplate.setTimeoutMinutes(240);
583 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
584 heatTemplate.setVersion(BigDecimalVersion
585 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
586 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
588 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
589 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
591 heatTemplate.setArtifactChecksum(MANUAL_RECORD);
594 Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(
595 vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
596 heatTemplate.setParameters(heatParam);
597 vfModuleArtifact.setHeatTemplate(heatTemplate);
600 protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
601 VfModuleArtifact vfModuleArtifact) {
602 HeatEnvironment heatEnvironment = new HeatEnvironment();
603 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
604 List<String> typeList = new ArrayList<>();
605 typeList.add(ASDCConfiguration.HEAT);
606 typeList.add(ASDCConfiguration.HEAT_VOL);
607 heatEnvironment.setEnvironment(
608 verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
609 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
610 heatEnvironment.setVersion(BigDecimalVersion
611 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
612 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
614 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
615 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
617 heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
619 vfModuleArtifact.setHeatEnvironment(heatEnvironment);
622 protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
623 VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
625 HeatFiles heatFile = new HeatFiles();
626 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
627 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
628 heatFile.setFileBody(vfModuleArtifact.getResult());
629 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
630 heatFile.setVersion(BigDecimalVersion
631 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
632 toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
633 if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
634 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
636 heatFile.setArtifactChecksum(MANUAL_RECORD);
638 vfModuleArtifact.setHeatFiles(heatFile);
641 protected Service createService(ToscaResourceStructure toscaResourceStructure,
642 VfResourceStructure vfResourceStructure) {
644 toscaResourceStructure.getServiceMetadata();
646 Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
648 Service service = new Service();
650 if (serviceMetadata != null) {
652 if (toscaResourceStructure.getServiceVersion() != null) {
653 service.setModelVersion(toscaResourceStructure.getServiceVersion());
656 service.setServiceType(serviceMetadata.getValue("serviceType"));
657 service.setServiceRole(serviceMetadata.getValue("serviceRole"));
659 service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
660 service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
661 service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
662 service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
664 if (vfResourceStructure != null)
665 service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
667 service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
668 service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
672 toscaResourceStructure.setCatalogService(service);
676 protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) {
678 Metadata spMetadata = nodeTemplate.getMetaData();
680 ServiceProxyResource spResource = new ServiceProxyResource();
682 spResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
683 spResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
684 spResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
685 spResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
686 spResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
688 ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization();
690 Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>();
692 spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
693 spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
694 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
695 spCustomizationResource.setSourceService(service);
696 spCustomizationResource.setServiceProxyResource(spResource);
697 spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
698 spCustomizationResource.setServiceProxyResource(spResource);
699 serviceProxyCustomizationSet.add(spCustomizationResource);
702 spResource.setServiceProxyCustomization(serviceProxyCustomizationSet);
704 toscaResourceStructure.setCatalogServiceProxyResource(spResource);
706 toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
708 return spCustomizationResource;
711 protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
713 Metadata metadata = nodeTemplate.getMetaData();
715 ConfigurationResource configResource = new ConfigurationResource();
717 configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
718 configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
719 configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
720 configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
721 configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
722 configResource.setToscaNodeType(nodeTemplate.getType());
724 ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
726 Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
728 configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
729 configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
731 configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
732 configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
733 configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
734 configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
735 configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
736 configCustomizationResource.setConfigurationResource(configResource);
737 configResourceCustomizationSet.add(configCustomizationResource);
739 configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
741 toscaResourceStructure.setCatalogConfigurationResource(configResource);
743 toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource);
745 return configCustomizationResource;
749 protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
750 ToscaCsar toscaCsar = new ToscaCsar();
751 if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) {
752 toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum());
754 toscaCsar.setArtifactChecksum(MANUAL_RECORD);
756 toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
757 toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName());
758 toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion());
759 toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription());
760 toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL());
762 toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
765 protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
766 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
768 NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
769 if(networkResourceCustomization==null){
770 networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
771 toscaResourceStructure);
773 NetworkResource networkResource = findExistingNetworkResource(service,
774 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
775 if(networkResource == null)
776 networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
779 networkResource.addNetworkResourceCustomization(networkResourceCustomization);
780 networkResourceCustomization.setNetworkResource(networkResource);
782 return networkResourceCustomization;
785 protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) {
786 NetworkResource networkResource = null;
787 for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){
788 if (networkCustom.getNetworkResource() != null
789 && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) {
790 networkResource = networkCustom.getNetworkResource();
793 if(networkResource==null)
794 networkResource = networkRepo.findResourceByModelUUID(modelUUID);
796 return networkResource;
799 protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate,
800 ToscaResourceStructure toscaResourceStructure) {
801 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
802 networkResourceCustomization.setModelInstanceName(
803 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
804 networkResourceCustomization.setModelCustomizationUUID(
805 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
807 networkResourceCustomization.setNetworkTechnology(
808 testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
809 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)));
810 networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper()
811 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)));
812 networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper()
813 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)));
814 networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper()
815 .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)));
816 return networkResourceCustomization;
819 protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate,
820 ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
821 NetworkResource networkResource = new NetworkResource();
822 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
823 networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
825 if ("true".equalsIgnoreCase(providerNetwork)) {
826 networkResource.setNeutronNetworkType(PROVIDER);
828 networkResource.setNeutronNetworkType(BASIC);
831 networkResource.setModelName(
832 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
834 networkResource.setModelInvariantUUID(
835 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
836 networkResource.setModelUUID(
837 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
838 networkResource.setModelVersion(
839 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
841 networkResource.setAicVersionMax(aicMax);
842 networkResource.setAicVersionMin(aicMin);
843 networkResource.setToscaNodeType(networkNodeTemplate.getType());
844 networkResource.setDescription(
845 testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
846 networkResource.setOrchestrationMode(HEAT);
847 networkResource.setHeatTemplate(heatTemplate);
848 return networkResource;
851 protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate,
852 ToscaResourceStructure toscaResourceStructure, Service service) {
854 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
856 // **** Build Object to populate Collection_Resource table
857 CollectionResource collectionResource = new CollectionResource();
860 .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
861 collectionResource.setModelInvariantUUID(
862 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
864 .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
866 .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
868 .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
869 collectionResource.setToscaNodeType(networkNodeTemplate.getType());
871 toscaResourceStructure.setCatalogCollectionResource(collectionResource);
873 // **** Build object to populate Collection_Resource_Customization table
874 NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
876 ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
878 ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
880 ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
883 ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
884 ncfc.setModelCustomizationUUID(
885 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
887 Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
888 networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
890 ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
892 ncfc.setCollectionResource(collectionResource);
893 toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
895 //*** Build object to populate the Instance_Group table
896 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
897 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate,
898 "org.openecomp.groups.NetworkCollection");
900 List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
902 List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>();
904 for (Group group : groupList) {
906 NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
907 Metadata instanceMetadata = group.getMetadata();
908 networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
910 .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
911 networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
912 networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
913 networkInstanceGroup.setToscaNodeType(group.getType());
914 networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set
916 networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set
918 networkInstanceGroup.setCollectionResource(collectionResource);
920 // ****Build object to populate
921 // Collection_Resource_Instance_Group_Customization table
922 CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
923 crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
924 crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
925 crInstanceGroupCustomization.setModelCustomizationUUID(
926 networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
928 String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
929 String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
930 if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
931 fixedQuantity + "_quantity") != null) {
933 crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
934 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
935 fixedQuantity + "_quantity")));
938 crInstanceGroupCustomization.setDescription(
939 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
940 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
941 + "_network_collection_description"));
942 crInstanceGroupCustomization.setFunction(
943 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
944 instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
945 + "_network_collection_function"));
946 crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
947 collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
950 .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
952 networkInstanceGroupList.add(networkInstanceGroup);
956 toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
958 List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper()
959 .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL);
961 List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
963 //*****Build object to populate the NetworkResource table
964 NetworkResource networkResource = new NetworkResource();
966 for(NodeTemplate vlNodeTemplate : vlNodeList){
968 String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(
969 vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
971 if ("true".equalsIgnoreCase(providerNetwork)) {
972 networkResource.setNeutronNetworkType(PROVIDER);
974 networkResource.setNeutronNetworkType(BASIC);
977 networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
979 networkResource.setModelInvariantUUID(
980 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
981 networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
983 .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
985 networkResource.setAicVersionMax(
986 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
988 TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(
989 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
991 if (tempNetworkLookUp != null ) {
993 HeatTemplate heatTemplate = heatRepo
994 .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
995 networkResource.setHeatTemplate(heatTemplate);
997 networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
1001 networkResource.setToscaNodeType(vlNodeTemplate.getType());
1003 .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1004 networkResource.setOrchestrationMode(HEAT);
1006 // Build object to populate the
1007 // Collection_Network_Resource_Customization table
1008 for (NodeTemplate memberNode : group.getMemberNodes()) {
1009 collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName());
1012 collectionNetworkResourceCustomization.setModelCustomizationUUID(
1013 vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1015 collectionNetworkResourceCustomization.setNetworkTechnology(
1016 toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate,
1017 SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
1018 collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper()
1019 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
1020 collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper()
1021 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
1022 collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper()
1023 .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
1024 collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
1025 collectionNetworkResourceCustomization.setNetworkResource(networkResource);
1026 collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
1028 collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
1033 return collectionNetworkResourceCustomization;
1036 protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group,
1037 VnfResourceCustomization vnfResourceCustomization) {
1039 Metadata instanceMetadata = group.getMetadata();
1040 // Populate InstanceGroup
1041 VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup();
1043 vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
1044 vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
1045 vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1046 vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
1047 vfcInstanceGroup.setToscaNodeType(group.getType());
1048 vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role
1049 vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type
1051 //Populate VNFCInstanceGroupCustomization
1052 VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
1054 vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID());
1055 vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1056 vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1057 vfcInstanceGroupCustom.setFunction("FUNCTION");
1058 vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
1059 vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
1061 return vfcInstanceGroupCustom;
1065 protected VFCInstanceGroup findExistingVnfcInstanceGroup(VnfResourceCustomization vnfResourceCustomization,
1067 VFCInstanceGroup vfcInstanceGroup = null;
1068 List<VnfcInstanceGroupCustomization> vnfInstanceGroupCustomizations = vnfResourceCustomization
1069 .getVnfcInstanceGroupCustomizations();
1070 if(vnfInstanceGroupCustomizations != null){
1071 for (VnfcInstanceGroupCustomization vnfcInstanceGroupCustom : vnfResourceCustomization
1072 .getVnfcInstanceGroupCustomizations()) {
1073 if (vnfcInstanceGroupCustom.getInstanceGroup() != null
1074 && vnfcInstanceGroupCustom.getInstanceGroup().getModelUUID().equals(modelUUID)) {
1075 vfcInstanceGroup = (VFCInstanceGroup)vnfcInstanceGroupCustom.getInstanceGroup();
1079 if (vfcInstanceGroup == null)
1080 vfcInstanceGroup = (VFCInstanceGroup) instanceGroupRepo.findByModelUUID(modelUUID);
1082 return vfcInstanceGroup;
1085 protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
1086 ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
1087 IVfModuleData vfModuleData, VnfResourceCustomization vnfResource) {
1088 VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
1089 vfModuleData.getVfModuleModelCustomizationUUID());
1090 if(vfModuleCustomization == null){
1091 VfModule vfModule = findExistingVfModule(vnfResource,
1092 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1093 Metadata vfMetadata = group.getMetadata();
1095 vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
1097 vfModuleCustomization = createVfModuleCustomzation(group, toscaResourceStructure, vfModule, vfModuleData);
1098 setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
1100 vfModuleCustomization.setVfModule(vfModule);
1101 vfModule.getVfModuleCustomization().add(vfModuleCustomization);
1102 vnfResource.getVfModuleCustomizations().add(vfModuleCustomization);
1104 vfResourceStructure.setAlreadyDeployed(true);
1107 return vfModuleCustomization;
1110 protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
1111 String vfModuleModelCustomizationUUID) {
1112 VfModuleCustomization vfModuleCustomization = null;
1113 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1114 if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){
1115 vfModuleCustomization = vfModuleCustom;
1118 if(vfModuleCustomization==null)
1119 vfModuleCustomization = vfModuleCustomizationRepo
1120 .findByModelCustomizationUUID(vfModuleModelCustomizationUUID);
1122 return vfModuleCustomization;
1125 protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) {
1126 VfModule vfModule = null;
1127 for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){
1128 if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){
1129 vfModule = vfModuleCustom.getVfModule();
1133 vfModule = vfModuleRepo.findByModelUUID(modelUUID);
1138 protected VfModuleCustomization createVfModuleCustomzation(Group group,
1139 ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
1140 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
1142 vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID());
1144 vfModuleCustomization.setVfModule(vfModule);
1146 String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1147 SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT);
1148 if (initialCount != null && initialCount.length() > 0) {
1149 vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount));
1152 vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper()
1153 .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT)));
1155 String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1156 SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT);
1157 if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) {
1158 vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount));
1161 vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1162 SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL));
1164 String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1165 SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES);
1166 if (maxInstances != null && maxInstances.length() > 0) {
1167 vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances));
1170 String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1171 SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
1172 if (minInstances != null && minInstances.length() > 0) {
1173 vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances));
1175 return vfModuleCustomization;
1178 protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure,
1179 IVfModuleData vfModuleData, Metadata vfMetadata) {
1180 VfModule vfModule = new VfModule();
1181 String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID();
1183 if(vfModuleModelUUID == null) {
1184 vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1185 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
1186 } else if (vfModuleModelUUID.indexOf('.') > -1) {
1187 vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.'));
1190 vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper()
1191 .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
1192 vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1193 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
1194 vfModule.setModelUUID(vfModuleModelUUID);
1195 vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1196 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
1197 vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1198 SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1200 String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group,
1201 SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE);
1202 if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) {
1203 vfModule.setIsBase(true);
1205 vfModule.setIsBase(false);
1210 protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
1211 VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1212 Metadata vfMetadata) {
1213 Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
1214 .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
1215 .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
1216 SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)))
1219 if (matchingObject.isPresent()) {
1220 List<HeatFiles> heatFilesList = new ArrayList<>();
1221 List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>();
1222 List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>();
1223 HeatTemplate parentHeatTemplate = new HeatTemplate();
1224 String parentArtifactType = null;
1225 Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
1226 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
1228 List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>();
1230 if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
1231 checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact,
1232 childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
1235 if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){
1236 parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
1238 if(!childNestedHeatTemplates.isEmpty()){
1240 if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
1241 volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
1243 heatChildTemplates.add(childNestedHeatTemplates.get(0));
1249 if(!heatFilesList.isEmpty()){
1250 vfModule.setHeatFiles(heatFilesList);
1254 // Set all Child Templates related to HEAT_VOLUME
1255 if(!volumeHeatChildTemplates.isEmpty()){
1256 if(vfModule.getVolumeHeatTemplate() != null){
1257 vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
1259 logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
1263 // Set all Child Templates related to HEAT
1264 if(!heatChildTemplates.isEmpty()){
1265 if(vfModule.getModuleHeatTemplate() != null){
1266 vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
1268 logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
1274 protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization,
1275 List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates,
1276 HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) {
1277 if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) {
1278 vfModuleArtifact.incrementDeployedInDB();
1279 vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate());
1280 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) {
1281 vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate());
1282 VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact);
1283 vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
1284 vfModuleArtifact.incrementDeployedInDB();
1285 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
1286 if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
1287 vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
1289 vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
1291 vfModuleArtifact.incrementDeployedInDB();
1292 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
1293 heatFilesList.add(vfModuleArtifact.getHeatFiles());
1294 vfModuleArtifact.incrementDeployedInDB();
1295 } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
1296 nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate());
1297 vfModuleArtifact.incrementDeployedInDB();
1301 protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate,
1302 ToscaResourceStructure toscaResourceStructure, Service service) {
1303 VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID(
1304 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1305 if(vnfResourceCustomization == null){
1306 VnfResource vnfResource = findExistingVnfResource(service,
1307 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1309 if(vnfResource==null)
1310 vnfResource=createVnfResource(vfNodeTemplate);
1312 vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure,
1314 vnfResourceCustomization.setVnfResources(vnfResource);
1315 vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
1317 // Fetch VNFC Instance Group Info
1318 List<Group> groupList = toscaResourceStructure.getSdcCsarHelper()
1319 .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate,
1320 "org.openecomp.groups.VfcInstanceGroup");
1322 for (Group group : groupList) {
1324 VFCInstanceGroup vfcInstanceGroup = findExistingVnfcInstanceGroup(vnfResourceCustomization,
1325 group.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1326 if(vfcInstanceGroup == null){
1327 VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(
1328 vfNodeTemplate, group, vnfResourceCustomization);
1330 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
1335 return vnfResourceCustomization;
1338 protected VnfResource findExistingVnfResource(Service service, String modelUUID) {
1339 VnfResource vnfResource = null;
1340 for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){
1341 if (vnfResourceCustom.getVnfResources() != null
1342 && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) {
1343 vnfResource = vnfResourceCustom.getVnfResources();
1346 if(vnfResource==null)
1347 vnfResource = vnfRepo.findResourceByModelUUID(modelUUID);
1352 protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate,
1353 ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) {
1354 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
1355 vnfResourceCustomization.setModelCustomizationUUID(
1356 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1357 vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
1359 vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1360 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1361 vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1362 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code")));
1363 vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1364 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1365 vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1366 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1368 vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
1369 .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
1371 vnfResourceCustomization.setVnfResources(vnfResource);
1372 vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
1373 vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));
1375 CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1376 .getCapabilitiesOf(vfNodeTemplate);
1378 if (vnfCustomizationCapability != null) {
1379 CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE);
1381 if (capAssign != null) {
1382 vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1383 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1384 vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
1385 .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1390 toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
1392 return vnfResourceCustomization;
1395 protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) {
1396 VnfResource vnfResource = new VnfResource();
1397 vnfResource.setModelInvariantUUID(
1398 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1399 vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1400 vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1402 vnfResource.setModelVersion(
1403 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1404 vnfResource.setDescription(
1405 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
1406 vnfResource.setOrchestrationMode(HEAT);
1407 vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
1408 vnfResource.setAicVersionMax(
1409 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1410 vnfResource.setAicVersionMin(
1411 testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1416 protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate,
1417 ToscaResourceStructure toscaResourceStructure, Service service) {
1418 AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo
1419 .findOneByModelCustomizationUUID(
1420 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
1422 if(allottedResourceCustomization == null){
1423 AllottedResource allottedResource = findExistingAllottedResource(service,
1424 nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
1426 if(allottedResource==null)
1427 allottedResource=createAR(nodeTemplate);
1429 toscaResourceStructure.setAllottedResource(allottedResource);
1430 allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure);
1431 allottedResourceCustomization.setAllottedResource(allottedResource);
1432 allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
1434 return allottedResourceCustomization;
1437 protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) {
1438 AllottedResource allottedResource = null;
1439 for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){
1440 if (allottedResourceCustom.getAllottedResource() != null
1441 && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) {
1442 allottedResource = allottedResourceCustom.getAllottedResource();
1445 if(allottedResource==null)
1446 allottedResource = allottedRepo.findResourceByModelUUID(modelUUID);
1448 return allottedResource;
1451 protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate,
1452 ToscaResourceStructure toscaResourceStructure) {
1453 AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
1454 allottedResourceCustomization.setModelCustomizationUUID(
1455 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
1456 allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName());
1459 allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper()
1460 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
1461 allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper()
1462 .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")));
1463 allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper()
1464 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)));
1465 allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper()
1466 .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
1468 List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID());
1470 if(vfcNodes != null){
1471 for(NodeTemplate vfcNode : vfcNodes){
1473 allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid"));
1474 allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid"));
1475 allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name"));
1480 CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper()
1481 .getCapabilitiesOf(nodeTemplate);
1483 if (arCustomizationCapability != null) {
1484 CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE);
1486 if (capAssign != null) {
1487 allottedResourceCustomization.setMinInstances(
1488 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1489 capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
1490 allottedResourceCustomization.setMaxInstances(
1491 Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue(
1492 capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
1495 return allottedResourceCustomization;
1498 protected AllottedResource createAR(NodeTemplate nodeTemplate) {
1499 AllottedResource allottedResource = new AllottedResource();
1501 .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
1502 allottedResource.setModelInvariantUUID(
1503 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
1505 .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
1507 .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
1508 allottedResource.setToscaNodeType(testNull(nodeTemplate.getType()));
1509 allottedResource.setSubcategory(
1510 testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
1512 .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
1513 return allottedResource;
1516 protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
1517 // Scan the payload downloadResult and extract the HeatTemplate
1519 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
1520 return yamlEditor.getParameterList(artifactUUID);
1523 protected String testNull(Object object) {
1525 if (object == null) {
1527 } else if (object.equals("NULL")) {
1529 } else if (object instanceof Integer) {
1530 return object.toString();
1531 } else if (object instanceof String) {
1532 return (String) object;
1534 return "Type not recognized";
1538 protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,
1539 VfModuleArtifact heatNestedArtifact) {
1541 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure
1542 .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
1543 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
1544 .getArtifactInfo().getRelatedArtifacts()) {
1545 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1546 return ASDCConfiguration.HEAT;
1552 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
1553 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()
1554 .getRelatedArtifacts() != null) {
1555 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL)
1556 .get(0).getArtifactInfo().getRelatedArtifacts()) {
1557 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
1558 return ASDCConfiguration.HEAT_VOL;
1564 // Does not belong to anything
1569 protected static String createVNFName(VfResourceStructure vfResourceStructure) {
1571 return vfResourceStructure.getNotification().getServiceName() + "/"
1572 + vfResourceStructure.getResourceInstance().getResourceInstanceName();
1575 protected static String createVfModuleName(VfModuleStructure vfModuleStructure) {
1577 return createVNFName(vfModuleStructure.getParentVfResource()) + "::"
1578 + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
1582 protected static Timestamp getCurrentTimeStamp() {
1584 return new Timestamp(new Date().getTime());