From 11e9d33f2f50ad3990905fba184b7c10d255070a Mon Sep 17 00:00:00 2001 From: kooper Date: Mon, 4 Mar 2019 13:47:51 +0000 Subject: Add manifest non mano set support Issue-ID: SDC-2141 Change-Id: I056e8f7c1da8f17ce8583207660882f85a4d11a4 Signed-off-by: kooper --- .../impl/VendorSoftwareProductManagerImpl.java | 15 +- .../OrchestrationTemplateCSARHandler.java | 11 +- .../impl/orchestration/csar/CSARConstants.java | 41 ----- .../orchestration/csar/OnboardingManifest.java | 171 --------------------- .../csar/OnboardingToscaMetadata.java | 4 +- 5 files changed, 23 insertions(+), 219 deletions(-) delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp') 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 275aee646b..19d06ed493 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 @@ -19,6 +19,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder; import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate; import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; @@ -106,8 +107,12 @@ import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageInvalidErrorBuilder import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder; +import org.openecomp.sdc.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.OnboardingManifest; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult; @@ -655,7 +660,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } @Override - public PackageInfo createPackage(String vspId, Version version) { + public PackageInfo createPackage(String vspId, Version version) throws IOException { ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version); VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version)); Version vlmVersion = vspDetails.getVlmVersion(); @@ -669,7 +674,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa FileContentHandler licenseArtifacts = licenseArtifactsService .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups()); - //todo add tosca validation here + ETSIService etsiService = new ETSIServiceImpl(); + if(etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())){ + FileContentHandler handler = toscaServiceModel.getArtifactFiles(); + Manifest onboardingManifest = OnboardingManifest.parse(handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)); + etsiService.moveNonManoFileToArtifactFolder(handler, onboardingManifest); + + } packageInfo.setTranslatedFile(ByteBuffer.wrap( toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts))); 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 index 4047937059..bfe602b3ad 100644 --- 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 @@ -31,7 +31,8 @@ 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.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.OnboardingManifest; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingToscaMetadata; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; @@ -45,7 +46,11 @@ import java.util.Optional; import java.util.stream.Collectors; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; +import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGBLE_FOLDERS; +import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGIBLE_FILES; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { @@ -114,7 +119,7 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH try (InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { - OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); + Manifest onboardingManifest = OnboardingManifest.parse(fileContent); if (!onboardingManifest.isValid()) { onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); 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 deleted file mode 100644 index ee81527a18..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2016-2017 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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 String TOSCA_META_PATH_FILE_NAME="TOSCA-Metadata/TOSCA.meta"; - public static final String TOSCA_META_ENTRY_DEFINITIONS="Entry-Definitions"; - 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 = ":"; - - private CSARConstants() { - - } -} 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 deleted file mode 100644 index fd3d3c43f2..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright © 2016-2017 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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, PROCESS_METADATA, PROCESS_SOURCES, 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) { - State newState = state; - switch (state) { - case START: - newState = startProcessLine(state, line); - break; - case PROCESS_METADATA: - newState = processMetaData(state, line); - break; - case PROCESS_SOURCES: - processSourceLine(line); - - break; - case ERROR: - break; - default: - } - return newState; - } - - private State startProcessLine(State state, String line) { - State newState = state; - if (line.trim().equals(METADATA_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE)) { - newState = State.PROCESS_METADATA; - } else { - reportError(line); - } - return newState; - } - - private State processMetaData(State state, String line) { - State newState = state; - String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE); - if (metaSplit.length < 2){ - reportError(line); - return state; - } - if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){ - String value = line.replace(metaSplit[0] + SEPERATOR_MF_ATTRIBUTE, "").trim(); - metadata.put(metaSplit[0],value); - } else { - newState = State.PROCESS_SOURCES; - processSourceLine(line); - } - return newState; - } - - 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.emptyMap(); - } - return ImmutableMap.copyOf(metadata); - } - - public List getSources() { - if (!isValid()){ - return Collections.emptyList(); - } - 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/csar/OnboardingToscaMetadata.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java index 037e76aa16..6f06289d96 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java @@ -27,8 +27,8 @@ import java.io.IOException; import org.apache.commons.io.IOUtils; import java.util.List; -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE; public class OnboardingToscaMetadata { -- cgit 1.2.3-korg