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.sdc.vendorsoftwareproduct.impl;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.enrichment.api.EnrichmentManager;
26 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
27 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
28 import org.openecomp.core.model.dao.ServiceModelDao;
29 import org.openecomp.core.model.types.ServiceElement;
30 import org.openecomp.core.util.UniqueValueUtil;
31 import org.openecomp.core.utilities.file.FileContentHandler;
32 import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
33 import org.openecomp.core.utilities.json.JsonUtil;
34 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
35 import org.openecomp.core.validation.api.ValidationManager;
36 import org.openecomp.core.validation.util.MessageContainerUtil;
37 import org.openecomp.sdc.activityLog.ActivityLogManager;
38 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
39 import org.openecomp.sdc.common.errors.CoreException;
40 import org.openecomp.sdc.common.errors.ErrorCategory;
41 import org.openecomp.sdc.common.errors.ErrorCode;
42 import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
43 import org.openecomp.sdc.common.utils.CommonUtil;
44 import org.openecomp.sdc.common.utils.SdcCommon;
45 import org.openecomp.sdc.datatypes.error.ErrorLevel;
46 import org.openecomp.sdc.datatypes.error.ErrorMessage;
47 import org.openecomp.sdc.generator.datatypes.tosca.VspModelInfo;
48 import org.openecomp.sdc.healing.api.HealingManager;
49 import org.openecomp.sdc.logging.api.Logger;
50 import org.openecomp.sdc.logging.api.LoggerFactory;
51 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
52 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
53 import org.openecomp.sdc.logging.messages.AuditMessages;
54 import org.openecomp.sdc.logging.types.LoggerConstants;
55 import org.openecomp.sdc.logging.types.LoggerErrorCode;
56 import org.openecomp.sdc.logging.types.LoggerServiceName;
57 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
58 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
59 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
60 import org.openecomp.sdc.validation.util.ValidationManagerUtil;
61 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
62 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
63 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
64 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
65 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
66 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
67 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
68 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
69 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
70 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
71 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
72 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.VendorSoftwareProductNotFoundErrorBuilder;
73 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
74 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
75 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
76 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
77 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
78 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
79 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
80 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
81 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
82 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
83 import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentDependencyModelErrorBuilder;
84 import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentErrorBuilder;
85 import org.openecomp.sdc.vendorsoftwareproduct.errors.CreatePackageForNonFinalVendorSoftwareProductErrorBuilder;
86 import org.openecomp.sdc.vendorsoftwareproduct.errors.DeploymentFlavorErrorBuilder;
87 import org.openecomp.sdc.vendorsoftwareproduct.errors.FileCreationErrorBuilder;
88 import org.openecomp.sdc.vendorsoftwareproduct.errors.InformationArtifactCreationErrorBuilder;
89 import org.openecomp.sdc.vendorsoftwareproduct.errors.NicInternalNetworkErrorBuilder;
90 import org.openecomp.sdc.vendorsoftwareproduct.errors.OnboardingMethodErrorBuilder;
91 import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageInvalidErrorBuilder;
92 import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder;
93 import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder;
94 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder;
95 import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory;
96 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
97 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
98 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
99 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
100 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult;
101 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
102 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
103 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
104 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
105 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
106 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
107 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
108 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
109 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
110 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput;
111 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
112 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
113 import org.openecomp.sdc.vendorsoftwareproduct.utils.ComponentDependencyTracker;
114 import org.openecomp.sdc.versioning.VersioningManager;
115 import org.openecomp.sdc.versioning.VersioningUtil;
116 import org.openecomp.sdc.versioning.dao.types.Version;
117 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
118 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
119 import org.openecomp.sdc.versioning.types.VersionInfo;
120 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
121 import org.openecomp.sdcrests.activitylog.types.ActivityType;
122 import org.slf4j.MDC;
124 import java.io.BufferedOutputStream;
125 import java.io.ByteArrayInputStream;
126 import java.io.ByteArrayOutputStream;
128 import java.io.FileOutputStream;
129 import java.io.IOException;
130 import java.io.OutputStream;
131 import java.nio.ByteBuffer;
132 import java.util.ArrayList;
133 import java.util.Collection;
134 import java.util.HashMap;
135 import java.util.HashSet;
136 import java.util.List;
137 import java.util.Map;
138 import java.util.Objects;
139 import java.util.Optional;
140 import java.util.Set;
141 import java.util.zip.ZipInputStream;
142 import java.util.zip.ZipOutputStream;
144 public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
145 private static String VALIDATION_VSP_ID = "validationOnlyVspId";
146 private static final String VALIDATION_VSP_NAME = "validationOnlyVspName";
147 //private static final String VALIDATION_VSP_USER = "validationOnlyVspUser";
149 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
150 private static final Logger logger =
151 LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class);
153 private OrchestrationTemplateDao orchestrationTemplateDao;
154 private VendorSoftwareProductInfoDao vspInfoDao;
155 private VersioningManager versioningManager;
156 private VendorSoftwareProductDao vendorSoftwareProductDao;
157 private VendorLicenseFacade vendorLicenseFacade;
158 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
159 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
160 private HealingManager healingManager;
161 private VendorLicenseArtifactsService licenseArtifactsService;
162 private InformationArtifactGenerator informationArtifactGenerator;
163 private PackageInfoDao packageInfoDao;
164 private ActivityLogManager activityLogManager;
165 private DeploymentFlavorDao deploymentFlavorDao;
166 private NicDao nicDao;
167 private ManualVspToscaManager manualVspToscaManager;
170 * Instantiates a new Vendor software product manager.
172 * @param versioningManager the versioning manager
173 * @param vendorSoftwareProductDao the vendor software product dao
174 * @param orchestrationTemplateDataDao the orchestration template data dao
175 * @param vspInfoDao the vsp info dao
176 * @param vendorLicenseFacade the vendor license facade
177 * @param serviceModelDao the service model dao
178 * @param enrichedServiceModelDao the enriched service model dao
179 * @param healingManager the healing manager
180 * @param licenseArtifactsService the license artifacts service
181 * @param informationArtifactGenerator the information artifact generator
182 * @param packageInfoDao the package info dao
183 * @param activityLogManager the activity log manager
184 * @param deploymentFlavorDao the deployment flavor dao
185 * @param nicDao the nic dao
187 public VendorSoftwareProductManagerImpl(
188 VersioningManager versioningManager,
189 VendorSoftwareProductDao vendorSoftwareProductDao,
190 OrchestrationTemplateDao orchestrationTemplateDataDao,
191 VendorSoftwareProductInfoDao vspInfoDao,
192 VendorLicenseFacade vendorLicenseFacade,
193 ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
194 EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao,
195 HealingManager healingManager,
196 VendorLicenseArtifactsService licenseArtifactsService,
197 InformationArtifactGenerator informationArtifactGenerator,
198 PackageInfoDao packageInfoDao,
199 ActivityLogManager activityLogManager,
200 DeploymentFlavorDao deploymentFlavorDao,
202 ManualVspToscaManager manualVspToscaManager) {
203 this.versioningManager = versioningManager;
204 this.vendorSoftwareProductDao = vendorSoftwareProductDao;
205 this.orchestrationTemplateDao = orchestrationTemplateDataDao;
206 this.vspInfoDao = vspInfoDao;
207 this.vendorLicenseFacade = vendorLicenseFacade;
208 this.serviceModelDao = serviceModelDao;
209 this.enrichedServiceModelDao = enrichedServiceModelDao;
210 this.healingManager = healingManager;
211 this.licenseArtifactsService = licenseArtifactsService;
212 this.informationArtifactGenerator = informationArtifactGenerator;
213 this.packageInfoDao = packageInfoDao;
214 this.activityLogManager = activityLogManager;
215 this.deploymentFlavorDao = deploymentFlavorDao;
216 this.nicDao = nicDao;
217 this.manualVspToscaManager = manualVspToscaManager;
219 registerToVersioning();
222 private void registerToVersioning() {
223 vendorSoftwareProductDao.registerVersioning(
224 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
225 serviceModelDao.registerVersioning(
226 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
227 enrichedServiceModelDao.registerVersioning(
228 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
232 public Version checkout(String vendorSoftwareProductId, String user) {
233 mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
234 MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkout_Entity.toString());
236 Version newVersion = versioningManager
237 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
238 vendorSoftwareProductId, user);
240 if (newVersion != null) {
241 ActivityLogEntity activityLogEntity =
242 new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1),
243 ActivityType.CHECKOUT.toString(), user, true, "", "");
244 activityLogManager.addActionLog(activityLogEntity, user);
247 mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
253 public Version undoCheckout(String vendorSoftwareProductId, String user) {
254 mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
257 getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user)
259 String preVspName = vspInfoDao
260 .get(new VspDetails(vendorSoftwareProductId, version)).getName();
262 Version newVersion = versioningManager.undoCheckout(
263 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
264 vendorSoftwareProductId, user);
266 String postVspName = vspInfoDao
267 .get(new VspDetails(vendorSoftwareProductId, newVersion))
270 updateUniqueName(preVspName, postVspName);
272 mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
278 public Version checkin(String vendorSoftwareProductId, String user) {
279 mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
281 Version newVersion = versioningManager.checkin(
282 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
283 vendorSoftwareProductId, user, null);
285 if (newVersion != null) {
286 ActivityLogEntity activityLogEntity =
287 new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1),
288 ActivityType.CHECKIN.toString(), user, true, "", "");
289 activityLogManager.addActionLog(activityLogEntity, user);
292 mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
298 public ValidationResponse submit(String vspId, String user) throws IOException {
299 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
301 Version version = getVersionInfo(vspId, VersionableEntityAction.Read, user).getActiveVersion();
302 VspDetails vspDetails = getVsp(vspId, version, user);
303 UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
304 ToscaServiceModel serviceModel =
305 serviceModelDao.getServiceModel(vspId, vspDetails.getVersion());
307 ValidationResponse validationResponse = new ValidationResponse();
309 .setVspErrors(validateCompletedVendorSoftwareProduct(vspDetails, uploadData, serviceModel),
310 LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP);
312 if (isCyclicDependencyInComponents(vspId, vspDetails.getVersion())) {
313 Collection<ErrorCode> vspErrors = validationResponse.getVspErrors() == null
315 : validationResponse.getVspErrors();
316 vspErrors.add(ComponentDependencyModelErrorBuilder
317 .getcyclicDependencyComponentErrorBuilder());
318 validationResponse.setVspErrors(vspErrors, LoggerServiceName.Submit_VSP,
319 LoggerTragetServiceName.SUBMIT_VSP);
322 validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
324 .setUploadDataErrors(validateUploadData(uploadData, vspDetails),
325 LoggerServiceName.Submit_VSP,
326 LoggerTragetServiceName.SUBMIT_VSP);
328 validationResponse.setQuestionnaireValidationResult(
329 validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), vspDetails
330 .getOnboardingMethod()));
332 if (vspDetails.getOnboardingMethod().equals("Manual")) {
333 Collection<ErrorCode> deploymentFlavourValidationErrList =
334 deploymentFlavorValidation(vspDetails.getId(), vspDetails.getVersion());
335 if (validationResponse.getVspErrors() != null) {
336 if (deploymentFlavourValidationErrList != null) {
337 validationResponse.getVspErrors().addAll(deploymentFlavourValidationErrList);
341 .setVspErrors(deploymentFlavourValidationErrList, LoggerServiceName.Submit_VSP,
342 LoggerTragetServiceName.SUBMIT_VSP);
345 Set<CompositionEntityValidationData> compositionEntityValidationData =
346 componentValidation(vspDetails.getId(), vspDetails.getVersion());
347 if (validationResponse.getQuestionnaireValidationResult() != null) {
348 if (!CollectionUtils.isEmpty(compositionEntityValidationData)) {
349 validationResponse.getQuestionnaireValidationResult().getValidationData()
350 .addAll(compositionEntityValidationData);
353 validationResponse.setQuestionnaireValidationResult(
354 CollectionUtils.isEmpty(compositionEntityValidationData) ? null :
355 new QuestionnaireValidationResult(compositionEntityValidationData));
358 //Generate Tosca service model for Manual Onboarding flow
359 VspModelInfo vspModelInfo = manualVspToscaManager.gatherVspInformation(vspId, version, user);
360 serviceModel = manualVspToscaManager.generateToscaModel(vspModelInfo);
362 validationResponse.setCompilationErrors(
363 compile(vspId, vspDetails.getVersion(), serviceModel),
364 LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP);
366 if (validationResponse.isValid()) {
367 Version newVersion = versioningManager.submit(
368 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
370 ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String
371 .valueOf(newVersion.getMajor()),
372 ActivityType.SUBMIT.toString(), user, true, "", "");
373 activityLogManager.addActionLog(activityLogEntity, user);
376 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
377 return validationResponse;
380 private boolean isCyclicDependencyInComponents(String vendorSoftwareProductId,
382 final Collection<ComponentDependencyModelEntity> componentDependencyModelEntities =
383 vendorSoftwareProductDao.listComponentDependencies(vendorSoftwareProductId, version);
384 ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker();
386 for (ComponentDependencyModelEntity entity : componentDependencyModelEntities) {
387 dependencyTracker.addDependency(entity.getSourceComponentId(), entity.getTargetComponentId());
389 return dependencyTracker.isCyclicDependencyPresent();
392 private Collection<ErrorCode> deploymentFlavorValidation(String vspId,
394 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
395 Set<CompositionEntityValidationData> validationData = new HashSet<>();
396 Collection<ErrorCode> errorCodeList = new ArrayList<>();
397 Collection<DeploymentFlavorEntity> deploymentFlavors =
398 vendorSoftwareProductDao.listDeploymentFlavors(vspId, version);
399 if (!CollectionUtils.isEmpty(deploymentFlavors)) {
400 deploymentFlavors.forEach(deploymentFlavor -> {
401 DeploymentFlavorEntity deployment = vendorSoftwareProductDao.getDeploymentFlavor(vspId,
402 version, deploymentFlavor.getId());
403 DeploymentFlavor deploymentlocalFlavor = deployment.getDeploymentFlavorCompositionData();
404 if (deploymentlocalFlavor != null) {
405 if (deploymentlocalFlavor.getFeatureGroupId() == null) {
406 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
407 getFeatureGroupMandatoryErrorBuilder(deploymentlocalFlavor.getModel());
408 errorCodeList.add(deploymentFlavorErrorBuilder);
410 List<ComponentComputeAssociation> componetComputeAssociations = new ArrayList<>();
411 componetComputeAssociations = deploymentlocalFlavor.getComponentComputeAssociations();
412 if (CollectionUtils.isEmpty(componetComputeAssociations)) {
413 CompositionEntityValidationData compositionEntityValidationData = new
414 CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
416 compositionEntityValidationData.setEntityName(deployment
417 .getDeploymentFlavorCompositionData().getModel());
418 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
419 .getInvalidComponentComputeAssociationErrorBuilder(
420 deploymentlocalFlavor.getModel());
422 errorCodeList.add(deploymentFlavorErrorBuilder);
424 componetComputeAssociations.forEach(componetComputeAssociation -> {
425 if (componetComputeAssociation == null
426 || !(componetComputeAssociation.getComponentId() != null
427 && componetComputeAssociation.getComputeFlavorId() != null)) {
428 CompositionEntityValidationData compositionEntityValidationData = new
429 CompositionEntityValidationData(CompositionEntityType.deployment,
430 deploymentFlavor.getId());
431 compositionEntityValidationData.setEntityName(deployment
432 .getDeploymentFlavorCompositionData().getModel());
433 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
434 .getInvalidComponentComputeAssociationErrorBuilder(
435 deploymentlocalFlavor.getModel());
437 errorCodeList.add(deploymentFlavorErrorBuilder);
444 return errorCodeList;
447 private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
448 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
450 Set<CompositionEntityValidationData> validationData = new HashSet<>();
451 Collection<ComponentEntity> components =
452 vendorSoftwareProductDao.listComponents(vspId, version);
453 if (!CollectionUtils.isEmpty(components)) {
454 components.forEach(component -> {
455 validateImage(vspId, version, validationData, component);
456 validateNic(vspId, version, validationData, component);
461 return validationData;
464 private void validateNic(String vspId, Version version,
465 Set<CompositionEntityValidationData> validationData,
466 ComponentEntity component) {
467 Collection<NicEntity> nics =
468 nicDao.list(new NicEntity(vspId, version, component.getId(), null));
469 if (CollectionUtils.isNotEmpty(nics)) {
470 nics.forEach(nicEntity -> {
471 NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(),
473 NetworkType networkType = nic.getNicCompositionData().getNetworkType();
474 String networkId = nic.getNicCompositionData().getNetworkId();
475 if (networkType.equals(NetworkType.Internal) && networkId == null) {
476 CompositionEntityValidationData compositionEntityValidationData = new
477 CompositionEntityValidationData(CompositionEntityType.nic, nic.getId());
478 compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName());
479 ErrorCode nicInternalNetworkErrorBuilder = NicInternalNetworkErrorBuilder
480 .getNicNullNetworkIdInternalNetworkIdErrorBuilder();
481 List<String> errors = new ArrayList<>();
482 errors.add(nicInternalNetworkErrorBuilder.message());
483 compositionEntityValidationData.setErrors(errors);
484 validationData.add(compositionEntityValidationData);
490 private void validateImage(String vspId, Version version,
491 Set<CompositionEntityValidationData> validationData,
492 ComponentEntity component) {
493 Collection<ImageEntity> images = vendorSoftwareProductDao.listImages(vspId, version,
495 if (CollectionUtils.isEmpty(images)) {
496 CompositionEntityValidationData compositionEntityValidationData = new
497 CompositionEntityValidationData(component.getType(), component.getId());
498 compositionEntityValidationData.setEntityName(component.getComponentCompositionData()
500 ErrorCode vfcMissingImageErrorBuilder =
501 ComponentErrorBuilder.VfcMissingImageErrorBuilder();
502 List<String> errors = new ArrayList<>();
503 errors.add(vfcMissingImageErrorBuilder.message());
504 compositionEntityValidationData.setErrors(errors);
505 validationData.add(compositionEntityValidationData);
510 private List<ErrorCode> validateCompletedVendorSoftwareProduct(
511 VspDetails vspDetails, UploadDataEntity uploadData, Object serviceModel) {
513 List<ErrorCode> errors = new ArrayList<>();
515 if (vspDetails.getName() == null) {
516 errors.add(createMissingMandatoryFieldError("name"));
518 if (vspDetails.getDescription() == null) {
519 errors.add(createMissingMandatoryFieldError("description"));
521 if (vspDetails.getVendorId() == null) {
522 errors.add(createMissingMandatoryFieldError("vendor Id"));
524 if (vspDetails.getCategory() == null) {
525 errors.add(createMissingMandatoryFieldError("category"));
527 if (vspDetails.getSubCategory() == null) {
528 errors.add(createMissingMandatoryFieldError("sub category"));
530 if (vspDetails.getOnboardingMethod().equals("Manual")) {
531 //Manual Onboarding specific validations
532 Collection<DeploymentFlavorEntity> deploymentFlavorEntities = vendorSoftwareProductDao
533 .listDeploymentFlavors(vspDetails.getId(), vspDetails.getVersion());
534 if (CollectionUtils.isEmpty(deploymentFlavorEntities)) {
535 ErrorCode vspMissingDeploymentFlavorErrorBuilder =
536 VendorSoftwareProductInvalidErrorBuilder.VspMissingDeploymentFlavorErrorBuilder();
537 errors.add(vspMissingDeploymentFlavorErrorBuilder);
539 errors.addAll(validateMandatoryLicenseFields(vspDetails));
541 //Heat flow specific VSP validations
542 if (uploadData == null || uploadData.getContentData() == null || serviceModel == null) {
543 errors.add(VendorSoftwareProductInvalidErrorBuilder
544 .VendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
545 vspDetails.getVersion()));
547 if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
548 || vspDetails.getFeatureGroups() != null) {
549 errors.addAll(validateMandatoryLicenseFields(vspDetails));
552 return errors.isEmpty() ? null : errors;
555 private List<ErrorCode> validateMandatoryLicenseFields(VspDetails vspDetails) {
556 List<ErrorCode> errors = new ArrayList<>();
557 if (vspDetails.getVlmVersion() == null) {
558 errors.add(createMissingMandatoryFieldError(
559 "licensing version (in the format of: {integer}.{integer})"));
561 if (vspDetails.getLicenseAgreement() == null) {
562 errors.add(createMissingMandatoryFieldError("license agreement"));
564 if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
565 errors.add(createMissingMandatoryFieldError("feature groups"));
570 private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
571 return new ValidationErrorBuilder("must be supplied", fieldName).build();
574 String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
575 mdcDataDebugMessage.debugEntryMessage(null);
576 mdcDataDebugMessage.debugExitMessage(null);
577 return SchemaGenerator
578 .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
581 private static void sortVspListByModificationTimeDescOrder(
582 List<VersionedVendorSoftwareProductInfo> vsps) {
583 vsps.sort((o1, o2) -> o2.getVspDetails().getWritetimeMicroSeconds()
584 .compareTo(o1.getVspDetails().getWritetimeMicroSeconds()));
588 private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
589 ToscaServiceModel serviceModel) {
590 if (serviceModel == null) {
594 enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version);
596 EnrichmentManager<ToscaServiceModel> enrichmentManager =
597 EnrichmentManagerFactory.getInstance().createInterface();
598 enrichmentManager.init(vendorSoftwareProductId, version);
599 enrichmentManager.setModel(serviceModel);
600 Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
602 if (MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, enrichErrors))) {
603 logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.ENRICHMENT_COMPLETED
604 + vendorSoftwareProductId);
606 enrichErrors.values().forEach(errorList ->
607 auditIfContainsErrors(errorList, vendorSoftwareProductId,
608 AuditMessages.ENRICHMENT_ERROR));
611 enrichedServiceModelDao
612 .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
617 private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
618 mdcDataDebugMessage.debugEntryMessage("VSP id", vspDetails.getId());
620 if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
621 || vspDetails.getLicenseAgreement() == null
622 || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
626 mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId());
627 return vendorLicenseFacade
628 .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
629 vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
633 public String fetchValidationVsp(String user) {
635 validateUniqueName(VALIDATION_VSP_NAME);
636 } catch (Exception ignored) {
637 return VALIDATION_VSP_ID;
639 VspDetails validationVsp = new VspDetails();
640 validationVsp.setName(VALIDATION_VSP_NAME);
642 vspInfoDao.create(validationVsp);
643 Version version = versioningManager.create(
644 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
645 validationVsp.getId(), user);
646 validationVsp.setVersion(version);
648 createUniqueName(VALIDATION_VSP_NAME);
649 VALIDATION_VSP_ID = validationVsp.getId();
650 return VALIDATION_VSP_ID;
654 public VspDetails createVsp(VspDetails vspDetails, String user) {
655 mdcDataDebugMessage.debugEntryMessage(null);
657 validateUniqueName(vspDetails.getName());
659 vspDetails.setOnboardingOrigin(OnboardingTypesEnum.NONE.toString());
661 vspInfoDao.create(vspDetails);//id will be set in the dao
662 vspInfoDao.updateQuestionnaireData(vspDetails.getId(), null,
663 new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
665 Version version = versioningManager
666 .create(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
667 vspDetails.getId(), user);
668 vspDetails.setVersion(version);
669 ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String
670 .valueOf(vspDetails.getVersion().getMajor() + 1),
671 ActivityType.CREATE_NEW.toString(), user, true, "", "");
672 activityLogManager.addActionLog(activityLogEntity, user);
673 String vspName = vspDetails.getName();
674 createUniqueName(vspName);
675 mdcDataDebugMessage.debugExitMessage(null);
680 public List<VersionedVendorSoftwareProductInfo> listVsps(String versionFilter, String user) {
681 mdcDataDebugMessage.debugEntryMessage(null);
683 Map<String, VersionInfo> idToVersionsInfo = versioningManager.listEntitiesVersionInfo(
684 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user,
685 VersionableEntityAction.Read);
687 List<VersionedVendorSoftwareProductInfo> vsps = new ArrayList<>();
688 for (Map.Entry<String, VersionInfo> entry : idToVersionsInfo.entrySet()) {
689 VersionInfo versionInfo = entry.getValue();
690 if (versionFilter != null && versionFilter.equals(VersionStatus.Final.name())) {
691 if (versionInfo.getLatestFinalVersion() == null) {
694 versionInfo.setActiveVersion(versionInfo.getLatestFinalVersion());
695 versionInfo.setStatus(VersionStatus.Final);
696 versionInfo.setLockingUser(null);
699 Version version = versionInfo.getActiveVersion();
700 if (user.equals(versionInfo.getLockingUser())) {
701 version.setStatus(VersionStatus.Locked);
704 VspDetails vsp = vspInfoDao.get(new VspDetails(entry.getKey(), version));
705 if (vsp != null && !vsp.getId().equals(VALIDATION_VSP_ID)) {
706 vsp.setValidationDataStructure(null);
707 vsps.add(new VersionedVendorSoftwareProductInfo(vsp, versionInfo));
709 } catch (RuntimeException rte) {
711 "Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString
718 sortVspListByModificationTimeDescOrder(vsps);
720 mdcDataDebugMessage.debugExitMessage(null);
726 public void updateVsp(VspDetails vspDetails, String user) {
727 mdcDataDebugMessage.debugEntryMessage("VSP id", vspDetails.getId());
729 VspDetails retrieved = vspInfoDao.get(vspDetails);
730 if (!retrieved.getOnboardingMethod().equals(vspDetails.getOnboardingMethod())) {
731 final ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
732 .getOnboardingUpdateError();
734 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
735 LoggerTragetServiceName.UPDATE_VSP, ErrorLevel.ERROR.name(),
736 LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message());
738 throw new CoreException(onboardingMethodUpdateErrorCode);
741 //If any existing feature group is removed from VSP which is also associated in DF then
742 //update DF to remove feature group associations.
743 updateDeploymentFlavor(vspDetails, user);
745 updateUniqueName(retrieved.getName(), vspDetails.getName());
746 vspDetails.setOldVersion(retrieved.getOldVersion());
748 vspInfoDao.update(vspDetails);
749 //vendorSoftwareProductDao.updateVspLatestModificationTime(vspDetails.getId(), activeVersion);
751 mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId());
754 private void updateDeploymentFlavor(VspDetails vspDetails, String user) {
755 final List<String> featureGroups = vspDetails.getFeatureGroups();
756 if (featureGroups != null) {
757 final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao
758 .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails
759 .getVersion(), null));
760 if (Objects.nonNull(deploymentFlavorEntities)) {
761 deploymentFlavorEntities.forEach(deploymentFlavorEntity -> {
762 final String featureGroupId =
763 deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId();
764 if (!featureGroups.contains(featureGroupId)) {
765 DeploymentFlavor deploymentFlavorCompositionData =
766 deploymentFlavorEntity.getDeploymentFlavorCompositionData();
767 deploymentFlavorCompositionData.setFeatureGroupId(null);
768 deploymentFlavorEntity.setDeploymentFlavorCompositionData
769 (deploymentFlavorCompositionData);
770 vendorSoftwareProductDao.updateDeploymentFlavor(deploymentFlavorEntity);
779 public VspDetails getVsp(String vspId, Version version, String user) {
780 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
782 VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
784 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
785 LoggerTragetServiceName.GET_VSP, ErrorLevel.ERROR.name(),
786 LoggerErrorCode.DATA_ERROR.getErrorCode(), "Requested VSP not found");
787 throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
789 vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version));
791 if (Objects.isNull(vsp.getOnboardingOrigin())) {
792 vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString());
795 if (Objects.isNull(vsp.getNetworkPackageName())) {
796 vsp.setNetworkPackageName("Upload File");
799 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
804 public Version callAutoHeal(String vspId, VersionInfo versionInfo,
805 VspDetails vendorSoftwareProductInfo, String user)
807 switch (versionInfo.getStatus()) {
809 if (user.equals(versionInfo.getLockingUser())) {
810 autoHeal(vspId, versionInfo.getActiveVersion(), vendorSoftwareProductInfo,
811 versionInfo.getLockingUser());
813 return versionInfo.getActiveVersion();
815 Version checkoutVersion = checkout(vspId, user);
816 autoHeal(vspId, checkoutVersion, vendorSoftwareProductInfo, user);
817 return checkin(vspId, user);
819 Version checkoutFinalVersion = checkout(vspId, user);
820 autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user);
821 Version checkinFinalVersion = checkin(vspId, user);
822 ValidationResponse response = submit(vspId, user);
823 if (!response.isValid()) {
824 return checkout(vspId, user);
828 Version finalVersion = checkinFinalVersion.calculateNextFinal();
829 createPackage(vspId, finalVersion, user);
831 } catch (IOException ex) {
832 throw new Exception(ex.getMessage());
838 return versionInfo.getActiveVersion();
843 public void deleteVsp(String vspId, String user) {
844 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
846 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
847 LoggerTragetServiceName.DELETE_VSP, ErrorLevel.ERROR.name(),
848 LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Unsupported operation");
849 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
851 throw new UnsupportedOperationException(
852 VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR);
856 public void heal(String vspId, Version version, String user) {
857 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
859 VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
861 version = VersionStatus.Locked.equals(versionInfo.getStatus())
862 ? versionInfo.getActiveVersion()
863 : checkout(vspId, user);
864 version.setStatus(VersionStatus.Locked);
866 Optional<String> errorMessages =
867 healingManager.healAll(getHealingParamsAsMap(vspId, version, user));
869 VspDetails vspDetails = new VspDetails(vspId, version);
870 vspDetails.setOldVersion(null);
871 vspInfoDao.updateOldVersionIndication(vspDetails);
873 logger.audit("Healed VSP " + vspDetails.getId());
874 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
876 if (errorMessages.isPresent()) {
877 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
878 .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
882 private void autoHeal(String vspId, Version checkoutVersion, VspDetails vspDetails, String user) {
883 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
885 checkoutVersion.setStatus(VersionStatus.Locked);
886 Map<String, Object> healingParams = getHealingParamsAsMap(vspId, checkoutVersion, user);
888 Optional<String> errorMessages = healingManager.healAll(healingParams);
890 vspDetails.setVersion(checkoutVersion);
891 vspDetails.setOldVersion(null);
892 vspInfoDao.updateOldVersionIndication(vspDetails);
894 logger.audit("Healed VSP " + vspDetails.getName());
895 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
897 if (errorMessages.isPresent()) {
898 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
899 .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
903 private Map<String, Object> getHealingParamsAsMap(String vspId, Version version, String user) {
904 Map<String, Object> healingParams = new HashMap<>();
906 healingParams.put(SdcCommon.VSP_ID, vspId);
907 healingParams.put(SdcCommon.VERSION, version);
908 healingParams.put(SdcCommon.USER, user);
910 return healingParams;
914 public List<PackageInfo> listPackages(String category, String subCategory) {
915 return packageInfoDao.listByCategory(category, subCategory);
919 public File getTranslatedFile(String vspId, Version version, String user) {
920 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
922 if (version == null) {
923 errorMessage = "Package not found";
924 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
925 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
926 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
927 throw new CoreException(new PackageNotFoundErrorBuilder(vspId).build());
928 } else if (!version.isFinal()) {
929 errorMessage = "Invalid requested version";
930 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
931 LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
932 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
933 throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
936 PackageInfo packageInfo =
937 packageInfoDao.get(new PackageInfo(vspId, version));
938 if (packageInfo == null) {
939 errorMessage = "Package not found";
940 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
941 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
942 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
943 throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
946 ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
947 if (translatedFileBuffer == null) {
948 errorMessage = "Package not found";
949 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
950 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
951 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
952 throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
955 File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
958 FileOutputStream fos = new FileOutputStream(translatedFile);
959 fos.write(translatedFileBuffer.array());
961 } catch (IOException exception) {
962 errorMessage = "Can't create package";
963 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
964 LoggerTragetServiceName.CREATE_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
965 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
966 throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(),
970 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
972 return translatedFile;
977 public byte[] getOrchestrationTemplateFile(String vspId, Version version, String user) {
978 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
980 UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
981 ByteBuffer contentData = uploadData.getContentData();
982 if (contentData == null) {
986 ByteArrayOutputStream baos = new ByteArrayOutputStream();
988 try (final ZipOutputStream zos = new ZipOutputStream(baos);
989 ZipInputStream zipStream = new ZipInputStream(
990 new ByteArrayInputStream(contentData.array()))) {
991 zos.write(contentData.array());
992 } catch (IOException exception) {
993 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
994 LoggerTragetServiceName.GET_UPLOADED_HEAT, ErrorLevel.ERROR.name(),
995 LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get uploaded HEAT");
996 throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
999 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1000 return baos.toByteArray();
1004 public PackageInfo createPackage(String vspId, Version version, String user) throws IOException {
1005 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
1007 if (!version.isFinal()) {
1008 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
1009 LoggerTragetServiceName.CREATE_PACKAGE, ErrorLevel.ERROR.name(),
1010 LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't create package");
1011 throw new CoreException(
1012 new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version)
1016 ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version);
1017 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
1018 Version vlmVersion = vspDetails.getVlmVersion();
1020 PackageInfo packageInfo = createPackageInfo(vspId, vspDetails);
1022 ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar =
1023 new ToscaFileOutputServiceCsarImpl();
1024 FileContentHandler licenseArtifacts = licenseArtifactsService
1025 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
1026 vspDetails.getFeatureGroups(), user);
1027 //todo add tosca validation here
1028 packageInfo.setTranslatedFile(ByteBuffer.wrap(
1029 toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
1031 packageInfoDao.create(packageInfo);
1033 logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_PACKAGE + vspId);
1035 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1039 private PackageInfo createPackageInfo(String vspId, VspDetails vspDetails) {
1040 PackageInfo packageInfo = new PackageInfo();
1041 packageInfo.setVspId(vspId);
1042 packageInfo.setVersion(vspDetails.getVersion());
1043 packageInfo.setVspName(vspDetails.getName());
1044 packageInfo.setVspDescription(vspDetails.getDescription());
1045 packageInfo.setCategory(vspDetails.getCategory());
1046 packageInfo.setSubCategory(vspDetails.getSubCategory());
1047 packageInfo.setVendorName(vspDetails.getVendorName());
1048 packageInfo.setPackageType(VendorSoftwareProductConstants.CSAR);
1049 packageInfo.setVendorRelease("1.0"); //todo TBD
1055 public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version, String user) {
1056 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
1058 VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
1059 VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
1060 VspDetails.ENTITY_TYPE);
1062 String questionnaireData = retrieved.getQuestionnaireData();
1064 QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
1065 questionnaireResponse.setData(questionnaireData);
1066 questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
1068 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1070 return questionnaireResponse;
1074 public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData,
1076 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
1078 vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
1080 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1084 private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData,
1085 VspDetails vspDetails)
1086 throws IOException {
1088 Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
1089 if (uploadData == null || uploadData.getContentData() == null) {
1093 FileContentHandler fileContentMap =
1094 CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.getOnboardingTypesEnum
1095 (vspDetails.getOnboardingOrigin()),
1096 uploadData.getContentData().array());
1098 if (vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.name().toLowerCase())) {
1099 ValidationManager validationManager =
1100 ValidationManagerUtil.initValidationManager(fileContentMap);
1101 validationErrors.putAll(validationManager.validate());
1105 MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors))
1106 ? null : validationErrors;
1109 private VersionInfo getVersionInfo(String vendorSoftwareProductId, VersionableEntityAction action,
1111 return versioningManager.getEntityVersionInfo(
1112 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
1113 vendorSoftwareProductId, user, action);
1117 private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
1118 String onboardingMethod) {
1119 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
1121 // The apis of CompositionEntityDataManager used here are stateful!
1122 // so, it must be re-created from scratch when it is used!
1123 CompositionEntityDataManager compositionEntityDataManager =
1124 CompositionEntityDataManagerFactory.getInstance().createInterface();
1125 compositionEntityDataManager
1126 .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null);
1128 Collection<NicEntity> nics = vendorSoftwareProductDao.listNicsByVsp(vspId, version);
1130 Map<String, List<String>> nicNamesByComponent = new HashMap<>();
1131 for (NicEntity nicEntity : nics) {
1132 compositionEntityDataManager.addEntity(nicEntity, null);
1134 Nic nic = nicEntity.getNicCompositionData();
1135 if (nic != null && nic.getName() != null) {
1136 List<String> nicNames =
1137 nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>());
1138 nicNames.add(nic.getName());
1142 Collection<ComponentEntity> components =
1143 vendorSoftwareProductDao.listComponentsCompositionAndQuestionnaire(vspId, version);
1144 components.forEach(component -> compositionEntityDataManager.addEntity(component,
1145 new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
1146 JsonUtil.json2Object(component.getQuestionnaireData(), Map.class))));
1148 Collection<ComputeEntity> computes = vendorSoftwareProductDao.listComputesByVsp(vspId, version);
1149 computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null));
1151 if ("Manual".equals(onboardingMethod)) {
1152 Collection<ImageEntity> images = vendorSoftwareProductDao.listImagesByVsp(vspId, version);
1153 images.forEach(image -> compositionEntityDataManager.addEntity(image, null));
1156 Map<CompositionEntityId, Collection<String>> errorsByEntityId =
1157 compositionEntityDataManager.validateEntitiesQuestionnaire();
1158 if (MapUtils.isNotEmpty(errorsByEntityId)) {
1159 compositionEntityDataManager.buildTrees();
1160 compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
1161 /* Set<CompositionEntityValidationData> entitiesWithValidationErrors =
1162 compositionEntityDataManager.getEntityListWithErrors();*/
1163 //Collection<CompositionEntityValidationData> roots = compositionEntityDataManager.getTrees();
1165 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1166 return new QuestionnaireValidationResult(
1167 compositionEntityDataManager.getAllErrorsByVsp(vspId));
1170 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1175 public File getInformationArtifact(String vspId, Version version, String user) {
1176 mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
1177 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
1179 if (vspDetails == null) {
1183 String vspName = vspDetails.getName();
1184 ByteBuffer infoArtifactAsByteBuffer;
1185 File infoArtifactFile;
1187 infoArtifactAsByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(vspId,
1188 version).getBytes());
1192 String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
1193 OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile));
1194 out.write(infoArtifactAsByteBuffer.array());
1196 } catch (IOException ex) {
1197 throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
1200 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
1201 return infoArtifactFile;
1204 void validateUniqueName(String vspName) {
1205 UniqueValueUtil.validateUniqueValue(
1206 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName);
1209 void createUniqueName(String vspName) {
1210 UniqueValueUtil.createUniqueValue(
1211 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName);
1214 void updateUniqueName(String oldVspName, String newVspName) {
1215 UniqueValueUtil.updateUniqueValue(
1216 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
1217 oldVspName, newVspName);
1221 public Collection<ComputeEntity> getComputeByVsp(String vspId, Version version,
1223 return vendorSoftwareProductDao.listComputesByVsp(vspId, version);
1226 private void auditIfContainsErrors(List<ErrorMessage> errorList, String vspId, String auditType) {
1228 errorList.forEach(errorMessage -> {
1229 if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
1230 logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),