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 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 final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
150 private static final Logger LOGGER =
151 LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class);
153 private final OrchestrationTemplateDao orchestrationTemplateDao;
154 private final VendorSoftwareProductInfoDao vspInfoDao;
155 private final VersioningManager versioningManager;
156 private final VendorSoftwareProductDao vendorSoftwareProductDao;
157 private final VendorLicenseFacade vendorLicenseFacade;
158 private final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
159 private final EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
160 private final HealingManager healingManager;
161 private final VendorLicenseArtifactsService licenseArtifactsService;
162 private final InformationArtifactGenerator informationArtifactGenerator;
163 private final PackageInfoDao packageInfoDao;
164 private final ActivityLogManager activityLogManager;
165 private final DeploymentFlavorDao deploymentFlavorDao;
166 private final NicDao nicDao;
167 private final 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 MDC_DATA_DEBUG_MESSAGE.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 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
253 public Version undoCheckout(String vendorSoftwareProductId, String user) {
254 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vendorSoftwareProductId);
257 getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user)
260 ActivityLogEntity activityLogEntity =
261 new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(version.getMajor() + 1),
262 ActivityType.UNDO_CHECKOUT.toString(), user, true, "", "");
263 activityLogManager.addActionLog(activityLogEntity, user);
265 String preVspName = vspInfoDao
266 .get(new VspDetails(vendorSoftwareProductId, version)).getName();
268 Version newVersion = versioningManager.undoCheckout(
269 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
270 vendorSoftwareProductId, user);
272 String postVspName = vspInfoDao
273 .get(new VspDetails(vendorSoftwareProductId, newVersion))
276 updateUniqueName(preVspName, postVspName);
278 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
284 public Version checkin(String vendorSoftwareProductId, String user) {
285 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vendorSoftwareProductId);
287 Version newVersion = versioningManager.checkin(
288 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
289 vendorSoftwareProductId, user, null);
291 if (newVersion != null) {
292 ActivityLogEntity activityLogEntity =
293 new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1),
294 ActivityType.CHECKIN.toString(), user, true, "", "");
295 activityLogManager.addActionLog(activityLogEntity, user);
298 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
304 public ValidationResponse submit(String vspId, String user) throws IOException {
305 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
307 Version version = getVersionInfo(vspId, VersionableEntityAction.Read, user).getActiveVersion();
308 VspDetails vspDetails = getVsp(vspId, version, user);
309 UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
310 ToscaServiceModel serviceModel =
311 serviceModelDao.getServiceModel(vspId, vspDetails.getVersion());
313 ValidationResponse validationResponse = new ValidationResponse();
315 .setVspErrors(validateCompletedVendorSoftwareProduct(vspDetails, uploadData, serviceModel),
316 LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP);
318 if (isCyclicDependencyInComponents(vspId, vspDetails.getVersion())) {
319 Collection<ErrorCode> vspErrors = validationResponse.getVspErrors() == null
321 : validationResponse.getVspErrors();
322 vspErrors.add(ComponentDependencyModelErrorBuilder
323 .getcyclicDependencyComponentErrorBuilder());
324 validationResponse.setVspErrors(vspErrors, LoggerServiceName.Submit_VSP,
325 LoggerTragetServiceName.SUBMIT_VSP);
328 validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
330 .setUploadDataErrors(validateUploadData(uploadData, vspDetails),
331 LoggerServiceName.Submit_VSP,
332 LoggerTragetServiceName.SUBMIT_VSP);
334 validationResponse.setQuestionnaireValidationResult(
335 validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), vspDetails
336 .getOnboardingMethod()));
338 if ("Manual".equals(vspDetails.getOnboardingMethod())) {
339 Collection<ErrorCode> deploymentFlavourValidationErrList =
340 deploymentFlavorValidation(vspDetails.getId(), vspDetails.getVersion());
341 if (validationResponse.getVspErrors() != null) {
342 if (deploymentFlavourValidationErrList != null) {
343 validationResponse.getVspErrors().addAll(deploymentFlavourValidationErrList);
347 .setVspErrors(deploymentFlavourValidationErrList, LoggerServiceName.Submit_VSP,
348 LoggerTragetServiceName.SUBMIT_VSP);
351 Set<CompositionEntityValidationData> compositionEntityValidationData =
352 componentValidation(vspDetails.getId(), vspDetails.getVersion());
353 if (validationResponse.getQuestionnaireValidationResult() != null) {
354 if (!CollectionUtils.isEmpty(compositionEntityValidationData)) {
355 validationResponse.getQuestionnaireValidationResult().getValidationData()
356 .addAll(compositionEntityValidationData);
359 validationResponse.setQuestionnaireValidationResult(
360 CollectionUtils.isEmpty(compositionEntityValidationData) ? null :
361 new QuestionnaireValidationResult(compositionEntityValidationData));
364 //Generate Tosca service model for Manual Onboarding flow
365 VspModelInfo vspModelInfo = manualVspToscaManager.gatherVspInformation(vspId, version, user);
366 serviceModel = manualVspToscaManager.generateToscaModel(vspModelInfo);
368 validationResponse.setCompilationErrors(
369 compile(vspId, vspDetails.getVersion(), serviceModel),
370 LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP);
372 if (validationResponse.isValid()) {
373 Version newVersion = versioningManager.submit(
374 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
376 ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String
377 .valueOf(newVersion.getMajor()),
378 ActivityType.SUBMIT.toString(), user, true, "", "");
379 activityLogManager.addActionLog(activityLogEntity, user);
382 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
383 return validationResponse;
386 private boolean isCyclicDependencyInComponents(String vendorSoftwareProductId,
388 final Collection<ComponentDependencyModelEntity> componentDependencyModelEntities =
389 vendorSoftwareProductDao.listComponentDependencies(vendorSoftwareProductId, version);
390 ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker();
392 for (ComponentDependencyModelEntity entity : componentDependencyModelEntities) {
393 dependencyTracker.addDependency(entity.getSourceComponentId(), entity.getTargetComponentId());
395 return dependencyTracker.isCyclicDependencyPresent();
398 private Collection<ErrorCode> deploymentFlavorValidation(String vspId,
400 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
401 Set<CompositionEntityValidationData> validationData = new HashSet<>();
402 Collection<ErrorCode> errorCodeList = new ArrayList<>();
403 Collection<DeploymentFlavorEntity> deploymentFlavors =
404 vendorSoftwareProductDao.listDeploymentFlavors(vspId, version);
405 if (!CollectionUtils.isEmpty(deploymentFlavors)) {
406 deploymentFlavors.forEach(deploymentFlavor -> {
407 DeploymentFlavorEntity deployment = vendorSoftwareProductDao.getDeploymentFlavor(vspId,
408 version, deploymentFlavor.getId());
409 DeploymentFlavor deploymentlocalFlavor = deployment.getDeploymentFlavorCompositionData();
410 if (deploymentlocalFlavor != null) {
411 if (deploymentlocalFlavor.getFeatureGroupId() == null) {
412 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
413 getFeatureGroupMandatoryErrorBuilder(deploymentlocalFlavor.getModel());
414 errorCodeList.add(deploymentFlavorErrorBuilder);
416 List<ComponentComputeAssociation> componetComputeAssociations =
417 deploymentlocalFlavor.getComponentComputeAssociations();
418 if (CollectionUtils.isEmpty(componetComputeAssociations)) {
419 CompositionEntityValidationData compositionEntityValidationData = new
420 CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
422 compositionEntityValidationData.setEntityName(deployment
423 .getDeploymentFlavorCompositionData().getModel());
424 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
425 .getInvalidComponentComputeAssociationErrorBuilder(
426 deploymentlocalFlavor.getModel());
428 errorCodeList.add(deploymentFlavorErrorBuilder);
430 componetComputeAssociations.forEach(componetComputeAssociation -> {
431 if (componetComputeAssociation == null
432 || !(componetComputeAssociation.getComponentId() != null
433 && componetComputeAssociation.getComputeFlavorId() != null)) {
434 CompositionEntityValidationData compositionEntityValidationData = new
435 CompositionEntityValidationData(CompositionEntityType.deployment,
436 deploymentFlavor.getId());
437 compositionEntityValidationData.setEntityName(deployment
438 .getDeploymentFlavorCompositionData().getModel());
439 ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
440 .getInvalidComponentComputeAssociationErrorBuilder(
441 deploymentlocalFlavor.getModel());
443 errorCodeList.add(deploymentFlavorErrorBuilder);
450 return errorCodeList;
453 private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
454 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
456 Set<CompositionEntityValidationData> validationData = new HashSet<>();
457 Collection<ComponentEntity> components =
458 vendorSoftwareProductDao.listComponents(vspId, version);
459 if (!CollectionUtils.isEmpty(components)) {
460 components.forEach(component -> {
461 validateImage(vspId, version, validationData, component);
462 validateNic(vspId, version, validationData, component);
467 return validationData;
470 private void validateNic(String vspId, Version version,
471 Set<CompositionEntityValidationData> validationData,
472 ComponentEntity component) {
473 Collection<NicEntity> nics =
474 nicDao.list(new NicEntity(vspId, version, component.getId(), null));
475 if (CollectionUtils.isNotEmpty(nics)) {
476 nics.forEach(nicEntity -> {
477 NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(),
479 NetworkType networkType = nic.getNicCompositionData().getNetworkType();
480 String networkId = nic.getNicCompositionData().getNetworkId();
481 if (networkType.equals(NetworkType.Internal) && networkId == null) {
482 CompositionEntityValidationData compositionEntityValidationData = new
483 CompositionEntityValidationData(CompositionEntityType.nic, nic.getId());
484 compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName());
485 ErrorCode nicInternalNetworkErrorBuilder = NicInternalNetworkErrorBuilder
486 .getNicNullNetworkIdInternalNetworkIdErrorBuilder();
487 List<String> errors = new ArrayList<>();
488 errors.add(nicInternalNetworkErrorBuilder.message());
489 compositionEntityValidationData.setErrors(errors);
490 validationData.add(compositionEntityValidationData);
496 private void validateImage(String vspId, Version version,
497 Set<CompositionEntityValidationData> validationData,
498 ComponentEntity component) {
499 Collection<ImageEntity> images = vendorSoftwareProductDao.listImages(vspId, version,
501 if (CollectionUtils.isEmpty(images)) {
502 CompositionEntityValidationData compositionEntityValidationData = new
503 CompositionEntityValidationData(component.getType(), component.getId());
504 compositionEntityValidationData.setEntityName(component.getComponentCompositionData()
506 ErrorCode vfcMissingImageErrorBuilder =
507 ComponentErrorBuilder.VfcMissingImageErrorBuilder();
508 List<String> errors = new ArrayList<>();
509 errors.add(vfcMissingImageErrorBuilder.message());
510 compositionEntityValidationData.setErrors(errors);
511 validationData.add(compositionEntityValidationData);
516 private List<ErrorCode> validateCompletedVendorSoftwareProduct(
517 VspDetails vspDetails, UploadDataEntity uploadData, Object serviceModel) {
519 List<ErrorCode> errors = new ArrayList<>();
521 if (vspDetails.getName() == null) {
522 errors.add(createMissingMandatoryFieldError("name"));
524 if (vspDetails.getDescription() == null) {
525 errors.add(createMissingMandatoryFieldError("description"));
527 if (vspDetails.getVendorId() == null) {
528 errors.add(createMissingMandatoryFieldError("vendor Id"));
530 if (vspDetails.getCategory() == null) {
531 errors.add(createMissingMandatoryFieldError("category"));
533 if (vspDetails.getSubCategory() == null) {
534 errors.add(createMissingMandatoryFieldError("sub category"));
536 if ("Manual".equals(vspDetails.getOnboardingMethod())) {
537 //Manual Onboarding specific validations
538 Collection<DeploymentFlavorEntity> deploymentFlavorEntities = vendorSoftwareProductDao
539 .listDeploymentFlavors(vspDetails.getId(), vspDetails.getVersion());
540 if (CollectionUtils.isEmpty(deploymentFlavorEntities)) {
541 ErrorCode vspMissingDeploymentFlavorErrorBuilder =
542 VendorSoftwareProductInvalidErrorBuilder.VspMissingDeploymentFlavorErrorBuilder();
543 errors.add(vspMissingDeploymentFlavorErrorBuilder);
545 errors.addAll(validateMandatoryLicenseFields(vspDetails));
547 //Heat flow specific VSP validations
548 if (uploadData == null || uploadData.getContentData() == null || serviceModel == null) {
549 errors.add(VendorSoftwareProductInvalidErrorBuilder
550 .VendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
551 vspDetails.getVersion()));
553 if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
554 || vspDetails.getFeatureGroups() != null) {
555 errors.addAll(validateMandatoryLicenseFields(vspDetails));
558 return errors.isEmpty() ? null : errors;
561 private List<ErrorCode> validateMandatoryLicenseFields(VspDetails vspDetails) {
562 List<ErrorCode> errors = new ArrayList<>();
563 if (vspDetails.getVlmVersion() == null) {
564 errors.add(createMissingMandatoryFieldError(
565 "licensing version (in the format of: {integer}.{integer})"));
567 if (vspDetails.getLicenseAgreement() == null) {
568 errors.add(createMissingMandatoryFieldError("license agreement"));
570 if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
571 errors.add(createMissingMandatoryFieldError("feature groups"));
576 private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
577 return new ValidationErrorBuilder("must be supplied", fieldName).build();
580 String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
581 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
582 MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
583 return SchemaGenerator
584 .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
587 private static void sortVspListByModificationTimeDescOrder(
588 List<VersionedVendorSoftwareProductInfo> vsps) {
589 vsps.sort((o1, o2) -> o2.getVspDetails().getWritetimeMicroSeconds()
590 .compareTo(o1.getVspDetails().getWritetimeMicroSeconds()));
594 private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
595 ToscaServiceModel serviceModel) {
596 if (serviceModel == null) {
600 enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version);
602 EnrichmentManager<ToscaServiceModel> enrichmentManager =
603 EnrichmentManagerFactory.getInstance().createInterface();
604 enrichmentManager.init(vendorSoftwareProductId, version);
605 enrichmentManager.setModel(serviceModel);
606 Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
608 if (MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, enrichErrors))) {
609 LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.ENRICHMENT_COMPLETED
610 + vendorSoftwareProductId);
612 enrichErrors.values().forEach(errorList ->
613 auditIfContainsErrors(errorList, vendorSoftwareProductId,
614 AuditMessages.ENRICHMENT_ERROR));
617 enrichedServiceModelDao
618 .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
623 private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
624 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspDetails.getId());
626 if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
627 || vspDetails.getLicenseAgreement() == null
628 || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
632 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspDetails.getId());
633 return vendorLicenseFacade
634 .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
635 vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
639 public String fetchValidationVsp(String user) {
641 validateUniqueName(VALIDATION_VSP_NAME);
642 } catch (Exception ignored) {
643 LOGGER.debug("Ignored exception when validating unique VSP name", ignored);
644 return VALIDATION_VSP_ID;
646 VspDetails validationVsp = new VspDetails();
647 validationVsp.setName(VALIDATION_VSP_NAME);
649 vspInfoDao.create(validationVsp);
650 Version version = versioningManager.create(
651 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
652 validationVsp.getId(), user);
653 validationVsp.setVersion(version);
655 createUniqueName(VALIDATION_VSP_NAME);
656 VALIDATION_VSP_ID = validationVsp.getId();
657 return VALIDATION_VSP_ID;
661 public VspDetails createVsp(VspDetails vspDetails, String user) {
662 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
664 validateUniqueName(vspDetails.getName());
666 vspDetails.setOnboardingOrigin(OnboardingTypesEnum.NONE.toString());
668 vspInfoDao.create(vspDetails);//id will be set in the dao
669 vspInfoDao.updateQuestionnaireData(vspDetails.getId(), null,
670 new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
672 Version version = versioningManager
673 .create(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
674 vspDetails.getId(), user);
675 vspDetails.setVersion(version);
676 ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String
677 .valueOf(vspDetails.getVersion().getMajor() + 1),
678 ActivityType.CREATE_NEW.toString(), user, true, "", "");
679 activityLogManager.addActionLog(activityLogEntity, user);
680 String vspName = vspDetails.getName();
681 createUniqueName(vspName);
682 MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
687 public List<VersionedVendorSoftwareProductInfo> listVsps(String versionFilter, String user) {
688 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
690 Map<String, VersionInfo> idToVersionsInfo = versioningManager.listEntitiesVersionInfo(
691 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user,
692 VersionableEntityAction.Read);
694 List<VersionedVendorSoftwareProductInfo> vsps = new ArrayList<>();
695 for (Map.Entry<String, VersionInfo> entry : idToVersionsInfo.entrySet()) {
696 VersionInfo versionInfo = entry.getValue();
697 if (versionFilter != null && versionFilter.equals(VersionStatus.Final.name())) {
698 if (versionInfo.getLatestFinalVersion() == null) {
701 versionInfo.setActiveVersion(versionInfo.getLatestFinalVersion());
702 versionInfo.setStatus(VersionStatus.Final);
703 versionInfo.setLockingUser(null);
706 Version version = versionInfo.getActiveVersion();
707 if (user.equals(versionInfo.getLockingUser())) {
708 version.setStatus(VersionStatus.Locked);
711 VspDetails vsp = vspInfoDao.get(new VspDetails(entry.getKey(), version));
712 if (vsp != null && !vsp.getId().equals(VALIDATION_VSP_ID)) {
713 vsp.setValidationDataStructure(null);
714 vsps.add(new VersionedVendorSoftwareProductInfo(vsp, versionInfo));
716 } catch (RuntimeException rte) {
718 "Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString
720 "message:" + rte.getMessage(), rte);
724 sortVspListByModificationTimeDescOrder(vsps);
726 MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
732 public void updateVsp(VspDetails vspDetails, String user) {
733 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspDetails.getId());
735 VspDetails retrieved = vspInfoDao.get(vspDetails);
736 if (!Objects.equals(retrieved.getOnboardingMethod(), vspDetails.getOnboardingMethod())) {
737 final ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
738 .getOnboardingUpdateError();
740 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
741 LoggerTragetServiceName.UPDATE_VSP, ErrorLevel.ERROR.name(),
742 LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message());
744 throw new CoreException(onboardingMethodUpdateErrorCode);
747 //If any existing feature group is removed from VSP which is also associated in DF then
748 //update DF to remove feature group associations.
749 updateDeploymentFlavor(vspDetails, user);
751 updateUniqueName(retrieved.getName(), vspDetails.getName());
752 vspDetails.setOldVersion(retrieved.getOldVersion());
754 vspInfoDao.update(vspDetails);
755 //vendorSoftwareProductDao.updateVspLatestModificationTime(vspDetails.getId(), activeVersion);
757 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspDetails.getId());
760 private void updateDeploymentFlavor(VspDetails vspDetails, String user) {
761 final List<String> featureGroups = vspDetails.getFeatureGroups();
762 if (featureGroups != null) {
763 final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao
764 .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails
765 .getVersion(), null));
766 if (Objects.nonNull(deploymentFlavorEntities)) {
767 deploymentFlavorEntities.forEach(deploymentFlavorEntity -> {
768 final String featureGroupId =
769 deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId();
770 if (!featureGroups.contains(featureGroupId)) {
771 DeploymentFlavor deploymentFlavorCompositionData =
772 deploymentFlavorEntity.getDeploymentFlavorCompositionData();
773 deploymentFlavorCompositionData.setFeatureGroupId(null);
774 deploymentFlavorEntity.setDeploymentFlavorCompositionData
775 (deploymentFlavorCompositionData);
776 vendorSoftwareProductDao.updateDeploymentFlavor(deploymentFlavorEntity);
785 public VspDetails getVsp(String vspId, Version version, String user) {
786 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
788 VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
790 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
791 LoggerTragetServiceName.GET_VSP, ErrorLevel.ERROR.name(),
792 LoggerErrorCode.DATA_ERROR.getErrorCode(), "Requested VSP not found");
793 throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
795 vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version));
796 if (Objects.isNull(vsp.getOnboardingOrigin())) { //todo should this only be done for non-Manual?
797 vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString());
800 if (Objects.isNull(vsp.getNetworkPackageName())) {
801 vsp.setNetworkPackageName("Upload File");
804 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
809 public Version callAutoHeal(String vspId, VersionInfo versionInfo,
810 VspDetails vendorSoftwareProductInfo, String user)
812 switch (versionInfo.getStatus()) {
814 if (user.equals(versionInfo.getLockingUser())) {
815 autoHeal(vspId, versionInfo.getActiveVersion(), vendorSoftwareProductInfo,
816 versionInfo.getLockingUser());
818 return versionInfo.getActiveVersion();
820 Version checkoutVersion = checkout(vspId, user);
821 autoHeal(vspId, checkoutVersion, vendorSoftwareProductInfo, user);
822 return checkin(vspId, user);
824 return healAndAdvanceFinalVersion(vspId, vendorSoftwareProductInfo, user);
829 return versionInfo.getActiveVersion();
832 public Version healAndAdvanceFinalVersion(String vspId, VspDetails vendorSoftwareProductInfo,
833 String user) throws IOException {
835 Version checkoutFinalVersion = checkout(vspId, user);
836 autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user);
837 Version checkinFinalVersion = checkin(vspId, user);
839 ValidationResponse response = Objects.requireNonNull(submit(vspId, user),
840 "Null response not expected");
842 if (!response.isValid()) {
843 return checkout(vspId, user);
846 Version finalVersion = checkinFinalVersion.calculateNextFinal();
847 createPackage(vspId, finalVersion, user);
853 public void deleteVsp(String vspId, String user) {
854 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
856 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
857 LoggerTragetServiceName.DELETE_VSP, ErrorLevel.ERROR.name(),
858 LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Unsupported operation");
859 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
861 throw new UnsupportedOperationException(
862 VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR);
866 public void heal(String vspId, Version version, String user) {
867 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
869 VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
871 version = VersionStatus.Locked.equals(versionInfo.getStatus())
872 ? versionInfo.getActiveVersion()
873 : checkout(vspId, user);
874 version.setStatus(VersionStatus.Locked);
876 Optional<String> errorMessages =
877 healingManager.healAll(getHealingParamsAsMap(vspId, version, user));
879 VspDetails vspDetails = new VspDetails(vspId, version);
880 vspDetails.setOldVersion(null);
881 vspInfoDao.updateOldVersionIndication(vspDetails);
883 LOGGER.audit("Healed VSP " + vspDetails.getId());
884 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
886 errorMessages.ifPresent(s -> {
887 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
888 .withCategory(ErrorCategory.APPLICATION).withMessage(s).build());
892 private void autoHeal(String vspId, Version checkoutVersion, VspDetails vspDetails, String user) {
893 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
895 checkoutVersion.setStatus(VersionStatus.Locked);
896 Map<String, Object> healingParams = getHealingParamsAsMap(vspId, checkoutVersion, user);
898 Optional<String> errorMessages = healingManager.healAll(healingParams);
900 vspDetails.setVersion(checkoutVersion);
901 vspDetails.setOldVersion(null);
902 vspInfoDao.updateOldVersionIndication(vspDetails);
904 LOGGER.audit("Healed VSP " + vspDetails.getName());
905 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
907 errorMessages.ifPresent(s -> {
908 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
909 .withCategory(ErrorCategory.APPLICATION).withMessage(s).build());
913 private Map<String, Object> getHealingParamsAsMap(String vspId, Version version, String user) {
914 Map<String, Object> healingParams = new HashMap<>();
916 healingParams.put(SdcCommon.VSP_ID, vspId);
917 healingParams.put(SdcCommon.VERSION, version);
918 healingParams.put(SdcCommon.USER, user);
920 return healingParams;
924 public List<PackageInfo> listPackages(String category, String subCategory) {
925 return packageInfoDao.listByCategory(category, subCategory);
929 public File getTranslatedFile(String vspId, Version version, String user) {
930 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
932 if (version == null) {
933 errorMessage = "Package not found";
934 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
935 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
936 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
937 throw new CoreException(new PackageNotFoundErrorBuilder(vspId).build());
938 } else if (!version.isFinal()) {
939 errorMessage = "Invalid requested version";
940 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
941 LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
942 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
943 throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
946 PackageInfo packageInfo =
947 packageInfoDao.get(new PackageInfo(vspId, version));
948 if (packageInfo == null) {
949 errorMessage = "Package not found";
950 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
951 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
952 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
953 throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
956 ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
957 if (translatedFileBuffer == null) {
958 errorMessage = "Package not found";
959 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
960 LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
961 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
962 throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
965 File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
967 try (FileOutputStream fos = new FileOutputStream(translatedFile)) {
968 fos.write(translatedFileBuffer.array());
969 } catch (IOException exception) {
970 errorMessage = "Can't create package";
971 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
972 LoggerTragetServiceName.CREATE_TRANSLATED_FILE, ErrorLevel.ERROR.name(),
973 LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage);
974 throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(),
978 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
980 return translatedFile;
985 public byte[] getOrchestrationTemplateFile(String vspId, Version version, String user) {
986 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
988 UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
989 ByteBuffer contentData = uploadData.getContentData();
990 if (contentData == null) {
994 ByteArrayOutputStream baos = new ByteArrayOutputStream();
996 try (final ZipOutputStream zos = new ZipOutputStream(baos);
997 ZipInputStream zipStream = new ZipInputStream(
998 new ByteArrayInputStream(contentData.array()))) {
999 zos.write(contentData.array());
1000 } catch (IOException exception) {
1001 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
1002 LoggerTragetServiceName.GET_UPLOADED_HEAT, ErrorLevel.ERROR.name(),
1003 LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get uploaded HEAT");
1004 throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
1007 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1008 return baos.toByteArray();
1012 public PackageInfo createPackage(String vspId, Version version, String user) throws IOException {
1013 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
1015 if (!version.isFinal()) {
1016 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
1017 LoggerTragetServiceName.CREATE_PACKAGE, ErrorLevel.ERROR.name(),
1018 LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't create package");
1019 throw new CoreException(
1020 new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version)
1024 ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version);
1025 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
1026 Version vlmVersion = vspDetails.getVlmVersion();
1028 PackageInfo packageInfo = createPackageInfo(vspId, vspDetails);
1030 ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar =
1031 new ToscaFileOutputServiceCsarImpl();
1032 FileContentHandler licenseArtifacts = licenseArtifactsService
1033 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
1034 vspDetails.getFeatureGroups(), user);
1035 //todo add tosca validation here
1036 packageInfo.setTranslatedFile(ByteBuffer.wrap(
1037 toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
1039 packageInfoDao.create(packageInfo);
1041 LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_PACKAGE + vspId);
1043 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1047 private PackageInfo createPackageInfo(String vspId, VspDetails vspDetails) {
1048 PackageInfo packageInfo = new PackageInfo();
1049 packageInfo.setVspId(vspId);
1050 packageInfo.setVersion(vspDetails.getVersion());
1051 packageInfo.setVspName(vspDetails.getName());
1052 packageInfo.setVspDescription(vspDetails.getDescription());
1053 packageInfo.setCategory(vspDetails.getCategory());
1054 packageInfo.setSubCategory(vspDetails.getSubCategory());
1055 packageInfo.setVendorName(vspDetails.getVendorName());
1056 packageInfo.setPackageType(VendorSoftwareProductConstants.CSAR);
1057 packageInfo.setVendorRelease("1.0"); //todo TBD
1063 public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version, String user) {
1064 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
1066 VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
1067 VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
1068 VspDetails.ENTITY_TYPE);
1070 String questionnaireData = retrieved.getQuestionnaireData();
1072 QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
1073 questionnaireResponse.setData(questionnaireData);
1074 questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
1076 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1078 return questionnaireResponse;
1082 public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData,
1084 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
1086 vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
1088 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1092 private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData,
1093 VspDetails vspDetails)
1094 throws IOException {
1096 Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
1097 if (uploadData == null || uploadData.getContentData() == null) {
1101 FileContentHandler fileContentMap =
1102 CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.getOnboardingTypesEnum
1103 (vspDetails.getOnboardingOrigin()),
1104 uploadData.getContentData().array());
1106 if (vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.name().toLowerCase())) {
1107 ValidationManager validationManager =
1108 ValidationManagerUtil.initValidationManager(fileContentMap);
1109 validationErrors.putAll(validationManager.validate());
1113 MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors))
1114 ? null : validationErrors;
1117 private VersionInfo getVersionInfo(String vendorSoftwareProductId, VersionableEntityAction action,
1119 return versioningManager.getEntityVersionInfo(
1120 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
1121 vendorSoftwareProductId, user, action);
1125 private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
1126 String onboardingMethod) {
1127 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
1129 // The apis of CompositionEntityDataManager used here are stateful!
1130 // so, it must be re-created from scratch when it is used!
1131 CompositionEntityDataManager compositionEntityDataManager =
1132 CompositionEntityDataManagerFactory.getInstance().createInterface();
1133 compositionEntityDataManager
1134 .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null);
1136 Collection<NicEntity> nics = vendorSoftwareProductDao.listNicsByVsp(vspId, version);
1138 Map<String, List<String>> nicNamesByComponent = new HashMap<>();
1139 for (NicEntity nicEntity : nics) {
1140 compositionEntityDataManager.addEntity(nicEntity, null);
1142 Nic nic = nicEntity.getNicCompositionData();
1143 if (nic != null && nic.getName() != null) {
1144 List<String> nicNames =
1145 nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>());
1146 nicNames.add(nic.getName());
1150 Collection<ComponentEntity> components =
1151 vendorSoftwareProductDao.listComponentsCompositionAndQuestionnaire(vspId, version);
1152 components.forEach(component -> compositionEntityDataManager.addEntity(component,
1153 new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
1154 JsonUtil.json2Object(component.getQuestionnaireData(), Map.class))));
1156 Collection<ComputeEntity> computes = vendorSoftwareProductDao.listComputesByVsp(vspId, version);
1157 computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null));
1159 if ("Manual".equals(onboardingMethod)) {
1160 Collection<ImageEntity> images = vendorSoftwareProductDao.listImagesByVsp(vspId, version);
1161 images.forEach(image -> compositionEntityDataManager.addEntity(image, null));
1164 Map<CompositionEntityId, Collection<String>> errorsByEntityId =
1165 compositionEntityDataManager.validateEntitiesQuestionnaire();
1166 if (MapUtils.isNotEmpty(errorsByEntityId)) {
1167 compositionEntityDataManager.buildTrees();
1168 compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
1169 /* Set<CompositionEntityValidationData> entitiesWithValidationErrors =
1170 compositionEntityDataManager.getEntityListWithErrors();*/
1171 //Collection<CompositionEntityValidationData> roots = compositionEntityDataManager.getTrees();
1173 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1174 return new QuestionnaireValidationResult(
1175 compositionEntityDataManager.getAllErrorsByVsp(vspId));
1178 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1183 public File getInformationArtifact(String vspId, Version version, String user) {
1184 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
1185 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
1187 if (vspDetails == null) {
1191 String vspName = vspDetails.getName();
1192 ByteBuffer infoArtifactAsByteBuffer;
1193 File infoArtifactFile;
1195 infoArtifactAsByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(vspId,
1196 version).getBytes());
1200 String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
1201 try (OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile))) {
1202 out.write(infoArtifactAsByteBuffer.array());
1205 } catch (IOException ex) {
1206 throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
1209 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
1210 return infoArtifactFile;
1213 void validateUniqueName(String vspName) {
1214 UniqueValueUtil.validateUniqueValue(
1215 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName);
1218 void createUniqueName(String vspName) {
1219 UniqueValueUtil.createUniqueValue(
1220 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName);
1223 void updateUniqueName(String oldVspName, String newVspName) {
1224 UniqueValueUtil.updateUniqueValue(
1225 VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
1226 oldVspName, newVspName);
1230 public Collection<ComputeEntity> getComputeByVsp(String vspId, Version version,
1232 return vendorSoftwareProductDao.listComputesByVsp(vspId, version);
1235 private void auditIfContainsErrors(List<ErrorMessage> errorList, String vspId, String auditType) {
1237 errorList.forEach(errorMessage -> {
1238 if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
1239 LOGGER.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),