2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.asdc.installer.heat;
23 import java.sql.Timestamp;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.List;
32 import org.hibernate.exception.ConstraintViolationException;
33 import org.hibernate.exception.LockAcquisitionException;
34 import org.openecomp.sdc.api.notification.IArtifactInfo;
36 import org.openecomp.mso.asdc.client.ASDCConfiguration;
37 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
38 import org.openecomp.mso.asdc.installer.ASDCElementInfo;
39 import org.openecomp.mso.asdc.installer.BigDecimalVersion;
40 import org.openecomp.mso.asdc.installer.IVfResourceInstaller;
41 import org.openecomp.mso.asdc.installer.VfModuleArtifact;
42 import org.openecomp.mso.asdc.installer.VfModuleStructure;
43 import org.openecomp.mso.asdc.installer.VfResourceStructure;
44 import org.openecomp.mso.asdc.util.YamlEditor;
45 import org.openecomp.mso.db.catalog.CatalogDatabase;
46 import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
47 import org.openecomp.mso.db.catalog.beans.HeatFiles;
48 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
49 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
50 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
51 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
52 import org.openecomp.mso.db.catalog.beans.Service;
53 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
54 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
55 import org.openecomp.mso.db.catalog.beans.VfModule;
56 import org.openecomp.mso.db.catalog.beans.VnfResource;
57 import org.openecomp.mso.logger.MessageEnum;
58 import org.openecomp.mso.logger.MsoLogger;
60 public class VfResourceInstaller implements IVfResourceInstaller {
62 private MsoLogger logger;
64 public VfResourceInstaller() {
65 logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.ASDC);
69 public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct)
70 throws ArtifactInstallerException {
72 boolean status = false;
73 VfResourceStructure vfResourceStructure = (VfResourceStructure)vfResourceStruct;
75 try(CatalogDatabase db = CatalogDatabase.getInstance()) {
77 String resourceType = vfResourceStruct.getResourceInstance().getResourceType();
78 String category = vfResourceStruct.getResourceInstance().getCategory();
80 // Check for duplicate VF Module that is not an Allotted Resource
81 if(resourceType.equals("VF") && !category.equalsIgnoreCase("Allotted Resource")){
82 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "VNFResource",
83 VfResourceInstaller.createVNFName(vfResourceStructure),
84 BigDecimalVersion.castAndCheckNotificationVersionToString(
85 vfResourceStructure.getNotification().getServiceVersion()), "", "");
87 VnfResource vnfResource = db.getVnfResource(
88 VfResourceInstaller.createVNFName(vfResourceStructure),
89 BigDecimalVersion.castAndCheckNotificationVersionToString(
90 vfResourceStructure.getNotification().getServiceVersion()));
92 if (vnfResource != null) {
99 // Check dup for VF Allotted Resource
100 if(resourceType.equals("VF") && category.equalsIgnoreCase("Allotted Resource")){
101 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "AllottedResource",
102 vfResourceStruct.getResourceInstance().getResourceInstanceName(),
103 BigDecimalVersion.castAndCheckNotificationVersionToString(
104 vfResourceStructure.getNotification().getServiceVersion()), "", "");
106 List<AllottedResourceCustomization> allottedResources = db.getAllAllottedResourcesByServiceModelUuid(vfResourceStruct.getNotification().getServiceUUID());
108 if(allottedResources != null && allottedResources.size() > 0){
109 for(AllottedResourceCustomization allottedResource : allottedResources){
111 String existingAllottedResource = allottedResource.getModelCustomizationUuid();
112 String notificationAllottedResource = vfResourceStruct.getResourceInstance().getResourceCustomizationUUID();
114 if(existingAllottedResource.equals(notificationAllottedResource)){
123 // Check Network for duplicates
124 if(resourceType.equals("VL")){
125 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "NetworkResource",
126 vfResourceStruct.getResourceInstance().getResourceInstanceName(),
127 BigDecimalVersion.castAndCheckNotificationVersionToString(
128 vfResourceStructure.getNotification().getServiceVersion()), "", "");
130 List<NetworkResourceCustomization> networkResources = db.getAllNetworksByServiceModelUuid(vfResourceStruct.getNotification().getServiceUUID());
132 if(networkResources != null && networkResources.size() > 0){
133 for(NetworkResourceCustomization networkResource : networkResources){
135 String existingNetworkResource = networkResource.getModelCustomizationUuid();
136 String notificationNetworkResource = vfResourceStruct.getResourceInstance().getResourceCustomizationUUID();
138 if(existingNetworkResource.equals(notificationNetworkResource)){
148 logger.info(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED_DETAIL,
149 vfResourceStructure.getResourceInstance().getResourceInstanceName(),
150 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
151 vfResourceStructure.getNotification().getServiceName(),
152 BigDecimalVersion.castAndCheckNotificationVersionToString(
153 vfResourceStructure.getNotification().getServiceVersion()),
154 vfResourceStructure.getNotification().getServiceUUID(),
155 vfResourceStructure.getResourceInstance().getResourceName(),"", "");
157 logger.info(MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL,
158 vfResourceStructure.getResourceInstance().getResourceInstanceName(),
159 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
160 vfResourceStructure.getNotification().getServiceName(),
161 BigDecimalVersion.castAndCheckNotificationVersionToString(
162 vfResourceStructure.getNotification().getServiceVersion()),
163 vfResourceStructure.getNotification().getServiceUUID(),
164 vfResourceStructure.getResourceInstance().getResourceName(),"", "");
169 } catch (Exception e) {
170 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception - isResourceAlreadyDeployed");
171 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
176 public void installTheResource(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
178 // 1. Add the DB object list (Hashed) to be created from the HashMap
180 // The DB objects will be stored in each VfModuleArtifact objects
181 // Those objects could be reused by different VfModule
183 VfResourceStructure vfResourceStructure = (VfResourceStructure)vfResourceStruct;
185 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
187 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
188 case ASDCConfiguration.HEAT:
189 case ASDCConfiguration.HEAT_VOL:
190 case ASDCConfiguration.HEAT_NESTED:
191 VfResourceInstaller.createHeatTemplateFromArtifact(vfResourceStructure, vfModuleArtifact);
193 case ASDCConfiguration.HEAT_ENV:
194 VfResourceInstaller.createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
196 case ASDCConfiguration.HEAT_ARTIFACT:
197 VfResourceInstaller.createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact);
199 case ASDCConfiguration.HEAT_NET:
200 case ASDCConfiguration.OTHER:
201 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT, vfModuleArtifact.getArtifactInfo().getArtifactType()+"(Artifact Name:"+vfModuleArtifact.getArtifactInfo().getArtifactName()+")", "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
209 // in case of deployment failure, use a string that will represent the type of artifact that failed...
210 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
212 CatalogDatabase catalogDB = CatalogDatabase.getInstance();
213 // 2. Create the VFModules/VNFResource objects by linking them to the
214 // objects created before and store them in Resource/module structure
215 // Opening a DB transaction, starting from here
218 VfResourceInstaller.createService(vfResourceStructure);
220 String resourceType = vfResourceStructure.getResourceInstance().getResourceType();
221 String resourceCategory = vfResourceStructure.getResourceInstance().getCategory();
223 if(resourceType.equals("VF")){
225 if(resourceCategory.equalsIgnoreCase("Allotted Resource")){
226 VfResourceInstaller.createAllottedResourceCustomization(vfResourceStructure);
227 catalogDB.saveAllottedResourceCustomization(vfResourceStructure.getCatalogResourceCustomization());
229 VfResourceInstaller.createVnfResource(vfResourceStructure);
230 catalogDB.saveOrUpdateVnfResource(vfResourceStructure.getCatalogVnfResource());
234 if(resourceType.equals("VL")){
235 VfResourceInstaller.createNetworkResourceCustomization(vfResourceStructure);
236 catalogDB.saveNetworkResourceCustomization(vfResourceStructure.getCatalogNetworkResourceCustomization());
239 // Add this one for logging
240 artifactListForLogging.add(ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure));
242 //catalogDB.saveOrUpdateVnfResource(vfResourceStructure.getCatalogVnfResource());
243 catalogDB.saveService(vfResourceStructure.getCatalogService());
245 // Now that the service has been added we can populate the Service_to_AllottedResources table
246 if(resourceType.equals("VF") && resourceCategory.equalsIgnoreCase("Allotted Resource")){
247 catalogDB.saveServiceToAllottedResources(vfResourceStructure.getCatalogServiceToAllottedResources());
250 // Now that the service has been added we can populate the Service_to_Network table
251 if(resourceType.equals("VL")){
252 catalogDB.saveServiceToNetworks(vfResourceStructure.getCatalogServiceToNetworks());
255 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
257 // Here we set the right db structure according to the Catalog
260 // We expect only one MAIN HEAT per VFMODULE
261 // we can also obtain from it the Env ArtifactInfo, that's why
263 // get the Main IArtifactInfo
265 HeatTemplate heatMainTemplate = null;
266 HeatEnvironment heatEnv = null;
268 HeatTemplate heatVolumeTemplate = null;
269 HeatEnvironment heatVolumeEnv = null;
271 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT)) {
272 IArtifactInfo mainEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT)
273 .get(0).getArtifactInfo().getGeneratedArtifact();
276 heatMainTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap()
277 .get(ASDCConfiguration.HEAT).get(0).getCatalogObject();
279 // Add this one for logging
280 artifactListForLogging.add(ASDCElementInfo
281 .createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo()));
283 catalogDB.saveHeatTemplate(heatMainTemplate, heatMainTemplate.getParameters());
284 // Indicate we have deployed it in the DB
285 vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).incrementDeployedInDB();
289 // We expect only one VOL HEAT per VFMODULE
290 // we can also obtain from it the Env ArtifactInfo, that's why
291 // we get the Volume IArtifactInfo
293 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_VOL)) {
294 IArtifactInfo volEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0)
295 .getArtifactInfo().getGeneratedArtifact();
297 heatVolumeTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap()
298 .get(ASDCConfiguration.HEAT_VOL).get(0).getCatalogObject();
300 // Add this one for logging
301 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()));
303 catalogDB.saveHeatTemplate(heatVolumeTemplate, heatVolumeTemplate.getParameters());
304 // Indicate we have deployed it in the DB
305 vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).incrementDeployedInDB();
307 if (volEnvArtifactInfo != null) {
308 heatVolumeEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID()
309 .get(volEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
311 // Add this one for logging
312 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(volEnvArtifactInfo));
314 catalogDB.saveHeatEnvironment(heatVolumeEnv);
315 // Indicate we have deployed it in the DB
316 vfResourceStructure.getArtifactsMapByUUID().get(volEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB();
322 // Here we expect many HEAT_NESTED template to be there
323 // check first if we really have nested heat templates
324 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_NESTED)) {
325 for (VfModuleArtifact heatNestedArtifact : vfModuleStructure.getArtifactsMap()
326 .get(ASDCConfiguration.HEAT_NESTED)) {
328 // Check if this nested is well referenced by the MAIN HEAT
329 String parentArtifactType = VfResourceInstaller.identifyParentOfNestedTemplate(vfModuleStructure,heatNestedArtifact);
330 HeatTemplate heatNestedTemplate = (HeatTemplate) heatNestedArtifact.getCatalogObject();
332 if (parentArtifactType != null) {
334 switch (parentArtifactType) {
335 case ASDCConfiguration.HEAT:
337 // Add this one for logging
338 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
340 catalogDB.saveNestedHeatTemplate (heatMainTemplate.getArtifactUuid(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
341 // Indicate we have deployed it in the DB
342 heatNestedArtifact.incrementDeployedInDB();
344 case ASDCConfiguration.HEAT_VOL:
346 // Add this one for logging
347 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
348 catalogDB.saveNestedHeatTemplate (heatVolumeTemplate.getArtifactUuid(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
349 // Indicate we have deployed it in the DB
350 heatNestedArtifact.incrementDeployedInDB();
357 } else { // Assume it belongs to HEAT MAIN
358 // Add this one for logging
359 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
361 catalogDB.saveNestedHeatTemplate (heatMainTemplate.getArtifactUuid(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
362 // Indicate we have deployed it in the DB
363 heatNestedArtifact.incrementDeployedInDB();
368 if (mainEnvArtifactInfo != null) {
369 heatEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID()
370 .get(mainEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
372 // Add this one for logging
373 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(mainEnvArtifactInfo));
375 catalogDB.saveHeatEnvironment(heatEnv);
376 // Indicate we have deployed it in the DB
377 vfResourceStructure.getArtifactsMapByUUID().get(mainEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB();
383 // here we expect one VFModule to be there
384 /* VfResourceInstaller.createVfModule(vfModuleStructure,heatMainTemplate, heatVolumeTemplate, heatEnv, heatVolumeEnv);
385 VfModule vfModule = vfModuleStructure.getCatalogVfModule();
387 // Add this one for logging
388 artifactListForLogging.add(ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure));
390 catalogDB.saveOrUpdateVfModule(vfModule);
392 // Here we expect many HEAT_TEMPLATE files to be there
393 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_ARTIFACT)) {
394 for (VfModuleArtifact heatArtifact : vfModuleStructure.getArtifactsMap()
395 .get(ASDCConfiguration.HEAT_ARTIFACT)) {
397 HeatFiles heatFile = (HeatFiles) heatArtifact.getCatalogObject();
399 // Add this one for logging
400 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatArtifact.getArtifactInfo()));
403 catalogDB.saveVfModuleToHeatFiles (vfModule.getArtifactUuid(), heatFile);
404 // Indicate we will deploy it in the DB
405 heatArtifact.incrementDeployedInDB();
412 vfResourceStructure.setSuccessfulDeployment();
414 } catch (Exception e) {
416 Throwable dbExceptionToCapture = e;
417 while (!(dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException)
418 && (dbExceptionToCapture.getCause() != null)) {
419 dbExceptionToCapture = dbExceptionToCapture.getCause();
422 if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) {
423 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED, vfResourceStructure.getResourceInstance().getResourceName(),
424 vfResourceStructure.getNotification().getServiceVersion(), "", "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
426 String endEvent = "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.";
427 String elementToLog = (artifactListForLogging.size() > 0 ? artifactListForLogging.get(artifactListForLogging.size()-1).toString() : "No element listed");
428 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError, "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback", e);
429 catalogDB.rollback();
430 throw new ArtifactInstallerException(
431 "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
436 // Debug log the whole collection...
437 logger.debug(artifactListForLogging.toString());
442 private static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,VfModuleArtifact heatNestedArtifact) {
444 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null
445 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
446 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
447 .getArtifactInfo().getRelatedArtifacts()) {
448 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
449 return ASDCConfiguration.HEAT;
455 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
456 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
457 for (IArtifactInfo unknownArtifact:vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts()) {
458 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
459 return ASDCConfiguration.HEAT_VOL;
465 // Does not belong to anything
470 private static void createVnfResource(VfResourceStructure vfResourceStructure) {
471 VnfResource vnfResource = new VnfResource();
473 vnfResource.setModelUuid(vfResourceStructure.getResourceInstance().getResourceUUID());
474 vnfResource.setDescription(vfResourceStructure.getNotification().getServiceDescription());
476 vnfResource.setOrchestrationMode("HEAT");
477 // Set the version but Version is stored into ASDC_SERVICE_MODEL_VERSION
478 vnfResource.setVersion(BigDecimalVersion
479 .castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()));
480 // vnfResource.setVnfType(VfResourceInstaller.createVNFName(vfResourceStructure));
481 vnfResource.setModelVersion(BigDecimalVersion
482 .castAndCheckNotificationVersionToString(vfResourceStructure.getResourceInstance().getResourceVersion()));
484 vnfResource.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID());
485 vnfResource.setModelVersion(vfResourceStructure.getResourceInstance().getResourceVersion());
486 // vnfResource.setModelCustomizationName(vfResourceStructure.getResourceInstance().getResourceInstanceName());
487 // vnfResource.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID());
488 vnfResource.setModelName(vfResourceStructure.getResourceInstance().getResourceName());
489 // vnfResource.setServiceModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID());
491 //vnfResource.setCreated(getCurrentTimeStamp());
493 vfResourceStructure.setCatalogVnfResource(vnfResource);
496 private static void createNetworkResourceCustomization(VfResourceStructure vfResourceStructure) {
497 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
499 networkResourceCustomization.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID().trim());
500 // networkResourceCustomization.setModelName(vfResourceStructure.getResourceInstance().getResourceName().trim());
501 networkResourceCustomization.setModelInstanceName(vfResourceStructure.getResourceInstance().getResourceInstanceName().trim());
502 // networkResourceCustomization.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID().trim());
503 // networkResourceCustomization.setModelUuid(vfResourceStructure.getResourceInstance().getResourceUUID().trim());
504 // networkResourceCustomization.setModelVersion(vfResourceStructure.getResourceInstance().getResourceVersion().trim());
505 //networkResourceCustomization.setCreated(getCurrentTimeStamp());
507 vfResourceStructure.setCatalogNetworkResourceCustomization(networkResourceCustomization);
509 ServiceToNetworks serviceNetworks = new ServiceToNetworks();
510 serviceNetworks.setNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
511 serviceNetworks.setServiceModelUuid(vfResourceStructure.getNotification().getServiceUUID());
513 vfResourceStructure.setCatalogServiceToNetworks(serviceNetworks);
517 private static void createAllottedResourceCustomization(VfResourceStructure vfResourceStructure) {
518 AllottedResourceCustomization resourceCustomization = new AllottedResourceCustomization();
520 resourceCustomization.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID().trim());
521 // resourceCustomization.setModelName(vfResourceStructure.getResourceInstance().getResourceName().trim());
522 resourceCustomization.setModelInstanceName(vfResourceStructure.getResourceInstance().getResourceInstanceName().trim());
523 // resourceCustomization.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID().trim());
524 // resourceCustomization.setModelUuid(vfResourceStructure.getResourceInstance().getResourceUUID().trim());
525 resourceCustomization.setVersion(vfResourceStructure.getResourceInstance().getResourceVersion().trim());
526 //resourceCustomization.setCreated(getCurrentTimeStamp());
528 vfResourceStructure.setCatalogResourceCustomization(resourceCustomization);
530 ServiceToAllottedResources serviceAllottedResources = new ServiceToAllottedResources();
531 serviceAllottedResources.setArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
532 serviceAllottedResources.setServiceModelUuid(vfResourceStructure.getNotification().getServiceUUID());
534 vfResourceStructure.setCatalogServiceToAllottedResources(serviceAllottedResources);
538 private static void createVfModule(VfModuleStructure vfModuleStructure,HeatTemplate heatMain, HeatTemplate heatVolume,HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) {
539 VfModule vfModule = new VfModule();
540 // vfModule.setType(createVfModuleName(vfModuleStructure));
541 // vfModule.setAsdcUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelUUID());
542 vfModule.setDescription(vfModuleStructure.getVfModuleMetadata().getVfModuleModelDescription());
544 if (vfModuleStructure.getVfModuleMetadata().isBase()) {
545 vfModule.setIsBase(1);
547 vfModule.setIsBase(0);
550 // vfModule.setModelCustomizationUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelCustomizationUUID());
551 vfModule.setModelInvariantUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelInvariantUUID());
552 vfModule.setModelName(vfModuleStructure.getVfModuleMetadata().getVfModuleModelName());
554 vfModule.setVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(vfModuleStructure.getParentVfResource().getNotification().getServiceVersion()));
555 vfModule.setModelVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(
556 vfModuleStructure.getVfModuleMetadata().getVfModuleModelVersion()));
558 Map<String,String> map = vfModuleStructure.getVfModuleMetadata().getProperties();
562 if(map.get("vf_module_label") != null){
563 // vfModule.setLabel(map.get("vf_module_label"));
565 if(map.get("initial_count") != null && map.get("initial_count").length() > 0){
566 // vfModule.setInitialCount(Integer.parseInt(map.get("initial_count")));
568 if(map.get("min_vf_module_instances") != null && map.get("min_vf_module_instances").length() > 0){
569 // vfModule.setMinInstances(Integer.parseInt(map.get("min_vf_module_instances")));
571 if(map.get("max_vf_module_instances") != null && map.get("max_vf_module_instances").length() > 0){
572 // vfModule.setMaxInstances(Integer.parseInt(map.get("max_vf_module_instances")));
577 vfModuleStructure.setCatalogVfModule(vfModule);
579 VfResourceInstaller.createVfModuleLinks(vfModule, vfModuleStructure.getParentVfResource().getCatalogVnfResource(), heatMain,heatVolume, heatEnv,heatVolumeEnv);
582 private static void createVfModuleLinks(VfModule vfModule, VnfResource vnfResource, HeatTemplate heatMain,
583 HeatTemplate heatVolume, HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) {
585 if (heatMain !=null) {
586 // vfModule.setTemplateId(heatMain.getId());
588 if (heatEnv != null) {
589 // vfModule.setEnvironmentId(heatEnv.getId());
591 if (heatVolume != null) {
592 // vfModule.setVolTemplateId(heatVolume.getId());
594 if (heatVolumeEnv != null) {
595 // vfModule.setVolEnvironmentId(heatVolumeEnv.getId());
598 // vfModule.setVnfResourceId(vnfResource.getId());
603 private static Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) {
605 // Scan the payload downloadResult and extract the HeatTemplate
607 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
608 return yamlEditor.getParameterList(artifactUUID);
613 public static String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure, List<String> listTypes) {
614 String newFileBody = filebody;
615 for (VfModuleArtifact moduleArtifact:vfResourceStructure.getArtifactsMapByUUID().values()) {
617 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
619 newFileBody = verifyTheFilePrefixInString(newFileBody,moduleArtifact.getArtifactInfo().getArtifactName());
625 public static String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
627 String needlePrefix = "file:///";
628 String prefixedFilenameToVerify = needlePrefix+filenameToVerify;
630 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
634 StringBuffer sb = new StringBuffer(body.length());
636 int currentIndex = 0;
639 while (currentIndex != -1) {
640 startIndex = currentIndex;
641 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
643 if (currentIndex == -1) {
647 // We append from the startIndex up to currentIndex (start of File Name)
648 sb.append(body.substring(startIndex, currentIndex));
649 sb.append(filenameToVerify);
651 currentIndex += prefixedFilenameToVerify.length();
654 sb.append(body.substring(startIndex));
656 return sb.toString();
659 private static void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
660 VfModuleArtifact vfModuleArtifact) {
661 HeatTemplate heatTemplate = new HeatTemplate();
663 // TODO Set the label
664 // heatTemplate.setAsdcLabel("label");
665 // Use the ResourceName of the ASDC template because the HEAT could be
667 // heatTemplate.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName());
668 heatTemplate.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
670 List<String> typeList = new ArrayList<String>();
671 typeList.add(ASDCConfiguration.HEAT_NESTED);
672 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
674 heatTemplate.setTemplateBody(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList));
675 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
677 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
678 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
680 heatTemplate.setTimeoutMinutes(240);
683 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
684 heatTemplate.setVersion(BigDecimalVersion
685 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
686 heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
688 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
689 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
691 heatTemplate.setArtifactChecksum("MANUAL_RECORD");
694 Set<HeatTemplateParam> heatParam = VfResourceInstaller
695 .extractHeatTemplateParameters(vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
696 heatTemplate.setParameters(heatParam);
697 //heatTemplate.setCreated(getCurrentTimeStamp());
699 vfModuleArtifact.setCatalogObject(heatTemplate);
702 private static void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
703 VfModuleArtifact vfModuleArtifact) {
704 HeatEnvironment heatEnvironment = new HeatEnvironment();
706 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
707 // TODO Set the label
708 // heatEnvironment.setAsdcLabel("Label");
710 List<String> typeList = new ArrayList<String>();
711 typeList.add(ASDCConfiguration.HEAT);
712 typeList.add(ASDCConfiguration.HEAT_VOL);
714 heatEnvironment.setEnvironment(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList));
715 // heatEnvironment.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
716 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
717 heatEnvironment.setVersion(BigDecimalVersion
718 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
719 // heatEnvironment.setAsdcResourceName(VfResourceInstaller.createVNFName(vfResourceStructure));
720 heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
722 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
723 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
725 heatEnvironment.setArtifactChecksum("MANUAL_RECORD");
727 //heatEnvironment.setCreated(getCurrentTimeStamp());
729 vfModuleArtifact.setCatalogObject(heatEnvironment);
733 private static void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
734 VfModuleArtifact vfModuleArtifact) {
736 HeatFiles heatFile = new HeatFiles();
737 // TODO Set the label
738 // heatFile.setAsdcLabel("Label");
739 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
740 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
741 heatFile.setFileBody(vfModuleArtifact.getResult());
742 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
743 heatFile.setVersion(BigDecimalVersion
744 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
745 //heatFile.setCreated(getCurrentTimeStamp());
747 // heatFile.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName());
749 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
750 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
752 heatFile.setArtifactChecksum("MANUAL_RECORD");
755 vfModuleArtifact.setCatalogObject(heatFile);
759 private static void createService(VfResourceStructure vfResourceStructure) {
761 Service service = new Service();
762 service.setDescription(vfResourceStructure.getNotification().getServiceDescription());
763 service.setModelName(vfResourceStructure.getNotification().getServiceName());
764 service.setModelUUID(vfResourceStructure.getNotification().getServiceUUID());
765 service.setVersion(vfResourceStructure.getNotification().getServiceVersion());
766 service.setModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID());
767 //service.setCreated(getCurrentTimeStamp());
769 vfResourceStructure.setCatalogService(service);
773 private static String createVNFName(VfResourceStructure vfResourceStructure) {
775 return vfResourceStructure.getNotification().getServiceName() + "/" + vfResourceStructure.getResourceInstance().getResourceInstanceName();
778 private static String createVfModuleName(VfModuleStructure vfModuleStructure) {
780 return createVNFName(vfModuleStructure.getParentVfResource())+"::"+vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
784 private static Timestamp getCurrentTimeStamp() {
786 return new Timestamp(new Date().getTime());