diff options
author | shrikantawachar <shrikant.awachar@amdocs.com> | 2018-02-12 16:57:59 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-02-14 11:23:44 +0000 |
commit | 9f33060362b6bf8b3a7cdcdab6ce3d1c81946300 (patch) | |
tree | 4900df52242ab5804408ccda3e51159e344f01e4 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main | |
parent | 71904f241cd3047054dc0a36c04120a3f53205ae (diff) |
Enforcing HEAT validation after HEAT upload
Back end implementation , Junits for Enforcing HEAT validation after heat upload.
Change-Id: I0572b1d5e455023d45dc3b50b0bae7f3b6bbcc2e
Issue-ID: SDC-1027
Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main')
9 files changed, 177 insertions, 75 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java index 84318dbdd8..a28e2c8144 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorsoftwareproduct; @@ -46,4 +42,6 @@ public interface OrchestrationTemplateCandidateManager { Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException; OrchestrationTemplateCandidateData getInfo(String vspId, Version version); + + void abort(String vspId, Version version); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java index 2e38122856..7528110d37 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java @@ -1,21 +1,17 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorsoftwareproduct; @@ -27,6 +23,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.versioning.dao.types.Version; import java.io.File; @@ -34,6 +31,7 @@ import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; public interface VendorSoftwareProductManager { @@ -59,6 +57,7 @@ public interface VendorSoftwareProductManager { OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version); + Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId, Version version); PackageInfo createPackage(String vspId, Version version) throws IOException; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java index ca20d97e4a..c3a2862e39 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,13 @@ public class VendorSoftwareProductInvalidErrorBuilder { private static final String VSP_INVALID_MSG = "Vendor software product with Id %s and version %s is invalid - does not contain " + "service model."; - private static final String VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG = "VSP has to have a " + - "minimum of one Deployment Flavor defined for being able to be instantiated.Please add a Deployment Flavor and re-submit the VSP."; + private static final String VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG = "VSP has to have a " + + "minimum of one Deployment Flavor defined for being able to be instantiated.Please add a " + + "Deployment Flavor and re-submit the VSP."; + private static final String CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED = "Uploaded network package" + + " file %s was not processed/aborted."; + private static final String INVALID_PROCESSED_CANDIDATE = "Uploaded network package file %s" + + " is invalid and need to be aborted"; private VendorSoftwareProductInvalidErrorBuilder() { @@ -60,4 +65,25 @@ public class VendorSoftwareProductInvalidErrorBuilder { return builder.build(); } + public static ErrorCode candidateDataNotProcessedOrAbortedErrorBuilder(String fileName) { + ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes + .VSP_INVALID, ErrorCategory.APPLICATION); + builder.withMessage(String.format(CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED, fileName)); + return builder.build(); + } + + public static ErrorCode invalidProcessedCandidate(String fileName) { + ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes + .VSP_INVALID, ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_PROCESSED_CANDIDATE, fileName)); + return builder.build(); + } + + public static ErrorCode.ErrorCodeBuilder getErrorCodeBuilder(String errorCode, ErrorCategory + errorCategory) { + ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + builder.withId(errorCode); + builder.withCategory(errorCategory); + return builder; + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java index aa90b5dee6..97a4a213af 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ public class OrchestrationTemplateCandidateManagerImpl public OrchestrationTemplateCandidateManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, CandidateService candidateService - ) { + ) { this.vspInfoDao = vspInfoDao; this.candidateService = candidateService; } @@ -129,8 +129,8 @@ public class OrchestrationTemplateCandidateManagerImpl if (!candidateDataEntity.isPresent()) { ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage - (), "")); + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), + "")); LOGGER.error(errorMessage.getMessage()); return Optional.empty(); } @@ -157,6 +157,11 @@ public class OrchestrationTemplateCandidateManagerImpl return candidateService.getOrchestrationTemplateCandidateInfo(vspId, version); } + @Override + public void abort(String vspId, Version version) { + candidateService.deleteOrchestrationTemplateCandidate(vspId, version); + } + private Optional<OrchestrationTemplateCandidateData> fetchCandidateDataEntity( String vspId, Version version) { return Optional diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 78ce0787bf..cc24873e92 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsSe import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -63,6 +64,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; @@ -82,6 +84,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGe import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; @@ -114,6 +117,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -121,6 +125,7 @@ import java.util.zip.ZipOutputStream; public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager { private final OrchestrationTemplateDao orchestrationTemplateDao; + private final OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager; private final VendorSoftwareProductInfoDao vspInfoDao; private final VendorLicenseFacade vendorLicenseFacade; private final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao; @@ -137,22 +142,24 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private final ManualVspToscaManager manualVspToscaManager; public VendorSoftwareProductManagerImpl( - OrchestrationTemplateDao orchestrationTemplateDataDao, - VendorSoftwareProductInfoDao vspInfoDao, - VendorLicenseFacade vendorLicenseFacade, - ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao, - EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao, - VendorLicenseArtifactsService licenseArtifactsService, - InformationArtifactGenerator informationArtifactGenerator, - PackageInfoDao packageInfoDao, - DeploymentFlavorDao deploymentFlavorDao, - ComponentDao componentDao, - ComponentDependencyModelDao componentDependencyModelDao, - NicDao nicDao, - ComputeDao computeDao, - ImageDao imageDao, - ManualVspToscaManager manualVspToscaManager) { + OrchestrationTemplateDao orchestrationTemplateDataDao, + OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager, + VendorSoftwareProductInfoDao vspInfoDao, + VendorLicenseFacade vendorLicenseFacade, + ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao, + EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao, + VendorLicenseArtifactsService licenseArtifactsService, + InformationArtifactGenerator informationArtifactGenerator, + PackageInfoDao packageInfoDao, + DeploymentFlavorDao deploymentFlavorDao, + ComponentDao componentDao, + ComponentDependencyModelDao componentDependencyModelDao, + NicDao nicDao, + ComputeDao computeDao, + ImageDao imageDao, + ManualVspToscaManager manualVspToscaManager) { this.orchestrationTemplateDao = orchestrationTemplateDataDao; + this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager; this.vspInfoDao = vspInfoDao; this.vendorLicenseFacade = vendorLicenseFacade; this.serviceModelDao = serviceModelDao; @@ -170,6 +177,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa registerToVersioning(); } + private void registerToVersioning() { serviceModelDao.registerVersioning( VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); @@ -177,27 +185,19 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); } - @Override public ValidationResponse validate(String vspId, Version version) throws IOException { VspDetails vspDetails = getValidatedVsp(vspId, version); - Collection<ComponentDependencyModelEntity> componentDependencies = - componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null)); - - ValidationResponse validationResponse = new ValidationResponse(); - validationResponse.setQuestionnaireValidationResult( - validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), - vspDetails.getOnboardingMethod())); - List<ErrorCode> vspErrors = new ArrayList<>(validateVspFields(vspDetails)); - if (validateComponentDependencies(componentDependencies)) { - vspErrors - .add(ComponentDependencyModelErrorBuilder.getcyclicDependencyComponentErrorBuilder()); - } - if (Objects.nonNull(vspDetails.getOnboardingMethod()) && - OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) { + ValidationResponse validationResponse = new ValidationResponse(); + if (Objects.nonNull(vspDetails.getOnboardingMethod()) + && OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) { validateManualOnboardingMethod(vspDetails, validationResponse, vspErrors); } else { + validateOrchestrationTemplateCandidate(validationResponse, vspErrors, vspId, version); + if (!validationResponse.isValid()) { + return validationResponse; + } if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null || vspDetails.getFeatureGroups() != null) { vspErrors.addAll(validateMandatoryLicenseFields(vspDetails)); @@ -206,20 +206,59 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa orchestrationTemplateDao.get(vspId, version); ToscaServiceModel serviceModel = serviceModelDao.getServiceModel(vspId, vspDetails.getVersion()); - if (!isOrchestrationTemplateExist(orchestrationTemplate) || - !isServiceModelExist(serviceModel)) { + if (!isOrchestrationTemplateExist(orchestrationTemplate) + || !isServiceModelExist(serviceModel)) { vspErrors.add(VendorSoftwareProductInvalidErrorBuilder .vendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(), vspDetails.getVersion())); } validationResponse.setUploadDataErrors(validateOrchestrationTemplate(orchestrationTemplate)); } + Collection<ComponentDependencyModelEntity> componentDependencies = + componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null)); + + QuestionnaireValidationResult questionnaireValidationResult = validateQuestionnaire + (vspDetails.getId(), vspDetails.getVersion(), vspDetails.getOnboardingMethod()); + + if (Objects.nonNull(questionnaireValidationResult)) { + if (validationResponse.getQuestionnaireValidationResult() == null || validationResponse + .getQuestionnaireValidationResult().getValidationData() == null) { + validationResponse.setQuestionnaireValidationResult(questionnaireValidationResult); + } else { + validationResponse.getQuestionnaireValidationResult().getValidationData().addAll + (questionnaireValidationResult.getValidationData()); + } + } + + if (validateComponentDependencies(componentDependencies)) { + vspErrors + .add(ComponentDependencyModelErrorBuilder.getcyclicDependencyComponentErrorBuilder()); + } validationResponse .setVspErrors(vspErrors); validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails)); return validationResponse; } + private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse, + List<ErrorCode> vspErrors, String vspId, + Version version) { + OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = + orchestrationTemplateCandidateManager.getInfo(vspId, version); + String validationData = orchestrationTemplateCandidateData.getValidationData(); + String fileName = orchestrationTemplateCandidateData.getFileName(); + if (Objects.nonNull(orchestrationTemplateCandidateData.getFileSuffix())) { + if (validationData.isEmpty()) { + vspErrors.add(VendorSoftwareProductInvalidErrorBuilder + .candidateDataNotProcessedOrAbortedErrorBuilder(fileName)); + validationResponse.setVspErrors(vspErrors); + } else { + vspErrors.add(VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate(fileName)); + validationResponse.setVspErrors(vspErrors); + } + } + } + private void validateManualOnboardingMethod(VspDetails vspDetails, ValidationResponse validationResponse, List<ErrorCode> vspErrors) { @@ -236,8 +275,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa Set<CompositionEntityValidationData> componentValidationResult = componentValidation(vspDetails.getId(), vspDetails.getVersion()); if (!CollectionUtils.isEmpty(componentValidationResult)) { - if (validationResponse.getQuestionnaireValidationResult() == null || - validationResponse.getQuestionnaireValidationResult().getValidationData() == null) { + if (validationResponse.getQuestionnaireValidationResult() == null + || validationResponse.getQuestionnaireValidationResult().getValidationData() == null) { validationResponse.setQuestionnaireValidationResult( new QuestionnaireValidationResult(componentValidationResult)); } else { @@ -588,6 +627,20 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } @Override + public Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId, + Version version) { + Optional<String> jsonFileDataStructure = + orchestrationTemplateDao.getOrchestrationTemplateStructure(vspId, version); + + if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) { + return Optional + .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); + } else { + return Optional.empty(); + } + } + + @Override public PackageInfo createPackage(String vspId, Version version) { ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version); VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version)); @@ -770,10 +823,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } private boolean isOrchestrationTemplateExist(OrchestrationTemplateEntity orchestrationTemplate) { - return orchestrationTemplate != null && - orchestrationTemplate.getContentData() != null && - orchestrationTemplate.getFileSuffix() != null && - orchestrationTemplate.getFileName() != null; + return orchestrationTemplate != null + && orchestrationTemplate.getContentData() != null + && orchestrationTemplate.getFileSuffix() != null + && orchestrationTemplate.getFileName() != null; } private boolean isServiceModelExist(ToscaServiceModel serviceModel) { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java index a2c0aea423..4749e7f2dd 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorsoftwareproduct.impl; @@ -24,6 +20,7 @@ import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; import org.openecomp.core.model.dao.ServiceModelDaoFactory; import org.openecomp.sdc.vendorlicense.VendorLicenseArtifactServiceFactory; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; @@ -41,6 +38,7 @@ public class VspManagerFactoryImpl extends VspManagerFactory { private static final VendorSoftwareProductManager INSTANCE = new VendorSoftwareProductManagerImpl( OrchestrationTemplateDaoFactory.getInstance().createInterface(), + OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(), VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(), VendorLicenseFacadeFactory.getInstance().createInterface(), ServiceModelDaoFactory.getInstance().createInterface(), diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java index 9031e926a4..fae8f8b697 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -317,6 +317,7 @@ public class OrchestrationUtil { (String) manifestAsMap.get("name")); uploadData.setPackageVersion(Objects.isNull(manifestAsMap.get("version")) ? null : (String) manifestAsMap.get("version")); + uploadData.setFilesDataStructure(candidateData.getFilesDataStructure()); orchestrationTemplateDataDao.update(vspDetails.getId(), vspDetails.getVersion(), uploadData); VspMergeDaoFactory.getInstance().createInterface() diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java index 1db8875a05..6365b9ef74 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.openecomp.sdc.common.errors.GeneralErrorBuilder; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.heat.services.tree.ToscaTreeManager; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -97,7 +98,13 @@ public class OrchestrationTemplateProcessCsarHandler OrchestrationTemplateActionResponse response) throws IOException { response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); Map<String, List<ErrorMessage>> errors = validateCsar(fileContentHandler); + toscaTreeManager.createTree(); + if (!isValid(errors)) { + response.addStructureErrors(errors); + toscaTreeManager.addErrors(errors); + candidateService.updateValidationData(vspDetails.getId(), vspDetails.getVersion(), + new ValidationStructureList(toscaTreeManager.getTree())); return; } @@ -126,7 +133,8 @@ public class OrchestrationTemplateProcessCsarHandler orchestrationUtil.saveServiceModel(vspDetails.getId(), vspDetails.getVersion(), toscaServiceModel, toscaServiceModel); - + candidateService + .deleteOrchestrationTemplateCandidate(vspDetails.getId(), vspDetails.getVersion()); } private void addFiles(FileContentHandler fileContentHandler) { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java index 9f29d9316b..f155e45c06 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.messages.AuditMessages; @@ -61,7 +62,6 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface(); - private static final String VSP_ID = "VSP id"; @Override public OrchestrationTemplateActionResponse process(VspDetails vspDetails, @@ -108,7 +108,12 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp } HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); - + Map<String, List<ErrorMessage>> errors = getErrors(response); + if (MapUtils.isNotEmpty(errors)) { + response.addStructureErrors(errors); + candidateService.updateValidationData(vspId, version, new ValidationStructureList(tree)); + return response; + } Map<String, String> componentsQuestionnaire = new HashMap<>(); Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); @@ -152,9 +157,18 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); uploadFileResponse.addStructureErrors(uploadErrors); + candidateService.deleteOrchestrationTemplateCandidate(vspId, version); return response; } + private Map<String, List<ErrorMessage>> getErrors(OrchestrationTemplateActionResponse + orchestrationTemplateActionResponse) { + Map<String, List<ErrorMessage>> errors = + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, + orchestrationTemplateActionResponse.getErrors()); + return MapUtils.isEmpty(errors) ? null : orchestrationTemplateActionResponse.getErrors(); + } + private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, FileContentHandler fileContentMap) { VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); |