From c8a540b3c234449163f6fb1899807bba951113b4 Mon Sep 17 00:00:00 2001 From: shrek2000 Date: Mon, 11 Sep 2017 15:45:37 +0300 Subject: [PATCH] Create new VSP, onboard from TOSCA file - UI Change-Id: I018c6d07a4b9ec7e6b1507ab37e2550865423cfe Issue-ID: SDC-230 Signed-off-by: shrek2000 --- .../pom.xml | 54 +- .../dependency-reduced-pom.xml | 1 - .../globalTypes/openecomp/capabilities.yml | 50 ++ .../main/resources/globalTypes/openecomp/data.yml | 223 ++++++++- .../main/resources/globalTypes/openecomp/nodes.yml | 536 +++++++++++++++++++- .../globalTypes/openecomp/relationships.yml | 12 + .../vendor-software-products-rest-services/pom.xml | 4 +- .../sdcrests/vsp/rest/ComponentProcesses.java | 19 +- .../vsp/rest/OrchestrationTemplateCandidate.java | 3 +- ...pUploadFileResponseToUploadFileResponseDto.java | 2 + ...edVendorSoftwareProductInfoToVspDetailsDto.java | 2 + .../mapping/MapVspDescriptionDtoToVspDetails.java | 2 + .../OrchestrationTemplateCandidateImpl.java | 29 +- .../rest/services/VendorSoftwareProductsImpl.java | 35 +- .../types/OnboardingMethod.java | 2 +- .../types/UploadFileResponseDto.java | 17 + .../types/VspDescriptionDto.java | 18 + .../types/VspDetailsDto.java | 16 +- ...E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 | 1 - .../pom.xml | 27 + .../OrchestrationTemplateCandidateManager.java | 5 +- .../impl/MonitoringUploadsManagerImpl.java | 5 +- .../OrchestrationTemplateCandidateManagerImpl.java | 427 ++-------------- .../impl/VendorSoftwareProductManagerImpl.java | 21 +- .../BaseOrchestrationTemplateHandler.java | 100 ++++ .../OrchestrationTemplateCSARHandler.java | 154 ++++++ .../OrchestrationTemplateFileHandler.java | 12 + .../OrchestrationTemplateZipHandler.java | 55 ++ .../orchestration/OrchestrationUploadFactory.java | 29 ++ .../impl/orchestration/OrchestrationUtil.java | 282 +++++++++++ .../impl/orchestration/csar/CSARConstants.java | 18 + .../orchestration/csar/OnboardingManifest.java | 141 ++++++ .../process/OrchestrationProcessFactory.java | 64 +++ .../OrchestrationTemplateProcessCsarHandler.java | 133 +++++ .../OrchestrationTemplateProcessHandler.java | 12 + .../OrchestrationTemplateProcessZipHandler.java | 184 +++++++ .../types/ConfigConstants.java | 6 + .../types/UploadFileResponse.java | 19 + .../src/main/resources/config-orchestration.json | 26 + .../main/resources/orchestrationConfiguration.json | 3 + .../QuestionnaireDataServiceTest.java | 5 +- ...hestrationTemplateCandidateManagerImplTest.java | 8 +- .../impl/VendorSoftwareProductManagerImplTest.java | 188 +------ .../vendorsoftwareproduct/tree/UploadFileTest.java | 139 +++--- .../upload/csar/ManifestParsingTest.java | 58 +++ .../upload/csar/UploadCSARFileTest.java | 221 +++++++++ .../test/resources/vspmanager.csar/SDCmock.csar | Bin 0 -> 4211 bytes .../resources/vspmanager.csar/SDCmockBrokenMF.csar | Bin 0 -> 4022 bytes .../resources/vspmanager.csar/SDCmockFail1.csar | Bin 0 -> 4372 bytes .../resources/vspmanager.csar/SDCmockFail2.csar | Bin 0 -> 3263 bytes .../resources/vspmanager.csar/SDCmockFail3.csar | Bin 0 -> 4521 bytes .../vspmanager.csar/manifest/InvalidTosca1.mf | 11 + .../vspmanager.csar/manifest/InvalidTosca2.mf | 18 + .../vspmanager.csar/manifest/InvalidTosca3.mf | 7 + .../vspmanager.csar/manifest/InvalidTosca4.mf | 12 + .../vspmanager.csar/manifest/ValidTosca.mf | 15 + .../org/openecomp/sdc/common/errors/Messages.java | 14 +- .../org/openecomp/sdc/common/utils/CommonUtil.java | 47 +- .../org/openecomp/sdc/common/utils/SdcCommon.java | 1 + .../openecomp/core/utilities/file/FileUtils.java | 14 + .../orchestration/OnboardingTypesEnum.java | 32 ++ .../openecomp-sdc-healing-impl/pom.xml | 7 + .../sdc/healing/healers/CompositionDataHealer.java | 5 +- .../healing/healers/FileDataStructureHealer.java | 3 +- .../healers/HeatToToscaTranslationHealer.java | 3 +- .../healing/healers/VspOnboardingMethodHealer.java | 32 +- .../healers/VspOnboardingMethodHealerTest.java | 70 +++ openecomp-be/lib/openecomp-heat-lib/pom.xml | 27 + .../sdc/heat/services/tree/ToscaTreeManager.java | 79 +++ .../sdc/logging/messages/AuditMessages.java | 1 + .../openecomp-sdc-model-impl/pom.xml | 5 + .../impl/zusammen/ServiceModelDaoZusammenImpl.java | 2 +- .../openecomp-sdc-orchesrtation-api/pom.xml | 37 ++ .../openecomp-sdc-orchesrtation-core/pom.xml | 42 ++ .../openecomp-sdc-orchesrtation-impl/pom.xml | 30 ++ .../lib/openecomp-sdc-orchestration-lib/pom.xml | 23 + .../vendorsoftwareproduct/dao/type/VspDetails.java | 22 + .../filedatastructuremodule/CandidateService.java | 9 +- .../services/utils/CandidateEntityBuilder.java | 8 + .../VendorSoftwareProductInfoDaoZusammenImpl.java | 10 +- .../CandidateServiceImpl.java | 33 +- .../openecomp-tosca-converter-api/pom.xml | 35 ++ .../converter/ServiceTemplateReaderService.java | 24 + .../openecomp/core/converter/ToscaConverter.java | 12 + .../core/converter/api/ToscaConverterManager.java | 9 + .../core/converter/datatypes/Constants.java | 45 ++ .../core/converter/datatypes/CsarFileTypes.java | 9 + .../converter/factory/ToscaConverterFactory.java | 12 + .../src/resources/factoryConfiguration.json | 3 + .../openecomp-tosca-converter-core/pom.xml | 51 ++ .../impl/GlobalSubstitutionServiceTemplate.java | 59 +++ .../openecomp/core/impl/ToscaConverterImpl.java | 446 +++++++++++++++++ .../core/impl/ToscaConverterManagerImpl.java | 49 ++ .../impl/factory/ToscaConverterFactoryImpl.java | 12 + .../services/ServiceTemplateReaderServiceImpl.java | 76 +++ .../src/resources/ToscaConverters.json | 3 + .../converter/impl/ToscaConverterImplTest.java | 193 ++++++++ .../impl/ToscaConvertorDefinitionsTest.java | 62 +++ .../src/test/resources/csar/vCSCF.csar | Bin 0 -> 8186 bytes .../convertMainSt/in/Artifacts/checksum.lst | 1 + .../convertMainSt/in/Artifacts/csar.meta | 3 + .../GlobalSubstitutionTypesServiceTemplate.yaml | 60 +++ .../convertMainSt/in/MainServiceTemplate.mf | 12 + .../convertMainSt/in/MainServiceTemplate.yaml | 551 +++++++++++++++++++++ .../convertMainSt/in/TOSCA-Metadata/TOSCA.meta | 135 +++++ .../convertMainSt/out/MainServiceTemplate.yaml | 546 ++++++++++++++++++++ .../lib/openecomp-tosca-converter-lib/pom.xml | 23 + .../sdc/tosca/datatypes/ToscaServiceModel.java | 18 + .../services/impl/ToscaAnalyzerServiceImpl.java | 3 +- openecomp-be/lib/pom.xml | 2 + openecomp-be/pom.xml | 2 +- .../src/main/resources/zusammenMainTool.sh | 18 +- .../scss/modules/_softwareProductLandingPage.scss | 42 +- .../sdc-app/onboarding/OnboardingActionHelper.js | 18 +- .../src/sdc-app/onboarding/OnboardingPunchOut.jsx | 21 +- .../onboarding/softwareProduct/SoftwareProduct.js | 24 +- .../softwareProduct/SoftwareProductActionHelper.js | 22 +- .../softwareProduct/SoftwareProductConstants.js | 10 +- .../softwareProduct/SoftwareProductReducer.js | 2 + .../attachments/SoftwareProductAttachments.js | 12 +- .../SoftwareProductAttachmentsActionHelper.js | 26 + .../SoftwareProductAttachmentsConstants.js | 6 + .../SoftwareProductAttachmentsReducer.js | 25 + .../attachments/SoftwareProductAttachmentsView.jsx | 42 +- .../validation/HeatValidationReducer.js | 11 +- .../attachments/validation/HeatValidationView.jsx | 6 +- .../creation/SoftwareProductCreationView.jsx | 8 +- .../landingPage/SoftwareProductLandingPage.js | 5 +- .../landingPage/SoftwareProductLandingPageView.jsx | 41 +- .../SoftwareProductAttachmentsView.test.js | 5 +- 130 files changed, 5886 insertions(+), 901 deletions(-) delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java create mode 100644 openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java create mode 100644 openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java create mode 100644 openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-api/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-core/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-impl/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-orchestration-lib/pom.xml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/pom.xml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ToscaConverter.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/api/ToscaConverterManager.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/CsarFileTypes.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/factory/ToscaConverterFactory.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/resources/factoryConfiguration.json create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterManagerImpl.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/resources/ToscaConverters.json create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/csar/vCSCF.csar create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/checksum.lst create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/csar.meta create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Definitions/GlobalSubstitutionTypesServiceTemplate.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.mf create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/TOSCA-Metadata/TOSCA.meta create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/out/MainServiceTemplate.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/pom.xml create mode 100644 openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsActionHelper.js create mode 100644 openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsReducer.js diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/pom.xml b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/pom.xml index 609e8abdf7..186a50849a 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/pom.xml +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/pom.xml @@ -24,62 +24,62 @@ jackson-dataformat-yaml ${jackson.version} - + org.apache.commons commons-configuration2 2.1 - + commons-logging commons-logging 1.2 - + commons-beanutils commons-beanutils ${commons.beanutils.version} - + org.apache.commons commons-lang3 3.3.2 - + com.github.adejanovski cassandra-jdbc-wrapper ${cassandra.version} - + org.apache.commons commons-dbcp2 2.0 - + org.apache.commons commons-pool2 2.4.2 - + commons-io commons-io ${commons.io.version} - + net.sf.corn corn-cps 1.1.7 - - com.sun - tools - - + + com.sun + tools + + - com.virtlink.commons - commons-configuration2-jackson - 0.6.1 - + com.virtlink.commons + commons-configuration2-jackson + 0.6.1 + org.apache.logging.log4j log4j-core @@ -95,16 +95,16 @@ slf4j-log4j12 ${slf4j.version} - - org.slf4j - slf4j-ext - ${slf4j.version} - - org.openecomp.sdc.common - openecomp-configuration-management-api - 1.1.0-SNAPSHOT - + org.slf4j + slf4j-ext + ${slf4j.version} + + + org.openecomp.sdc.common + openecomp-configuration-management-api + 1.1.0-SNAPSHOT + javax.servlet javax.servlet-api diff --git a/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/dependency-reduced-pom.xml b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/dependency-reduced-pom.xml index a71fe7feaa..5a51961846 100644 --- a/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/dependency-reduced-pom.xml +++ b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/dependency-reduced-pom.xml @@ -7,7 +7,6 @@ ../../pom.xml 4.0.0 - org.openecomp.sdc.common openecomp-sdc-artifact-generator-test diff --git a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/capabilities.yml b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/capabilities.yml index 77d8eb9857..e395e3fc27 100644 --- a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/capabilities.yml +++ b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/capabilities.yml @@ -98,3 +98,53 @@ capability_types: description: Runtime monitored value type: string status: SUPPORTED + + tosca.capabilities.nfv.VirtualLinkable: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.Metric: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.VirtualBindable: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.VirtualCompute: + derived_from: tosca.capabilities.Root + properties: + virtual_memory: + type: tosca.datatypes.nfv.VirtualMemory + requested_additional_capabilities: + entry_schema: + type: tosca.datatypes.nfv.RequestedAdditionalCapability + required: false + type: map + virtual_cpu: + type: tosca.datatypes.nfv.VirtualCpu + + + tosca.capabilities.nfv.VirtualStorage: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.Forwarder: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.ext.Compute.Container.Architecture: + derived_from: tosca.capabilities.Root + properties: + num_cpus: + required: false + type: string + flavor_extra_specs: + entry_schema: + type: string + required: false + type: map + mem_size: + required: false + type: string + + tosca.capabilities.nfv.ext.ImageFile: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.ext.LocalAttachment: + derived_from: tosca.capabilities.Root \ No newline at end of file diff --git a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/data.yml b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/data.yml index c7ce3c13e0..85ff50c112 100644 --- a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/data.yml +++ b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/data.yml @@ -554,4 +554,225 @@ data_types: description: Hash type required: false default: md5 - + + tosca.datatypes.nfv.RequestedAdditionalCapability: + derived_from: tosca.datatypes.Root + properties: + support_mandatory: + type: boolean + required: true + min_requested_additional_capability_version: + type: string + required: false + preferred_requested_additional_capability_version: + type: string + required: false + requested_additional_capability_name: + type: string + required: true + target_performance_parameters: + type: map + entry_schema: + type: string + required: true + tosca.datatypes.nfv.VirtualMemory: + derived_from: tosca.datatypes.Root + properties: + virtual_mem_size: + type: string + required: true + virtual_mem_oversubscription_policy: + type: string + required: false + numa_enabled: + type: boolean + required: false + tosca.datatypes.nfv.VirtualCpu: + derived_from: tosca.datatypes.Root + properties: + cpu_architecture: + type: string + required: false + num_virtual_cpu: + type: integer + required: true + virtual_cpu_clock: + type: scalar-unit.frequency + required: false + virtual_cpu_oversubscription_policy: + type: string + required: false + virtual_cpu_pinning: + type: tosca.datatypes.nfv.VirtualCpuPinning + required: false + tosca.datatypes.nfv.VirtualCpuPinning: + derived_from: tosca.datatypes.Root + properties: + cpu_pinning_policy: + type: string + constraints: + - valid_values: [ static, dynamic ] + required: false + cpu_pinning_map: + type: map + entry_schema: + type: string + required: false + tosca.datatypes.nfv.VnfcConfigurableProperties: + properties: + additional_vnfc_configurable_properties: + entry_schema: + type: string + required: false + type: map + tosca.datatypes.network.NetworkInfo: + properties: + network_id: + required: false + type: string + addresses: + entry_schema: + type: string + required: false + type: list + network_name: + required: false + type: string + tosca.datatypes.network.PortInfo: + properties: + port_name: + required: false + type: string + network_id: + required: false + type: string + addresses: + entry_schema: + type: string + required: false + type: list + mac_address: + required: false + type: string + port_id: + required: false + type: string + tosca.datatypes.nfv.L3AddressData: + properties: + number_of_ip_address: + required: false + type: integer + ip_address_assignment: + type: boolean + ip_address_type: + constraints: + - valid_values: + - ipv4 + - ipv6 + required: false + type: string + floating_ip_activated: + type: string + tosca.datatypes.nfv.VirtualNetworkInterfaceRequirements: + properties: + name: + required: false + type: string + support_mandatory: + type: boolean + description: + required: false + type: string + requirement: + entry_schema: + type: string + type: map + tosca.datatype.nfv.AddressData: + properties: + address_type: + constraints: + - valid_values: + - mac_address + - ip_address + type: string + l2_address_data: + required: false + type: tosca.datatypes.nfv.L2AddressData + l3_address_data: + required: false + type: tosca.datatypes.nfv.L3AddressData + tosca.datatypes.nfv.L2AddressData: {} + tosca.datatypes.nfv.ConnectivityType: + properties: + layer_protocol: + constraints: + - valid_values: + - ethernet + - mpls + - odu2 + - ipv4 + - ipv6 + - pseudo_wire + type: string + flow_pattern: + required: false + type: string + tosca.datatypes.nfv.ext.FloatingIP: + properties: + external_network: + required: false + type: string + ip_address: + required: false + type: string + tosca.datatypes.nfv.ext.AddressPairs: + properties: + ip: + required: false + type: string + mac: + required: false + type: string + tosca.datatypes.nfv.ext.InjectData: + properties: + file_name: + required: false + type: string + file_data: + required: false + type: string + tosca.datatypes.nfv.ext.zte.WatchDog: + properties: + enable_delay: + required: false + type: integer + action: + required: false + type: string + tosca.datatypes.nfv.ext.LocalAffinityOrAntiAffinityRule: + properties: + scope: + required: false + type: string + affinity_antiaffinity: + required: false + type: string + tosca.datatypes.nfv.ext.LocationInfo: + properties: + availability_zone: + required: false + type: string + vimid: + required: false + type: integer + tenant: + required: false + type: string + tosca.datatypes.nfv.ext.HostRouteInfo: + properties: + destination: + required: false + type: string + nexthop: + required: false + type: string \ No newline at end of file diff --git a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/nodes.yml b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/nodes.yml index fb2e030a06..aaff11b0ed 100644 --- a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/nodes.yml +++ b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/nodes.yml @@ -569,4 +569,538 @@ node_types: type: map entry_schema: type: org.openecomp.datatypes.ImageInfo - required: false \ No newline at end of file + required: false + tosca.nodes.nfv.NS.vEPC_NS: + derived_from: tosca.nodes.nfv.NS + properties: + vendor: + default: ChinaMobile + required: false + type: string + csarVersion: + default: v1.0 + required: false + type: string + name: + default: vEPC_NS + required: false + type: string + csarProvider: + default: ChinaMobile + required: false + type: string + id: + default: vEPC_NS + required: false + type: string + version: + default: v1.0 + required: false + type: string + csarType: + default: NSAR + required: false + type: string + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + occurrences: + - 0 + - UNBOUNDED + + tosca.nodes.nfv.NS.vIMS_NS: + derived_from: tosca.nodes.nfv.NS + properties: + vendor: + default: ChinaMobile + required: false + type: string + csarVersion: + default: v1.0 + required: false + type: string + name: + default: vIMS_NS + required: false + type: string + csarProvider: + default: ChinaMobile + required: false + type: string + id: + default: vIMS_NS + required: false + type: string + version: + default: v1.0 + required: false + type: string + csarType: + default: NSAR + required: false + type: string + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + occurrences: + - 0 + - UNBOUNDED + + tosca.nodes.nfv.NS: + derived_from: tosca.nodes.Root + properties: + vendor: + required: false + type: string + name: + required: false + type: string + id: + required: false + type: string + version: + required: false + type: string + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + occurrences: + - 0 + - UNBOUNDED + + tosca.nodes.nfv.VDU.Compute: + attributes: + private_address: + type: string + public_address: + type: string + networks: + type: string + ports: + type: string + capabilities: + scalable: + type: tosca.capabilities.Scalable + virtual_compute: + type: tosca.capabilities.nfv.VirtualCompute + endpoint: + type: tosca.capabilities.Endpoint.Admin + os: + type: tosca.capabilities.OperatingSystem + virtual_binding: + type: tosca.capabilities.nfv.VirtualBindable + host: + type: tosca.capabilities.Container + binding: + type: tosca.capabilities.network.Bindable + monitoring_parameter: + type: tosca.capabilities.nfv.Metric + derived_from: tosca.nodes.Root + properties: + configurable_properties: + entry_schema: + type: tosca.datatypes.nfv.VnfcConfigurableProperties + type: map + name: + type: string + nfvi_constraints: + entry_schema: + type: string + required: false + type: list + descrption: + type: string + boot_order: + entry_schema: + type: string + required: false + type: list + requirements: + - local_storage: + capability: tosca.capabilities.Attachment + occurrences: + - 0 + - UNBOUNDED + - virtual_storage: + capability: tosca.capabilities.nfv.VirtualStorage + occurrences: + - 0 + - UNBOUNDED + + tosca.nodes.nfv.VDU.VirtualStorage: + capabilities: + virtual_storage: + type: tosca.capabilities.nfv.VirtualStorage + derived_from: tosca.nodes.Root + properties: + id: + type: string + size_of_storage: + type: string + rdma_enabled: + required: false + type: boolean + type_of_storage: + type: string + + tosca.nodes.nfv.VduCpd: + derived_from: tosca.nodes.Root + properties: + virtual_network_interface_requirements: + entry_schema: + type: tosca.datatypes.nfv.VirtualNetworkInterfaceRequirements + required: false + type: list + role: + constraints: + - valid_values: + - root + - leaf + required: false + type: string + bitrate_requirement: + required: false + type: integer + description: + required: false + type: string + layer_protocol: + constraints: + - valid_values: + - ethernet + - mpls + - odu2 + - ipv4 + - ipv6 + - pseudo_wire + type: string + address_data: + entry_schema: + type: tosca.datatype.nfv.AddressData + required: false + type: list + requirements: + - virtual_binding: + capability: tosca.capabilities.nfv.VirtualBindable + occurrences: + - 0 + - UNBOUNDED + - virtual_link: + capability: tosca.capabilities.nfv.VirtualBindable + occurrences: + - 0 + - UNBOUNDED + tosca.nodes.nfv.ext.ImageFile: + capabilities: + guest_os: + type: tosca.capabilities.nfv.ext.GuestOs + image_fle: + type: tosca.capabilities.nfv.ext.ImageFile + derived_from: tosca.nodes.Root + properties: + file_url: + required: false + type: string + container_type: + required: false + type: string + name: + required: false + type: string + disk_format: + required: false + type: string + version: + required: false + type: string + tosca.nodes.nfv.ext.LocalStorage: + capabilities: + local_attachment: + type: tosca.capabilities.nfv.ext.LocalAttachment + derived_from: tosca.nodes.Root + properties: + size: + required: false + type: string + disk_type: + required: false + type: string + tosca.nodes.nfv.ext.zte.CP: + capabilities: + forwarder: + type: tosca.capabilities.nfv.Forwarder + derived_from: tosca.nodes.Root + properties: + guest_os_mtu: + required: false + type: integer + bandwidth: + required: false + type: integer + interface_name: + required: false + type: string + allowed_address_pairs: + entry_schema: + type: tosca.datatypes.nfv.ext.AddressPairs + required: false + type: list + ip_address: + required: false + type: string + bond: + required: false + type: string + proxiedVNFs: + entry_schema: + type: string + required: false + type: list + sfc_encapsulation: + required: false + type: string + floating_ip_address: + required: false + type: tosca.datatypes.nfv.ext.FloatingIP + service_ip_address: + required: false + type: string + mac_address: + required: false + type: string + proxiedVNFtype: + required: false + type: string + macbond: + required: false + type: string + vnic_type: + required: false + type: string + direction: + required: false + type: string + order: + required: false + type: integer + requirements: + - forwarder: + capability: tosca.capabilities.nfv.Forwarder + occurrences: + - 0 + - UNBOUNDED + - virtualbinding: + capability: tosca.capabilities.nfv.VirtualBindable + occurrences: + - 0 + - UNBOUNDED + - virtualLink: + capability: tosca.capabilities.nfv.VirtualBindable + occurrences: + - 0 + - UNBOUNDED + tosca.nodes.nfv.ext.zte.VDU: + capabilities: + scalable: + type: tosca.capabilities.Scalable + monitoring_parameter: + type: tosca.capabilities.nfv.Metric + nfv_compute: + type: tosca.capabilities.nfv.ext.Compute.Container.Architecture + virtualbinding: + type: tosca.capabilities.nfv.VirtualBindable + derived_from: tosca.nodes.Root + properties: + manual_scale_select_vim: + required: false + type: boolean + vdu_type: + required: false + type: string + watchdog: + required: false + type: tosca.datatypes.nfv.ext.zte.WatchDog + name: + required: false + type: string + local_affinity_antiaffinity_rule: + required: false + type: tosca.datatypes.nfv.ext.LocalAffinityOrAntiAffinityRule + support_scaling: + required: false + type: boolean + storage_policy: + required: false + type: string + key_vdu: + required: false + type: boolean + location_info: + required: false + type: tosca.datatypes.nfv.ext.LocationInfo + inject_data_list: + entry_schema: + type: tosca.datatypes.nfv.ext.InjectData + required: false + type: list + requirements: + - guest_os: + capability: tosca.capabilities.nfv.ext.GuestOs + occurrences: + - 0 + - UNBOUNDED + - local_storage: + capability: tosca.capabilities.nfv.ext.LocalAttachment + occurrences: + - 0 + - UNBOUNDED + - volume_storage: + capability: tosca.capabilities.Attachment + occurrences: + - 0 + - UNBOUNDED + - dependency: + capability: tosca.capabilities.Node + occurrences: + - 0 + - UNBOUNDED + tosca.nodes.nfv.ext.zte.VL: + capabilities: + virtual_linkable: + type: tosca.capabilities.nfv.VirtualLinkable + derived_from: tosca.nodes.Root + properties: + segmentation_id: + required: false + type: string + network_name: + required: false + type: string + is_predefined: + required: false + type: boolean + mtu: + required: false + type: integer + dns_nameservers: + entry_schema: + type: string + required: false + type: list + physical_network: + required: false + type: string + dhcp_enabled: + required: false + type: boolean + network_id: + required: false + type: string + host_routes: + entry_schema: + type: tosca.datatypes.nfv.ext.HostRouteInfo + required: false + type: list + ip_version: + required: false + type: integer + vendor: + required: false + type: string + name: + required: false + type: string + start_ip: + required: false + type: string + vlan_transparent: + required: false + type: boolean + cidr: + required: false + type: string + gateway_ip: + required: false + type: string + network_type: + required: false + type: string + end_ip: + required: false + type: string + location_info: + required: false + type: tosca.datatypes.nfv.ext.LocationInfo + tosca.nodes.nfv.ext.zte.VNF: + capabilities: + forwarder: + type: tosca.capabilities.nfv.Forwarder + derived_from: tosca.nodes.Root + properties: + request_reclassification: + required: false + type: boolean + domain_type: + required: false + type: string + nsh_aware: + required: false + type: boolean + plugin_info: + required: false + type: string + adjust_vnf_capacity: + required: false + type: boolean + vnfd_version: + required: false + type: string + vmnumber_overquota_alarm: + required: false + type: boolean + custom_properties: + entry_schema: + type: string + required: false + type: map + version: + required: false + type: string + cross_dc: + required: false + type: boolean + script_info: + required: false + type: string + vendor: + required: false + type: string + is_shared: + required: false + type: boolean + name: + required: false + type: string + vnf_extend_type: + required: false + type: string + id: + required: false + type: string + vnf_type: + required: false + type: string + is_sfc_proxy: + required: false + type: boolean + requirements: + - forwarder: + capability: tosca.capabilities.nfv.Forwarder + occurrences: + - 0 + - UNBOUNDED + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + occurrences: + - 0 + - UNBOUNDED \ No newline at end of file diff --git a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/relationships.yml b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/relationships.yml index 6243cfa5d1..220658a8bf 100644 --- a/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/relationships.yml +++ b/common/openecomp-tosca-datatype/src/main/resources/globalTypes/openecomp/relationships.yml @@ -54,3 +54,15 @@ relationship_types: status: SUPPORTED required: false + tosca.relationships.nfv.VDU.AttachedTo: + derived_from: tosca.relationships.Root + properties: + location: + required: false + type: string + + tosca.relationships.nfv.VirtualBindsTo: + derived_from: tosca.relationships.Root + + tosca.relationships.nfv.VirtualLinksTo: + derived_from: tosca.relationships.Root \ No newline at end of file diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/pom.xml index f146881751..d65e9e6b27 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/pom.xml +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/pom.xml @@ -102,11 +102,11 @@ woodstox-core-asl ${woodstox.version} - + com.sun.jersey.contribs jersey-multipart diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/ComponentProcesses.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/ComponentProcesses.java index ca50ef1426..edb3b5bfc2 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/ComponentProcesses.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/ComponentProcesses.java @@ -20,35 +20,24 @@ package org.openecomp.sdcrests.vsp.rest; -import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; -import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; - import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; -import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdcrests.vendorsoftwareproducts.types.ProcessEntityDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.ProcessRequestDto; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; +import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; + @Path("/v1.0/vendor-software-products/{vspId}/versions/{versionId}/components/{componentId}/processes") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/OrchestrationTemplateCandidate.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/OrchestrationTemplateCandidate.java index fbf29185e3..fa7f421fc8 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/OrchestrationTemplateCandidate.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/OrchestrationTemplateCandidate.java @@ -23,6 +23,7 @@ package org.openecomp.sdcrests.vsp.rest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.openecomp.sdc.vendorsoftwareproduct.types.FileDataStructureDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.UploadFileResponseDto; @@ -61,7 +62,7 @@ public interface OrchestrationTemplateCandidate extends VspEntities { Response upload( @PathParam("vspId") String vspId, @ApiParam(value = "Version Id") @PathParam("versionId") String versionId, - @Multipart("upload") InputStream heatFileToUpload, + @Multipart("upload") Attachment fileToUpload, @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); @GET diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapUploadFileResponseToUploadFileResponseDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapUploadFileResponseToUploadFileResponseDto.java index cccfd02371..48053d053d 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapUploadFileResponseToUploadFileResponseDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapUploadFileResponseToUploadFileResponseDto.java @@ -34,5 +34,7 @@ public class MapUploadFileResponseToUploadFileResponseDto public void doMapping(UploadFileResponse source, UploadFileResponseDto target) { target.setStatus(source.getStatus()); target.setErrors(source.getErrors()); + target.setOnboardingOrigin(source.getOnboardingType().toString()); + target.setNetworkPackageName(source.getNetworkPackageName()); } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVersionedVendorSoftwareProductInfoToVspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVersionedVendorSoftwareProductInfoToVspDetailsDto.java index 9093da599f..815135f834 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVersionedVendorSoftwareProductInfoToVspDetailsDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVersionedVendorSoftwareProductInfoToVspDetailsDto.java @@ -45,8 +45,10 @@ public class MapVersionedVendorSoftwareProductInfoToVspDetailsDto target.setSubCategory(vsp.getSubCategory()); target.setVendorId(vsp.getVendorId()); target.setVendorName(vsp.getVendorName()); + target.setOnboardingOrigin(vsp.getOnboardingOrigin()); target.setLicensingVersion(vsp.getVlmVersion() == null ? null : new VersionDto(vsp.getVlmVersion().toString(), vsp.getVlmVersion().toString())); target.setIsOldVersion("False"); + target.setNetworkPackageName(vsp.getNetworkPackageName()); if (vsp.getLicenseAgreement() != null || vsp.getFeatureGroups() != null) { LicensingData licensingData = new LicensingData(); diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVspDescriptionDtoToVspDetails.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVspDescriptionDtoToVspDetails.java index 9808bbb2b6..ba3d92e5d2 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVspDescriptionDtoToVspDetails.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapVspDescriptionDtoToVspDetails.java @@ -39,6 +39,8 @@ public class MapVspDescriptionDtoToVspDetails extends MappingBase zipFile = - candidateManager - .get(vspId, resolveVspVersion(vspId, null, user, VersionableEntityAction.Read), user); + + Optional> zipFile = candidateManager + .get(vspId, resolveVspVersion(vspId, null, user, VersionableEntityAction.Read), user); if (!zipFile.isPresent()) { return Response.status(Response.Status.NOT_FOUND).build(); } - Response.ResponseBuilder response = Response.ok(zipFile.get()); - response.header("Content-Disposition", "attachment; filename=HeatCandidate.zip"); + Response.ResponseBuilder response = Response.ok(zipFile.get().getRight()); + String filename = "Candidate." + zipFile.get().getLeft(); + response.header("Content-Disposition", "attachment; filename=" + filename); return response.build(); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java index 8f2e73bff6..0b73cbcee6 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java @@ -47,14 +47,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProd import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionInfo; import org.openecomp.sdc.versioning.types.VersionableEntityAction; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.PackageInfoDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.ValidationResponseDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.VersionSoftwareProductActionRequestDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspComputeDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspCreationDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDescriptionDto; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.*; import org.openecomp.sdcrests.vsp.rest.VendorSoftwareProducts; import org.openecomp.sdcrests.vsp.rest.mapping.MapComputeEntityToVspComputeDto; import org.openecomp.sdcrests.vsp.rest.mapping.MapPackageInfoToPackageInfoDto; @@ -100,9 +93,13 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { + vspDescriptionDto.getName()); VspCreationDto vspCreationDto = null; - switch (vspDescriptionDto.getOnboardingMethod()) { - case "HEAT": - case "Manual": + OnboardingMethod onboardingMethod = OnboardingMethod.valueOf(vspDescriptionDto.getOnboardingMethod()); + if (onboardingMethod == null){ + return handleUnkownOnboardingMethod(); + } + switch (onboardingMethod) { + case NetworkPackage: + case Manual: VspDetails vspDetails = new MapVspDescriptionDtoToVspDetails(). applyMapping(vspDescriptionDto, VspDetails.class); @@ -112,17 +109,21 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { vspCreationDto = mapping.applyMapping(vspDetails, VspCreationDto.class); break; default: - ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder - .getInvalidOnboardingMethodErrorBuilder(); - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, - LoggerTragetServiceName.ADD_VSP, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message()); - throw new CoreException(onboardingMethodUpdateErrorCode); + return handleUnkownOnboardingMethod(); } return Response.ok(vspCreationDto).build(); } + private Response handleUnkownOnboardingMethod() { + ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder + .getInvalidOnboardingMethodErrorBuilder(); + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.ADD_VSP, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message()); + throw new CoreException(onboardingMethodUpdateErrorCode); + } + @Override public Response listVsps(String versionFilter, String user) { MdcUtil.initMdc(LoggerServiceName.List_VSP.toString()); diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/OnboardingMethod.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/OnboardingMethod.java index 3059efb171..0db4b0476d 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/OnboardingMethod.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/OnboardingMethod.java @@ -1,6 +1,6 @@ package org.openecomp.sdcrests.vendorsoftwareproducts.types; public enum OnboardingMethod { - HEAT, + NetworkPackage, Manual; } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/UploadFileResponseDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/UploadFileResponseDto.java index a79c70a4d2..3bf2e8ced1 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/UploadFileResponseDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/UploadFileResponseDto.java @@ -32,6 +32,8 @@ import java.util.Map; public class UploadFileResponseDto { private Map> errors; private UploadFileStatus status; + private String onboardingOrigin; + private String networkPackageName; public Map> getErrors() { return errors; @@ -49,4 +51,19 @@ public class UploadFileResponseDto { this.status = status; } + public String getOnboardingOrigin() { + return onboardingOrigin; + } + + public void setOnboardingOrigin(String onboardingOrigin) { + this.onboardingOrigin = onboardingOrigin; + } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDescriptionDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDescriptionDto.java index 80b68deeeb..9062f89d22 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDescriptionDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDescriptionDto.java @@ -44,6 +44,8 @@ public class VspDescriptionDto { @NotNull private String onboardingMethod; + private String onboardingOrigin; + private String networkPackageName; public String getName() { return name; @@ -124,4 +126,20 @@ public class VspDescriptionDto { public void setOnboardingMethod(String onboardingMethod) { this.onboardingMethod = onboardingMethod; } + + public String getOnboardingOrigin() { + return onboardingOrigin; + } + + public void setOnboardingOrigin(String onboardingOrigin) { + this.onboardingOrigin = onboardingOrigin; + } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java index d105acb406..28a77f2e66 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java @@ -41,7 +41,8 @@ public class VspDetailsDto extends VspDescriptionDto { private String lockingUser; private ValidationStructureList validationData; private String isOldVersion; - + private String onboardingOrigin; + private String networkPackageName; public String getId() { return id; } @@ -104,8 +105,21 @@ public class VspDetailsDto extends VspDescriptionDto { public void setValidationData(ValidationStructureList validationData) { this.validationData = validationData; + } + + public String getOnboardingOrigin() { + return onboardingOrigin; + } + public void setOnboardingOrigin(String onboardingOrigin) { + this.onboardingOrigin = onboardingOrigin; + } + public String getNetworkPackageName() { + return networkPackageName; } + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 deleted file mode 100644 index 58e6f9e5e2..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 +++ /dev/null @@ -1 +0,0 @@ -bla bla \ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml index ba95d4a3e4..b3fc9aa797 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml @@ -14,6 +14,18 @@ + + org.openecomp.sdc.common + openecomp-configuration-management-core + ${openecomp.sdc.common.version} + runtime + + + org.slf4j + slf4j-log4j12 + + + org.openecomp.sdc.common openecomp-tosca-datatype @@ -185,6 +197,21 @@ openecomp-sdc-tosca-generator-core ${project.version} + + org.openecomp.sdc + openecomp-sdc-orchesrtation-core + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-tosca-converter-api + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-tosca-converter-core + 1.1.0-SNAPSHOT + 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 e648ccef26..e2ef86149b 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 @@ -20,6 +20,7 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; @@ -32,7 +33,7 @@ import java.util.Optional; public interface OrchestrationTemplateCandidateManager { UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user); + String user, String filePrefix, String networkPackageName); OrchestrationTemplateActionResponse process(String vspId, Version version, String user); @@ -41,5 +42,5 @@ public interface OrchestrationTemplateCandidateManager { ValidationResponse updateFilesDataStructure(String vspId, Version version, String user, FilesDataStructure fileDataStructure); - Optional get(String vspId, Version version, String user) throws IOException; + Optional> get(String vspId, Version version, String user) throws IOException; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java index 73558b465a..fcf54eef2f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java @@ -25,6 +25,7 @@ import org.openecomp.core.enrichment.types.MonitoringUploadType; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; @@ -44,6 +45,7 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.MonitoringUploadErrorBuilder; @@ -67,6 +69,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private ActivityLogManager activityLogManager; private ComponentArtifactDao componentArtifactDao; + private VendorSoftwareProductDao vendorSoftwareProductDao; private static final Logger logger = LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); @@ -253,7 +256,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { Map> errors) { FileContentHandler contentMap; try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); + contentMap = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, uploadedFileData); VendorSoftwareProductUtils.validateContentZipData(contentMap, errors); } catch (IOException exception) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, 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 07e84803aa..3f6ffcc622 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 @@ -21,29 +21,20 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; -import org.openecomp.core.translator.datatypes.TranslatorOutput; -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; -import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.utils.CommonUtil; 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.healing.api.HealingManager; import org.openecomp.sdc.healing.types.HealCode; -import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; -import org.openecomp.sdc.heat.services.tree.HeatTreeManager; -import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.api.annotations.Metrics; @@ -52,8 +43,6 @@ import org.openecomp.sdc.logging.messages.AuditMessages; import org.openecomp.sdc.logging.types.LoggerServiceName; import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; -import org.openecomp.sdc.validation.util.ValidationManagerUtil; import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -62,40 +51,29 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.OrchestrationTemplateNotFoundErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateFileHandler; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessHandler; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; -import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; -import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdcrests.activitylog.types.ActivityType; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; - public class OrchestrationTemplateCandidateManagerImpl implements OrchestrationTemplateCandidateManager { private static final Logger logger = @@ -162,65 +140,31 @@ public class OrchestrationTemplateCandidateManagerImpl @Override @Metrics - public UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user) { + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, + String user, String filePrefix, + String networkPackageName) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); - + OrchestrationTemplateFileHandler orchestrationTemplateFileHandler = + OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(filePrefix); VspDetails vspDetails = getVspDetails(vspId, version); + UploadFileResponse uploadResponse = orchestrationTemplateFileHandler + .upload(vspId, version, fileToUpload, user, candidateService, + vspDetails); + vspDetails.setOnboardingOrigin(filePrefix); + vspDetails.setNetworkPackageName(networkPackageName); + vspInfoDao.update(vspDetails); + + uploadResponse.setNetworkPackageName(networkPackageName); + return uploadResponse; + } - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - if (isNotEmptyFileToUpload(heatFileToUpload, uploadFileResponse)) { - return uploadFileResponse; - } - - byte[] uploadedFileData = FileUtils.toByteArray(heatFileToUpload); - if (isInvalidRawZipData(uploadFileResponse, uploadedFileData)) { - return uploadFileResponse; - } - - Optional optionalContentMap = - getZipContentMap(uploadFileResponse, uploadedFileData); - if (!optionalContentMap.isPresent()) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.ZIP_CONTENT_MAP.getErrorMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - - if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - try { - OrchestrationTemplateCandidateData candidateData = - new CandidateEntityBuilder(candidateService) - .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), - uploadFileResponse.getErrors(), user); - candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); - } catch (Exception exception) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } @Override public OrchestrationTemplateActionResponse process(String vspId, Version version, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); Optional candidate = fetchCandidateDataEntity(vspId, version); @@ -228,97 +172,15 @@ public class OrchestrationTemplateCandidateManagerImpl throw new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + vspId); - OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - OrchestrationTemplateCandidateData candidateDataEntity = candidate.get(); - Optional fileContent = - getZipContentMap(uploadFileResponse, candidateDataEntity.getContentData().array()); - if (!fileContent.isPresent()) { - response.addStructureErrors(uploadFileResponse.getErrors()); - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - Map> uploadErrors = uploadFileResponse.getErrors(); - FileContentHandler fileContentMap = fileContent.get(); - FilesDataStructure structure = - JsonUtil.json2Object(candidateDataEntity.getFilesDataStructure(), FilesDataStructure.class); - - if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { - response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, - Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - VspDetails vspDetails = getVspDetails(vspId, version); + Optional processInstance = + OrchestrationProcessFactory.getInstance(vspDetails.getOnboardingOrigin()); - String manifest = candidateService.createManifest(vspDetails, structure); - fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); - - Optional zipByteArrayInputStream = candidateService - .fetchZipFileByteArrayInputStream(vspId, candidateDataEntity, manifest, uploadErrors); - if (!zipByteArrayInputStream.isPresent()) { - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); - - Map componentsQuestionnaire = new HashMap<>(); - Map> componentNicsQuestionnaire = new HashMap<>(); - Map> componentMibList = new HashMap<>(); - Map> processes = new HashMap<>(); - Map processArtifact = new HashMap<>(); - - backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - deleteUploadDataAndContent(vspId, version); - saveHotData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, tree); - - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors - ()))) { - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + if(processInstance.isPresent()){ + response = processInstance.get().process(vspDetails, candidate.get(), user); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); - - TranslatorOutput translatorOutput = - HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); - - ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); - if (toscaServiceModel != null) { - serviceModelDao.storeServiceModel(vspId, version, toscaServiceModel); - //Extracting the compostion data from the output service model of the first phase of - // translation - compositionEntityDataManager.saveCompositionData(vspId, version, - compositionDataExtractor.extractServiceCompositionData(translatorOutput - .getNonUnifiedToscaServiceModel())); - retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); - } - - uploadFileResponse.addStructureErrors(uploadErrors); - - ActivityLogEntity activityLogEntity = - new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), - ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); - activityLogManager.addActionLog(activityLogEntity, user); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return response; } @@ -374,7 +236,7 @@ public class OrchestrationTemplateCandidateManagerImpl @Override - public Optional get(String vspId, Version version, String user) + public Optional> get(String vspId, Version version, String user) throws IOException { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); @@ -393,15 +255,25 @@ public class OrchestrationTemplateCandidateManagerImpl .debugExitMessage("VSP id", vspId); return Optional.empty(); } + OnboardingTypesEnum type = + OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin()); - FilesDataStructure structure = JsonUtil - .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); - String manifest = candidateService.createManifest(vspDetails, structure); + if(vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.toString())) { + FilesDataStructure structure = JsonUtil + .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); + String manifest = candidateService.createManifest(vspDetails, structure); - mdcDataDebugMessage - .debugExitMessage("VSP id", vspId); - return Optional.ofNullable(candidateService - .replaceManifestInZip(candidateDataEntity.get().getContentData(), manifest, vspId)); + mdcDataDebugMessage + .debugExitMessage("VSP id", vspId); + return Optional.ofNullable( + new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService + .replaceManifestInZip(candidateDataEntity.get().getContentData(), + manifest, vspId, type))); + } + + return Optional.ofNullable( + new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get() + .getContentData().array())); } private Optional fetchCandidateDataEntity( @@ -410,213 +282,6 @@ public class OrchestrationTemplateCandidateManagerImpl .ofNullable(candidateService.getOrchestrationTemplateCandidate(vspId, version)); } - private void retainComponentQuestionnaireData(String vspId, Version activeVersion, - Map componentsQustanniare, - Map> - componentNicsQustanniare, - Map> componentMibList, - Map> processes, - Map processArtifact) { - //VSP processes - restoreProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, - processArtifact); - Collection - components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); - components.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - if (componentsQustanniare.containsKey(componentName)) { - componentDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), - componentsQustanniare.get(componentEntity.getComponentCompositionData() - .getName())); - if (componentNicsQustanniare.containsKey(componentName)) { - Map nicsQustanniare = componentNicsQustanniare.get(componentName); - Collection - nics = - nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - nics.forEach(nicEntity -> { - if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { - nicDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId(), - nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); - } - }); - } - //MIB //todo add for VES_EVENTS - if (componentMibList.containsKey(componentName)) { - Collection mibList = - componentMibList.get(componentName); - mibList.forEach(mib -> { - mib.setComponentId(componentEntity.getId()); - componentArtifactDao.create(mib); - }); - } - //VFC processes - restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, - processArtifact); - } - }); - } - - private void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, - Map componentsQustanniare, - Map> - componentNicsQustanniare, - Map> - componentMibList, - Map> - componentProcesses, - Map processArtifact) { - //backup VSP processes - backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, - componentProcesses, processArtifact); - Collection componentsCompositionAndQuestionnaire = vendorSoftwareProductDao - .listComponentsCompositionAndQuestionnaire(vspId, - activeVersion); - componentsCompositionAndQuestionnaire.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - componentsQustanniare.put(componentName, componentEntity - .getQuestionnaireData()); - Collection - nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - //backup mib - Collection componentMib = - componentArtifactDao.listArtifacts(new - ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), - null)); - if (CollectionUtils.isNotEmpty(componentMib)) { - componentMibList.put(componentName,componentMib); - } - - //backup component processes - backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, - componentProcesses, processArtifact); - if (CollectionUtils.isNotEmpty(nics)) { - Map nicsQustanniare = new HashMap<>(); - nics.forEach(nicEntity -> { - NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), - nicEntity.getId())); - NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId()); - - nicsQustanniare - .put(nicEntity.getNicCompositionData().getName(), - nicQuestionnaire.getQuestionnaireData()); - }); - componentNicsQustanniare.put(componentName, nicsQustanniare); - } - }); - } - - private void backupProcess(String vspId, Version activeVersion, String componentId, - String componentName, Map> processes, - Map processArtifact) { - Collection processList = vendorSoftwareProductDao.listProcesses(vspId, - activeVersion, componentId); - if (!processList.isEmpty()) { - processes.put(componentName, processList); - processList.forEach(process -> { - //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, - // activeVersion, componentId, process.getId()); - ProcessEntity artifact = - processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); - if (artifact.getArtifact() != null) { - processArtifact.put(process.getId(), artifact); - } - }); - } - } - - private void restoreProcess(String vspId, Version activeVersion, String componentId, - String componentName, - Map> processes, - Map processArtifact) { - if (processes.containsKey(componentName)) { - Collection processList = processes.get(componentName); - processList.forEach(process -> { - //Reatin VFC process - if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId - ())) { - ProcessEntity artifact = processArtifact.get(process.getId()); - artifact.setComponentId(componentId); - UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), - componentId, process.getName()); - vendorSoftwareProductDao.createProcess(artifact); - } - }); - } - } - - private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, - FileContentHandler fileContentMap) { - VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); - Map> validationErrors = - ValidationManagerUtil.initValidationManager(fileContentMap).validate(); - response.getErrors().putAll(validationErrors); - - HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); - heatTreeManager.createTree(); - heatTreeManager.addErrors(validationErrors); - return heatTreeManager.getTree(); - } - - private void saveHotData(String vspId, Version activeVersion, InputStream uploadedFileData, - FileContentHandler fileContentMap, HeatStructureTree tree) { - Map manifestAsMap = - (Map) JsonUtil.json2Object(fileContentMap.getFileContent( - SdcCommon.MANIFEST_NAME), Map.class); - - UploadData uploadData = new UploadData(); - uploadData.setPackageName((String) manifestAsMap.get("name")); - uploadData.setPackageVersion((String) manifestAsMap.get("version")); - uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); - uploadData.setValidationDataStructure(new ValidationStructureList(tree)); - orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); - } - - private void deleteUploadDataAndContent(String vspId, Version version) { - //fixme change this when more tables are zusammenized - vendorSoftwareProductDao.deleteUploadData(vspId, version); - } - - private boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - Optional errorMessage; - errorMessage = candidateService.validateRawZipData(uploadedFileData); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private boolean isNotEmptyFileToUpload(InputStream heatFileToUpload, - UploadFileResponse uploadFileResponse) { - Optional errorMessage = - candidateService.validateNonEmptyFileToUpload(heatFileToUpload); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private Optional getZipContentMap(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - FileContentHandler contentMap = null; - try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); - } catch (IOException exception) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); - } catch (CoreException coreException) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); - } - return Optional.ofNullable(contentMap); - } // todo *************************** move to reusable place! ************************* @@ -646,4 +311,4 @@ public class OrchestrationTemplateCandidateManagerImpl }); } - } +} 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 5163cfde9f..78c4cbf5d9 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 @@ -22,6 +22,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.datatypes.Constants; import org.openecomp.core.enrichment.api.EnrichmentManager; import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -31,6 +32,7 @@ import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.api.ValidationManager; import org.openecomp.core.validation.util.MessageContainerUtil; import org.openecomp.sdc.activityLog.ActivityLogManager; @@ -318,7 +320,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails)); validationResponse - .setUploadDataErrors(validateUploadData(uploadData), LoggerServiceName.Submit_VSP, + .setUploadDataErrors(validateUploadData(uploadData,vspDetails), LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); validationResponse.setQuestionnaireValidationResult( @@ -641,6 +643,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa validateUniqueName(vspDetails.getName()); + vspDetails.setOnboardingOrigin(OnboardingTypesEnum.NONE.toString()); + vspInfoDao.create(vspDetails);//id will be set in the dao vspInfoDao.updateQuestionnaireData(vspDetails.getId(), null, new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData()); @@ -771,6 +775,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version)); + if(Objects.isNull(vsp.getOnboardingOrigin())){ + vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString()); + } + + if(Objects.isNull(vsp.getNetworkPackageName())){ + vsp.setNetworkPackageName("Upload File"); + } + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return vsp; } @@ -1044,7 +1056,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } - private Map> validateUploadData(UploadDataEntity uploadData) + private Map> validateUploadData(UploadDataEntity uploadData, + VspDetails vspDetails) throws IOException { Map> validationErrors = new HashMap<>(); @@ -1053,7 +1066,9 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } FileContentHandler fileContentMap = - CommonUtil.validateAndUploadFileContent(uploadData.getContentData().array()); + CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.getOnboardingTypesEnum + (vspDetails.getOnboardingOrigin()), + uploadData.getContentData().array()); //todo - check ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java new file mode 100644 index 0000000000..c7fb43770d --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java @@ -0,0 +1,100 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +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.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +import java.util.Optional; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { + protected static final Logger logger = + LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); + protected static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + @Override + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails) { + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + uploadFileResponse.setOnboardingType(getHandlerType()); + if (isNotEmptyFileToUpload(fileToUpload, uploadFileResponse, candidateService)) { + return uploadFileResponse; + } + + byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload); + if (isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService)) { + return uploadFileResponse; + } + + Optional optionalContentMap = + getFileContentMap(uploadFileResponse, uploadedFileData); + if (!optionalContentMap.isPresent()) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString())); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString()))); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + + if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + if (updateCandidateData(vspId, user, candidateService, vspDetails, uploadFileResponse, + uploadedFileData, optionalContentMap)) + return uploadFileResponse; + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + + } + + protected abstract boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, + Optional optionalContentMap); + + + private boolean isNotEmptyFileToUpload(InputStream fileToUpload, + UploadFileResponse uploadFileResponse, CandidateService candidateService) { + Optional errorMessage = + candidateService.validateNonEmptyFileToUpload(fileToUpload); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + Optional errorMessage; + errorMessage = candidateService.validateRawZipData(uploadedFileData); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + public abstract Optional getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData); + protected abstract OnboardingTypesEnum getHandlerType(); +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java new file mode 100644 index 0000000000..53d34749e7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java @@ -0,0 +1,154 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +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.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; +public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + + @Override + public Optional getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + List folderList = new ArrayList<>(); + try { + Pair> fileContentMapFromOrchestrationCandidateZip = CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData); + contentMap = fileContentMapFromOrchestrationCandidateZip.getKey(); + folderList = fileContentMapFromOrchestrationCandidateZip.getRight(); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + validateContent(uploadFileResponse, contentMap, folderList); + return Optional.ofNullable(contentMap); + } + + private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, List folderList) { + validateManifest(uploadFileResponse, contentMap); + validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + validateNoExtraFiles(uploadFileResponse, contentMap); + validateFolders(uploadFileResponse, folderList); + } + + private void validateManifest(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)){ + return; + } + InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); + OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); + if (!onboardingManifest.isValid()){ + onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); + } + } + + private void validateNoExtraFiles(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + List unwantedFiles = contentMap.getFileList().stream() + .filter(this::filterFiles).collect(Collectors.toList()); + if (!unwantedFiles.isEmpty()) { + unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), + unwantedFile)))); + + ; + } + } + + private void validateFolders(UploadFileResponse uploadFileResponse, List folderList) { + List filterResult = folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); + if (!filterResult.isEmpty()) { + folderList.stream().filter(this::filterFolders).forEach( unwantedFolder -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), + unwantedFolder)))); + + } + } + private boolean filterFiles(String inFileName) { + boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName)); + if (valid){ + return !valid; + } + return filterFolders(inFileName); + } + + private boolean filterFolders(String fileName) { + return !ELIGBLE_FOLDERS.stream().anyMatch(dirName -> fileName.startsWith(dirName)); + } + + private boolean validateFileExist(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, String fileName) { + + boolean containsFile = contentMap.containsFile(fileName); + if (!containsFile) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); + } + return containsFile; + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional optionalContentMap) { + try { + candidateService.updateCandidateUploadData(new OrchestrationTemplateCandidateData( + ByteBuffer.wrap(uploadedFileData), ""), vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()), exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.CSAR; + } + + @Override + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); + + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java new file mode 100644 index 0000000000..3f7d18de9f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java @@ -0,0 +1,12 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +public interface OrchestrationTemplateFileHandler { + UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails); +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java new file mode 100644 index 0000000000..626d941911 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java @@ -0,0 +1,55 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +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.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.util.Optional; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + @Override + public Optional getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + return OrchestrationUtil.getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, uploadedFileData); + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional optionalContentMap) { + try { + OrchestrationTemplateCandidateData candidateData = + new CandidateEntityBuilder(candidateService) + .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), + uploadFileResponse.getErrors(), user); + candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()),exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.ZIP; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java new file mode 100644 index 0000000000..104da69ed8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java @@ -0,0 +1,29 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_Impl_Key; + +public class OrchestrationUploadFactory { + private static Map fileHanlders; + + static { + Configuration config = ConfigurationManager.lookup(); + fileHanlders = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ORCHESTRATION_Impl_Key, ImplementationConfiguration.class)); + + } + + public static final OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(String filePrefix) { + ImplementationConfiguration orchestrationTemplateFileHandler = fileHanlders.get(filePrefix); + return CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(), + OrchestrationTemplateFileHandler.class); + } +} 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 new file mode 100644 index 0000000000..5d14477339 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -0,0 +1,282 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +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.heat.services.tree.HeatTreeManager; +import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MonitoringUploadDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; + +public class OrchestrationUtil { + + public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration"; + public static final String ORCHESTRATION_Impl_Key = "orchestration_impl"; + + + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static ComponentArtifactDao componentArtifactDao = MonitoringUploadDaoFactory.getInstance().createInterface(); + private static ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface(); + private static OrchestrationTemplateDao orchestrationTemplateDataDao = + OrchestrationTemplateDaoFactory.getInstance().createInterface(); + private static ComponentDao componentDao = + ComponentDaoFactory.getInstance().createInterface(); + private static ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance() + .createInterface(); + private static CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private static CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + + public static Optional getFileContentMap(OnboardingTypesEnum type, + UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + try { + contentMap = CommonUtil.validateAndUploadFileContent(type, uploadedFileData); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + return Optional.ofNullable(contentMap); + } + + public static void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, + Map componentsQustanniare, + Map> + componentNicsQustanniare, + Map> + componentMibList, + Map> + componentProcesses, + Map processArtifact) { + //backup VSP processes + backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, + componentProcesses, processArtifact); + Collection componentsCompositionAndQuestionnaire = vendorSoftwareProductDao + .listComponentsCompositionAndQuestionnaire(vspId, + activeVersion); + componentsCompositionAndQuestionnaire.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + componentsQustanniare.put(componentName, componentEntity + .getQuestionnaireData()); + Collection + nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + //backup mib + Collection componentMib = + componentArtifactDao.listArtifacts(new + ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), + null)); + if (CollectionUtils.isNotEmpty(componentMib)) { + componentMibList.put(componentName,componentMib); + } + + //backup component processes + backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, + componentProcesses, processArtifact); + if (CollectionUtils.isNotEmpty(nics)) { + Map nicsQustanniare = new HashMap<>(); + nics.forEach(nicEntity -> { + NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), + nicEntity.getId())); + NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId()); + + nicsQustanniare + .put(nicEntity.getNicCompositionData().getName(), + nicQuestionnaire.getQuestionnaireData()); + }); + componentNicsQustanniare.put(componentName, nicsQustanniare); + } + }); + } + + private static void backupProcess(String vspId, Version activeVersion, String componentId, + String componentName, Map> processes, + Map processArtifact) { + Collection processList = vendorSoftwareProductDao.listProcesses(vspId, + activeVersion, componentId); + if (!processList.isEmpty()) { + processes.put(componentName, processList); + processList.forEach(process -> { + //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, + // activeVersion, componentId, process.getId()); + ProcessEntity artifact = + processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); + if (artifact.getArtifact() != null) { + processArtifact.put(process.getId(), artifact); + } + }); + } + } + + public static void retainComponentQuestionnaireData(String vspId, Version activeVersion, + Map componentsQustanniare, + Map> + componentNicsQustanniare, + Map> componentMibList, + Map> processes, + Map processArtifact) { + //VSP processes + restoreProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, + processArtifact); + Collection + components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); + components.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + if (componentsQustanniare.containsKey(componentName)) { + componentDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), + componentsQustanniare.get(componentEntity.getComponentCompositionData() + .getName())); + if (componentNicsQustanniare.containsKey(componentName)) { + Map nicsQustanniare = componentNicsQustanniare.get(componentName); + Collection + nics = + nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + nics.forEach(nicEntity -> { + if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { + nicDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId(), + nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); + } + }); + } + //MIB //todo add for VES_EVENTS + if (componentMibList.containsKey(componentName)) { + Collection mibList = + componentMibList.get(componentName); + mibList.forEach(mib -> { + mib.setComponentId(componentEntity.getId()); + componentArtifactDao.create(mib); + }); + } + //VFC processes + restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, + processArtifact); + } + }); + } + + private static void restoreProcess(String vspId, Version activeVersion, String componentId, + String componentName, + Map> processes, + Map processArtifact) { + if (processes.containsKey(componentName)) { + Collection processList = processes.get(componentName); + processList.forEach(process -> { + //Reatin VFC process + if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId + ())) { + ProcessEntity artifact = processArtifact.get(process.getId()); + artifact.setComponentId(componentId); + UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), + componentId, process.getName()); + vendorSoftwareProductDao.createProcess(artifact); + } + }); + } + } + + public static void deleteUploadDataAndContent(String vspId, Version version) { + //fixme change this when more tables are zusammenized + vendorSoftwareProductDao.deleteUploadData(vspId, version); + } + + public static void saveUploadData(String vspId, Version activeVersion, InputStream uploadedFileData, + FileContentHandler fileContentMap, HeatStructureTree tree) { + Map manifestAsMap = + fileContentMap.containsFile(SdcCommon.MANIFEST_NAME) ? + (Map) JsonUtil.json2Object(fileContentMap.getFileContent( + SdcCommon.MANIFEST_NAME), Map.class) + : new HashMap<>(); + + UploadData uploadData = new UploadData(); + uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); + uploadData.setValidationDataStructure(new ValidationStructureList(tree)); + uploadData.setPackageName(Objects.isNull(manifestAsMap.get("name")) ? null : + (String) manifestAsMap.get("name")); + uploadData.setPackageVersion(Objects.isNull(manifestAsMap.get("version")) ? null : + (String) manifestAsMap.get("version")); + orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); + } + + public static void saveServiceModel(String vspId, + Version version, + ToscaServiceModel serviceModelToExtract, + ToscaServiceModel serviceModelToStore){ + if (serviceModelToExtract != null) { + serviceModelDao.storeServiceModel(vspId, version, serviceModelToStore); + //Extracting the compostion data from the output service model of the first phase of + // translation + compositionEntityDataManager.saveCompositionData(vspId, version, + compositionDataExtractor.extractServiceCompositionData(serviceModelToExtract)); +// OrchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, +// componentNicsQuestionnaire, componentMibList, processes, processArtifact); + } + } + + public static HeatStructureTree createHeatTree(FileContentHandler fileContentMap, + Map> validationErrors){ + HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); + heatTreeManager.createTree(); + heatTreeManager.addErrors(validationErrors); + return heatTreeManager.getTree(); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java new file mode 100644 index 0000000000..0d204ef2c0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java @@ -0,0 +1,18 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableSet; +import static com.google.common.collect.ImmutableSet.of; +public class CSARConstants { + + public static final ImmutableSet ELIGBLE_FOLDERS = of("Artifacts/","Definitions/", + "Licenses/", "TOSCA-Metadata/"); + + public static final String MAIN_SERVICE_TEMPLATE_MF_FILE_NAME = "MainServiceTemplate.mf"; + public static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml"; + public static final ImmutableSet ELIGIBLE_FILES = + of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + + public static final String METADATA_MF_ATTRIBUTE = "metadata"; + public static final String SOURCE_MF_ATTRIBUTE = "source"; + public static final String SEPERATOR_MF_ATTRIBUTE = ":"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java new file mode 100644 index 0000000000..d88d883e67 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java @@ -0,0 +1,141 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang.StringUtils; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; + +public class OnboardingManifest { + private static final Logger logger = LoggerFactory.getLogger(OnboardingManifest.class); + private Map metadata; + private List sources; + private List errors; + private State state; + private enum State { + Start, ProcessMetadata, ProcessSources, Error + } + + public OnboardingManifest(InputStream is) { + errors = new ArrayList<>(); + sources = new ArrayList<>(); + metadata = new HashMap<>(); + parseManifest(is); + } + + private void parseManifest(InputStream is) { + try { + ImmutableList lines = readAllLines(is); + state = State.Start; + + for (String line : lines) { + line = line.trim(); + if (!StringUtils.isEmpty(line.trim())) { + state = processLine(state, line); + } + } + if (errors.isEmpty()) { + if (metadata.isEmpty()) { + errors.add(Messages.MANIFEST_NO_METADATA.getErrorMessage()); + } + if (sources.isEmpty()) { + errors.add(Messages.MANIFEST_NO_SOURCES.getErrorMessage()); + } + } + } catch (IOException e){ + logger.error(e.getMessage(),e); + errors.add(Messages.MANIFEST_PARSER_INTERNAL.getErrorMessage()); + } + } + + private State processLine(State state, String line) { + switch (state) { + case Start: + if (line.trim().equals(METADATA_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE)) { + state = State.ProcessMetadata; + } else { + reportError(line); + } + break; + case ProcessMetadata: + String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE); + if (metaSplit.length < 2){ + reportError(line); + break; + } + if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){ + String value = line.replace(metaSplit[0] + SEPERATOR_MF_ATTRIBUTE, "").trim(); + metadata.put(metaSplit[0],value); + } else { + state = State.ProcessSources; + processSourceLine(line); + } + break; + case ProcessSources: + processSourceLine(line); + + break; + case Error: + break; + + } return state; + } + + private void processSourceLine(String line) { + if (line.startsWith(SOURCE_MF_ATTRIBUTE+SEPERATOR_MF_ATTRIBUTE)){ + String value = line.replaceAll(SOURCE_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE, "").trim(); + sources.add(value); + }else { + reportError(line); + } + } + + private void reportError(String line) { + errors.add(getErrorWithParameters(Messages.MANIFEST_INVALID_LINE.getErrorMessage(), line)); + state = State.Error; + } + + private ImmutableList readAllLines(InputStream is) throws IOException { + ImmutableList.Builder builder = ImmutableList. builder(); + try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8.newDecoder()); + BufferedReader bufferedReader = new BufferedReader(reader);) { + for (; ; ) { + String line = bufferedReader.readLine(); + if (line == null) + break; + builder.add(line); + } + } + return builder.build(); + } + + public Map getMetadata() { + if (!isValid()){ + return Collections.EMPTY_MAP; + } + return ImmutableMap.copyOf(metadata); + } + + public List getSources() { + if (!isValid()){ + return Collections.EMPTY_LIST; + } + return ImmutableList.copyOf(sources); + } + + public List getErrors() { + return ImmutableList.copyOf(errors); + } + + public boolean isValid() { + return errors.isEmpty(); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java new file mode 100644 index 0000000000..5295e6a6d6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -0,0 +1,64 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; +public class OrchestrationProcessFactory { + + private static final String confFile = "config-orchestration.json"; + private static Map processImplMap; + + static { + Configuration config = ConfigurationManager.lookup(); + processImplMap = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ConfigConstants.processImplKey, ImplementationConfiguration.class)); + + } + + public static Optional getInstance(String filePrefix) { + filePrefix = filePrefix == null ? null : filePrefix.toLowerCase().trim(); + if (filePrefix == null) { + return Optional.empty(); + } + + OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(filePrefix); + if (onboardingTypesEnum == null) { + return Optional.empty(); + } + + try { + return Optional.of(createInstance(processImplMap.get(onboardingTypesEnum.toString()))); + }catch (Exception e){ + return Optional.empty(); + } + } + + private static Map getOrchestrationImplMap(){ + try { + return FileUtils.readViaInputStream(confFile, + stream -> JsonUtil.json2Object(stream, Map.class)); + }catch (Exception e){ + return new HashMap<>(); + } + } + + private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass) + throws Exception { + OrchestrationTemplateProcessHandler handler; + handler = + CommonMethods.newInstance(implClass.getImplementationClass(), OrchestrationTemplateProcessHandler.class); + return handler; + } +} 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 new file mode 100644 index 0000000000..4866d93411 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.impl.ToscaConverterImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.common.errors.CoreException; +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.services.tree.ToscaTreeManager; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.messages.AuditMessages; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { + + private static Logger logger = + LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); + private ToscaConverter toscaConverter = new ToscaConverterImpl(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + ToscaTreeManager toscaTreeManager = new ToscaTreeManager(); + + @Override + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CSAR_VALIDATION_STARTED + vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional fileContent = + OrchestrationUtil + .getFileContentMap( + OnboardingTypesEnum.CSAR, uploadFileResponse, candidateData.getContentData().array()); + + if(fileContent.isPresent()){ + try { + FileContentHandler fileContentHandler = fileContent.get(); + processCsar(vspId, version, fileContentHandler, candidateData, response); + } catch (CoreException e){ + logger.error(e.getMessage()); + throw e; + } catch (Exception e){ + logger.error(e.getMessage()); + } + } + + return response; + } + + private void processCsar(String vspId, Version version, + FileContentHandler fileContentHandler, + OrchestrationTemplateCandidateData candidateData, + OrchestrationTemplateActionResponse response) throws IOException { + + + response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); + Map> errors = validateCsar(fileContentHandler, response); + if(!isValid(errors)){ + return; + } + + HeatStructureTree tree = toscaTreeManager.getTree(); + + Map componentsQuestionnaire = new HashMap<>(); + Map> componentNicsQuestionnaire = new HashMap<>(); + Map> componentMibList = new HashMap<>(); + Map> processes = new HashMap<>(); + Map processArtifact = new HashMap<>(); + + OrchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + Optional zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream(vspId, candidateData, null, OnboardingTypesEnum.CSAR, errors); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData( + vspId, version, zipByteArrayInputStream.get(), fileContentHandler, tree); + + ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler); + OrchestrationUtil.saveServiceModel(vspId, version, toscaServiceModel, toscaServiceModel); + + } + + private void addFiles(FileContentHandler fileContentHandler){ + for(Map.Entry fileEntry : fileContentHandler.getFiles().entrySet()){ + toscaTreeManager.addFile(fileEntry.getKey(), fileEntry.getValue()); + } + } + + private Map> validateCsar(FileContentHandler fileContentHandler, + OrchestrationTemplateActionResponse response){ + + + Map> errors = new HashMap<>(); + addFiles(fileContentHandler); + toscaTreeManager.createTree(); + toscaTreeManager.addErrors(errors); + //todo - add tosca validation here to the existing validation framework + return errors; + } + + private boolean isValid(Map> errors){ + return MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors)); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java new file mode 100644 index 0000000000..8b513b4347 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java @@ -0,0 +1,12 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; + +public interface OrchestrationTemplateProcessHandler { + OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user); +} 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 new file mode 100644 index 0000000000..cceacd47b3 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java @@ -0,0 +1,184 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.translator.datatypes.TranslatorOutput; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.activityLog.ActivityLogManagerFactory; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.common.errors.Messages; +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.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.messages.AuditMessages; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; +import org.openecomp.sdc.validation.util.ValidationManagerUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdcrests.activitylog.types.ActivityType; + +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; + +public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemplateProcessHandler { + Logger logger = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + private ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface(); + private CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + private ActivityLogManager activityLogManager = + ActivityLogManagerFactory.getInstance().createInterface(); + + + public OrchestrationTemplateProcessZipHandler(){} + + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + + vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional fileContent = + OrchestrationUtil + .getFileContentMap( + OnboardingTypesEnum.ZIP, uploadFileResponse, candidateData.getContentData().array()); + if (!fileContent.isPresent()) { + response.addStructureErrors(uploadFileResponse.getErrors()); + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + Map> uploadErrors = uploadFileResponse.getErrors(); + FileContentHandler fileContentMap = fileContent.get(); + FilesDataStructure structure = + JsonUtil.json2Object(candidateData.getFilesDataStructure(), FilesDataStructure.class); + + if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { + response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, + Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + + String manifest = candidateService.createManifest(vspDetails, structure); + fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); + + Optional zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream( + vspId, candidateData, manifest, OnboardingTypesEnum.ZIP, uploadErrors); + if (!zipByteArrayInputStream.isPresent()) { + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); + + Map componentsQuestionnaire = new HashMap<>(); + Map> componentNicsQuestionnaire = new HashMap<>(); + Map> componentMibList = new HashMap<>(); + Map> processes = new HashMap<>(); + Map processArtifact = new HashMap<>(); + + OrchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, + tree); + + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors + ()))) { + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + } + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); + + TranslatorOutput translatorOutput = + HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); + + ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); + OrchestrationUtil.saveServiceModel(vspId, version, translatorOutput + .getNonUnifiedToscaServiceModel(), toscaServiceModel); + OrchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); + uploadFileResponse.addStructureErrors(uploadErrors); + + ActivityLogEntity activityLogEntity = + new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), + ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); + activityLogManager.addActionLog(activityLogEntity, user); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return response; + } + + private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, + FileContentHandler fileContentMap) { + VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); + Map> validationErrors = + ValidationManagerUtil.initValidationManager(fileContentMap).validate(); + response.getErrors().putAll(validationErrors); + + return OrchestrationUtil.createHeatTree(fileContentMap, validationErrors); + } + + private void printAuditForErrors(List errorList, String vspId, String auditType) { + + errorList.forEach(errorMessage -> { + if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) { + logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), + vspId)); + } + }); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java new file mode 100644 index 0000000000..5e217d4d60 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorsoftwareproduct.types; + +public class ConfigConstants { + public static final String namespace = "Orchestration"; + public static final String processImplKey = "process_impl"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java index 99f3fa1fdf..ca0eed2153 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.types; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -35,6 +36,8 @@ import java.util.Map; public class UploadFileResponse { private Map> errors = new HashMap<>(); private UploadFileStatus status = UploadFileStatus.Success; + private OnboardingTypesEnum onboardingType; + private String networkPackageName; public UploadFileStatus getStatus() { return status; @@ -44,6 +47,22 @@ public class UploadFileResponse { this.status = status; } + public OnboardingTypesEnum getOnboardingType() { + return onboardingType; + } + + public void setOnboardingType(OnboardingTypesEnum onboardingTypesEnum) { + this.onboardingType = onboardingTypesEnum; + } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } + /** * Add structure error. * diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json new file mode 100644 index 0000000000..9193b818b7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json @@ -0,0 +1,26 @@ +{ + "orchestration_impl": { + "zip": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateCSARHandler" + } + }, + "process_impl": { + "zip" : { + "enzble": true, + "implementationClass" : "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessCsarHandler" + } + }, + + "_config":{ + "namespace": "orchestration" + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json new file mode 100644 index 0000000000..7509094b56 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json @@ -0,0 +1,3 @@ +{ + "zip" :"org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.orchestrationTemplateProcessZipHandler" +} \ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index 948d46ba10..3e42a23c6a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -48,7 +48,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.Com import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.InputStream; import java.util.List; @@ -112,7 +111,7 @@ public class QuestionnaireDataServiceTest { public void testQuestionnaireDataAfterIllegalUpload() { InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml"); UploadFileResponse uploadFileResponse = candidateManager - .upload(vspId, VERSION, zipInputStream, USER1); + .upload(vspId, VERSION, zipInputStream, USER1, "zip", "missingYml"); InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); @@ -124,7 +123,7 @@ public class QuestionnaireDataServiceTest { InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath); UploadFileResponse uploadFileResponse = candidateManager .upload(vspId, VERSION, - zipInputStream, USER1); + zipInputStream, USER1,"zip", "file"); candidateManager.process(vspId, VERSION, USER1); Assert.assertTrue(MapUtils.isEmpty( diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java index e6d06f2e2c..252e152740 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java @@ -6,6 +6,7 @@ import org.mockito.MockitoAnnotations; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -23,7 +24,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -90,7 +90,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject()); doReturn(Optional.empty()).when(candidateServiceMock) - .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), anyObject()); + .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), OnboardingTypesEnum.ZIP, anyObject()); OrchestrationTemplateActionResponse response = @@ -123,7 +123,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); @@ -136,7 +136,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUploadWithManifest() { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 4ead8a57d2..e0e00f8d9d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -39,7 +39,6 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.errors.ValidationErrorBuilder; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; @@ -54,14 +53,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; @@ -92,7 +87,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -357,7 +351,7 @@ public class VendorSoftwareProductManagerImplTest { "subCategory", "456", fgs); List updFgs = new ArrayList(); - //updFgs.add("fg2"); + updFgs.add("fg2"); VspDetails updatedVsp = createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", "category_updated", @@ -659,7 +653,7 @@ public class VendorSoftwareProductManagerImplTest { InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip"); UploadFileResponse uploadFileResponse = - candidateManager.upload(VSP_ID, VERSION01, zis, USER1); + candidateManager.upload(VSP_ID, VERSION01, zis, USER1, "zip", "missingYml"); Assert.assertEquals(uploadFileResponse.getErrors().size(), 0); } @@ -672,7 +666,7 @@ public class VendorSoftwareProductManagerImplTest { try { candidateManager .upload(VSP_ID, VERSION01, - url.openStream(), USER1); + url.openStream(), USER1, "zip", "notZipFile"); candidateManager.process(VSP_ID, VERSION01, USER1); } catch (Exception ce) { Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); @@ -680,107 +674,7 @@ public class VendorSoftwareProductManagerImplTest { verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); } -/* - @Test - public void testEnrichModelInSubmit() { - UniqueValueUtil - .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - "VSP_syb"); - VspDetails vspDetails = vendorSoftwareProductManager.createVsp( - createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "456", null), USER1); - String id = vspDetails.getId(); - - //upload file - InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); - candidateManager.upload(id, VERSION01, zis, USER1); - OrchestrationTemplateActionResponse uploadFileResponse = - candidateManager.process(id, VERSION01, USER1); - - //check in - vendorSoftwareProductManager.checkin(id, USER1); - //submit - try { - ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); - } catch (IOException exception) { - Assert.fail(); - } - VersionedVendorSoftwareProductInfo details = - vendorSoftwareProductManager.getVsp(id, null, USER1); - Collection components =vendorSoftwareProductManager - .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1); - - ToscaServiceModel model = - (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() - .getServiceModel(id, details.getVersionInfo().getActiveVersion()); - - Map capabilities = new HashMap<>(); - for (ComponentEntity component : components) { - model.getServiceTemplates(). - entrySet(). - stream(). - filter(entryValue -> entryValue.getValue() != null && - entryValue.getValue().getNode_types() != null && - entryValue.getValue(). - getNode_types(). - containsKey(component.getComponentCompositionData().getName())). - forEach(entryValue -> entryValue.getValue().getNode_types(). - values(). - stream(). - filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). - forEach(type -> type.getCapabilities(). - entrySet(). - forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), - entry.getValue())))); - - } - - Assert.assertNotNull(capabilities); - } - - @Test(dependsOnMethods = {"testCreatePackage"}) - public void testEnrichedFilesDeletedOnNewUpload() throws IOException { - Version activeVersion; - createPackageFromUpload(VSP_ID, USER1, "/fullComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List firstExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - createPackageFromUpload(VSP_ID, USER1, "/emptyComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List secondExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts); - Assert.assertNotEquals(firstServiceModel, secondServiceModel); - - } - - @Test(dependsOnMethods = {"testMibsDeletedInCsar"}) - public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException { - String nestedPath = "Definitions" + File.separator + "nested"; - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List nestedFileNamesServiceTemplates = - getWantedFileNamesFromCsar(nestedPath); - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath); - - Assert.assertEquals(emptyNestedNamesList.size(), 0); - Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size()); - }*/ private List getWantedFileNamesFromCsar(String pathInCsar) throws IOException { @@ -806,21 +700,6 @@ public class VendorSoftwareProductManagerImplTest { return fileNames; } - /* - //Disabled for sonar null pointer issue for componentEntities - private Pair uploadMib(String vspId, String user, String filePath, - String fileName) { - List componentEntities = null; - //(List) vendorSoftwareProductManager.listComponents(vspId, null, user); - monitoringUploadsManager.upload(getFileInputStream(filePath), - fileName, vspId, - VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user); - //TODO: add validate of addActionLog() func call - - return new ImmutablePair<>(componentEntities.get(0).getId(), - componentEntities.get(0).getComponentCompositionData() - .getDisplayName()); - }*/ private void createPackageFromUpload(String vspId, String user, String filePath) throws IOException { @@ -830,7 +709,7 @@ public class VendorSoftwareProductManagerImplTest { private void uploadFileAndProcess(String vspId, String user, String filePath) { vendorSoftwareProductManager.checkout(vspId, user); - candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user); + candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user, "zip", "file"); candidateManager.process(vspId, VERSION01, user); } @@ -888,7 +767,7 @@ public class VendorSoftwareProductManagerImplTest { */ private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, VERSION01, upload, USER1); + candidateManager.upload(vspId, VERSION01, upload, USER1, "zip", "file"); candidateManager.process(vspId, VERSION01, user); UploadDataEntity uploadData = @@ -919,23 +798,6 @@ public class VendorSoftwareProductManagerImplTest { } - // private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName) -// throws IOException { -// ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName))); -// boolean isInfoArtifactInZip = false; -// -// ZipEntry zipEntry; -// while ((zipEntry = inputZipStream.getNextEntry()) != null) { -// String currentEntryName = zipEntry.getName(); -// if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" + -// vspId + "_Information.txt")){ -// isInfoArtifactInZip = true; -// break; -// } -// } -// -// Assert.assertTrue(isInfoArtifactInZip); -// } static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, @@ -969,45 +831,7 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups()); } - -// @Test -// public void testDownloadFile() throws IOException { -// VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null); -// VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1); -// -// id005 = createdVsp.getId(); -// Assert.assertNotNull(id005); -// Assert.assertNotNull(createdVsp.getVersion()); -// -// try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) { -// -// UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1); -// vendorSoftwareProductManager.process(id005, USER1); -// Optional fileCandidate = vendorSoftwareProductManager.get(id005, USER1); -// -// File latestHeatPackage = fileCandidate.get(); -// -// zipInputStream.reset(); -// byte[] uploaded = IOUtils.toByteArray(zipInputStream); -// -// Optional zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded); -// FileContentHandler fileContentHandler = new FileContentHandler(); -// if(zipContentMap.isPresent()){ -// fileContentHandler = zipContentMap.get(); -// } -// -// uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values()); -// -// byte[] downloaded; -// try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) { -// downloaded = IOUtils.toByteArray(fileStream); -// } -// -// Assert.assertTrue(Arrays.equals(uploaded, downloaded)); -// } -// } - - // todo ********************** move to common ************************************** + // todo ********************** move to common ************************************** private void mockVersioning(VersionableEntityAction action) { VersionInfo versionInfo = new VersionInfo(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index 236b7e7594..dfb7409bd0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -27,6 +27,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; @@ -37,92 +38,86 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; -import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; import java.util.zip.ZipOutputStream; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; +import static org.testng.Assert.assertEquals; public class UploadFileTest { - private static final String USER1 = "vspTestUser1"; - - public static final Version VERSION01 = new Version(0, 1); - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; - @Spy - private CandidateServiceImpl candidateService; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private VendorSoftwareProductInfoDao vspInfoDaoMock; - - @InjectMocks - private OrchestrationTemplateCandidateManagerImpl candidateManager; - - private static String vlm1Id; - public static String id001 = null; - public static String id002 = null; - - public static Version activeVersion002 = null; - - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUploadFile() { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1); - } - - - private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, activeVersion002, upload, user); - - UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); - - } - - public InputStream getZipInputStream(String name) { - URL url = this.getClass().getResource(name); - File templateDir = new File(url.getFile()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ZipOutputStream zos = new ZipOutputStream(baos); - - VSPCommon.zipDir(templateDir, "", zos, true); - try { - zos.close(); - } catch (IOException e) { - e.printStackTrace(); + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + + @InjectMocks + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + private static String vlm1Id; + public static String id001 = null; + public static String id002 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testUploadFile() { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1, OnboardingTypesEnum.ZIP.toString(), "legalUpload"); + } + + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, + upload, user, OnboardingTypesEnum.ZIP.toString(),"file" ); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); + UploadDataEntity uploadData = + orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); + + } + + public InputStream getZipInputStream(String name) { + URL url = this.getClass().getResource(name); + File templateDir = new File(url.getFile()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + VSPCommon.zipDir(templateDir, "", zos, true); + } catch (IOException e) { + e.printStackTrace(); + } + return new ByteArrayInputStream(baos.toByteArray()); } - return new ByteArrayInputStream(baos.toByteArray()); - } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java new file mode 100644 index 0000000000..3332e81e36 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java @@ -0,0 +1,58 @@ +package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; + +import org.junit.Test; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.*; + +public class ManifestParsingTest { + + @Test + public void testSuccessfulParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertTrue(onboardingManifest.isValid()); + assertEquals(onboardingManifest.getMetadata().size(), 4); + assertEquals(onboardingManifest.getSources().size(), 5); + } + } + + @Test + public void testNoMetadataParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testBrokenMDParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testNoMetaParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java new file mode 100644 index 0000000000..a7fc0e1ba0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.upload.csar; + + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.healing.api.HealingManager; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.function.Predicate; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; + +public class UploadCSARFileTest { + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + @Mock + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; + @Mock + private ManifestCreatorNamingConventionImpl manifestCreator; + + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + + public static String id001 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + candidateService = new CandidateServiceImpl(manifestCreator,orchestrationTemplateCandidateDao); + candidateManager = new OrchestrationTemplateCandidateManagerImpl( vendorSoftwareProductDaoMock, + vspInfoDaoMock, + orchestrationTemplateDataDaoMock, + candidateService, healingManagerMock, + compositionDataExtractorMock, + serviceModelDaoMock, + compositionEntityDataManagerMock, + null, + null, + null, + null, + null); + } + + @Test + public void testSuccessfulUploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmock"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(0, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().isEmpty()); + } + } + + @Test + public void testFail1UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail1"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED + .getErrorMessage().substring(0, 7))).findAny().isPresent()); + } + } + + private Predicate> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List error) { + return error.iterator().next().getMessage().contains(substring); + } + + @Test + public void testFail2UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail2"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testFail3UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail3"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testUploadFileIsNotZip() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( "Thia is not a zip file".getBytes() );) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertFalse(uploadFileResponse.getErrors().isEmpty()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testUploadFileIsEmpty() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( new byte[]{} )) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, + activeVersion002, is, USER1, "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testMFError() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmockBrokenMF"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors() + .values().stream() + .filter(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage())).findAny().isPresent()); + + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar new file mode 100644 index 0000000000000000000000000000000000000000..f69efd2bb813aed10a5bd249cc5d4ce60afb8487 GIT binary patch literal 4211 zcmbVPTT@$A6b=L^p-^ZIx6%R%rG;|o4GJ{jS}c$hV!1Wn`6=7V*-J~&z@R%bdLb?Vgd(MSJ+-*?vGRf23m`tXPNUr0bZ@)ecj_*Yyve3}j6ZE>n z-pNqd?OCV|%`Gl@7D_{&pznJ4Io;5e*qFWmdhq*q?Ewyq8l5)2kGF&2+I4qemcu5V zW+p~F@15}ld|}^GK<3Go=_d5PsZ2B#T1tDeiI#Me>1^B^7yL`pZvVi_bSUf#udtWF z_3PfyfH%16^LPini`V^F47joAM+ZX}mmp7MLga(Dz!DI+99e*zmdbaZqO1ZBfa&0o zeu&d+5L@8vp|g-cF4%WcbjWTy-$?;afWzQw1H@?%Xa$eWiw?P0)1JNsbrdWHXTWX{ zCv50iS$sefW*j?5m>Bz>pNf$tc6Y7RZL$I>_NiZ(9N=Ye7BSs7!$! z?e&Z!zzVL=>xOd>bX7yOXq$9pCHgAld2nbg5*R!Nh0`wrrvrV8n;z(9&~8A35mFAjr(F)5rS4t9EApzW3zj_*fl z;R^tx7RXNJ!=FEcczQ=n`=o#j(jk{rAKuM@!i5ByqVKieupE|($PpBFP@Pu_)M7su zu;qulkb=MNH$kZcCmJ>5i_n@GJHXXV&1|C`NPX}L zP0+`45X*;!Wz1faAkABx)J+c)i=gPHl-1GKpfv5_5l#Z_AYW{B?&lsBf&$w#bN2Zc zAhyK9=37jT8tiNWR5KD?*^C!K^2vjmE(#qTvi9Y7^+K8JZVrfep%jtvHVIz1jn%m4``Cy@4{7f{99?Y_aoba`h`bUTKDB zCCjLmFRq_D(;4iR=8(x_Q=-pYRD7u``D)=R)K;k3jN_T?K11Pgzj_-@kdX zpe&bjPZa|s^E%KWMHvdG4PtqUr|vAsJXXQ}m}}VI2!o)i86tR%wwm0vEoNUmc&5)) zWbd&#Qq+)#p$(jtRwK6lqRL2yQg6B88gxS~{{a4yo3Bl=TrcU{~lG<4xd2(N6ya3!|F4 zDw^#m{TlI1RhL`4__6x&!yc|P_X4OInN$asI;0v+eyG`EjA+j)o1(X0LTxWi`~YgW z22F_)D(XyKE%KNL8Hj$#sk3|TA7C*<)MRB;J-FkW_~YaDpYEYP`S;z|bG zI>pzur=sjUJFq9b{OFenZS)T4E<*-i&@89NE=MQckNA2lb3E_vw9}EqcPWD_>Ze>c z>39d?>w1Tt^}W}-lbM?MV#lw)!5#5K$=mBnki?H3Uw1iD(-5B~^r9d|IW&stUtbqb AnE(I) literal 0 HcmV?d00001 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar new file mode 100644 index 0000000000000000000000000000000000000000..02593a1d2f4196b3a30f1f7df14f9b39ae387e5a GIT binary patch literal 4022 zcmbVOTT@e46i!G`!bOk?H&LLKiy#ENfGBtH0wh8#Hvubz7$A@YNCE;9v@@M)XVgw- zoUu=>4}Ec_FP%QrPOlG6YX@yRPH$st$HzYQFZBD)IvkQ?&}lQ@xAxkXv-jF-uf4LJ zc9Yp^;BWtQj$Khyk(LalEg1Gry4>MVwG#uCCWB!$l4bwro39RnBPkd}=EV$l2R*K^ zXDk$Uxo2&mY5$yiwkYHddgsG0nTDopt?3P52A^-+8DPNqSfgXV$JfEIZN(Ls;Yo1_@+=J%>bx>}=vUX0Qev1efX{j(|W5cwk0!$P`U``Zm<_U;#J@c7i|= z*a{})r6o&CJBlvw$!FF_Upq|R3fc?|NHLgzG8}A%tg}@^4nBUz5{{bl6em*!6=uymcLpOmA5U_*UqP9#e zh;o$uPR^H>JO+8b3Bp%Y3t0+sQ}wj#GFY(s+Xvk>?RBq@paO)Y5Lt$Td;j@%_Tw+r z9{NXMu~l}jS3x%|OhFEeU#3m$SN#QTrXNB*AZVeWYq%ui}nwwGGX`zPlDeF+wZ$fr4Qv9EEmHn%UQSRT>WNMrq*( z0HYR2Ph{s0pF%vnAx*oafDF?MrYrAaOCl!%HD4IZZUuLKUK02`Z zyPJ@LXZManDF;XEwZ>PVonY($7uU4rMz#Zq4?cq2#Ykr00ZAZF6{s(_i?VT@$J@bC zh0-FDaTx)Z=yV2FHJ#x4>mDSKNpGa{P@-WCO6|$}C}}P4*ist=*#iQ(D^j+OqAcy> z<=7`JMJPI&=>az6Y@e$v$UF|@lt9Q6laTQhQnG{d0L*A4vzRv8C!g7t{XQidtM$#b zlx)|NZ%=4kW;o$Xk=fABy1W5>GV?P@0Ec+^HK~l$ZqQWL2^r|@tmH**pj%QHihZCO zCS_Unos0|}rstVu0Y7+}s*D>o0eS9BhO2PV2%+O%Q6phU4fS_e0cZtAc|)n zKe~(JRq2^V!Oy#Xxh4&e4e5DmbgDCO(W9fht$*H@Q3>bzf4Xy@v+thU^3((LSQuvr^ACtgp_KFS;&Q$rW|oQ*5W!1qtIAqlXDW*ZFGxda`p!nXS&bqz zw1N{dYN)X{zx>Br9jMVC0v=TcZ_}ABh|~@y<}09jseb>QiNeXOn$6G~uC8dJ{@N)0 z0MPe<7p(1vSeN>u6lxY}Zcj^Q__H+!tc~PL{~}FO0}`4CY@>aGS^jehmZWGbqg_Mp z@ycTBDQ5of?{v}6YO1Li8dDdR;gD)H`JkptV?^sKKfZCDft3z+!@^N=vSIaKk(L$A@hXZ=pW+_sut@oBL*vmhfyeZm`#BHzu?wX(#S$vKY66zYHm&-g$Ue7AcKJT%n62+T`@UQD4`3MN!7c z$}fDLZm!OS4uD&)OxBayuWP-cJb!o4 z9`_{??Iw(gHX!O{5n~I6Wpp*k)zRCbuWx0J?H?k~n-KqDqBo+tWS5b7*Qj4qUynB8 sMgQ?SL(K7CNc_*&n*uA8Y`vm{hJJm0-DywUfv7ZK76n)c6DUpp0vOlCKL7v# literal 0 HcmV?d00001 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar new file mode 100644 index 0000000000000000000000000000000000000000..5e3ee6f387356f94cfd39e9b6f387325eb634a22 GIT binary patch literal 4372 zcmbVQTTfh76do8T43|Rda4RjKP+BMqy+MI8T#E%}3S+rLTNtJT3=Bh=Ib6%oXpEY) zH6~5;Nlo<8Hy^C=`e3vMt4Y(Ssj2bNNB@G~ch=#|nPF(78w?_%pxX@5FnM@nu9LGQ3etiNQOGhKJAgZw^=yfaJ ziIC#<%-ce<3yYrll8`6pyP-U%8@du1(-%Mwe*d05z=4ryr=#D;+d;*)?hedw*!a`T zz=#*T)4qUD@ht{qo@|+FLhqaEM3bQ|5o?iVV%k;YLJOo|UQ6<_YU0L3K74iZ&xE2l!9EZZ`7lKoPUe!$xbTjA#0SA~XYRk-$ zC};WH#r`tWCLl-b5dM-{$a0XAs;6J8V9~~JAM~7Tue&;i3ZO_K@)!!v{qeiGkG|5L zaD4<8TUF0iHFWdR4CLVCDt+Q}ZM~q)4M1oc1T7SFk5(7XSfF--oC`ysu?#}M<>?-# z*POh$?=YknyaMK3hXAzss>{)%*8()Oh$k+j{ZR+MG+JWQ;pFr+sBs1`URFJz0)K@q}*}l!~?O>~7 zv4~_`hQSpsIs>bQi{SqAJ|u9EtC7V`F~S;@+LQND(p#Rfl{N^n7XDgX zaYQU7C_0+C0yO09ovSR!JWk}4K*$@Fknt8$vXlJ)%xEODnBLkiui4fX{AxDV>N{hp z*$%lBuXDZvybmS8WXgqh$?XfornCj73ZP{kqBR48=Vdpv2-(RYXfQg}sBmj{LyHGI zV1#sBorTP1)&bV~%$aElr@8$R#Motsrj-x_ZL*ck1zhkJ28K2+v_Wq2<2PCvMUe^m zcn%`@u%MLLYXYQsi<7$PVPX*!-juRx`!y&HDLldnpdI9k_09v_!vavyG{u~K;RT2- zv9S3TlcNqhn*ddeL{}E$MUZ&vkgkhDM+dFFd7V8_X1f{#VrJL*qP9q(<*9v<&AlQY zvNd@QiA{w}GMV!C*jnvt)sI#jNBv%#!VOr~I>5~y43JeFAX3Xj*msAt7X zsFp3PpFZ0W?2_h?iKCOEPhaAfYF`+Fo0V;64qM8B$aNltaCQ2^h+c`Cm& zhjULB10?f0&@M$O3TG3<(j-saIgoj*oc%G^u)kpjL1iOE@H%bPIcrufKArC__{rvmUhIa*=-}C42x)oX_b+$=T#TYze)dLd zD(%!Sk8>RWu07xbYX=~>(ZI44THfhuxGNW%-YG1)sG)`bDg;tK;`g+Hn7wowP^A~%@Si+e^$}3efuTU(rMxcP{(y> zYLrmXX6kB|$2`cu_LrPGyXXD^7BfV3W?JQgJHGKhK5qNz9_kZ+-+f&kbKVTnqug7~ zOC||=w$(W|8t&od8^J*EfPFk7+N~DVP@ZEcqi9t%r~^?iN$GtQe zmkDi*4j3*`QNEyAcDG%QPOKlX^+@J;-koc=Bk}KGQLboL0K=qX9f++P9eUP1!RSs# za{LP+Zw*oIh#zXcUsr=9cJ$bK?1_$(l8ug_|9z1Z9XqtyKVjy_k@;+TUejHuxOa3% TGG6C@Fw#vkNhZ_&6xRL)Ossg} literal 0 HcmV?d00001 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar new file mode 100644 index 0000000000000000000000000000000000000000..4874578ad9a9e7ef13d9512d6235f4a6482591c1 GIT binary patch literal 3263 zcmbVO+fy556kiBbLZMJhxs(ENij}rB(5a<>goH~KND3Jt6zBz#G(aE(nk@HAM;{z# zw2n{uqz}IO=7aUY%Y!pI!_sVpv6eg$jF06y=&_#yj!Va40^$9!{w-b)BnBY_COA z-mQ;r@%&V9vlJzC+G!B z>dH%{rypt;ioTf}$o1q19wBWQVH_a`MS1_5`#GG$Mq?9N6D?m3ag> zz;$}v@fHMK&7f7RJ-V`f_#WgS7~I-VOtiq@@$12GVpMZ80^0`qLBI!Ai|JXoFUFg^ z9^iWArL&MzZiu+^D&#qkhw7wXn_%P4A775N_jlZxK?6`liF^Z!XMg%x^^@=QD~yl8 z?rI%5xCGmFe*rQ$w@IIPU5^*6r3ncA2Ej@tL(`Y)7wj;vgFFjUpt~7D!0-&;q}M#W zZR`wW6ub@A+=Br0^J?K3(fiQ-`=@&;s2O_E01Bo>`I~%Pv})Y@Ksqj-gtl`6z^nx- zih1$3Zy}z4EL|r=K_=-?K$?#qR>EK)fv&^P`!?+j(hzwQ$_?u0DuUSroes^Wd${Oy_H`x|ut`-MvhA5Bq`QU%!St!Axf20VN>sD$se}C&uANyuAY))g(P4 znV0+E27}JTYGV*We?Ec)su+z5-V`GoNohU%0-E0P8QbWCAV)!+SSjTD3zh z#dMxmfcY>A6r~#0jZiFMEomz(6@X_M!dnKx=jAB$3`y4z444jgtGu;Gq2~iGFhd6J zEJ9YY>Hu3~w(?Sy$2|NBV&+|lo{ba}ZO+T#0tVc}#L)MJ7358R`hk~Ols#aK&q1~x z)}3Ybng!W?z(eguSXc!0yP{hU--prl3LoJD&<%28r~f4HVI3&w3A1Joz6x<5Jsf_( z;+TP(Lx5IhVxWTgA}G9kI%A7LM}v;hn(HGl7KgeM(#@r7#q@~M>(sG;ub|MQr9sZO zdo%7Tf0d#P?_Ip-omyvsQmfq6m&4kOMS-;~duF6IMs|MT=R$gSZqx#1-};u12a_|* zvFheshK8{;LfhEb0sG%M<4}ywESa3ieuCun!x|84+Y}5qb>x%9xI3>m~(nS9a1Wiu37)6S>)R135?S=*VbhB4N3$ywQrVZvOa1BOa(@&&^xhu!k% sSpBfJvz6mzFNULz4;m}qGtnGlW_!u%mvEwi2Eh}dGA3TL97ytkO literal 0 HcmV?d00001 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar new file mode 100644 index 0000000000000000000000000000000000000000..c009a042e46a6af3c733b335dcdb9fa9e0f9e82f GIT binary patch literal 4521 zcmbVPTTfh76do8TmktH$a4RjK&{8NJdV>PxPO-pD%UJI80>gBGfng{!2MUy-(HJ#p zYfPHxlbYzGZ$4P#^}%QjR+FYtQ&Z!kkNyR}@2oRt&KZU_I{DURud~lyYwx}GI(yts zYl_{%U-@i-Q&lvUl?kOIr1+;jUL{=XMn~0Tv8+e(od10L^%2ncZge6QnL2wzK9Ay? z2rC}%ydylju;`sH3wuNU>&kP6VJI=5{vbvO1a=$&0gRf1HouRzLyBX~6P%&j#M89F z<5}OdKj>Hdi$R$ud!}13`i45uRA?z3$rf7DEtb=9Z=4G(PI&?Y%Tr;+uPk$v!L{qY z@PIG0;`jOneGAtESPX=*5WoOK=NG|`*}w`ww?L&J;BsUhd`cSMeF|9(+6zht9qb1? zxeB%kn%RFE9LNJ*I4(MPPYd5k0UZMkgI4OnPJ)0o(BV1J!FTK0)3>0Gf=WQspdJuV z25JYT7iDFNr4ynT^yG8GzUhC~b}Ln@(G@Onor`0%5*GlGx~kP#joPIHADtJK+(+k}Sa)AIRC|}gJ znI%z9@wuDhWo1r)kG6mX%Id%mfjFrK#&rW!vi{o#eaAZMuZ*JsC?bScLU8Vn-_3vY zmG*?|Bgk;n^lcu6Ze5xIADXubbIeBaUesCY?GN|Ah7@*BpU5-A@2J^4)Y=j}k8N~sRU`&Lo)X72j4z%AA!;xIb z488y`Yk}-kKK%JJu%~y#v_}MZhyl5!`S5NI6fPvtxb&g3&jFx9?r2~v~0R$ATiEO_F zd1!!#2hbH7ir$G`Bti8@~wFyb@-jO}4YUfD7Kn#L)ag8{#HEexsdP z6q}%*=O9)Oi^^HOCO|ZAa#AEwj!gwmu~-Us*jnvtHGp39qkgZ_ptSKY32N3MQ^{DU1nL&MDwAto;qlsK zdRDrGX2rtViBnyn9_bFAJT@u%^m%@%c16IrSvf7NVM}>n`L2WDJY!cu4%-Pk1n~Wv z#|z8zIQLXBfU~Xxog&I1T+LuhlRR~&L9AnkI38;a#~Wc1R5yWzuF-ZhZ*`N^*9e~J zGl#O%nw=?H%EQnOnvz~4&HcqyzufCWi|Zj^{^W2&&-H@Yx_CC2LRua8{RK5u3FL50Ju07xf)eVAiqk&}+TH$N$%*x!aSqmWRB3i;OGc@L#zz5O6_yqH# zy1F7-b0y;%@lMuM*t_|$`tieFt~2)ns2-Wn97`Kq%ccO-Y%xakXH|_`w_ieQH%bM3?%@QiwOx>;WmW8^J{Ig8HLJ#A3-+%s0tY91Pqa7mOEQyb&&NF4;qUkqNR8k2BFua4`{b9tCK^Z?0JIbTjc1(#}VI-RgULf&b9}V__AgSMY}5)CLJF@ zeA^h%vn~|IaBL`}iGtzv!W53gp?(pF literal 0 HcmV?d00001 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf new file mode 100644 index 0000000000..f28014e2d6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf @@ -0,0 +1,11 @@ + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf new file mode 100644 index 0000000000..95f7a41d68 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf @@ -0,0 +1,18 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + +source: MainServiceTemplate.yaml + + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf new file mode 100644 index 0000000000..64e9445f7f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf @@ -0,0 +1,7 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf new file mode 100644 index 0000000000..a563ddd581 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf @@ -0,0 +1,12 @@ +metadata: + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf new file mode 100644 index 0000000000..88c67517ce --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf @@ -0,0 +1,15 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java index 9fff4bd749..8bcb0a5ffe 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java @@ -28,6 +28,14 @@ public enum Messages { "functionalities"), INVALID_ZIP_FILE("Invalid zip file"), + INVALID_CSAR_FILE("Invalid csar file"), + CSAR_FILE_NOT_FOUND("Each CSAR file must contain %s file."), + CSAR_DIRECTORIES_NOT_ALLOWED("Directory : %s , is not allowed."), + CSAR_FILES_NOT_ALLOWED("File : %s , are not allowed."), + MANIFEST_INVALID_LINE("Manifest contains invalid line : %s"), + MANIFEST_NO_METADATA("Manifest must contain metadata"), + MANIFEST_NO_SOURCES("Manifest must contain source"), + MANIFEST_PARSER_INTERNAL("Invalid manifest file"), FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"), ZIP_NOT_EXIST("Zip file doesn't exist"), @@ -45,7 +53,7 @@ public enum Messages { NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST("no zip file was uploaded or zip file doesn't exist"), MAPPING_OBJECTS_FAILURE("Failed to map object %s to %s. Exception message: %s"), MORE_THEN_ONE_VOL_FOR_HEAT("heat contains more then one vol. selecting only first vol"), - ZIP_CONTENT_MAP("failed to load zip content"), + FILE_CONTENT_MAP("failed to load %s content"), CREATE_MANIFEST_FROM_ZIP("cannot create manifest from the attached zip file"), CANDIDATE_PROCESS_FAILED("Candidate zip file process failed"), FOUND_UNASSIGNED_FILES("cannot process zip since it has unassigned files"), @@ -66,7 +74,9 @@ public enum Messages { INVALID_MANIFEST_FILE("invalid manifest file"), INVALID_FILE_TYPE("Missing or Unknown file type in Manifest"), ENV_NOT_ASSOCIATED_TO_HEAT("ENV file must be associated to a HEAT file"), - + CSAR_MANIFEST_FILE_NOT_EXIST("CSAR manifest file does not exist"), + CSAR_FAILED_TO_READ("CSAR file is not readable"), + TOSCA_PARSING_FAILURE("Invalid tosca file. Error code : %s, Error message : %s/"), /* content errors*/ INVALID_YAML_FORMAT("Invalid YAML format - %s"), INVALID_YAML_FORMAT_REASON("Invalid YAML format Problem - [%s]"), diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java index f4d6209eec..1c5293004d 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java @@ -22,8 +22,11 @@ package org.openecomp.sdc.common.utils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; @@ -45,38 +48,54 @@ import java.util.zip.ZipInputStream; public class CommonUtil { - public static FileContentHandler validateAndUploadFileContent(byte[] uploadedFileData) + public static FileContentHandler validateAndUploadFileContent(OnboardingTypesEnum type, + byte[] uploadedFileData) throws IOException { - return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(uploadedFileData); + return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(type, uploadedFileData); } /** * Gets files out of the zip AND validates zip is flat (no folders) * + * + * @param type * @param uploadFileData zip file * @return FileContentHandler if input is valid and has no folders */ private static FileContentHandler getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders( - byte[] uploadFileData) + OnboardingTypesEnum type, byte[] uploadFileData) throws IOException { + Pair > pair = getFileContentMapFromOrchestrationCandidateZip(uploadFileData); - List folderList = new ArrayList<>(); - FileContentHandler mapFileContent = new FileContentHandler(); + if(type.equals(OnboardingTypesEnum.ZIP)) { + validateNoFolders(pair.getRight()); + } - try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData))) { + return pair.getLeft(); + } + public static Pair > getFileContentMapFromOrchestrationCandidateZip( + byte[] uploadFileData) + throws IOException { + ZipEntry zipEntry; + List folderList = new ArrayList<>(); + FileContentHandler mapFileContent = new FileContentHandler(); + try ( ByteArrayInputStream in = new ByteArrayInputStream(uploadFileData); + ZipInputStream inputZipStream = new ZipInputStream(in)){ + byte[] fileByteContent; String currentEntryName; - ZipEntry zipEntry; while ((zipEntry = inputZipStream.getNextEntry()) != null) { - currentEntryName = zipEntry.getName(); + // else, get the file content (as byte array) and save it in a map. + fileByteContent = FileUtils.toByteArray(inputZipStream); + int index = lastIndexFileSeparatorIndex(currentEntryName); if (index != -1) { //todo ? folderList.add(currentEntryName); - } else { - // else, get the file content (as byte array) and save it in a map. - mapFileContent.addFile(currentEntryName, FileUtils.toByteArray(inputZipStream)); + } + if(isFile(currentEntryName)) { + mapFileContent.addFile(currentEntryName, fileByteContent); } } @@ -84,9 +103,11 @@ public class CommonUtil { throw new IOException(exception); } - validateNoFolders(folderList); + return new ImmutablePair<>(mapFileContent,folderList); + } - return mapFileContent; + private static boolean isFile(String currentEntryName) { + return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/")); } private static void validateNoFolders(List folderList) { diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java index 156a86c841..24da8363c1 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.common.utils; public class SdcCommon { public static final String MANIFEST_NAME = "MANIFEST.json"; + public static final String CSAR_MANIFEST_NAME = "MainServiceTemplate.mf"; public static final String UPLOAD_FILE = "uploadFile"; public static final String PROCESS_FILE = "Process File"; public static final String ILLEGAL_MANIFEST = "Illegal manifest"; diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java index e04f02cce5..0fb587cc68 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java @@ -20,6 +20,7 @@ package org.openecomp.core.utilities.file; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.sdc.tosca.services.YamlUtil; @@ -195,6 +196,19 @@ public class FileUtils { return fileName.substring(0, fileName.lastIndexOf(".")); } + public static String getFileExtension(String filename) { + return FilenameUtils.getExtension(filename); + } + + public static String getNetworkPackageName(String filename){ + String[] split = filename.split("\\."); + String name = null; + if (split != null && split.length > 1){ + name = split[0]; + } + return name; + } + /** * Gets file content map from zip. * diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java new file mode 100644 index 0000000000..04e64c33a9 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java @@ -0,0 +1,32 @@ +package org.openecomp.core.utilities.orchestration; + +import java.util.Optional; + +import static java.util.Arrays.asList; +public enum OnboardingTypesEnum { + CSAR("csar"), ZIP("zip"), NONE("none"); + private String type; + + OnboardingTypesEnum(String type) { + this.type = type; + } + + @Override + public String toString() { + return type; + } + + public static final OnboardingTypesEnum getOnboardingTypesEnum(final String inStr) { + if (inStr == null) { + return null; + } + Optional onboardingTypesOptional = asList(OnboardingTypesEnum.values()).stream() + .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr)).findAny(); + if( onboardingTypesOptional.isPresent()){ + return onboardingTypesOptional.get(); + }else { + return null; + } + } + +} diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml index 618922c2af..03ee98dd4e 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml @@ -33,6 +33,13 @@ openecomp-sdc-vendor-license-api ${project.version} + + junit + junit + ${junit.version} + test + + diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java index bdb7bc3a93..9800d02ba6 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java @@ -27,6 +27,7 @@ import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.translator.datatypes.TranslatorOutput; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.healing.interfaces.Healer; @@ -49,7 +50,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; @@ -300,7 +300,8 @@ public class CompositionDataHealer implements Healer { FileContentHandler fileContentHandler; try { fileContentHandler = - CommonUtil.validateAndUploadFileContent(uploadData.getContentData().array()); + CommonUtil.validateAndUploadFileContent( + OnboardingTypesEnum.ZIP, uploadData.getContentData().array()); return HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler); } catch (Exception e) { return null; diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java index e0b7adb6d3..0d484440cf 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.healing.healers; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -94,7 +95,7 @@ public class FileDataStructureHealer implements Healer { byte[] byteContentData = uploadData.getContentData().array(); FileContentHandler fileContentHandler; try{ - fileContentHandler = CommonUtil.validateAndUploadFileContent(byteContentData); + fileContentHandler = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, byteContentData); Map> errors = new HashMap<>(); OrchestrationTemplateCandidateData candidateDataEntity = new CandidateEntityBuilder(candidateService) diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java index d5ccd36c95..44b6062e89 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java @@ -8,6 +8,7 @@ import org.openecomp.core.model.dao.ServiceTemplateDaoInter; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.translator.datatypes.TranslatorOutput; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.healing.interfaces.Healer; @@ -53,7 +54,7 @@ public class HeatToToscaTranslationHealer implements Healer { FileContentHandler fileContentHandler; TranslatorOutput translatorOutput; try { - fileContentHandler = CommonUtil.validateAndUploadFileContent(uploadData + fileContentHandler = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, uploadData .getContentData().array()); translatorOutput = HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler); diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealer.java index 5d6050a7f0..0b06fb1c83 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealer.java @@ -1,11 +1,10 @@ package org.openecomp.sdc.healing.healers; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.healing.interfaces.Healer; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; @@ -15,15 +14,18 @@ import java.util.Map; import java.util.Objects; public class VspOnboardingMethodHealer implements Healer { - /*private static final VendorSoftwareProductDao vendorSoftwareProductDao = - VendorSoftwareProductDaoFactory.getInstance().createInterface();*/ - private static final VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao = + private static VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao = VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); public VspOnboardingMethodHealer(){ + } + public VspOnboardingMethodHealer( VendorSoftwareProductInfoDao inVendorSoftwareProductInfoDao){ + vendorSoftwareProductInfoDao = inVendorSoftwareProductInfoDao; } + + @Override public Object heal(Map healingParams) throws Exception { mdcDataDebugMessage.debugEntryMessage(null, null); @@ -33,14 +35,22 @@ public class VspOnboardingMethodHealer implements Healer { Version version = (Version) healingParams.get(SdcCommon.VERSION); VspDetails vendorSoftwareProductInfo = vendorSoftwareProductInfoDao.get(new VspDetails(vspId, version)); - vendorSoftwareProductInfo.getOnboardingMethod(); + String onboardingValue = vendorSoftwareProductInfo.getOnboardingMethod(); - if(Objects.isNull(vendorSoftwareProductInfo.getOnboardingMethod())) { - onboardingMethod="HEAT"; - vendorSoftwareProductInfo.setOnboardingMethod(onboardingMethod); - vendorSoftwareProductInfoDao.update(vendorSoftwareProductInfo); - //vendorSoftwareProductDao.updateVendorSoftwareProductInfo(vendorSoftwareProductInfo); + if(Objects.isNull(onboardingValue)) { + onboardingMethod="NetworkPackage"; + + updateVSPInfo(OnboardingTypesEnum.ZIP.toString(), onboardingMethod, vendorSoftwareProductInfo); + } else if (onboardingValue.equals("HEAT")){ + onboardingMethod="NetworkPackage"; + updateVSPInfo(OnboardingTypesEnum.ZIP.toString(),onboardingMethod, vendorSoftwareProductInfo); } return onboardingMethod; } + + private void updateVSPInfo(String onboardingOrigin, String onboardingMethod, VspDetails vendorSoftwareProductInfo) { + vendorSoftwareProductInfo.setOnboardingMethod(onboardingMethod); + vendorSoftwareProductInfo.setOnboardingOrigin(onboardingOrigin); + vendorSoftwareProductInfoDao.update(vendorSoftwareProductInfo); + } } diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java new file mode 100644 index 0000000000..b732cb03b6 --- /dev/null +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java @@ -0,0 +1,70 @@ +package org.openecomp.sdc.healing.healers; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; + +public class VspOnboardingMethodHealerTest{ + + @Mock + private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(VspOnboardingMethodHealerTest.this); + } + + @Test + public void checkHealingWithNullOnboarding() throws Exception{ + VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); + Map params = new HashMap<>(); + params.put(SdcCommon.VSP_ID,"1"); + params.put(SdcCommon.VERSION, new Version(1,1)); + VspDetails vspDetails = new VspDetails(); + vspDetails.setOnboardingMethod(null); + Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); + vspOnboardingMethodHealer.heal(params); + assertEquals(vspDetails.getOnboardingMethod(),"NetworkPackage"); + assertEquals(vspDetails.getOnboardingOrigin(),"zip"); + } + + @Test + public void checkHealingWithHEATOnboarding() throws Exception{ + VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); + Map params = new HashMap<>(); + params.put(SdcCommon.VSP_ID,"1"); + params.put(SdcCommon.VERSION, new Version(1,1)); + VspDetails vspDetails = new VspDetails(); + vspDetails.setOnboardingMethod("HEAT"); + Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); + vspOnboardingMethodHealer.heal(params); + assertEquals(vspDetails.getOnboardingMethod(),"NetworkPackage"); + assertEquals(vspDetails.getOnboardingOrigin(),"zip"); + } + + @Test + public void checkHealingWithManualOnboarding() throws Exception{ + VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); + Map params = new HashMap<>(); + params.put(SdcCommon.VSP_ID,"1"); + params.put(SdcCommon.VERSION, new Version(1,1)); + VspDetails vspDetails = new VspDetails(); + vspDetails.setOnboardingMethod("Manual"); + Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); + vspOnboardingMethodHealer.heal(params); + assertEquals(vspDetails.getOnboardingMethod(),"Manual"); + assertEquals(vspDetails.getOnboardingOrigin(),null); + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-heat-lib/pom.xml b/openecomp-be/lib/openecomp-heat-lib/pom.xml index 55ab0623b4..0a4e14f417 100644 --- a/openecomp-be/lib/openecomp-heat-lib/pom.xml +++ b/openecomp-be/lib/openecomp-heat-lib/pom.xml @@ -14,6 +14,18 @@ + + org.openecomp.sdc.common + openecomp-configuration-management-core + ${openecomp.sdc.common.version} + runtime + + + org.slf4j + slf4j-log4j12 + + + org.openecomp.sdc.common openecomp-tosca-datatype @@ -52,4 +64,19 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + ${mvn.surefire.version} + + true + false + true + + + + + diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java new file mode 100644 index 0000000000..517c690194 --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java @@ -0,0 +1,79 @@ +package org.openecomp.sdc.heat.services.tree; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.Artifact; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +public class ToscaTreeManager { + + private static Logger logger = (Logger) LoggerFactory.getLogger(ToscaTreeManager.class); + + private FileContentHandler csarContentMap = new FileContentHandler(); + private byte[] manifest; + private HeatStructureTree tree = new HeatStructureTree(); + private Map artifactRef = new HashMap<>(); + private Map fileTreeRef = new HashMap<>(); + + + public void addFile(String fileName, byte[] content) { + if (fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) { + manifest = content; + + } else { + csarContentMap.addFile(fileName, content); + } + } + + public void createTree(){ + if (manifest == null) { + logger.error("Missing manifest file in the zip."); + return; + } + + for(Map.Entry fileEntry : csarContentMap.getFiles().entrySet()){ + String[] splitFilename = getFullFileNameAsArray(fileEntry.getKey()); + addFileToTree(splitFilename, 0, tree); + } + + + } + + private void addFileToTree(String[] splitFilename, int startIndex, HeatStructureTree parent){ + fileTreeRef.putIfAbsent(splitFilename[startIndex], new HeatStructureTree()); + HeatStructureTree heatStructureTree = fileTreeRef.get(splitFilename[startIndex]); + heatStructureTree.setFileName(splitFilename[startIndex]); + if(startIndex < splitFilename.length - 1){ + addFileToTree(splitFilename, startIndex + 1, heatStructureTree); + } + parent.addHeatStructureTreeToNestedHeatList(heatStructureTree); + } + + public void addErrors(Map> validationErrors){ + validationErrors.entrySet().stream().filter(entry -> { + return fileTreeRef.get(entry.getKey()) != null; + }).forEach(entry -> entry.getValue().stream().forEach(error -> + fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error))); + } + + private String[] getFullFileNameAsArray(String filename){ + if(filename.contains("/")){ + return filename.split("/"); + } + + return filename.split(Pattern.quote(File.separator)); + } + + public HeatStructureTree getTree(){ + return tree; + } +} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java index de39cff30f..387b2046fd 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java +++ b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java @@ -30,6 +30,7 @@ public class AuditMessages { public static final String HEAT_VALIDATION_STARTED = "HEAT validation started. VSP Id: "; public static final String HEAT_VALIDATION_COMPLETED = "HEAT validation completed. VSP Id: "; public static final String HEAT_VALIDATION_ERROR = "HEAT validation error: %s. VSP Id: %s"; + public static final String CSAR_VALIDATION_STARTED = "CSAR validation started. VSP Id: "; public static final String HEAT_TRANSLATION_STARTED = "HEAT translation started. VSP Id: "; public static final String HEAT_TRANSLATION_COMPLETED = "HEAT translation completed. VSP Id: "; public static final String ENRICHMENT_ERROR = "Enrichment error: %s. VSP Id: %s"; diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/pom.xml b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/pom.xml index 30c4bde443..b3b7598c11 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/pom.xml @@ -56,5 +56,10 @@ commons-io 2.5 + + org.openecomp.sdc + openecomp-tosca-converter-api + 1.1.0-SNAPSHOT + diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java index 575ba856a7..a7fecdd806 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java @@ -22,9 +22,9 @@ import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.core.converter.datatypes.Constants; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.util.Collection; import java.util.Map; import java.util.Objects; diff --git a/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-api/pom.xml b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-api/pom.xml new file mode 100644 index 0000000000..87a93ee6dd --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-api/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + org.openecomp.sdc + openecomp-sdc-datatypes-lib + 1.1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-orchestration-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-orchesrtation-api + 1.1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-core/pom.xml b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-core/pom.xml new file mode 100644 index 0000000000..343ff0213c --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-core/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + org.openecomp.sdc + openecomp-sdc-orchesrtation-api + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.core + openecomp-utilities-lib + 1.1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-orchestration-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-orchesrtation-core + 1.1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-impl/pom.xml b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-impl/pom.xml new file mode 100644 index 0000000000..8ecfa0de9e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-orchestration-lib/openecomp-sdc-orchesrtation-impl/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + + org.openecomp.sdc + openecomp-sdc-orchesrtation-api + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-logging-api + 1.1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-orchestration-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-orchesrtation-impl + 1.1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-orchestration-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-orchestration-lib/pom.xml new file mode 100644 index 0000000000..dbcef4da29 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-orchestration-lib/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + openecomp-sdc-orchestration-lib + 1.1.0-SNAPSHOT + pom + + + openecomp-sdc-lib + org.openecomp.sdc + 1.1.0-SNAPSHOT + .. + + + + openecomp-sdc-orchesrtation-api + openecomp-sdc-orchesrtation-core + openecomp-sdc-orchesrtation-impl + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java index 2758e3dfe9..ccadeced62 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java @@ -61,6 +61,11 @@ public class VspDetails implements VersionableEntity { private Long writetimeMicroSeconds; private String onboardingMethod; + + private String onboardingOrigin; + + private String networkPackageName; + public VspDetails() { } @@ -215,12 +220,29 @@ public class VspDetails implements VersionableEntity { this.oldVersion = oldVersion; } + public String getOnboardingOrigin() { + return onboardingOrigin; + } + + public void setOnboardingOrigin(String onboardingOrigin) { + this.onboardingOrigin = onboardingOrigin; + } + public String getOnboardingMethod() { return onboardingMethod; } public void setOnboardingMethod(String onboardingMethod) { this.onboardingMethod = onboardingMethod; } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } + @Override public String toString() { return String.format( diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java index 4ca623e6a3..6cc639fac0 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java @@ -21,10 +21,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.types.CandidateDataEntityTo; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.AnalyzedZipHeatFiles; @@ -61,9 +61,12 @@ public interface CandidateService { Optional fetchZipFileByteArrayInputStream(String vspId, OrchestrationTemplateCandidateData candidateDataEntity, - String manifest, Map> uploadErrors); + String manifest, + OnboardingTypesEnum type, + Map> uploadErrors); - byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId) + byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId, + OnboardingTypesEnum type) throws IOException; Optional createManifest(VspDetails vspDetails, diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java index 9540f3d965..ca5329344b 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java @@ -75,6 +75,14 @@ public class CandidateEntityBuilder { return candidateDataEntity; } +// public OrchestrationTemplateCandidateData buildOrchestrationTemplateFromCsar(VspDetails vspDetails, +// byte[] uploadedFileData, +// FileContentHandler contentMap, +// Map> uploadErrors, +// String user){ +// +// } + private HeatStructureTree getHeatStructureTree(VspDetails vspDetails, FileContentHandler contentMap, AnalyzedZipHeatFiles analyzedZipHeatFiles) { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java index eef90d4742..7ad7929ccb 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java @@ -200,6 +200,8 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP info.addProperty(InfoPropertyName.featureGroups.name(), vspDetails.getFeatureGroups()); info.addProperty(InfoPropertyName.oldVersion.name(), vspDetails.getOldVersion()); info.addProperty(InfoPropertyName.onboardingMethod.name(), vspDetails.getOnboardingMethod()); + info.addProperty(InfoPropertyName.obBoardingOrigin.name(), vspDetails.getOnboardingOrigin()); + info.addProperty(InfoPropertyName.networkPackageName.name(), vspDetails.getNetworkPackageName()); } private VspDetails mapInfoToVspDetails(String vspId, Version version, Info info, @@ -215,6 +217,7 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP Version.valueOf(info.getProperty(InfoPropertyName.vendorVersion.name()))); vspDetails.setLicenseAgreement(info.getProperty(InfoPropertyName.licenseAgreement.name())); vspDetails.setFeatureGroups(info.getProperty(InfoPropertyName.featureGroups.name())); + vspDetails.setWritetimeMicroSeconds( modificationTime == null ? creationTime.getTime() : modificationTime.getTime()); vspDetails.setVersion(version); @@ -223,7 +226,8 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP //Boolean oldVersion = ind == null || "true".equals( ind.toLowerCase()); vspDetails.setOldVersion(oldVersion); vspDetails.setOnboardingMethod(info.getProperty(InfoPropertyName.onboardingMethod.name())); - + vspDetails.setOnboardingOrigin(info.getProperty(InfoPropertyName.obBoardingOrigin.name())); + vspDetails.setNetworkPackageName(info.getProperty(InfoPropertyName.networkPackageName.name())); return vspDetails; } @@ -239,7 +243,9 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP licenseAgreement, featureGroups, oldVersion, - onboardingMethod + onboardingMethod, + obBoardingOrigin, + networkPackageName } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java index 6ccece1e76..e5f1a4c3ac 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructurem import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; @@ -89,17 +90,17 @@ public class CandidateServiceImpl implements CandidateService { } @Override - public Optional validateNonEmptyFileToUpload(InputStream heatFileToUpload) { + public Optional validateNonEmptyFileToUpload(InputStream fileToUpload) { mdcDataDebugMessage.debugEntryMessage(null); - if (Objects.isNull(heatFileToUpload)) { + if (Objects.isNull(fileToUpload)) { return Optional.of(new ErrorMessage(ErrorLevel.ERROR, Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); } else { try { - int available = heatFileToUpload.available(); + int available = fileToUpload.available(); if (available == 0) { mdcDataDebugMessage.debugExitMessage(null); return Optional.of(new ErrorMessage(ErrorLevel.ERROR, @@ -321,10 +322,7 @@ public class CandidateServiceImpl implements CandidateService { public void updateCandidateUploadData(OrchestrationTemplateCandidateData uploadData, String itemId) { mdcDataDebugMessage.debugEntryMessage(null); - - //vendorSoftwareProductDao.updateCandidateUploadData(uploadData); orchestrationTemplateCandidateDataDao.update(itemId, uploadData); - mdcDataDebugMessage.debugExitMessage(null); } @@ -393,11 +391,12 @@ public class CandidateServiceImpl implements CandidateService { public Optional fetchZipFileByteArrayInputStream(String vspId, OrchestrationTemplateCandidateData candidateDataEntity, String manifest, + OnboardingTypesEnum type, Map> uploadErrors) { byte[] file; ByteArrayInputStream byteArrayInputStream = null; try { - file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId); + file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId, type); byteArrayInputStream = new ByteArrayInputStream( Objects.isNull(file) ? candidateDataEntity.getContentData().array() : file); @@ -413,7 +412,8 @@ public class CandidateServiceImpl implements CandidateService { } @Override - public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId) + public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId, + OnboardingTypesEnum type) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -433,12 +433,12 @@ public class CandidateServiceImpl implements CandidateService { } } else { manifestWritten = true; - writeManifest(manifest, zos); + writeManifest(manifest, type, zos); } zos.closeEntry(); } if (!manifestWritten) { - writeManifest(manifest, zos); + writeManifest(manifest, type, zos); zos.closeEntry(); } } @@ -451,7 +451,14 @@ public class CandidateServiceImpl implements CandidateService { return candidateServiceValidator.validateFileDataStructure(filesDataStructure); } - private void writeManifest(String manifest, ZipOutputStream zos) throws IOException { + private void writeManifest(String manifest, + OnboardingTypesEnum type, + ZipOutputStream zos) throws IOException { + + if(isManifestNeedsToGetWritten(type)){ + return; + } + zos.putNextEntry(new ZipEntry(SdcCommon.MANIFEST_NAME)); try (InputStream manifestStream = new ByteArrayInputStream( manifest.getBytes(StandardCharsets.UTF_8))) { @@ -463,6 +470,10 @@ public class CandidateServiceImpl implements CandidateService { } } + private boolean isManifestNeedsToGetWritten(OnboardingTypesEnum type) { + return type.equals(OnboardingTypesEnum.CSAR); + } + private void handleArtifactsFromTree(HeatStructureTree tree, FilesDataStructure structure) { if (Objects.isNull(tree) || Objects.isNull(tree.getArtifacts())) { diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/pom.xml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/pom.xml new file mode 100644 index 0000000000..faf890f672 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + org.openecomp.sdc.common + openecomp-tosca-datatype + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.core + openecomp-tosca-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.core + openecomp-facade-core + 1.1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-tosca-converter-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-tosca-converter-api + 1.1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java new file mode 100644 index 0000000000..09c823ce7e --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java @@ -0,0 +1,24 @@ +package org.openecomp.core.converter; + +import java.util.Map; + +public interface ServiceTemplateReaderService { + + Map readServiceTemplate(byte[] serivceTemplateContent); + + Object getMetadata(); + + Object getToscaVersion(); + + Object getNodeTypes(); + + Object getTopologyTemplate(); + + Map getNodeTemplates(); + + Map getInputs(); + + Map getOutputs(); + + Map getSubstitutionMappings(); +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ToscaConverter.java new file mode 100644 index 0000000000..543d32347f --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ToscaConverter.java @@ -0,0 +1,12 @@ +package org.openecomp.core.converter; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; + +import java.io.IOException; + +public interface ToscaConverter { + + ToscaServiceModel convert(FileContentHandler fileContentHandler) + throws IOException; +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/api/ToscaConverterManager.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/api/ToscaConverterManager.java new file mode 100644 index 0000000000..1cf010c1b5 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/api/ToscaConverterManager.java @@ -0,0 +1,9 @@ +package org.openecomp.core.converter.api; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; + +public interface ToscaConverterManager { + + ToscaServiceModel convert(String csarName, FileContentHandler fileContentHandler); +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java new file mode 100644 index 0000000000..6f7e6be8af --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java @@ -0,0 +1,45 @@ +package org.openecomp.core.converter.datatypes; + +import java.io.File; + +public class Constants { + public static final String mainStName = "MainServiceTemplate.yaml"; + public static final String globalStName = "GlobalSubstitutionTypesServiceTemplate.yaml"; + public static final String manifestFileName = "MainServiceTemplate.mf"; + public static final String definitionsDir = "Definitions/"; + public static final String metadataFile = "TOSCA-Metadata/TOSCA.meta"; + + + public static final String definitionVersion = "tosca_definitions_version"; + private static final String DEFAULT_NAMESPACE = "tosca_default_namespace"; + private static final String TEMPLATE_NAME = "template_name"; + public static final String topologyTemplate = "topology_template"; + private static final String TEMPLATE_AUTHOR = "template_author"; + private static final String TEMPLATE_VERSION = "template_version"; + private static final String DESCRIPTION = "description"; + private static final String IMPORTS = "imports"; + private static final String DSL_DEFINITIONS = "dsl_definitions"; + public static final String nodeType = "node_type"; + public static final String nodeTypes = "node_types"; + private static final String RELATIONSHIP_TYPES = "relationship_types"; + private static final String RELATIONSHIP_TEMPLATES = "relationship_templates"; + private static final String CAPABILITY_TYPES = "capability_types"; + private static final String ARTIFACT_TYPES = "artifact_types"; + private static final String DATA_TYPES = "data_types"; + private static final String INTERFACE_TYPES = "interface_types"; + private static final String POLICY_TYPES = "policy_types"; + private static final String GROUP_TYPES = "group_types"; + private static final String REPOSITORIES = "repositories"; + public static final String metadata = "metadata"; + public static final String nodeTemplates = "node_templates"; + public static final String inputs = "inputs"; + public static final String outputs = "outputs"; + public static final String substitutionMappings = "substitution_mappings"; + public static final String capabilities = "capabilities"; + public static final String requirements = "requirements"; + + public static final String openecompHeatIndex = "openecomp_heat_index"; + public static final String globalSubstitution = "GlobalSubstitutionTypes"; + + public static final String externalFilesFolder = "External" + File.separator; +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/CsarFileTypes.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/CsarFileTypes.java new file mode 100644 index 0000000000..323bd8a5fb --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/CsarFileTypes.java @@ -0,0 +1,9 @@ +package org.openecomp.core.converter.datatypes; + +public enum CsarFileTypes { + mainServiceTemplate, + globalServiceTemplate, + externalFile, + toscaMetadata, + definitionsFile,; +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/factory/ToscaConverterFactory.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/factory/ToscaConverterFactory.java new file mode 100644 index 0000000000..7506759d25 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/factory/ToscaConverterFactory.java @@ -0,0 +1,12 @@ +package org.openecomp.core.converter.factory; + +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class ToscaConverterFactory extends AbstractComponentFactory { + + public static ToscaConverterFactory getInstance(){ + return AbstractFactory.getInstance(ToscaConverterFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/resources/factoryConfiguration.json new file mode 100644 index 0000000000..d9f4ff3cbd --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/resources/factoryConfiguration.json @@ -0,0 +1,3 @@ +{ + "org.openecomp.core.converter.factory.ToscaConverterFactory" : "org.openecomp.core.impl.factory.ToscaConverterFactoryImpl" +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml new file mode 100644 index 0000000000..39f02becf8 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + + org.openecomp.sdc + openecomp-tosca-converter-api + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.core + openecomp-tosca-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.core + openecomp-facade-core + 1.1.0-SNAPSHOT + + + org.openecomp.sdc.jtosca + jtosca + 1.1.1-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-translator-core + 1.1.0-SNAPSHOT + + + junit + junit + ${junit.version} + test + + + + + org.openecomp.sdc + openecomp-tosca-converter-lib + 1.1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-tosca-converter-core + 1.1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java new file mode 100644 index 0000000000..2d33748e26 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java @@ -0,0 +1,59 @@ +package org.openecomp.core.impl; + +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { + private static final Logger logger = LoggerFactory.getLogger(ServiceTemplate.class); + + public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = "GlobalSubstitutionServiceTemplate.yaml"; + public static final String TEMPLATE_NAME_PROPERTY = "template_name"; + public static final String DEFININTION_VERSION = "tosca_simple_yaml_1_0_0"; + public static final String HEAT_INDEX = "openecomp_heat_index"; + + public GlobalSubstitutionServiceTemplate() { + super(); + init(); + } + + + public void appendNodes(Map nodes) { + getNode_types().putAll(nodes); + } + + public void init() { + writeDefinitionSection(); + writeMetadataSection(); + writeImportsSection(); + setNode_types(new HashMap<>()); + } + + private void writeImportsSection() { + List> imports = new ArrayList<>(); + Map stringImportMap = new HashMap<>(); + imports.add(stringImportMap); + setImports(imports); + Import imprtObj = new Import(); + imprtObj.setFile("openecomp-heat/_index.yml"); + stringImportMap.put("openecomp_heat_index", imprtObj); + } + + + private void writeMetadataSection() { + Map metadata = new HashMap<>(); + metadata.put(TEMPLATE_NAME_PROPERTY, "GlobalSubstitutionTypes"); + setMetadata(metadata); + } + + private void writeDefinitionSection() { + setTosca_definitions_version(DEFININTION_VERSION); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java new file mode 100644 index 0000000000..c4ed6f9c5f --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java @@ -0,0 +1,446 @@ +package org.openecomp.core.impl; + +import org.apache.commons.collections.MapUtils; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.converter.datatypes.Constants; +import org.openecomp.core.converter.datatypes.CsarFileTypes; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.*; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; +import org.yaml.snakeyaml.error.YAMLException; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.jar.Manifest; +import java.util.regex.Pattern; + +import static org.openecomp.core.converter.datatypes.Constants.*; +import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME; + +public class ToscaConverterImpl implements ToscaConverter { + + public ToscaConverterImpl() { + + } + + @Override + public ToscaServiceModel convert(FileContentHandler fileContentHandler) + throws IOException { + Map csarFiles = new HashMap<>(fileContentHandler.getFiles()); + ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); + Map serviceTemplates = new HashMap<>(); + FileContentHandler artifacts = new FileContentHandler(); + GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate(); + for (Map.Entry fileEntry : csarFiles.entrySet()) { + CsarFileTypes fileType = getFileType(fileEntry.getKey()); + switch (fileType) { + case mainServiceTemplate: + handleServiceTemplate(mainStName, fileEntry.getKey(), csarFiles, serviceTemplates); + break; + + case globalServiceTemplate: + handleServiceTemplate(globalStName, fileEntry.getKey(), csarFiles, serviceTemplates); + break; + + case externalFile: + artifacts.addFile(fileEntry.getKey(), fileEntry.getValue()); + break; + + case definitionsFile: + handleDefintionTemplate(fileEntry.getKey(), csarFiles, gsst); + break; + } + } + handleMetadataFile(csarFiles); + updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles); + return toscaServiceModel; + } + + private void handleMetadataFile(Map csarFiles) { + byte[] bytes = csarFiles.remove(metadataFile); + if (bytes != null) { + csarFiles.put(metadataFile + ".old", bytes); + } + } + + private void handleDefintionTemplate(String key, Map csarFiles, + GlobalSubstitutionServiceTemplate gsst) { + try { + ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(csarFiles.get(key)); + if (readerService == null) { + return; + } + Object nodeTypes = readerService.getNodeTypes(); + if (nodeTypes instanceof Map) { + Map nodeTypeMap = (Map) nodeTypes; + gsst.appendNodes(nodeTypeMap); + } + } catch (YAMLException ye) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withMessage("Invalid YAML content in file " + key + ". reason - " + + ye.getMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); + } + } + + private void updateToscaServiceModel(ToscaServiceModel toscaServiceModel, + Map serviceTemplates, + FileContentHandler externalFilesHandler, + GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate, + Map csarFiles) { + Collection globalServiceTemplates = + GlobalTypesGenerator.getGlobalTypesServiceTemplate().values(); + addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates); + serviceTemplates.put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate); + toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName); + toscaServiceModel.setServiceTemplates(serviceTemplates); + externalFilesHandler.addFile(metadataFile + ".old", csarFiles.get(metadataFile + ".old")); + toscaServiceModel.setArtifactFiles(externalFilesHandler); + } + + private void addGlobalServiceTemplates(Collection globalServiceTemplates, + Map serviceTemplates) { + for (ServiceTemplate serviceTemplate : globalServiceTemplates) { + serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate); + } + } + + private void handleServiceTemplate(String serviceTemplateName, + String fileName, Map csarFiles, + Map serviceTemplates) { + Optional serviceTemplate = + getServiceTemplateFromCsar(fileName, csarFiles); + serviceTemplate.ifPresent( + serviceTemplate1 -> addServiceTemplate(serviceTemplateName, serviceTemplate1, + serviceTemplates)); + } + + private void addServiceTemplate(String serviceTemplateName, + ServiceTemplate serviceTemplate, + Map serviceTemplates) { + serviceTemplates.put(serviceTemplateName, serviceTemplate); + } + + private Optional getManifestContent(Map csarFiles) { + for (Map.Entry csarFileEntry : csarFiles.entrySet()) { + if (csarFileEntry.getKey().contains(manifestFileName)) { + return Optional.of(csarFileEntry.getValue()); + } + } + + return Optional.empty(); + } + + private Optional getServiceTemplateFromCsar(String fileName, + Map csarFiles) { + byte[] fileContent = csarFiles.get(fileName); + ServiceTemplate serviceTemplate = convertServiceTemplate(fileName, fileContent); + + return Optional.of(serviceTemplate); + } + + private ServiceTemplate convertServiceTemplate(String serviceTemplateName, + byte[] fileContent) { + ServiceTemplate serviceTemplate = new ServiceTemplate(); + try { + ServiceTemplateReaderService readerService = + new ServiceTemplateReaderServiceImpl(fileContent); + convertMetadata(serviceTemplateName, serviceTemplate, readerService); + convertToscaVersion(serviceTemplate, readerService); + convertImports(serviceTemplate); + convertNodeTypes(serviceTemplate, readerService); + convertTopologyTemplate(serviceTemplate, readerService); + + } catch (YAMLException ye) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withMessage("Invalid YAML content in file" + serviceTemplateName + ". reason - " + + ye.getMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); + } + + + return serviceTemplate; + } + + private void convertToscaVersion(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Object toscaVersion = readerService.getToscaVersion(); + serviceTemplate.setTosca_definitions_version((String) toscaVersion); + } + + private void convertImports(ServiceTemplate serviceTemplate) { + serviceTemplate.setImports(new ArrayList<>()); + serviceTemplate.getImports() + .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml")); + serviceTemplate.getImports().add(createImportMap(globalSubstitution, globalStName)); + + } + + private Map createImportMap(String key, String fileName) { + Map importMap = new HashMap<>(); + Import anImport = new Import(); + anImport.setFile(fileName); + importMap.put(key, anImport); + + return importMap; + } + + private void convertMetadata(String serviceTemplateName, + ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map metadataToConvert = (Map) readerService.getMetadata(); + Map finalMetadata = new HashMap<>(); + + if (MapUtils.isNotEmpty(metadataToConvert)) { + for (Map.Entry metadataEntry : metadataToConvert.entrySet()) { + if (Objects.isNull(metadataEntry.getValue()) || + !(metadataEntry.getValue() instanceof String)) { + continue; + } + finalMetadata.put(metadataEntry.getKey(), (String) metadataEntry.getValue()); + } + } + + finalMetadata.put("template_name", getTemplateNameFromStName(serviceTemplateName)); + serviceTemplate.setMetadata(finalMetadata); + } + + private void convertNodeTypes(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + Map nodeTypes = (Map) readerService.getNodeTypes(); + if (MapUtils.isEmpty(nodeTypes)) { + return; + } + + for (Map.Entry nodeTypeEntry : nodeTypes.entrySet()) { + DataModelUtil + .addNodeType(serviceTemplate, nodeTypeEntry.getKey(), + (NodeType) createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), + NodeType.class)); + } + } + + private void convertTopologyTemplate(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + + convertInputs(serviceTemplate, readerService); + convertNodeTemplates(serviceTemplate, readerService); + convertOutputs(serviceTemplate, readerService); + convertSubstitutionMappings(serviceTemplate, readerService); + } + + private void convertInputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map inputs = readerService.getInputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, inputs, Constants.inputs); + } + + private void convertOutputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map outputs = readerService.getOutputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.outputs); + } + + private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, + Map mapToConvert, + String inputsOrOutputs) { + if (MapUtils.isEmpty(mapToConvert)) { + return; + } + + for (Map.Entry entry : mapToConvert.entrySet()) { + ParameterDefinition parameterDefinition = + (ParameterDefinition) createObjectFromClass( + entry.getKey(), entry.getValue(), ParameterDefinition.class); + addToServiceTemplateAccordingToSection( + serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition); + } + } + + private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, + String inputsOrOutputs, + String parameterId, + ParameterDefinition parameterDefinition) { + switch (inputsOrOutputs) { + case inputs: + DataModelUtil + .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + break; + case outputs: + DataModelUtil + .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + } + } + + private void convertNodeTemplates(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map nodeTemplates = readerService.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplates)) { + return; + } + + for (Map.Entry nodeTemplateEntry : nodeTemplates.entrySet()) { + NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue()); + DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); + } + } + + private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map substitutionMappings = readerService.getSubstitutionMappings(); + if (MapUtils.isEmpty(substitutionMappings)) { + return; + } + SubstitutionMapping substitutionMapping = convertSubstitutionMappings(substitutionMappings); + DataModelUtil.addSubstitutionMapping(serviceTemplate, substitutionMapping); + } + + private SubstitutionMapping convertSubstitutionMappings(Map substitutionMappings) { + SubstitutionMapping substitutionMapping = new SubstitutionMapping(); + + substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); + substitutionMapping.setCapabilities( + convertSubstitutionMappingsSections((Map) substitutionMappings.get(capabilities))); + substitutionMapping.setRequirements( + convertSubstitutionMappingsSections((Map) substitutionMappings.get(requirements))); + + return substitutionMapping; + } + + private Map> convertSubstitutionMappingsSections( + Map sectionToConvert) { + Map> convertedSection = new HashMap<>(); + if (MapUtils.isEmpty(sectionToConvert)) { + return null; + } + + for (Map.Entry entry : sectionToConvert.entrySet()) { + if (entry.getValue() instanceof List) { + convertedSection.put(entry.getKey(), (List) entry.getValue()); + } + } + + return convertedSection; + } + + private CsarFileTypes getFileType(String fileName) { + if (isMainServiceTemplate(fileName)) { + return CsarFileTypes.mainServiceTemplate; + } else if (isGlobalServiceTemplate(fileName)) { + return CsarFileTypes.globalServiceTemplate; + } else if (isDefinitions(fileName)) { + return CsarFileTypes.definitionsFile; + } else if (isMetadataFile(metadataFile)) { + return CsarFileTypes.toscaMetadata; + } + return CsarFileTypes.externalFile; + } + + private Optional getCsarManifest(Map csarFiles) throws IOException { + Optional manifestContent = getManifestContent(csarFiles); + + if (manifestContent.isPresent()) { + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(manifestContent.get()); + + return Optional.of(new Manifest(byteInputStream)); + } + + return Optional.empty(); + } + + private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) { + NodeTemplate nodeTemplate = new NodeTemplate(); + + Map nodeTemplateAsMap = (Map) candidateNodeTemplate; + nodeTemplate.setArtifacts((Map) nodeTemplateAsMap.get("artifacts")); + nodeTemplate.setAttributes((Map) nodeTemplateAsMap.get("attributes")); + nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy")); + nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); + nodeTemplate.setDirectives((List) nodeTemplateAsMap.get("directives")); + nodeTemplate.setInterfaces( + (Map) nodeTemplateAsMap.get("interfaces")); + nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); + nodeTemplate.setProperties((Map) nodeTemplateAsMap.get("properties")); + nodeTemplate.setRequirements( + (List>) nodeTemplateAsMap.get("requirements")); + nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); + nodeTemplate.setCapabilities( + convertCapabilities((Map) nodeTemplateAsMap.get("capabilities"))); + + return nodeTemplate; + } + + private List> convertCapabilities(Map capabilities) { + List> convertedCapabilities = new ArrayList<>(); + if (MapUtils.isEmpty(capabilities)) { + return null; + } + for (Map.Entry capabilityAssignmentEntry : capabilities.entrySet()) { + Map tempMap = new HashMap<>(); + tempMap.put(capabilityAssignmentEntry.getKey(), + (CapabilityAssignment) createObjectFromClass + (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), CapabilityAssignment.class)); + convertedCapabilities.add(tempMap); + } + return convertedCapabilities; + } + + private Object createObjectFromClass(String nodeTypeId, + Object objectCandidate, + Class classToCreate) { + try { + return JsonUtil.json2Object(objectCandidate.toString(), classToCreate); + } catch (Exception e) { + //todo - return error to user? + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withCategory(ErrorCategory.APPLICATION) + .withMessage("Can't create Node Type from " + nodeTypeId).build()); + } + } + + private boolean isMainServiceTemplate(String fileName) { + return fileName.endsWith(mainStName); + } + + private boolean isMetadataFile(String fileName) { + return fileName.equals(metadataFile); + } + + private boolean isGlobalServiceTemplate(String fileName) { + return fileName.endsWith(globalStName); + } + + private boolean isDefinitions(String fileName) { + return fileName.startsWith(definitionsDir); + } + + private String getTemplateNameFromStName(String serviceTemplateName) { + String fileNameWithoutDirectories; + fileNameWithoutDirectories = getFileNameWithoutDirectories(serviceTemplateName); + return fileNameWithoutDirectories.split("ServiceTemplate")[0]; + } + + private String getFileNameWithoutDirectories(String serviceTemplateName) { + String fileNameWithoutDirectories; + if (serviceTemplateName.contains("/")) { + String[] split = serviceTemplateName.split("/"); + fileNameWithoutDirectories = split[split.length - 1]; + } else if (serviceTemplateName.contains(File.separator)) { + String[] split = serviceTemplateName.split(Pattern.quote(File.separator)); + fileNameWithoutDirectories = split[split.length - 1]; + } else { + fileNameWithoutDirectories = serviceTemplateName; + } + return fileNameWithoutDirectories; + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterManagerImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterManagerImpl.java new file mode 100644 index 0000000000..520e41817e --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterManagerImpl.java @@ -0,0 +1,49 @@ +package org.openecomp.core.impl; + +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.converter.api.ToscaConverterManager; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ToscaConverterManagerImpl implements ToscaConverterManager { + + private static List toscaConverters; + private static final String toscaConverterFileName = "ToscaConverters.json"; + + static { + toscaConverters = getConvertersList(); + } + + @Override + public ToscaServiceModel convert(String csarName, FileContentHandler fileContentHandler) { + return null; + } + + private static List getConvertersList(){ + List toscaConvertersList = new ArrayList<>(); + Map convertersMap = FileUtils.readViaInputStream(toscaConverterFileName, + stream -> JsonUtil.json2Object(stream, Map.class)); + return getToscaConvertersList(toscaConvertersList, convertersMap); + } + + private static List getToscaConvertersList( + List toscaConvertersList, Map convertersMap) { + for(String implClassName : convertersMap.values()){ + try{ + Class clazz = Class.forName(implClassName); + Constructor constructor = clazz.getConstructor(); + toscaConvertersList.add((ToscaConverter) constructor.newInstance()); + }catch (Exception e){ + continue; + } + } + return toscaConvertersList; + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java new file mode 100644 index 0000000000..e04cd239c9 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java @@ -0,0 +1,12 @@ +package org.openecomp.core.impl.factory; + +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.converter.factory.ToscaConverterFactory; +import org.openecomp.core.impl.ToscaConverterImpl; + +public class ToscaConverterFactoryImpl extends ToscaConverterFactory { + @Override + public ToscaConverter createInterface() { + return new ToscaConverterImpl(); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java new file mode 100644 index 0000000000..fa8532546c --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java @@ -0,0 +1,76 @@ +package org.openecomp.core.impl.services; + +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.tosca.services.YamlUtil; +import org.yaml.snakeyaml.error.YAMLException; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import static org.openecomp.core.converter.datatypes.Constants.*; + +public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderService { + + private Map readServiceTemplate = new HashMap<>(); + + public ServiceTemplateReaderServiceImpl(byte[] serviceTemplateContent){ + this.readServiceTemplate = readServiceTemplate(serviceTemplateContent); + } + + @Override + public Map readServiceTemplate(byte[] serviceTemplateContent) { + + Map readSt = + new YamlUtil().yamlToObject(new String(serviceTemplateContent), Map.class); + + return readSt; + } + + @Override + public Object getMetadata(){ + return this.readServiceTemplate.get(metadata); + } + + @Override + public Object getToscaVersion(){ + return this.readServiceTemplate.get(definitionVersion); + } + + @Override + public Object getNodeTypes(){ + return this.readServiceTemplate.get(nodeTypes); + } + + @Override + public Object getTopologyTemplate(){ + return this.readServiceTemplate.get(topologyTemplate); + } + + @Override + public Map getNodeTemplates(){ + return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>() + : (Map) ((Map)this.getTopologyTemplate()).get(nodeTemplates); + } + + @Override + public Map getInputs(){ + return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>() + : (Map) ((Map)this.getTopologyTemplate()).get(inputs); + } + + @Override + public Map getOutputs(){ + return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>() + : (Map) ((Map)this.getTopologyTemplate()).get(outputs); + } + + @Override + public Map getSubstitutionMappings(){ + return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>() + : (Map) ((Map)this.getTopologyTemplate()).get(substitutionMappings); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/resources/ToscaConverters.json b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/resources/ToscaConverters.json new file mode 100644 index 0000000000..e1cddeb854 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/resources/ToscaConverters.json @@ -0,0 +1,3 @@ +{ + "ToscaConverter" : "org.openecomp.core.converter.impl.ToscaConverterImpl" +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java new file mode 100644 index 0000000000..4abed3e316 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java @@ -0,0 +1,193 @@ +package org.openecomp.core.converter.impl; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Test; +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.impl.ToscaConverterImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; +import org.openecomp.sdc.tosca.services.YamlUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.NotDirectoryException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Objects; + +import static org.junit.Assert.assertEquals; +import static org.openecomp.core.converter.datatypes.Constants.globalStName; +import static org.openecomp.core.converter.datatypes.Constants.mainStName; + +public class ToscaConverterImplTest { + + private static ToscaConverter toscaConverter = new ToscaConverterImpl(); + private static String inputFilesPath; + private static String outputFilesPath; + private static Map expectedOutserviceTemplates; + + + @Test + public void testConvertMainSt() throws IOException { + inputFilesPath = "/mock/toscaConverter/convertMainSt/in"; + outputFilesPath = "/mock/toscaConverter/convertMainSt/out"; + + FileContentHandler fileContentHandler = + createFileContentHandlerFromInput(inputFilesPath); + + expectedOutserviceTemplates = new HashMap<>(); + loadServiceTemplates(outputFilesPath, new ToscaExtensionYamlUtil(), + expectedOutserviceTemplates); + + ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler); + ServiceTemplate mainSt = toscaServiceModel.getServiceTemplates().get(mainStName); + + checkSTResults(expectedOutserviceTemplates, null, mainSt); + } + + + + private FileContentHandler createFileContentHandlerFromInput(String inputFilesPath) + throws IOException { + URL inputFilesUrl = this.getClass().getResource(inputFilesPath); + String path = inputFilesUrl.getPath(); + File directory = new File(path); + File[] listFiles = directory.listFiles(); + + FileContentHandler fileContentHandler = new FileContentHandler(); + insertFilesIntoFileContentHandler(listFiles, fileContentHandler); + return fileContentHandler; + } + + private void insertFilesIntoFileContentHandler(File[] listFiles, + FileContentHandler fileContentHandler) + throws IOException { + byte[] fileContent; + if(CollectionUtils.isEmpty(fileContentHandler.getFileList())) { + fileContentHandler.setFiles(new HashMap<>()); + } + + for (File file : listFiles) { + if(!file.isDirectory()) { + try (FileInputStream fis = new FileInputStream(file)) { + fileContent = FileUtils.toByteArray(fis); + fileContentHandler.addFile(file.getPath(), fileContent); + } + }else{ + File[] currFileList = file.listFiles(); + insertFilesIntoFileContentHandler(currFileList, fileContentHandler); + } + + } + } + + private void checkSTResults( + Map expectedOutserviceTemplates, + ServiceTemplate gloablSubstitutionServiceTemplate, ServiceTemplate mainServiceTemplate) { + YamlUtil yamlUtil = new YamlUtil(); + if (Objects.nonNull(gloablSubstitutionServiceTemplate)) { + assertEquals("difference global substitution service template: ", + yamlUtil.objectToYaml(expectedOutserviceTemplates.get(globalStName)), + yamlUtil.objectToYaml(gloablSubstitutionServiceTemplate)); + } + if (Objects.nonNull(mainServiceTemplate)) { + assertEquals("difference main service template: ", + yamlUtil.objectToYaml(expectedOutserviceTemplates.get(mainStName)), + yamlUtil.objectToYaml(mainServiceTemplate)); + } + } + + public static void loadServiceTemplates(String serviceTemplatesPath, + ToscaExtensionYamlUtil toscaExtensionYamlUtil, + Map serviceTemplates) + throws IOException { + URL urlFile = ToscaConverterImplTest.class.getResource(serviceTemplatesPath); + if (urlFile != null) { + File pathFile = new File(urlFile.getFile()); + File[] files = pathFile.listFiles(); + if (files != null) { + addServiceTemplateFiles(serviceTemplates, files, toscaExtensionYamlUtil); + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } + + private static void addServiceTemplateFiles(Map serviceTemplates, + File[] files, + ToscaExtensionYamlUtil toscaExtensionYamlUtil) + throws IOException { + for (File file : files) { + try (InputStream yamlFile = new FileInputStream(file)) { + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + createConcreteRequirementObjectsInServiceTemplate(serviceTemplateFromYaml, toscaExtensionYamlUtil); + serviceTemplates.put(file.getName(), serviceTemplateFromYaml); + try { + yamlFile.close(); + } catch (IOException ignore) { + } + } catch (FileNotFoundException e) { + throw e; + } catch (IOException e) { + throw e; + } + } + } + + private static void createConcreteRequirementObjectsInServiceTemplate(ServiceTemplate + serviceTemplateFromYaml, + ToscaExtensionYamlUtil + toscaExtensionYamlUtil) { + + if (serviceTemplateFromYaml == null + || serviceTemplateFromYaml.getTopology_template() == null + || serviceTemplateFromYaml.getTopology_template().getNode_templates() == null) { + return; + } + + //Creating concrete objects + Map nodeTemplates = + serviceTemplateFromYaml.getTopology_template().getNode_templates(); + for (Map.Entry entry : nodeTemplates.entrySet()) { + NodeTemplate nodeTemplate = entry.getValue(); + List> requirements = nodeTemplate.getRequirements(); + List> concreteRequirementList = new ArrayList<>(); + if (requirements != null) { + ListIterator> reqListIterator = requirements + .listIterator(); + while (reqListIterator.hasNext()){ + Map requirement = reqListIterator.next(); + Map concreteRequirement = new HashMap<>(); + for (Map.Entry reqEntry : requirement.entrySet()) { + RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()), + RequirementAssignment.class)); + concreteRequirement.put(reqEntry.getKey(), requirementAssignment); + concreteRequirementList.add(concreteRequirement); + reqListIterator.remove(); + } + } + requirements.clear(); + requirements.addAll(concreteRequirementList); + nodeTemplate.setRequirements(requirements); + } + System.out.println(); + //toscaExtensionYamlUtil.yamlToObject(nodeTemplate, NodeTemplate.class); + } + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java new file mode 100644 index 0000000000..9f7071e9e7 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java @@ -0,0 +1,62 @@ +package org.openecomp.core.converter.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.openecomp.core.impl.GlobalSubstitutionServiceTemplate; +import org.openecomp.core.impl.ToscaConverterImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; + +import java.net.URL; +import java.util.Map; +import java.util.Set; + +import static org.openecomp.sdc.common.utils.CommonUtil.*; +import static org.junit.Assert.*; +import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.*; +public class ToscaConvertorDefinitionsTest { + + + @Test + public void loadCsar() throws Exception { + URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar"); + byte[] bytes = IOUtils.toByteArray(resource); + assertNotNull(bytes); + FileContentHandler contentMap = validateAndUploadFileContent(OnboardingTypesEnum.CSAR, bytes); + ToscaConverterImpl toscaConverter = new ToscaConverterImpl(); + ToscaServiceModel convert = toscaConverter.convert(contentMap); + Map serviceTemplates = convert.getServiceTemplates(); + assertTrue(serviceTemplates.containsKey(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME)); + ServiceTemplate serviceTemplate = serviceTemplates.get(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME); + + assertNotNull(serviceTemplate); + assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate); + + assertNotNull(serviceTemplate.getMetadata()); + assertFalse(serviceTemplate.getMetadata().isEmpty()); + assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY)); + + assertNotNull(serviceTemplate.getImports()); + assertFalse(serviceTemplate.getImports().isEmpty()); + assertEquals(1 ,serviceTemplate.getImports().size()); + assertTrue(serviceTemplate.getImports().get(0).containsKey(HEAT_INDEX)); + + assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version()); + + + assertNotNull(serviceTemplate.getNode_types()); + assertEquals(7, serviceTemplate.getNode_types().size()); + Set keys = serviceTemplate.getNode_types().keySet(); + assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VDU")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.CP")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF.vCSCF")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.ImageFile")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.LocalStorage")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF")); + assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VL")); + } + + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/csar/vCSCF.csar b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/csar/vCSCF.csar new file mode 100644 index 0000000000000000000000000000000000000000..f1b77554e48d08cd56626dea9d726108035b206f GIT binary patch literal 8186 zcmbVR1z1$=wjKneQ$j+N?iT6p?(S|Fy1S7c0V(P3R6@GD1O!C71d(pIqyOQE{+@g8 ze`lU&*531cd#!h`{q1*^oFpU^2H^YWQx1vbkAr{xz=I{fy`#B_zM-Q7z1+Xo5vr2^ zvJMfvPRQ8A+{WC|+}7sjN?1UhG)Mw&3W4?1I4M>=t9eN$r*b1P#yH+^fXv^aj5P6kBbQ-^RJU-&w1Kqw|Uc7?!- z5|+4@)msA_*<=;S0FmS*_pLLpThFBNUV~YdkdR=}!PE{!y^{Bq9;^*0;YNY83EnS1 zPc@UVE;0*SMbmX@7AC@dSa39E@_^!udRJndj7dEtshJR_(2_;1WT__PXK7fRr4jQ* zlPX1$f%pz#m&6N?FUJx*18wr z2vB(MJpGsd*iOFQ_JaM^2mt_a{v-cM*&6CwDLUHPgWdSUh4J!?3SbxR9K!nmP-?a| z3l|}9A5n)q>|u)Q1vU||_W@im3l2(LYN^8#x(zsjm&kw}{Z2X%5l#|z613ckgv67Z zuAL|^QMhvLZ4>emp^Lj5H2US(iD&BdZ86&ET)t_X8qsV8rmY@N_)J?XbD)gB<-cX? zN7A}DwMt>g9u3DaSu$=CJLzpwOg>w+j}_Q@CVwAbup{D zZ+nh~#5AnrMO6k*9e%MQhP3^b3f5~02=lfB`&S2zm}o0pgPju%2LQ1ABL}%V8q*2N z{cuf}N}J3I1M2%j%yS5$li9f{tK4`M?HY8g(n4-ZVtmesv{whmGj`*7e8T8djEQxI zBZG&7hYpyosNSlXnnu{_>!qL=QPVF2(qpSVzP9bi**0wOS z3IP%rRs&sV zfwxl^ib6A!n@trmubK(C)tLxbE3GUo87w6Gc?Tn+TiyY}+WEq=LHPUVHFcUw*G}ll zvbV$SgKp%ho~`Kar-ai51JBVD$TmiR@8`NTve$)!`FS4|U4F0^c%%>b^t7^7H;uUH)P4t0nW{fgU88$TSkG=3P`ODS^&y@_>l z7s(@h%*9_Z<%*2&)5qlv6Z)cFPAw)=43QkyXqt(Hw*H$eUv?-;-Wg#ToespW`-!`s zktzjDRvchnd-0F=lZue?j}29-GGsHyfY^LWdGLUx!P0h%2@$#uYBT051qD+Y5JW1Q zRb4O3+n;baZDLq;9`|~x$H!Z#P@H-jH}n*g(iiCYyg{s8N9CP`W-C1v!6#OR=Z0<^ z-Lj87A^m`@$Ff0KuO?VX#JwL}nKAOY@fOxZR)DIVd9WxmG@rJE)&`a~n!E`qnk|@8 zl62Eg@lth2C-j`i>msA{kO(Df36EqDZ;Dsao5sXfvWu_WdX81HKTy|*rMd5a?eDa$ z>{dYJMowjOi|W*qUv$<`-ek)Ye$COozgt)fk$MrYPUZM;G74yt*z_|swiNSoj?zTusqo{eUxv9_`N z(`Flu2RBYRWBe3(ZB{X_>1Lm)9!L0TSU(+&=ZdtSH(k8K8{4N(ZF+Chat$)*=0TlB;OU&m8njY;q@i*i^A8uiU>ENqtGg=5c@3 za#cmP!ZCT*4nHZ>yg*^m;+M;8M_xDCjqZl2C`?M8LBuC*RSx0j5?pE2d$eY(B8qid z2bONjrn4lux-ZA#YF`mfmrJLx@xSlWr>apYJC=|jfXTE*hd7BBARigC^CLnD)CsU? z5_VvOLCM-1rKGEQ?78DNl%h&lu2YHJM=*lAW2;cq;-VfA(ge;d=w1PI`R2p!qein)jZ)p_ zZnH5Dlh_EXBE0R3FMVr`lz4fNKA6}#P+}xS&YD(t8ZY8u?FlCXO4E2zL>oBs*&;+X zwwz6>-Q2CnW&7(o>#y5AAqAelA55Q$u>T+WRFV2CI4kqp%rhW1U1HwwMV>U!oB46C z#T2*JZn2;xDUp^bZXCy3k>ZhyJ=5%or9ciLE`o&4uI>O96*s8B(LRUMstCR;Z1b5- z&4ngi;+>b|c$|2+JW5>}JKzu3+a5%-Wu+6yxVyTxzZc2noZkS0_YEo9ZMibz%~^6= zn8IikW^n`|q@~@ryR30VjIW@pYyv>5lK z+ilF!_@j{7O4Nsa-W>{hu6O6VGz->dCCT@$rxmP9Z7;l$uc~beoDZW%UVycmzu<2x z&iq77<51Ts!VLs2+VwzvzR1Y^s<)&n=NWtsgeXUj(1d}G(B@42B#|PjTcfp)N!sF7 zi_bJ5mJJo$$T?k#%1ii??3!#n@m&2H=GV=U<@s4!3e1I)2mk=rpSaN3#^le*+xOV2 zA|pcQET||b@~;p(WIxM*+Ppz|^_DKlFnq{G!g?W>t_?uzO3-p7L{ws;; zjKfH2lYQ06-t~7!u{3NOV?7FmZCU+W3%H;43I`6 zUpPAFji5~KAtLEW8+$w@vW|MSFnOMKL>!_$xr-TH$q?yl3QUy%CMSC$fexksrqgUA zt}kKRTnfV3qwg>w;Wdy+lvmf{#3(@@7hs<}n8dm;lX|r%5#X0Agcj~6$mM&cu7D|U z8x-!aHvPV^TTiph9}Phj+b-S4DShD>>gzgRiUK_eljLG~?s4lgm`O-;dl^A(YVUwQID3)+~7CcAQ+A6cW4 zX>7b+glufJQwnNXHIX3RVWBR?cc6auX~DAr4QCYQkrpo$H=2tnN;bQU9YGr3kytE^e8;&JLKoJl(CtYVg|JFcwbzU#5CUHntzSy?I+#@iO4_#I5l9 z_M2`1^R|MqlA5p9W$24^{N3StBYjAt)19yD|1L)UN|6(=#7ld?6y^x?A0qaD-KF0P zj9lfm?-Bd`DfJa3IATW$PEW)@K+YDoiYaAFqiai?YfupN*e!sXkO&%%du77x@so?k?&bM6Hr%3LO@Sw*RB26k`+96qdM$Xj zm#7Z?B>KK-m1MY{pgxcQ+6F}ROqpgtT=jhS#>{Qx46oJRfm;>iB5u`dZ-}8c1~`rr zUO5K!Z<&(V@gKKLX5kPDy|}4l^O`{rQ?Ct~e(;c!hYX_I(n6#F%J+gL&s|FAr54b9c^*+o zQXEx6s&|Qbt)xb3INBzJhN6ut5`*6t+Ih&V_E{1-G5NNt98E3M2vILL2gO%K^~e(B z;N^M>k3I~4xhnRC;TK{r1e+E~r8Y75-73jKD?%LKvNvJvwbi=tb)`PF!DSP_gw{5j zb!s7N31q>P9=PI3ANf+ha;^g?lkK)(@!9BJN{-CIPZ}GzjjTqW$G`q;+j8^n^MZFH z?dpVnn`hLG8FSn4auN|1FjEfC_CN_G#I1%PsK$skys4`b+s@$_%qs^Ibqk4HlJ4uB6VJg zw|9%9qT9dApA;Q~yVYG}epwhBL%V-=tj;B0vu>A;E8wLUw{e~z~ zVt`hi?in{>sXz1V!<0C0*x=gT`m~1-p6P8KM#65?tgNh`7(SPNE~rlpJq_Dje=fw0 zWmH)-!F#j>^Ns6pg*B6}hc!!tY~W=PYorNpfLT{%Jhj0qtr>>qQ=n<&P*xdt$5TuP z&8$R`AaS#gj(%3+&dgZdJbucWn)+2y*}Ec6%DW|eJ*srDlQqr}JSFq-$OcxALHp9I zOC3qh5{+z%vIVu#0v>rPrBh6V?-32W8je`5nO|Tf=tru7YAn}y`DxP|_|r7)rClL^ zK4e;OGr~QR2y+!0065|X03QE`hy48w-__K$onS!qNw3*M-A%Kg4G3v&>j#9DDN8Pm z**|()Ew-%3nFPPw=#ZG>GhXpwIC-@7LaFPtdZdN(bJ}hoOl*wCaoS-uc2uYuMI4Yn z6stcsP0m%ysa<&d+}>kCyn7myG93Q!Mg%K)s){ahGxbu-!BM$PDw-#*@1EoBX>SVq2cR_XKOjif7eNClb)ZhfkJB(Pg0OW(-$VvI ztoHO{ur{lwlwkjGQnx5+RC?fZJ$5?bK!kDzgBylkIhWJ3r!1m$p}`?k zAGCXoVbt~L&d>*S!_*o|Ks58IwVWbOhTn z8ShjRhJC_s^@M0b`$b*c6BGB|4z(IovZHz9TYcj&z5%NBubNKuIhydaD0zOW(Z+y2 zC&3GTr~bNElOV(3DMkff?}xg|c`09l)zxh;dDspJMO>~xcY>ZZr~_!swDgu6t^&NS zT(l0hXN|kVAF|gS^|=p?X&4)0U`z`6x#gA(M0wQ+=-dDvV=(d(^cUElUg~ltC(^{0 zBCqwsdO**8t~{Ph1qi?j>59^Xho&voD<5Nm zM2?Q5798JDU*-^Vr+eG8VDexs%1i7B#^d;KwqV}6yK^P4S8OgU%@X&sg7FhxmyFV7 z-VZmMN5n|$tI@&LMK>s;Se&k+00Bj-mX2b9U}OqoQTqb<=f@^&@r zirZ%^IR*@(W*!0T7Cu*@22Tb(1abZKZIfP*Hv=x`a&A8&AcdB$HbWm!SuKhP9`4SW znbo*?9A8``FX`~XA&jwSgg_r-7F(LKzKODSc7Ar#RLvPC1(i@S{}CdqKJ5wO)YUMu zOxG^l}2%}CtII(v?vvBtnS|?I^dZXfSE8& z?iB5y_>a@gGQGg=Tmdp0IohU@{Q_)+*#$ruiXPz!O`b+;ZGVfD z7#D!)snKb<@nQIKi^eX*xml!ayCLSxdWuwRFVgr|gT?HiN>iQx9Q z&EK@{jJp&mybg1#vgzUuoYbHs*yms#7yQv}hWptTF2B zf&S36(*MOd6b$z#-UY zW`-sv(lG%`{Av2u`Un!r&@jWYV9)y_RHr5${@E>9lrNkVGU+3sguFAXhBwUJp%0eL0d7$g22&8w0z*FuWuMp*Y1Bb__)CAv_l2ASh3YW{XuK z>dF<3@kuQLI@hUAJ>ZtXi_fI5=Ux~LaP#k++c$laZZ`P zTo(h_i92G*2TDZe9p5WbO@;@`zB`}AFb9!W2{W0T}e-|3IpUsSPh7Sv* zmM3K^?vv1GgOFVLZPh(E;p#w<*gR9}soiz)-q65Ie%uSqlt6k{r8JVacJ<;(g5lCO ztAU@jcbC*Q#f2}xCBgpYXlUIyZ+7WXi7Q^v)6ojG_uft-&9R-*$O%%}SPo?{XE)nZ zO3ugM+7ruIjjgH`Kpi)cDwIwA<5Y@s&%>r}A2h<57jl}5=xobu?{8d8eJ0I=xAa3; zljla)9u{Cha9EW0cx-Af{VB_+ph+}Qw$w*X65;_b;6IIWNdEO6p#Dq#9PGdYp8fa_ z0-QUoZM2o=kWN6{NiUb&g74?|b^m?*b6+;_Bo16u+`rHN9m(HD zF@FN%pcMQA%$@ul%&&uv`(UcUto45fb8qbNCm7GQeSg5XlfT3GwLg9z1|&EK|7S4n zy5)buL5&ym1IL~G9mlVY%lkMEz=Xoz zukR@Gf2zXo+rfgh9L@z3531_Eg*)y~dEd_8OTYVeYQaqRr)vNAJF4G?-v3TY87l0f zZeUA*%)QR<@~5Rgr4o0RzSHRlxUukCVsZagLghn$xav;oQvG%Q(*P{s@9D>#0bj6z ptG^rgnT*^w1qjQF`%Y_jrtYMiB=keD9sm;fiw8dH`<~ta{s*xp-c|qr literal 0 HcmV?d00001 diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/checksum.lst b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/checksum.lst new file mode 100644 index 0000000000..701f14d45d --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/checksum.lst @@ -0,0 +1 @@ +Definitions/openovnf__vPCRF.yaml:75bd8963ecc09bf769d0bb5cb475314d diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/csar.meta b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/csar.meta new file mode 100644 index 0000000000..aac2fed3c3 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Artifacts/csar.meta @@ -0,0 +1,3 @@ +Type:NFAR +Version:v1.0 +Provider:Huawei \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Definitions/GlobalSubstitutionTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Definitions/GlobalSubstitutionTypesServiceTemplate.yaml new file mode 100644 index 0000000000..a88171701e --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/Definitions/GlobalSubstitutionTypesServiceTemplate.yaml @@ -0,0 +1,60 @@ +node_types: + tosca.nodes.nfv.VDU.Compute: + attributes: + private_address: + type: string + public_address: + type: string + networks: + type: string + ports: + type: string + capabilities: + scalable: + type: tosca.capabilities.Scalable + virtual_compute: + type: tosca.capabilities.nfv.VirtualCompute + endpoint: + type: tosca.capabilities.Endpoint.Admin + os: + type: tosca.capabilities.OperatingSystem + virtual_binding: + type: tosca.capabilities.nfv.VirtualBindable + host: + type: tosca.capabilities.Container + binding: + type: tosca.capabilities.network.Bindable + monitoring_parameter: + type: tosca.capabilities.nfv.Metric + derived_from: tosca.nodes.Root + properties: + configurable_properties: + entry_schema: + type: tosca.datatypes.nfv.VnfcConfigurableProperties + type: map + name: + type: string + nfvi_constraints: + entry_schema: + type: string + required: false + type: list + descrption: + type: string + boot_order: + entry_schema: + type: string + required: false + type: list + requirements: + - local_storage: + capability: tosca.capabilities.Attachment + occurrences: + - 0 + - UNBOUNDED + - virtual_storage: + capability: tosca.capabilities.nfv.VirtualStorage + occurrences: + - 0 + - UNBOUNDED +tosca_definitions_version: tosca_simple_yaml_1_0 diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.mf b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.mf new file mode 100644 index 0000000000..e45f002332 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.mf @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 + +Name: Entry-Definitions +Name: MainServiceTemplate.yaml + +Name: Definitions\GlobalSubstitutionTypesServiceTemplate.yaml + +Name: Artifacts\install.sh + +Name: Artifacts\create_stack.sh + +Name: Licenses\license.xml diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.yaml new file mode 100644 index 0000000000..041afbacf8 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/MainServiceTemplate.yaml @@ -0,0 +1,551 @@ +imports: +- openovnf__tosca.nodes.nfv.VNF.vPCRF.yaml +- openonfv__tosca.capabilities.Scalable.yaml +- openonfv__tosca.capabilities.nfv.Metric.yaml +- openonfv__tosca.nodes.nfv.VnfVirtualLinkDesc.yaml +- openonfv__tosca.capabilities.network.Bindable.yaml +- openonfv__tosca.capabilities.Attachment.yaml +- openonfv__tosca.capabilities.nfv.VirtualBindable.yaml +- openonfv__tosca.capabilities.nfv.VirtualLinkable.yaml +- openonfv__tosca.requirements.nfv.VirtualStorage.yaml +- openonfv__tosca.nodes.nfv.VDU.VirtualStorage.yaml +- openonfv__tosca.relationships.nfv.VirtualBindsTo.yaml +- openonfv__tosca.nodes.nfv.VDU.Compute.yaml +- openonfv__tosca.relationships.nfv.VirtualLinksTo.yaml +- openonfv__tosca.capabilities.nfv.VirtualCompute.yaml +- openonfv__tosca.capabilities.Container.yaml +- openonfv__tosca.capabilities.nfv.VirtualStorage.yaml +- openonfv__tosca.requirements.nfv.VirtualBinding.yaml +- openonfv__tosca.capabilities.Endpoint.Admin.yaml +- openonfv__tosca.capabilities.OperatingSystem.yaml +- openonfv__tosca.nodes.nfv.VduCpd.yaml +- openonfv__tosca.relationships.nfv.VDU.AttachedTo.yaml + +metadata: + vendor: Huawei + csarVersion: v1.0 + csarProvider: Huawei + id: vPCRF_NF_HW + version: v1.0 + csarType: NFAR + name: vPCRF + vnfdVersion: v1.0 + vnfmType: hwvnfm + +node_types: + org.openecomp.resource.vfc.nodes.heat.nat_fw: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server + +topology_template: + node_templates: + PUPDU_Storage: + attributes: + tosca_name: PUPDU_Storage + properties: + id: PUPDU_Storage + size_of_storage: 200G + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + USRSU: + attributes: + tosca_name: USRSU + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: {} + virtual_cpu: + num_virtual_cpu: 4 + properties: + configurable_properties: + test: {"additional_vnfc_configurable_properties":{"aaa":"1"}} + name: USRSU + descrption: the virtual machine of USRSU + requirements: + - virtual_storage: + capability: virtual_storage + node: USRSU_Storage + - local_storage: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VDU.Compute + USPID3_VduCpd_Fabric: + attributes: + tosca_name: USPID3_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + PUPDU_VduCpd_Base: + attributes: + tosca_name: PUPDU_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + OMU_VduCpd_Fabric: + attributes: + tosca_name: OMU_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: OMU + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + USPID3: + attributes: + tosca_name: USPID3 + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: {} + virtual_cpu: + num_virtual_cpu: 4 + properties: + configurable_properties: + test: {"additional_vnfc_configurable_properties":{"aaa":"1"}} + name: USPID3 + descrption: the virtual machine of USPID3 + requirements: + - virtual_storage: + capability: virtual_storage + node: USPID3_Storage + - local_storage: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VDU.Compute + UPIRU_VduCpd_Base: + attributes: + tosca_name: UPIRU_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + OMU2ManageNet: + attributes: + tosca_name: OMU2ManageNet + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + node: tosca.nodes.Root + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + OMU_Storage: + attributes: + tosca_name: OMU_Storage + properties: + id: OMU_Storage + size_of_storage: 256G + rdma_enabled: false + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + UPSPU: + attributes: + tosca_name: UPSPU + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: {} + virtual_cpu: + num_virtual_cpu: 4 + properties: + configurable_properties: + test: {"additional_vnfc_configurable_properties":{"aaa":"1"}} + name: UPSPU + descrption: the virtual machine of UPSPU + requirements: + - virtual_storage: + capability: virtual_storage + node: UPSPU_Storage + - local_storage: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VDU.Compute + PUPDU_VduCpd_Fabric: + attributes: + tosca_name: PUPDU_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + USPID2BossNet: + attributes: + tosca_name: USPID2BossNet + properties: + role: root + layer_protocol: ethernet + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + OMU_VduCpd_Base: + attributes: + tosca_name: OMU_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: OMU + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + USPID3_Storage: + attributes: + tosca_name: USPID3_Storage + properties: + id: USPID3_Storage + size_of_storage: 300G + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + UPIRU2DataNet2: + attributes: + tosca_name: UPIRU2DataNet2 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + USPID2ManageNet: + attributes: + tosca_name: USPID2ManageNet + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + UPIRU2DataNet3: + attributes: + tosca_name: UPIRU2DataNet3 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + PUPDU2DataNet3: + attributes: + tosca_name: PUPDU2DataNet3 + properties: + role: root + layer_protocol: ethernet + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + USRSU2DataNet1: + attributes: + tosca_name: USRSU2DataNet1 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + USRSU2DataNet2: + attributes: + tosca_name: USRSU2DataNet2 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + UPIRU_Storage: + attributes: + tosca_name: UPIRU_Storage + properties: + id: UPIRU_Storage + size_of_storage: 4G + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + PUPDU2SignalNet1: + attributes: + tosca_name: PUPDU2SignalNet1 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + UPIRU2DataNet1: + attributes: + tosca_name: UPIRU2DataNet1 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + USPID3_VduCpd_Base: + attributes: + tosca_name: USPID3_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + Base: + attributes: + tosca_name: Base + properties: + vl_flavours: + flavours: test2 + connectivity_type: + layer_protocol: ipv4 + flow_pattern: + type: tosca.nodes.nfv.VnfVirtualLinkDesc + USRSU_Storage: + attributes: + tosca_name: USRSU_Storage + properties: + id: USRSU_Storage + size_of_storage: 200G + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + UPSPU_VduCpd_Base: + attributes: + tosca_name: UPSPU_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPSPU + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + PUPDU: + attributes: + tosca_name: PUPDU + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: {} + virtual_cpu: + num_virtual_cpu: 4 + properties: + configurable_properties: + test: {"additional_vnfc_configurable_properties":{"aaa":"1"}} + name: PUPDU + descrption: the virtual machine of PUPDU + requirements: + - virtual_storage: + capability: virtual_storage + node: PUPDU_Storage + - local_storage: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VDU.Compute + USRSU_VduCpd_Base: + attributes: + tosca_name: USRSU_VduCpd_Base + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + capability: virtual_linkable + node: Base + type: tosca.nodes.nfv.VduCpd + OMU: + attributes: + tosca_name: OMU + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 16G + requested_additional_capabilities: {} + virtual_cpu: + num_virtual_cpu: 4 + properties: + configurable_properties: + test: {"additional_vnfc_configurable_properties":{"aaa":"1"}} + name: OMU + descrption: the virtual machine of OMU + requirements: + - virtual_storage: + capability: virtual_storage + node: OMU_Storage + - local_storage: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VDU.Compute + UPIRU_VduCpd_Fabric: + attributes: + tosca_name: UPIRU_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + UPSPU_Storage: + attributes: + tosca_name: UPSPU_Storage + properties: + id: UPSPU_Storage + size_of_storage: 4G + type_of_storage: volume + type: tosca.nodes.nfv.VDU.VirtualStorage + PUPDU2ManageNet: + attributes: + tosca_name: PUPDU2ManageNet + properties: + role: root + layer_protocol: ethernet + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + USRSU_VduCpd_Fabric: + attributes: + tosca_name: USRSU_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + UPIRU2SignalNet1: + attributes: + tosca_name: UPIRU2SignalNet1 + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + type: tosca.nodes.nfv.VduCpd + Fabric: + attributes: + tosca_name: Fabric + properties: + vl_flavours: + flavours: test1 + connectivity_type: + layer_protocol: ipv4 + flow_pattern: + type: tosca.nodes.nfv.VnfVirtualLinkDesc + UPSPU_VduCpd_Fabric: + attributes: + tosca_name: UPSPU_VduCpd_Fabric + properties: + role: root + layer_protocol: ipv4 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPSPU + - virtual_link: + capability: virtual_linkable + node: Fabric + type: tosca.nodes.nfv.VduCpd + + substitution_mappings: + node_type: tosca.nodes.nfv.VNF.vPCRF +tosca_definitions_version: tosca_simple_yaml_1_0 \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/TOSCA-Metadata/TOSCA.meta b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000000..69f62ca864 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/in/TOSCA-Metadata/TOSCA.meta @@ -0,0 +1,135 @@ +TOSCA-Meta-Version: 1.0 +CSAR-Version: 1.0 +Created-By: Winery 0.1.37-SNAPSHOT +Entry-Definitions: Definitions/openovnf__vPCRF.yaml + +Name: Definitions/openovnf__vPCRF.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openovnf__tosca.nodes.nfv.VNF.vPCRF.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.Scalable.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.nfv.Metric.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.nodes.nfv.VnfVirtualLinkDesc.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.network.Bindable.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.Attachment.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.nfv.VirtualBindable.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.nfv.VirtualLinkable.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.requirements.nfv.VirtualStorage.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.nodes.nfv.VDU.VirtualStorage.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.relationships.nfv.VirtualBindsTo.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.nodes.nfv.VDU.Compute.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.relationships.nfv.VirtualLinksTo.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.nfv.VirtualCompute.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.Container.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.nfv.VirtualStorage.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.requirements.nfv.VirtualBinding.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.Endpoint.Admin.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.capabilities.OperatingSystem.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.nodes.nfv.VduCpd.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.relationships.nfv.VDU.AttachedTo.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openonfv__tosca.requirements.nfv.VirtualLink.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: Definitions/openovnf__tosca.nodes.nfv.VNF.yaml +Content-Type: application/vnd.oasis.tosca.definitions + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.VirtualStorage/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VnfVirtualLinkDesc/appearance/bigIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VnfVirtualLinkDesc/appearance/smallIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.Compute/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VduCpd/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: capabilitytypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.capabilities.nfv.VirtualCompute/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv%2Fvnf/tosca.nodes.nfv.VNF/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.VirtualStorage/appearance/bigIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.VirtualStorage/appearance/smallIcon.png +Content-Type: image/png + +Name: capabilitytypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.capabilities.Container/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.Compute/appearance/bigIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VDU.Compute/appearance/smallIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv%2Fvnf/tosca.nodes.nfv.VNF.vPCRF/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: capabilitytypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.capabilities.OperatingSystem/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VnfVirtualLinkDesc/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VduCpd/appearance/bigIcon.png +Content-Type: image/png + +Name: nodetypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.nodes.nfv.VduCpd/appearance/smallIcon.png +Content-Type: image/png + +Name: capabilitytypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.capabilities.Scalable/propertiesdefinition/Properties.xsd +Content-Type: text/xml + +Name: relationshiptypes/http%3A%2F%2Fwww.open-o.org%2Ftosca%2Fnfv/tosca.relationships.nfv.VDU.AttachedTo/propertiesdefinition/Properties.xsd +Content-Type: text/xml + + diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/out/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/out/MainServiceTemplate.yaml new file mode 100644 index 0000000000..77bfcac710 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/out/MainServiceTemplate.yaml @@ -0,0 +1,546 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + vnfdVersion: v1.0 + template_name: Main + vendor: Huawei + csarVersion: v1.0 + vnfmType: hwvnfm + csarProvider: Huawei + name: vPCRF + id: vPCRF_NF_HW + version: v1.0 + csarType: NFAR +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.nodes.heat.nat_fw: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + node_templates: + PUPDU_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: PUPDU_Storage + size_of_storage: 200G + type_of_storage: volume + attributes: + tosca_name: PUPDU_Storage + USRSU: + type: tosca.nodes.nfv.VDU.Compute + properties: + configurable_properties: + test: + additional_vnfc_configurable_properties: + aaa: '1' + name: USRSU + descrption: the virtual machine of USRSU + attributes: + tosca_name: USRSU + requirements: + - virtual_storage: + capability: virtual_storage + node: USRSU_Storage + - local_storage: + node: tosca.nodes.Root + capabilities: + - virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: { + } + virtual_cpu: + num_virtual_cpu: 4.0 + USPID3_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USPID3_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + capability: virtual_linkable + node: Fabric + PUPDU_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: PUPDU_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + capability: virtual_linkable + node: Base + OMU_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: OMU_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: OMU + - virtual_link: + capability: virtual_linkable + node: Fabric + USPID3: + type: tosca.nodes.nfv.VDU.Compute + properties: + configurable_properties: + test: + additional_vnfc_configurable_properties: + aaa: '1' + name: USPID3 + descrption: the virtual machine of USPID3 + attributes: + tosca_name: USPID3 + requirements: + - virtual_storage: + capability: virtual_storage + node: USPID3_Storage + - local_storage: + node: tosca.nodes.Root + capabilities: + - virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: { + } + virtual_cpu: + num_virtual_cpu: 4.0 + UPIRU_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + capability: virtual_linkable + node: Base + OMU2ManageNet: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: OMU2ManageNet + requirements: + - virtual_binding: + node: tosca.nodes.Root + - virtual_link: + node: tosca.nodes.Root + OMU_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: OMU_Storage + size_of_storage: 256G + rdma_enabled: false + type_of_storage: volume + attributes: + tosca_name: OMU_Storage + UPSPU: + type: tosca.nodes.nfv.VDU.Compute + properties: + configurable_properties: + test: + additional_vnfc_configurable_properties: + aaa: '1' + name: UPSPU + descrption: the virtual machine of UPSPU + attributes: + tosca_name: UPSPU + requirements: + - virtual_storage: + capability: virtual_storage + node: UPSPU_Storage + - local_storage: + node: tosca.nodes.Root + capabilities: + - virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: { + } + virtual_cpu: + num_virtual_cpu: 4.0 + PUPDU_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: PUPDU_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + capability: virtual_linkable + node: Fabric + USPID2BossNet: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ethernet + attributes: + tosca_name: USPID2BossNet + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + node: tosca.nodes.Root + OMU_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: OMU_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: OMU + - virtual_link: + capability: virtual_linkable + node: Base + USPID3_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: USPID3_Storage + size_of_storage: 300G + type_of_storage: volume + attributes: + tosca_name: USPID3_Storage + UPIRU2DataNet2: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU2DataNet2 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + USPID2ManageNet: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USPID2ManageNet + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + node: tosca.nodes.Root + UPIRU2DataNet3: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU2DataNet3 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + PUPDU2DataNet3: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ethernet + attributes: + tosca_name: PUPDU2DataNet3 + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + USRSU2DataNet1: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USRSU2DataNet1 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + node: tosca.nodes.Root + USRSU2DataNet2: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USRSU2DataNet2 + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + node: tosca.nodes.Root + UPIRU_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: UPIRU_Storage + size_of_storage: 4G + type_of_storage: volume + attributes: + tosca_name: UPIRU_Storage + PUPDU2SignalNet1: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: PUPDU2SignalNet1 + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + UPIRU2DataNet1: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU2DataNet1 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + USPID3_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USPID3_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: USPID3 + - virtual_link: + capability: virtual_linkable + node: Base + Base: + type: tosca.nodes.nfv.VnfVirtualLinkDesc + properties: + vl_flavours: + flavours: test2 + connectivity_type: + layer_protocol: ipv4 + flow_pattern: null + attributes: + tosca_name: Base + USRSU_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: USRSU_Storage + size_of_storage: 200G + type_of_storage: volume + attributes: + tosca_name: USRSU_Storage + UPSPU_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPSPU_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: UPSPU + - virtual_link: + capability: virtual_linkable + node: Base + PUPDU: + type: tosca.nodes.nfv.VDU.Compute + properties: + configurable_properties: + test: + additional_vnfc_configurable_properties: + aaa: '1' + name: PUPDU + descrption: the virtual machine of PUPDU + attributes: + tosca_name: PUPDU + requirements: + - virtual_storage: + capability: virtual_storage + node: PUPDU_Storage + - local_storage: + node: tosca.nodes.Root + capabilities: + - virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 24G + requested_additional_capabilities: { + } + virtual_cpu: + num_virtual_cpu: 4.0 + USRSU_VduCpd_Base: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USRSU_VduCpd_Base + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + capability: virtual_linkable + node: Base + OMU: + type: tosca.nodes.nfv.VDU.Compute + properties: + configurable_properties: + test: + additional_vnfc_configurable_properties: + aaa: '1' + name: OMU + descrption: the virtual machine of OMU + attributes: + tosca_name: OMU + requirements: + - virtual_storage: + capability: virtual_storage + node: OMU_Storage + - local_storage: + node: tosca.nodes.Root + capabilities: + - virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 16G + requested_additional_capabilities: { + } + virtual_cpu: + num_virtual_cpu: 4.0 + UPIRU_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + capability: virtual_linkable + node: Fabric + UPSPU_Storage: + type: tosca.nodes.nfv.VDU.VirtualStorage + properties: + id: UPSPU_Storage + size_of_storage: 4G + type_of_storage: volume + attributes: + tosca_name: UPSPU_Storage + PUPDU2ManageNet: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ethernet + attributes: + tosca_name: PUPDU2ManageNet + requirements: + - virtual_binding: + capability: virtual_binding + node: PUPDU + - virtual_link: + node: tosca.nodes.Root + USRSU_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: USRSU_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: USRSU + - virtual_link: + capability: virtual_linkable + node: Fabric + UPIRU2SignalNet1: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPIRU2SignalNet1 + requirements: + - virtual_binding: + capability: virtual_binding + node: UPIRU + - virtual_link: + node: tosca.nodes.Root + Fabric: + type: tosca.nodes.nfv.VnfVirtualLinkDesc + properties: + vl_flavours: + flavours: test1 + connectivity_type: + layer_protocol: ipv4 + flow_pattern: null + attributes: + tosca_name: Fabric + UPSPU_VduCpd_Fabric: + type: tosca.nodes.nfv.VduCpd + properties: + role: root + layer_protocol: ipv4 + attributes: + tosca_name: UPSPU_VduCpd_Fabric + requirements: + - virtual_binding: + capability: virtual_binding + node: UPSPU + - virtual_link: + capability: virtual_linkable + node: Fabric + substitution_mappings: + node_type: tosca.nodes.nfv.VNF.vPCRF diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/pom.xml b/openecomp-be/lib/openecomp-tosca-converter-lib/pom.xml new file mode 100644 index 0000000000..e789e09965 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + + org.openecomp.sdc + openecomp-sdc-lib + 1.1.0-SNAPSHOT + + + openecomp-tosca-converter-lib + 1.1.0-SNAPSHOT + pom + + + openecomp-tosca-converter-api + openecomp-tosca-converter-core + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java index 0fcaafa1c2..722c286f50 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java @@ -33,6 +33,7 @@ import java.util.Map; */ public class ToscaServiceModel implements AsdcModel { private FileContentHandler artifactFiles; + private FileContentHandler externalFiles; private Map serviceTemplates; private String entryDefinitionServiceTemplate; @@ -54,6 +55,15 @@ public class ToscaServiceModel implements AsdcModel { this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate; } + public ToscaServiceModel(FileContentHandler artifactFiles, + FileContentHandler externalFiles, + Map serviceTemplates, + String entryDefinitionServiceTemplate) { + this.artifactFiles = artifactFiles; + this.externalFiles = externalFiles; + this.serviceTemplates = serviceTemplates; + this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate; + } /** * Gets artifact files. @@ -113,4 +123,12 @@ public class ToscaServiceModel implements AsdcModel { public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) { return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel)); } + + public FileContentHandler getExternalFiles() { + return externalFiles; + } + + public void setExternalFiles(FileContentHandler externalFiles) { + this.externalFiles = externalFiles; + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java index dc2ed6c76b..45e6c3deef 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java @@ -492,7 +492,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { toscaServiceModel.getServiceTemplates().get(fetchFileNameForImport(importFile, serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"))); - if (filesScanned.contains(ToscaUtil.getServiceTemplateFileName(template))) { + if (Objects.isNull(template) || + filesScanned.contains(ToscaUtil.getServiceTemplateFileName(template))) { continue; } else { filesScanned.add(ToscaUtil.getServiceTemplateFileName(template)); diff --git a/openecomp-be/lib/pom.xml b/openecomp-be/lib/pom.xml index 5095578db4..df1b854a31 100644 --- a/openecomp-be/lib/pom.xml +++ b/openecomp-be/lib/pom.xml @@ -31,5 +31,7 @@ openecomp-logging-lib openecomp-healing-lib openecomp-sdc-activity-log-lib + openecomp-tosca-converter-lib + openecomp-sdc-orchestration-lib diff --git a/openecomp-be/pom.xml b/openecomp-be/pom.xml index 10b59fa23f..6147ea8fe4 100644 --- a/openecomp-be/pom.xml +++ b/openecomp-be/pom.xml @@ -192,7 +192,7 @@ groovy-all ${groovy.version} - + org.codehaus.janino janino ${janino.version} diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh index b92266fc84..42c347f4e8 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh +++ b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh @@ -1,16 +1,26 @@ #!/bin/bash +########################################################################################################### +# script name - zusammenMainTool.sh +# run script - ./zusammenMainTool.sh +# 1. Export all - ./zusammenMainTool.sh -c EXPORT +# 2. Export one item ./zusammenMainTool.sh -c EXPORT -i ${elementId} +# 3. Import one item - ./zusammenMainTool.sh -c IMPORT -f ${fileName} -i ${elementId} +# 4. Import all - ./zusammenMainTool.sh -c IMPORT -f ${fileName} +# 5. Reset old version - ./zusammenMainTool.sh -c RESET_OLD_VERSION +# +########################################################################################################## + OSTYPE=`uname -a | grep -iq ubuntu; echo $?` echo "${OSTYPE}" -if [ ${OSTYPE} -eq 1 ] +if [ ${OSTYPE} -eq 0 ] then CONF_FILE_LOCATION="/opt/app/jetty/base/be/config/catalog-be/configuration.yaml" else - CONF_FILE_LOCATION="/apps/jetty/base/be/config/catalog-be/configuration.yaml" + CONF_FILE_LOCATION="/apps/jetty/base/be/config/catalog-be/configuration.yaml" fi echo "Configuration file location: ${CONF_FILE_LOCATION}" -# change exist package and service templates in db java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=${CONF_FILE_LOCATION} -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6 -STATUS="${?}" echo "${STATUS}" \ No newline at end of file +STATUS="${?}" echo "${STATUS}" diff --git a/openecomp-ui/resources/scss/modules/_softwareProductLandingPage.scss b/openecomp-ui/resources/scss/modules/_softwareProductLandingPage.scss index 9b0375d24a..28b54cc78f 100644 --- a/openecomp-ui/resources/scss/modules/_softwareProductLandingPage.scss +++ b/openecomp-ui/resources/scss/modules/_softwareProductLandingPage.scss @@ -164,27 +164,29 @@ color: $light-blue; } } - .software-product-landing-view-top-block-col-upl { - @extend .flex; - text-align: center; - flex-direction: column; - justify-content: center; - border: 2px dashed $light-gray; - margin-bottom: 20px; - @extend .body-1; - align-items: center; - .upload-btn { - padding: 15px 55px; + } - } - .drag-text { - color: $blue; - @extend .body-1-semibold; - } - .or-text { - margin-top: 10px; - margin-bottom: 10px; - } + .software-product-landing-view-top-block-col-upl { + @extend .flex; + height: 215px; + text-align: center; + flex-direction: column; + justify-content: center; + border: 2px dashed $light-gray; + margin-bottom: 20px; + @extend .body-1; + align-items: center; + .upload-btn { + padding: 15px 55px; + + } + .drag-text { + color: $blue; + @extend .body-1-semibold; + } + .or-text { + margin-top: 10px; + margin-bottom: 10px; } } } diff --git a/openecomp-ui/src/sdc-app/onboarding/OnboardingActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/OnboardingActionHelper.js index 24ba05e303..fc65083bff 100644 --- a/openecomp-ui/src/sdc-app/onboarding/OnboardingActionHelper.js +++ b/openecomp-ui/src/sdc-app/onboarding/OnboardingActionHelper.js @@ -31,11 +31,13 @@ import OnboardActionHelper from './onboard/OnboardActionHelper.js'; import SoftwareProductComponentsMonitoringAction from './softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringActionHelper.js'; import {actionTypes, enums} from './OnboardingConstants.js'; import SoftwareProductComponentsImageActionHelper from './softwareProduct/components/images/SoftwareProductComponentsImageActionHelper.js'; -import {navigationItems as SoftwareProductNavigationItems, actionTypes as SoftwareProductActionTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; +import {navigationItems as SoftwareProductNavigationItems, actionTypes as SoftwareProductActionTypes, onboardingOriginTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; import ActivityLogActionHelper from 'sdc-app/common/activity-log/ActivityLogActionHelper.js'; import licenseModelOverviewActionHelper from 'sdc-app/onboarding/licenseModel/overview/licenseModelOverviewActionHelper.js'; import store from 'sdc-app/AppStore.js'; import {selectedButton as licenseModelOverviewSelectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js'; +import {tabsMapping as attachmentsTabsMapping} from 'sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsConstants.js'; +import SoftwareProductAttachmentsActionHelper from 'sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsActionHelper.js'; function setCurrentScreen(dispatch, screen, props = {}) { dispatch({ @@ -165,7 +167,9 @@ export default { SoftwareProductActionHelper.loadSoftwareProductDetailsData(dispatch, {licenseModelId, licensingVersion}); SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(dispatch, {softwareProductId, version: newVersion}); - SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(dispatch, {softwareProductId, version: newVersion}); + if(response[0].onboardingOrigin === onboardingOriginTypes.ZIP) { + SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(dispatch, {softwareProductId, version: newVersion}); + } setCurrentScreen(dispatch, enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, {softwareProductId, licenseModelId, version: newVersion}); }); }, @@ -175,11 +179,19 @@ export default { setCurrentScreen(dispatch, enums.SCREEN.SOFTWARE_PRODUCT_DETAILS, {softwareProductId, version}); }, - navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}) { + navigateToSoftwareProductAttachmentsSetupTab(dispatch, {softwareProductId, version}) { SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(dispatch, {softwareProductId, version}); + SoftwareProductAttachmentsActionHelper.setActiveTab(dispatch, {activeTab: attachmentsTabsMapping.SETUP}); setCurrentScreen(dispatch, enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS, {softwareProductId, version}); }, + navigateToSoftwareProductAttachmentsValidationTab(dispatch, {softwareProductId, version}) { + SoftwareProductActionHelper.processAndValidateHeatCandidate(dispatch, {softwareProductId, version}).then(() => { + SoftwareProductAttachmentsActionHelper.setActiveTab(dispatch, {activeTab: attachmentsTabsMapping.VALIDATION}); + setCurrentScreen(dispatch, enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS, {softwareProductId, version}); + }); + }, + navigateToSoftwareProductProcesses(dispatch, {softwareProductId, version}) { if (softwareProductId) { SoftwareProductProcessesActionHelper.fetchProcessesList(dispatch, {softwareProductId, version}); diff --git a/openecomp-ui/src/sdc-app/onboarding/OnboardingPunchOut.jsx b/openecomp-ui/src/sdc-app/onboarding/OnboardingPunchOut.jsx index aea5fc6406..c1f3251281 100644 --- a/openecomp-ui/src/sdc-app/onboarding/OnboardingPunchOut.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/OnboardingPunchOut.jsx @@ -28,7 +28,6 @@ import Onboard from './onboard/Onboard.js'; import LicenseModel from './licenseModel/LicenseModel.js'; import LicenseModelOverview from './licenseModel/overview/LicenseModelOverview.js'; import ActivityLog from 'sdc-app/common/activity-log/ActivityLog.js'; -import {doesHeatDataExist} from './softwareProduct/attachments/SoftwareProductAttachmentsUtils.js'; import LicenseAgreementListEditor from './licenseModel/licenseAgreement/LicenseAgreementListEditor.js'; import FeatureGroupListEditor from './licenseModel/featureGroups/FeatureGroupListEditor.js'; @@ -55,7 +54,8 @@ import SoftwareProductComponentsMonitoring from './softwareProduct/components/mo import { navigationItems as SoftwareProductNavigationItems, onboardingMethod as onboardingMethodTypes, - actionTypes as SoftwareProductActionTypes + actionTypes as SoftwareProductActionTypes, + onboardingOriginTypes } from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; import {statusEnum as VCItemStatus} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; @@ -314,7 +314,12 @@ export default class OnboardingPunchOut { OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, {softwareProductId, version: currentSoftwareProductVersion}); break; case enums.BREADCRUMS.SOFTWARE_PRODUCT_ATTACHMENTS: - OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version: currentSoftwareProductVersion}); + if(softwareProduct.onboardingOrigin === onboardingOriginTypes.ZIP) { + OnboardingActionHelper.navigateToSoftwareProductAttachmentsSetupTab(dispatch, {softwareProductId, version: currentSoftwareProductVersion}); + } + else if(softwareProduct.onboardingOrigin === onboardingOriginTypes.CSAR) { + OnboardingActionHelper.navigateToSoftwareProductAttachmentsValidationTab(dispatch, {softwareProductId, version: currentSoftwareProductVersion}); + } break; case enums.BREADCRUMS.SOFTWARE_PRODUCT_PROCESSES: OnboardingActionHelper.navigateToSoftwareProductProcesses(dispatch, {softwareProductId, version: currentSoftwareProductVersion}); @@ -415,9 +420,9 @@ export default class OnboardingPunchOut { handleStoreChange() { let {currentScreen, licenseModelList, softwareProductList, softwareProduct: {softwareProductEditor: {data = {onboardingMethod: ''}}, - softwareProductComponents: {componentsList}, softwareProductAttachments: {heatSetup}}} = store.getState(); - let {onboardingMethod} = data; - let breadcrumbsData = {onboardingMethod, currentScreen, licenseModelList, softwareProductList, componentsList, heatSetup}; + softwareProductComponents: {componentsList}}} = store.getState(); + let {onboardingMethod, onboardingOrigin} = data; + let breadcrumbsData = {onboardingMethod, currentScreen, licenseModelList, softwareProductList, componentsList, onboardingOrigin}; if (currentScreen.forceBreadCrumbsUpdate || !isEqual(breadcrumbsData, this.prevBreadcrumbsData) || this.breadcrumbsPrefixSelected) { this.prevBreadcrumbsData = breadcrumbsData; this.breadcrumbsPrefixSelected = false; @@ -434,7 +439,7 @@ export default class OnboardingPunchOut { } } - buildBreadcrumbs({currentScreen: {screen, props}, onboardingMethod, licenseModelList, softwareProductList, componentsList, heatSetup}) { + buildBreadcrumbs({currentScreen: {screen, props}, onboardingMethod, licenseModelList, softwareProductList, componentsList, onboardingOrigin}) { let screenToBreadcrumb; switch (screen) { case enums.SCREEN.ONBOARDING_CATALOG: @@ -593,7 +598,7 @@ export default class OnboardingPunchOut { key: enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENTS, displayText: i18n('Components') }].filter(item => { - let isHeatData = doesHeatDataExist(heatSetup); + let isHeatData = onboardingOrigin !== onboardingOriginTypes.NONE; let isManualMode = onboardingMethod === onboardingMethodTypes.MANUAL; switch (item.key) { case enums.BREADCRUMS.SOFTWARE_PRODUCT_ATTACHMENTS: diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProduct.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProduct.js index c9c95f359e..6426847cfc 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProduct.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProduct.js @@ -22,11 +22,10 @@ import TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx'; import {enums} from 'sdc-app/onboarding/OnboardingConstants.js'; import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js'; -import {navigationItems, mapScreenToNavigationItem, onboardingMethod as onboardingMethodTypes} from './SoftwareProductConstants.js'; +import {navigationItems, mapScreenToNavigationItem, onboardingMethod as onboardingMethodTypes, onboardingOriginTypes} from './SoftwareProductConstants.js'; import SoftwareProductActionHelper from './SoftwareProductActionHelper.js'; import SoftwareProductComponentsActionHelper from './components/SoftwareProductComponentsActionHelper.js'; import SoftwareProductDependenciesActionHelper from './dependencies/SoftwareProductDependenciesActionHelper.js'; -import {doesHeatDataExist} from './attachments/SoftwareProductAttachmentsUtils.js'; import HeatSetupActionHelper from './attachments/setup/HeatSetupActionHelper.js'; import { actionsEnum as versionControllerActions } from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; @@ -86,7 +85,7 @@ const buildComponentNavigationBarGroups = ({componentId, meta}) => { const buildNavigationBarProps = ({softwareProduct, meta, screen, componentId, componentsList, mapOfExpandedIds}) => { const {softwareProductEditor: {data: currentSoftwareProduct = {}}} = softwareProduct; - const {id, name, onboardingMethod} = currentSoftwareProduct; + const {id, name, onboardingMethod, onboardingOrigin} = currentSoftwareProduct; const groups = [{ id: id, name: name, @@ -122,7 +121,7 @@ const buildNavigationBarProps = ({softwareProduct, meta, screen, componentId, co id: navigationItems.ATTACHMENTS, name: i18n('Attachments'), disabled: false, - hidden: !doesHeatDataExist(meta.heatSetup), + hidden: onboardingOrigin === onboardingOriginTypes.NONE, meta }, { id: navigationItems.ACTIVITY_LOG, @@ -175,7 +174,7 @@ const buildVersionControllerProps = (softwareProduct) => { function buildMeta({softwareProduct, componentId, softwareProductDependencies}) { const {softwareProductEditor, softwareProductComponents, softwareProductQuestionnaire, softwareProductAttachments} = softwareProduct; const {data: currentSoftwareProduct = {}} = softwareProductEditor; - const {version} = currentSoftwareProduct; + const {version, onboardingOrigin} = currentSoftwareProduct; const isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct); const {qdata} = softwareProductQuestionnaire; const {heatSetup, heatSetupCache} = softwareProductAttachments; @@ -184,7 +183,7 @@ function buildMeta({softwareProduct, componentId, softwareProductDependencies}) const {componentEditor: {data: componentData = {} , qdata: componentQdata}} = softwareProductComponents; currentComponentMeta = {componentData, componentQdata}; } - const meta = {softwareProduct: currentSoftwareProduct, qdata, version, heatSetup, heatSetupCache, isReadOnlyMode, currentComponentMeta, softwareProductDependencies}; + const meta = {softwareProduct: currentSoftwareProduct, qdata, version, onboardingOrigin, heatSetup, heatSetupCache, isReadOnlyMode, currentComponentMeta, softwareProductDependencies}; return meta; } @@ -280,7 +279,7 @@ const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {softwarePr }, onToggle: (groups, itemIdToExpand) => groups.map(({items}) => SoftwareProductActionHelper.toggleNavigationItems(dispatch, {items, itemIdToExpand})), onNavigate: ({id, meta, version}) => { - let {heatSetup, heatSetupCache} = meta; + let {onboardingOrigin, heatSetup, heatSetupCache} = meta; let heatSetupPopupPromise = screen === enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS ? HeatSetupActionHelper.heatSetupLeaveConfirmation(dispatch, {softwareProductId, heatSetup, heatSetupCache}) : Promise.resolve(); @@ -307,7 +306,12 @@ const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {softwarePr OnboardingActionHelper.navigateToSoftwareProductDependencies(dispatch, {softwareProductId, version}); break; case navigationItems.ATTACHMENTS: - OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}); + if(onboardingOrigin === onboardingOriginTypes.ZIP) { + OnboardingActionHelper.navigateToSoftwareProductAttachmentsSetupTab(dispatch, {softwareProductId, version}); + } + else if(onboardingOrigin === onboardingOriginTypes.CSAR) { + OnboardingActionHelper.navigateToSoftwareProductAttachmentsValidationTab(dispatch, {softwareProductId, version}); + } break; case navigationItems.COMPONENTS: OnboardingActionHelper.navigateToSoftwareProductComponents(dispatch, {softwareProductId, version}); @@ -334,9 +338,7 @@ const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {softwarePr case enums.SCREEN.SOFTWARE_PRODUCT_DEPLOYMENT: case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_PROCESSES: case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_MONITORING: - props.onSave = () => { - return Promise.resolve(); - }; + props.onSave = () => Promise.resolve(); break; default: props.onSave = ({softwareProduct, qdata}) => SoftwareProductActionHelper.updateSoftwareProduct(dispatch, {softwareProduct, qdata}); diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js index d4bee0a876..41306a1c1a 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js @@ -20,7 +20,7 @@ import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseMod import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js'; import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js'; -import {actionTypes} from './SoftwareProductConstants.js'; +import {actionTypes, onboardingOriginTypes, PRODUCT_QUESTIONNAIRE, forms} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js'; import SoftwareProductComponentsActionHelper from './components/SoftwareProductComponentsActionHelper.js'; import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; @@ -29,10 +29,10 @@ import {actionTypes as featureGroupsActionConstants} from 'sdc-app/onboarding/li import {actionTypes as licenseAgreementActionTypes} from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementConstants.js'; import {actionTypes as componentActionTypes} from './components/SoftwareProductComponentsConstants.js'; import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; -import {PRODUCT_QUESTIONNAIRE} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js'; import {statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; +import {actionTypes as commonActionTypes} from 'sdc-app/common/reducers/PlainDataReducerConstants.js'; function baseUrl() { const restPrefix = Configuration.get('restPrefix'); @@ -59,7 +59,9 @@ function putSoftwareProduct(softwareProduct) { licensingVersion: softwareProduct.licensingVersion && softwareProduct.licensingVersion.id ? softwareProduct.licensingVersion : {} , icon: softwareProduct.icon, licensingData: softwareProduct.licensingData, - onboardingMethod: softwareProduct.onboardingMethod + onboardingMethod: softwareProduct.onboardingMethod, + networkPackageName: softwareProduct.networkPackageName, + onboardingOrigin: softwareProduct.onboardingOrigin }); } @@ -267,7 +269,19 @@ const SoftwareProductActionHelper = { .then(() => uploadFile(softwareProductId, formData, version)) .then(response => { if (response.status === 'Success') { - OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}); + dispatch({ + type: commonActionTypes.DATA_CHANGED, + deltaData: {onboardingOrigin: response.onboardingOrigin}, + formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS + }); + switch(response.onboardingOrigin){ + case onboardingOriginTypes.ZIP: + OnboardingActionHelper.navigateToSoftwareProductAttachmentsSetupTab(dispatch, {softwareProductId, version}); + break; + case onboardingOriginTypes.CSAR: + OnboardingActionHelper.navigateToSoftwareProductAttachmentsValidationTab(dispatch, {softwareProductId, version}); + break; + } } else { throw new Error(parseUploadErrorMsg(response.errors)); diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js index 0379ee5d4a..2c094ac36a 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js @@ -39,7 +39,7 @@ export const navigationItems = keyMirror({ GENERAL: 'general', PROCESS_DETAILS: 'process-details', DEPLOYMENT_FLAVORS: 'deployment-flavor', - NETWORKS: 'networks', + NETWORKS: 'networks', IMAGES: 'images', ATTACHMENTS: 'attachments', ACTIVITY_LOG: 'activity-log', @@ -54,7 +54,13 @@ export const navigationItems = keyMirror({ export const onboardingMethod = { MANUAL: 'Manual', - HEAT: 'HEAT' + NETWORK_PACKAGE: 'NetworkPackage' +}; + +export const onboardingOriginTypes = { + NONE: 'none', + ZIP: 'zip', + CSAR: 'csar' }; export const forms = keyMirror({ diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductReducer.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductReducer.js index 977a76ac69..d7a6c2ef5c 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductReducer.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductReducer.js @@ -15,6 +15,7 @@ */ import {combineReducers} from 'redux'; import {actionTypes, PRODUCT_QUESTIONNAIRE} from './SoftwareProductConstants.js'; +import SoftwareProductAttachmentsReducer from './attachments/SoftwareProductAttachmentsReducer.js'; import HeatValidationReducer from './attachments/validation/HeatValidationReducer.js'; import HeatSetupReducer from './attachments/setup/HeatSetupReducer.js'; import {actionTypes as heatSetupActionTypes} from './attachments/setup/HeatSetupConstants.js'; @@ -48,6 +49,7 @@ import {IMAGE_QUESTIONNAIRE} from 'sdc-app/onboarding/softwareProduct/components export default combineReducers({ softwareProductAttachments: combineReducers({ + attachmentsDetails: SoftwareProductAttachmentsReducer, heatValidation: HeatValidationReducer, heatSetup: HeatSetupReducer, heatSetupCache: (state = {}, action) => action.type === heatSetupActionTypes.FILL_HEAT_SETUP_CACHE ? action.payload : state diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachments.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachments.js index 945de4fc36..f14c988866 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachments.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachments.js @@ -23,6 +23,7 @@ import {errorLevels} from 'sdc-app/onboarding/softwareProduct/attachments/valida import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js'; import HeatSetup from './setup/HeatSetup.js'; import {doesHeatDataExist} from './SoftwareProductAttachmentsUtils.js'; +import SoftwareProductAttachmentsActionHelper from './SoftwareProductAttachmentsActionHelper.js'; import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js'; @@ -30,7 +31,7 @@ export const mapStateToProps = (state) => { let { softwareProduct: { softwareProductEditor:{data: currentSoftwareProduct = {}}, - softwareProductAttachments: {heatSetup, heatSetupCache, heatValidation : {errorList}} + softwareProductAttachments: {attachmentsDetails: {activeTab}, heatSetup, heatSetupCache, heatValidation : {errorList}} } } = state; @@ -47,7 +48,7 @@ export const mapStateToProps = (state) => { let isReadOnlyMode = currentSoftwareProduct && currentSoftwareProduct.version ? VersionControllerUtils.isReadOnly(currentSoftwareProduct) : false; - let {version} = currentSoftwareProduct; + let {version, onboardingOrigin} = currentSoftwareProduct; return { isValidationAvailable: unassigned.length === 0 && modules.length > 0, heatSetup, @@ -56,7 +57,9 @@ export const mapStateToProps = (state) => { goToOverview, HeatSetupComponent: HeatSetup, isReadOnlyMode, - version + version, + onboardingOrigin, + activeTab }; }; @@ -83,7 +86,8 @@ export const mapActionsToProps = (dispatch, {softwareProductId}) => { onProcessAndValidate: ({heatData, heatDataCache, isReadOnlyMode, version}) => { return HeatSetupActionHelper.processAndValidateHeat(dispatch, {softwareProductId, heatData, heatDataCache, isReadOnlyMode, version}); - } + }, + setActiveTab: ({activeTab}) => SoftwareProductAttachmentsActionHelper.setActiveTab(dispatch, {activeTab}) }; }; diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsActionHelper.js new file mode 100644 index 0000000000..ae4a615a40 --- /dev/null +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsActionHelper.js @@ -0,0 +1,26 @@ +/*! + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * 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. + */ + +import {actionTypes} from './SoftwareProductAttachmentsConstants'; + +export default { + setActiveTab(dispatch, {activeTab}) { + dispatch({ + type: actionTypes.SET_ACTIVE_TAB, + activeTab + }); + } +}; diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsConstants.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsConstants.js index b0410d1566..67265909d7 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsConstants.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsConstants.js @@ -13,7 +13,13 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ +import keyMirror from 'nfvo-utils/KeyMirror.js'; + export const tabsMapping = { SETUP: 1, VALIDATION: 2 }; + +export const actionTypes = keyMirror({ + SET_ACTIVE_TAB: null +}); diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsReducer.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsReducer.js new file mode 100644 index 0000000000..5f6538ab7e --- /dev/null +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsReducer.js @@ -0,0 +1,25 @@ +/*! + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * 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. + */ +import {actionTypes} from './SoftwareProductAttachmentsConstants.js'; + +export default (state = [], action) => { + switch (action.type) { + case actionTypes.SET_ACTIVE_TAB: + return {activeTab: action.activeTab}; + default: + return state; + } +}; diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsView.jsx b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsView.jsx index 3da26cc20f..8c59b2b1cc 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsView.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/SoftwareProductAttachmentsView.jsx @@ -20,34 +20,34 @@ import {tabsMapping} from './SoftwareProductAttachmentsConstants.js'; import i18n from 'nfvo-utils/i18n/i18n.js'; import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; import HeatValidation from './validation/HeatValidation.js'; +import {onboardingOriginTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; class HeatScreenView extends Component { static propTypes = { isValidationAvailable: PropTypes.bool, - goToOverview: PropTypes.bool - }; - - state = { - activeTab: tabsMapping.SETUP + goToOverview: PropTypes.bool, + setActiveTab: PropTypes.function }; render() { - let {isValidationAvailable, isReadOnlyMode, heatDataExist, onDownload, softwareProductId, onProcessAndValidate, heatSetup, HeatSetupComponent, onGoToOverview, version, ...other} = this.props; + let {isValidationAvailable, isReadOnlyMode, heatDataExist, onDownload, softwareProductId, onProcessAndValidate, + heatSetup, HeatSetupComponent, onGoToOverview, version, onboardingOrigin, activeTab, setActiveTab, ...other} = this.props; + return (
- {(this.state.activeTab === tabsMapping.SETUP) && + {(activeTab === tabsMapping.SETUP) && onDownload({heatCandidate: heatSetup, isReadOnlyMode, version}) : undefined} data-test-id='download-heat'/>} - {(this.state.activeTab === tabsMapping.VALIDATION && softwareProductId) && + {(activeTab === tabsMapping.VALIDATION && softwareProductId) && onGoToOverview({version}) : undefined} @@ -60,7 +60,7 @@ class HeatScreenView extends Component { this.handleImport(evt)}/>
- this.handleTabPress(key)}> - + this.handleTabPress(key)}> + this.setState({activeTab: tab})} + changeAttachmentsTab={tab => setActiveTab({activeTab: tab})} onProcessAndValidate={onProcessAndValidate} softwareProductId={softwareProductId} isReadOnlyMode={isReadOnlyMode} version={version}/> - + @@ -92,15 +92,15 @@ class HeatScreenView extends Component { } handleTabPress(key) { - let {heatSetup, heatSetupCache, onProcessAndValidate, isReadOnlyMode, version} = this.props; + let {heatSetup, heatSetupCache, onProcessAndValidate, isReadOnlyMode, version, setActiveTab} = this.props; switch (key) { case tabsMapping.VALIDATION: onProcessAndValidate({heatData: heatSetup, heatDataCache: heatSetupCache, isReadOnlyMode, version}).then( - () => this.setState({activeTab: tabsMapping.VALIDATION}) + () => setActiveTab({activeTab: tabsMapping.VALIDATION}) ); return; case tabsMapping.SETUP: - this.setState({activeTab: tabsMapping.SETUP}); + setActiveTab({activeTab: tabsMapping.SETUP}); return; } } @@ -112,11 +112,13 @@ class HeatScreenView extends Component { formData.append('upload', this.refs.hiddenImportFileInput.files[0]); this.refs.hiddenImportFileInput.value = ''; this.props.onUpload(formData, version); - this.setState({activeTab: tabsMapping.SETUP}); } save() { - return this.props.onSave(this.props.heatSetup, this.props.version); + + return this.props.onboardingOrigin === onboardingOriginTypes.ZIP ? + this.props.onSave(this.props.heatSetup, this.props.version) : + Promise.resolve(); } } diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationReducer.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationReducer.js index f0c10ed457..1d11bdd6b7 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationReducer.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationReducer.js @@ -89,16 +89,16 @@ function createErrorList(node, parent, deep = 0, errorList = []) { return errorList; } -const mapValidationDataToTree = validationData => { - let {heat, volume, network, artifacts, other} = validationData.importStructure || {}; +const mapValidationDataToTree = (validationData, packageName) => { + let {heat, nested, volume, network, artifacts, other} = validationData.importStructure || {}; return { children: [ { - name: 'HEAT', + name: packageName, expanded: true, type: 'heat', header: true, - children: (heat ? heat.map(mapHeatData) : []) + children: (heat ? heat.map(mapHeatData) : nested ? nested.map(mapHeatData) : []) }, ...(artifacts ? [{ name: 'artifacts', @@ -165,7 +165,8 @@ export default (state = {attachmentsTree: {}}, action) => { switch (action.type) { case softwareProductsActionTypes.SOFTWARE_PRODUCT_LOADED: let currentSoftwareProduct = action.response; - let attachmentsTree = currentSoftwareProduct.validationData ? mapValidationDataToTree(currentSoftwareProduct.validationData) : {}; + const packageName = currentSoftwareProduct.networkPackageName; + let attachmentsTree = currentSoftwareProduct.validationData ? mapValidationDataToTree(currentSoftwareProduct.validationData, packageName) : {}; let errorList = createErrorList(attachmentsTree); return { ...state, diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationView.jsx b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationView.jsx index 2a2f4ac291..80d74b2964 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationView.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationView.jsx @@ -93,9 +93,9 @@ function HeatFileTreeHeader(props) {
props.selectNode(nodeFilters.ALL)} className={classNames({'attachments-tree-header': true, 'header-selected' : props.selectedNode === nodeFilters.ALL})} data-test-id='validation-tree-header'>
- + {/**/} {i18n(`HEAT${hasErrors ? ' (Draft)' : ''}`)} + 'tree-header-title-selected' : props.selectedNode === nodeFilters.ALL})}>{i18n(`${props.headerTitle} ${hasErrors ? '(Draft)' : ''}`)}
); @@ -134,7 +134,7 @@ class HeatFileTree extends React.Component {
{ node.header ? - this.selectNode(nodeName)} /> : + this.selectNode(nodeName)} /> : this.selectNode(node.name)} /> } { diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx index 11f3543e39..c7ab3e644c 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx @@ -186,12 +186,12 @@ const OnboardingProcedure = ({onboardingMethod, onDataChanged, genericFieldInfo} onDataChanged({onboardingMethod:'HEAT'},SP_CREATION_FORM_NAME)} + onChange={() => onDataChanged({onboardingMethod: onboardingMethodConst.NETWORK_PACKAGE},SP_CREATION_FORM_NAME)} type='radio' data-test-id='new-vsp-creation-procedure-heat' /> @@ -202,7 +202,7 @@ const OnboardingProcedure = ({onboardingMethod, onDataChanged, genericFieldInfo} checked={onboardingMethod === onboardingMethodConst.MANUAL} isValid={genericFieldInfo.onboardingMethod.isValid} errorText={genericFieldInfo.onboardingMethod.errorText} - onChange={() => onDataChanged({onboardingMethod:'Manual'},SP_CREATION_FORM_NAME)} + onChange={() => onDataChanged({onboardingMethod: onboardingMethodConst.MANUAL},SP_CREATION_FORM_NAME)} type='radio' data-test-id='new-vsp-creation-procedure-manual' /> diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js index 8806ffd0bf..a13e742006 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js @@ -53,7 +53,7 @@ export const mapStateToProps = ({softwareProduct, licenseModel: {licenseAgreemen fullCategoryDisplayName }, isReadOnlyMode, - componentsList, + componentsList, isManual: currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL }; }; @@ -65,7 +65,6 @@ const mapActionsToProps = (dispatch, {version}) => { licenseModelId, version }), - onAttachmentsSelect: ({id: softwareProductId}) => OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}), onUpload: (softwareProductId, formData) => SoftwareProductActionHelper.uploadFile(dispatch, { softwareProductId, @@ -98,7 +97,7 @@ const mapActionsToProps = (dispatch, {version}) => { data: { title: i18n('Upload Failed'), confirmationButtonText: i18n('Continue'), - msg: i18n('no zip file was uploaded or zip file doesn\'t exist') + msg: i18n('no zip or csar file was uploaded or expected file doesn\'t exist') } }), onComponentSelect: ({id: softwareProductId, componentId}) => { diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx index 7ffbeda4dc..72a416473c 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx @@ -57,7 +57,6 @@ class SoftwareProductLandingPageView extends React.Component { isReadOnlyMode: React.PropTypes.bool, componentsList: React.PropTypes.arrayOf(ComponentPropType), onDetailsSelect: React.PropTypes.func, - onAttachmentsSelect: React.PropTypes.func, onUpload: React.PropTypes.func, onUploadConfirmation: React.PropTypes.func, onInvalidFileSizeUpload: React.PropTypes.func, @@ -78,15 +77,13 @@ class SoftwareProductLandingPageView extends React.Component { disableClick={true} ref='fileInput' name='fileInput' - accept='.zip' + accept='.zip, .csar' disabled>
- {isManual ? -
- : this.renderProductDetails(currentSoftwareProduct, isReadOnlyMode)} + {this.renderProductDetails(isManual, isReadOnlyMode)}
@@ -106,34 +103,18 @@ class SoftwareProductLandingPageView extends React.Component { } } - renderProductDetails(currentSoftwareProduct, isReadOnlyMode) { - let {validationData} = currentSoftwareProduct; - let {onAttachmentsSelect} = this.props; - let details = { - heatTemplates: validationData ? '1' : '0', - images: '0', - otherArtifacts: '0' - }; - + renderProductDetails(isManual, isReadOnlyMode) { return (
-
{i18n('Software Product Attachments')}
-
-
onAttachmentsSelect(currentSoftwareProduct)}> -
-
{i18n('HEAT Templates')} ({details.heatTemplates}) -
-
+ { !isManual &&
+
{i18n('Software Product Attachments')}
+ this.refs.fileInput.open()}/>
- this.refs.fileInput.open()}/> -
+ }
); } diff --git a/openecomp-ui/test/softwareProduct/attachments/SoftwareProductAttachmentsView.test.js b/openecomp-ui/test/softwareProduct/attachments/SoftwareProductAttachmentsView.test.js index 5dfe98f273..355a3162b1 100644 --- a/openecomp-ui/test/softwareProduct/attachments/SoftwareProductAttachmentsView.test.js +++ b/openecomp-ui/test/softwareProduct/attachments/SoftwareProductAttachmentsView.test.js @@ -36,13 +36,13 @@ describe('SoftwareProduct Attachments - View: ', function () { let versionControllerData = VersionControllerUtilsFactory.build(); let softwareProductAttachments = { + attachmentsDetails: {activeTab: tabsMapping.SETUP}, heatSetup: {}, heatValidation: { attachmentsTree, errorList }, - heatSetupCache: {}, - activeTab: tabsMapping.SETUP + heatSetupCache: {} }; let data = defaultStoreFactory.build({softwareProduct: {softwareProductAttachments, softwareProductEditor: {data: {...versionControllerData}}}}); var result = mapStateToProps(data); @@ -57,6 +57,7 @@ describe('SoftwareProduct Attachments - View: ', function () { let versionControllerData = VersionControllerUtilsFactory.build(); let softwareProductAttachments = { + attachmentsDetails: {}, heatSetup: {}, heatValidation: { attachmentsTree, -- 2.16.6