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 CatalogDatabase db = new CatalogDatabase();
73 boolean status = false;
74 VfResourceStructure vfResourceStructure = (VfResourceStructure)vfResourceStruct;
78 String resourceType = vfResourceStruct.getResourceInstance().getResourceType();
79 String category = vfResourceStruct.getResourceInstance().getCategory();
81 // Check for duplicate VF Module that is not an Allotted Resource
82 if(resourceType.equals("VF") && !category.equalsIgnoreCase("Allotted Resource")){
83 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "VNFResource",
84 VfResourceInstaller.createVNFName(vfResourceStructure),
85 BigDecimalVersion.castAndCheckNotificationVersionToString(
86 vfResourceStructure.getNotification().getServiceVersion()), "", "");
88 VnfResource vnfResource = db.getVnfResource(
89 VfResourceInstaller.createVNFName(vfResourceStructure),
90 BigDecimalVersion.castAndCheckNotificationVersionToString(
91 vfResourceStructure.getNotification().getServiceVersion()));
93 if (vnfResource != null) {
100 // Check dup for VF Allotted Resource
101 if(resourceType.equals("VF") && category.equalsIgnoreCase("Allotted Resource")){
102 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "AllottedResource",
103 vfResourceStruct.getResourceInstance().getResourceInstanceName(),
104 BigDecimalVersion.castAndCheckNotificationVersionToString(
105 vfResourceStructure.getNotification().getServiceVersion()), "", "");
107 List<AllottedResourceCustomization> allottedResources = db.getAllAllottedResourcesByServiceModelUuid(vfResourceStruct.getNotification().getServiceUUID());
109 if(allottedResources != null && allottedResources.size() > 0){
110 for(AllottedResourceCustomization allottedResource : allottedResources){
112 String existingAllottedResource = allottedResource.getModelCustomizationUuid();
113 String notificationAllottedResource = vfResourceStruct.getResourceInstance().getResourceCustomizationUUID();
115 if(existingAllottedResource.equals(notificationAllottedResource)){
124 // Check Network for duplicates
125 if(resourceType.equals("VL")){
126 logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "NetworkResource",
127 vfResourceStruct.getResourceInstance().getResourceInstanceName(),
128 BigDecimalVersion.castAndCheckNotificationVersionToString(
129 vfResourceStructure.getNotification().getServiceVersion()), "", "");
131 List<NetworkResourceCustomization> networkResources = db.getAllNetworksByServiceModelUuid(vfResourceStruct.getNotification().getServiceUUID());
133 if(networkResources != null && networkResources.size() > 0){
134 for(NetworkResourceCustomization networkResource : networkResources){
136 String existingNetworkResource = networkResource.getModelCustomizationUuid();
137 String notificationNetworkResource = vfResourceStruct.getResourceInstance().getResourceCustomizationUUID();
139 if(existingNetworkResource.equals(notificationNetworkResource)){
149 logger.info(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED_DETAIL,
150 vfResourceStructure.getResourceInstance().getResourceInstanceName(),
151 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
152 vfResourceStructure.getNotification().getServiceName(),
153 BigDecimalVersion.castAndCheckNotificationVersionToString(
154 vfResourceStructure.getNotification().getServiceVersion()),
155 vfResourceStructure.getNotification().getServiceUUID(),
156 vfResourceStructure.getResourceInstance().getResourceName(),"", "");
158 logger.info(MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL,
159 vfResourceStructure.getResourceInstance().getResourceInstanceName(),
160 vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(),
161 vfResourceStructure.getNotification().getServiceName(),
162 BigDecimalVersion.castAndCheckNotificationVersionToString(
163 vfResourceStructure.getNotification().getServiceVersion()),
164 vfResourceStructure.getNotification().getServiceUUID(),
165 vfResourceStructure.getResourceInstance().getResourceName(),"", "");
170 } catch (Exception e) {
171 logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception - isResourceAlreadyDeployed");
172 throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
177 public void installTheResource(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
179 // 1. Add the DB object list (Hashed) to be created from the HashMap
181 // The DB objects will be stored in each VfModuleArtifact objects
182 // Those objects could be reused by different VfModule
184 VfResourceStructure vfResourceStructure = (VfResourceStructure)vfResourceStruct;
186 for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
188 switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) {
189 case ASDCConfiguration.HEAT:
190 case ASDCConfiguration.HEAT_VOL:
191 case ASDCConfiguration.HEAT_NESTED:
192 VfResourceInstaller.createHeatTemplateFromArtifact(vfResourceStructure, vfModuleArtifact);
194 case ASDCConfiguration.HEAT_ENV:
195 VfResourceInstaller.createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact);
197 case ASDCConfiguration.HEAT_ARTIFACT:
198 VfResourceInstaller.createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact);
200 case ASDCConfiguration.HEAT_NET:
201 case ASDCConfiguration.OTHER:
202 logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT, vfModuleArtifact.getArtifactInfo().getArtifactType()+"(Artifact Name:"+vfModuleArtifact.getArtifactInfo().getArtifactName()+")", "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
210 // in case of deployment failure, use a string that will represent the type of artifact that failed...
211 List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
213 CatalogDatabase catalogDB = new CatalogDatabase();
214 // 2. Create the VFModules/VNFResource objects by linking them to the
215 // objects created before and store them in Resource/module structure
216 // Opening a DB transaction, starting from here
219 VfResourceInstaller.createService(vfResourceStructure);
221 String resourceType = vfResourceStructure.getResourceInstance().getResourceType();
222 String resourceCategory = vfResourceStructure.getResourceInstance().getCategory();
224 if(resourceType.equals("VF")){
226 if(resourceCategory.equalsIgnoreCase("Allotted Resource")){
227 VfResourceInstaller.createAllottedResourceCustomization(vfResourceStructure);
228 catalogDB.saveAllottedResourceCustomization(vfResourceStructure.getCatalogResourceCustomization());
230 VfResourceInstaller.createVnfResource(vfResourceStructure);
231 catalogDB.saveOrUpdateVnfResource(vfResourceStructure.getCatalogVnfResource());
235 if(resourceType.equals("VL")){
236 VfResourceInstaller.createNetworkResourceCustomization(vfResourceStructure);
237 catalogDB.saveNetworkResourceCustomization(vfResourceStructure.getCatalogNetworkResourceCustomization());
240 // Add this one for logging
241 artifactListForLogging.add(ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure));
243 //catalogDB.saveOrUpdateVnfResource(vfResourceStructure.getCatalogVnfResource());
244 catalogDB.saveService(vfResourceStructure.getCatalogService());
246 // Now that the service has been added we can populate the Service_to_AllottedResources table
247 if(resourceType.equals("VF") && resourceCategory.equalsIgnoreCase("Allotted Resource")){
248 catalogDB.saveServiceToAllottedResources(vfResourceStructure.getCatalogServiceToAllottedResources());
251 // Now that the service has been added we can populate the Service_to_Network table
252 if(resourceType.equals("VL")){
253 catalogDB.saveServiceToNetworks(vfResourceStructure.getCatalogServiceToNetworks());
256 for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
258 // Here we set the right db structure according to the Catalog
261 // We expect only one MAIN HEAT per VFMODULE
262 // we can also obtain from it the Env ArtifactInfo, that's why
264 // get the Main IArtifactInfo
266 HeatTemplate heatMainTemplate = null;
267 HeatEnvironment heatEnv = null;
269 HeatTemplate heatVolumeTemplate = null;
270 HeatEnvironment heatVolumeEnv = null;
272 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT)) {
273 IArtifactInfo mainEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT)
274 .get(0).getArtifactInfo().getGeneratedArtifact();
277 heatMainTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap()
278 .get(ASDCConfiguration.HEAT).get(0).getCatalogObject();
280 // Add this one for logging
281 artifactListForLogging.add(ASDCElementInfo
282 .createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo()));
284 catalogDB.saveHeatTemplate(heatMainTemplate, heatMainTemplate.getParameters());
285 // Indicate we have deployed it in the DB
286 vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).incrementDeployedInDB();
290 // We expect only one VOL HEAT per VFMODULE
291 // we can also obtain from it the Env ArtifactInfo, that's why
292 // we get the Volume IArtifactInfo
294 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_VOL)) {
295 IArtifactInfo volEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0)
296 .getArtifactInfo().getGeneratedArtifact();
298 heatVolumeTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap()
299 .get(ASDCConfiguration.HEAT_VOL).get(0).getCatalogObject();
301 // Add this one for logging
302 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()));
304 catalogDB.saveHeatTemplate(heatVolumeTemplate, heatVolumeTemplate.getParameters());
305 // Indicate we have deployed it in the DB
306 vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).incrementDeployedInDB();
308 if (volEnvArtifactInfo != null) {
309 heatVolumeEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID()
310 .get(volEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
312 // Add this one for logging
313 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(volEnvArtifactInfo));
315 catalogDB.saveHeatEnvironment(heatVolumeEnv);
316 // Indicate we have deployed it in the DB
317 vfResourceStructure.getArtifactsMapByUUID().get(volEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB();
323 // Here we expect many HEAT_NESTED template to be there
324 // check first if we really have nested heat templates
325 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_NESTED)) {
326 for (VfModuleArtifact heatNestedArtifact : vfModuleStructure.getArtifactsMap()
327 .get(ASDCConfiguration.HEAT_NESTED)) {
329 // Check if this nested is well referenced by the MAIN HEAT
330 String parentArtifactType = VfResourceInstaller.identifyParentOfNestedTemplate(vfModuleStructure,heatNestedArtifact);
331 HeatTemplate heatNestedTemplate = (HeatTemplate) heatNestedArtifact.getCatalogObject();
333 if (parentArtifactType != null) {
335 switch (parentArtifactType) {
336 case ASDCConfiguration.HEAT:
338 // Add this one for logging
339 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
341 catalogDB.saveNestedHeatTemplate (heatMainTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
342 // Indicate we have deployed it in the DB
343 heatNestedArtifact.incrementDeployedInDB();
345 case ASDCConfiguration.HEAT_VOL:
347 // Add this one for logging
348 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
349 catalogDB.saveNestedHeatTemplate (heatVolumeTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
350 // Indicate we have deployed it in the DB
351 heatNestedArtifact.incrementDeployedInDB();
358 } else { // Assume it belongs to HEAT MAIN
359 // Add this one for logging
360 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
362 catalogDB.saveNestedHeatTemplate (heatMainTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
363 // Indicate we have deployed it in the DB
364 heatNestedArtifact.incrementDeployedInDB();
369 if (mainEnvArtifactInfo != null) {
370 heatEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID()
371 .get(mainEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
373 // Add this one for logging
374 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(mainEnvArtifactInfo));
376 catalogDB.saveHeatEnvironment(heatEnv);
377 // Indicate we have deployed it in the DB
378 vfResourceStructure.getArtifactsMapByUUID().get(mainEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB();
384 // here we expect one VFModule to be there
385 VfResourceInstaller.createVfModule(vfModuleStructure,heatMainTemplate, heatVolumeTemplate, heatEnv, heatVolumeEnv);
386 VfModule vfModule = vfModuleStructure.getCatalogVfModule();
388 // Add this one for logging
389 artifactListForLogging.add(ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure));
391 catalogDB.saveOrUpdateVfModule(vfModule);
393 // Here we expect many HEAT_TEMPLATE files to be there
394 if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_ARTIFACT)) {
395 for (VfModuleArtifact heatArtifact : vfModuleStructure.getArtifactsMap()
396 .get(ASDCConfiguration.HEAT_ARTIFACT)) {
398 HeatFiles heatFile = (HeatFiles) heatArtifact.getCatalogObject();
400 // Add this one for logging
401 artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatArtifact.getArtifactInfo()));
404 catalogDB.saveVfModuleToHeatFiles (vfModule.getId(), heatFile);
405 // Indicate we will deploy it in the DB
406 heatArtifact.incrementDeployedInDB();
413 vfResourceStructure.setSuccessfulDeployment();
415 } catch (Exception e) {
417 Throwable dbExceptionToCapture = e;
418 while (!(dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException)
419 && (dbExceptionToCapture.getCause() != null)) {
420 dbExceptionToCapture = dbExceptionToCapture.getCause();
423 if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) {
424 logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED, vfResourceStructure.getResourceInstance().getResourceName(),
425 vfResourceStructure.getNotification().getServiceVersion(), "", "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
427 String endEvent = "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.";
428 String elementToLog = (artifactListForLogging.size() > 0 ? artifactListForLogging.get(artifactListForLogging.size()-1).toString() : "No element listed");
429 logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError, "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback", e);
430 catalogDB.rollback();
431 throw new ArtifactInstallerException(
432 "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
437 // Debug log the whole collection...
438 logger.debug(artifactListForLogging.toString());
443 private static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,VfModuleArtifact heatNestedArtifact) {
445 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null
446 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
447 for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0)
448 .getArtifactInfo().getRelatedArtifacts()) {
449 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
450 return ASDCConfiguration.HEAT;
456 if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null
457 && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts() != null) {
458 for (IArtifactInfo unknownArtifact:vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts()) {
459 if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) {
460 return ASDCConfiguration.HEAT_VOL;
466 // Does not belong to anything
471 private static void createVnfResource(VfResourceStructure vfResourceStructure) {
472 VnfResource vnfResource = new VnfResource();
474 vnfResource.setAsdcUuid(vfResourceStructure.getResourceInstance().getResourceUUID());
475 vnfResource.setDescription(vfResourceStructure.getNotification().getServiceDescription());
477 vnfResource.setOrchestrationMode("HEAT");
478 // Set the version but Version is stored into ASDC_SERVICE_MODEL_VERSION
479 vnfResource.setVersion(BigDecimalVersion
480 .castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()));
481 vnfResource.setVnfType(VfResourceInstaller.createVNFName(vfResourceStructure));
482 vnfResource.setModelVersion(BigDecimalVersion
483 .castAndCheckNotificationVersionToString(vfResourceStructure.getResourceInstance().getResourceVersion()));
485 vnfResource.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID());
486 vnfResource.setModelCustomizationName(vfResourceStructure.getResourceInstance().getResourceInstanceName());
487 vnfResource.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID());
488 vnfResource.setModelName(vfResourceStructure.getResourceInstance().getResourceName());
489 vnfResource.setServiceModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID());
490 //vnfResource.setCreated(getCurrentTimeStamp());
492 vfResourceStructure.setCatalogVnfResource(vnfResource);
495 private static void createNetworkResourceCustomization(VfResourceStructure vfResourceStructure) {
496 NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization();
498 networkResourceCustomization.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID().trim());
499 networkResourceCustomization.setModelName(vfResourceStructure.getResourceInstance().getResourceName().trim());
500 networkResourceCustomization.setModelInstanceName(vfResourceStructure.getResourceInstance().getResourceInstanceName().trim());
501 networkResourceCustomization.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID().trim());
502 networkResourceCustomization.setModelUuid(vfResourceStructure.getResourceInstance().getResourceUUID().trim());
503 networkResourceCustomization.setModelVersion(vfResourceStructure.getResourceInstance().getResourceVersion().trim());
504 //networkResourceCustomization.setCreated(getCurrentTimeStamp());
506 vfResourceStructure.setCatalogNetworkResourceCustomization(networkResourceCustomization);
508 ServiceToNetworks serviceNetworks = new ServiceToNetworks();
509 serviceNetworks.setNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
510 serviceNetworks.setServiceModelUuid(vfResourceStructure.getNotification().getServiceUUID());
512 vfResourceStructure.setCatalogServiceToNetworks(serviceNetworks);
516 private static void createAllottedResourceCustomization(VfResourceStructure vfResourceStructure) {
517 AllottedResourceCustomization resourceCustomization = new AllottedResourceCustomization();
519 resourceCustomization.setModelCustomizationUuid(vfResourceStructure.getResourceInstance().getResourceCustomizationUUID().trim());
520 resourceCustomization.setModelName(vfResourceStructure.getResourceInstance().getResourceName().trim());
521 resourceCustomization.setModelInstanceName(vfResourceStructure.getResourceInstance().getResourceInstanceName().trim());
522 resourceCustomization.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID().trim());
523 resourceCustomization.setModelUuid(vfResourceStructure.getResourceInstance().getResourceUUID().trim());
524 resourceCustomization.setVersion(vfResourceStructure.getResourceInstance().getResourceVersion().trim());
525 //resourceCustomization.setCreated(getCurrentTimeStamp());
527 vfResourceStructure.setCatalogResourceCustomization(resourceCustomization);
529 ServiceToAllottedResources serviceAllottedResources = new ServiceToAllottedResources();
530 serviceAllottedResources.setArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
531 serviceAllottedResources.setServiceModelUuid(vfResourceStructure.getNotification().getServiceUUID());
533 vfResourceStructure.setCatalogServiceToAllottedResources(serviceAllottedResources);
537 private static void createVfModule(VfModuleStructure vfModuleStructure,HeatTemplate heatMain, HeatTemplate heatVolume,HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) {
538 VfModule vfModule = new VfModule();
539 vfModule.setType(createVfModuleName(vfModuleStructure));
540 vfModule.setAsdcUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelUUID());
541 vfModule.setDescription(vfModuleStructure.getVfModuleMetadata().getVfModuleModelDescription());
543 if (vfModuleStructure.getVfModuleMetadata().isBase()) {
544 vfModule.setIsBase(1);
546 vfModule.setIsBase(0);
549 vfModule.setModelCustomizationUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelCustomizationUUID());
550 vfModule.setModelInvariantUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelInvariantUUID());
551 vfModule.setModelName(vfModuleStructure.getVfModuleMetadata().getVfModuleModelName());
553 vfModule.setVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(vfModuleStructure.getParentVfResource().getNotification().getServiceVersion()));
554 vfModule.setModelVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(
555 vfModuleStructure.getVfModuleMetadata().getVfModuleModelVersion()));
557 Map<String,String> map = vfModuleStructure.getVfModuleMetadata().getProperties();
561 if(map.get("vf_module_label") != null){
562 vfModule.setLabel(map.get("vf_module_label"));
564 if(map.get("initial_count") != null && map.get("initial_count").length() > 0){
565 vfModule.setInitialCount(Integer.parseInt(map.get("initial_count")));
567 if(map.get("min_vf_module_instances") != null && map.get("min_vf_module_instances").length() > 0){
568 vfModule.setMinInstances(Integer.parseInt(map.get("min_vf_module_instances")));
570 if(map.get("max_vf_module_instances") != null && map.get("max_vf_module_instances").length() > 0){
571 vfModule.setMaxInstances(Integer.parseInt(map.get("max_vf_module_instances")));
576 vfModuleStructure.setCatalogVfModule(vfModule);
578 VfResourceInstaller.createVfModuleLinks(vfModule, vfModuleStructure.getParentVfResource().getCatalogVnfResource(), heatMain,heatVolume, heatEnv,heatVolumeEnv);
581 private static void createVfModuleLinks(VfModule vfModule, VnfResource vnfResource, HeatTemplate heatMain,
582 HeatTemplate heatVolume, HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) {
584 if (heatMain !=null) {
585 vfModule.setTemplateId(heatMain.getId());
587 if (heatEnv != null) {
588 vfModule.setEnvironmentId(heatEnv.getId());
590 if (heatVolume != null) {
591 vfModule.setVolTemplateId(heatVolume.getId());
593 if (heatVolumeEnv != null) {
594 vfModule.setVolEnvironmentId(heatVolumeEnv.getId());
597 vfModule.setVnfResourceId(vnfResource.getId());
601 private static Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile) {
603 // Scan the payload downloadResult and extract the HeatTemplate
605 YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes());
606 return yamlEditor.getParameterList();
611 public static String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure, List<String> listTypes) {
612 String newFileBody = filebody;
613 for (VfModuleArtifact moduleArtifact:vfResourceStructure.getArtifactsMapByUUID().values()) {
615 if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) {
617 newFileBody = verifyTheFilePrefixInString(newFileBody,moduleArtifact.getArtifactInfo().getArtifactName());
623 public static String verifyTheFilePrefixInString(final String body, final String filenameToVerify) {
625 String needlePrefix = "file:///";
626 String prefixedFilenameToVerify = needlePrefix+filenameToVerify;
628 if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) {
632 StringBuffer sb = new StringBuffer(body.length());
634 int currentIndex = 0;
637 while (currentIndex != -1) {
638 startIndex = currentIndex;
639 currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex);
641 if (currentIndex == -1) {
645 // We append from the startIndex up to currentIndex (start of File Name)
646 sb.append(body.substring(startIndex, currentIndex));
647 sb.append(filenameToVerify);
649 currentIndex += prefixedFilenameToVerify.length();
652 sb.append(body.substring(startIndex));
654 return sb.toString();
657 private static void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
658 VfModuleArtifact vfModuleArtifact) {
659 HeatTemplate heatTemplate = new HeatTemplate();
661 // TODO Set the label
662 heatTemplate.setAsdcLabel("label");
663 // Use the ResourceName of the ASDC template because the HEAT could be
665 heatTemplate.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName());
666 heatTemplate.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
668 List<String> typeList = new ArrayList<String>();
669 typeList.add(ASDCConfiguration.HEAT_NESTED);
670 typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
672 heatTemplate.setTemplateBody(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList));
673 heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
675 if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
676 heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
678 heatTemplate.setTimeoutMinutes(240);
681 heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
682 heatTemplate.setVersion(BigDecimalVersion
683 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
685 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
686 heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
688 heatTemplate.setArtifactChecksum("MANUAL_RECORD");
691 Set<HeatTemplateParam> heatParam = VfResourceInstaller
692 .extractHeatTemplateParameters(vfModuleArtifact.getResult());
693 heatTemplate.setParameters(heatParam);
695 vfModuleArtifact.setCatalogObject(heatTemplate);
698 private static void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
699 VfModuleArtifact vfModuleArtifact) {
700 HeatEnvironment heatEnvironment = new HeatEnvironment();
702 heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
703 // TODO Set the label
704 heatEnvironment.setAsdcLabel("Label");
706 List<String> typeList = new ArrayList<String>();
707 typeList.add(ASDCConfiguration.HEAT);
708 typeList.add(ASDCConfiguration.HEAT_VOL);
710 heatEnvironment.setEnvironment(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList));
711 heatEnvironment.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
712 heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
713 heatEnvironment.setVersion(BigDecimalVersion
714 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
715 heatEnvironment.setAsdcResourceName(VfResourceInstaller.createVNFName(vfResourceStructure));
717 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
718 heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
720 heatEnvironment.setArtifactChecksum("MANUAL_RECORD");
723 vfModuleArtifact.setCatalogObject(heatEnvironment);
727 private static void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
728 VfModuleArtifact vfModuleArtifact) {
730 HeatFiles heatFile = new HeatFiles();
731 // TODO Set the label
732 heatFile.setAsdcLabel("Label");
733 heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
734 heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
735 heatFile.setFileBody(vfModuleArtifact.getResult());
736 heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
737 heatFile.setVersion(BigDecimalVersion
738 .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
740 heatFile.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName());
742 if(vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null){
743 heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
745 heatFile.setArtifactChecksum("MANUAL_RECORD");
748 vfModuleArtifact.setCatalogObject(heatFile);
752 private static void createService(VfResourceStructure vfResourceStructure) {
754 Service service = new Service();
755 service.setDescription(vfResourceStructure.getNotification().getServiceDescription());
756 service.setServiceName(vfResourceStructure.getNotification().getServiceName());
757 service.setServiceNameVersionId(vfResourceStructure.getNotification().getServiceUUID());
758 service.setVersion(vfResourceStructure.getNotification().getServiceVersion());
759 service.setModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID());
761 vfResourceStructure.setCatalogService(service);
765 private static String createVNFName(VfResourceStructure vfResourceStructure) {
767 return vfResourceStructure.getNotification().getServiceName() + "/" + vfResourceStructure.getResourceInstance().getResourceInstanceName();
770 private static String createVfModuleName(VfModuleStructure vfModuleStructure) {
772 return createVNFName(vfModuleStructure.getParentVfResource())+"::"+vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
776 private static Timestamp getCurrentTimeStamp() {
778 return new Timestamp(new Date().getTime());