aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java4
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java26
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java51
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java22
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java14
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java18
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java52
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java33
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java1
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java18
12 files changed, 171 insertions, 92 deletions
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 99de164fb3..5e5f82862e 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
@@ -59,6 +59,7 @@ public enum Messages {
MANIFEST_EMPTY("The manifest is empty"),
MANIFEST_ERROR_WITH_LINE("%s;%nAt line %s: '%s'."),
MANIFEST_PARSER_INTERNAL("Invalid manifest file"),
+ MANIFEST_UNEXPECTED_ERROR("An unexpected error occurred while validating manifest '%s': %s"),
METADATA_PARSER_INTERNAL("Invalid Metadata file"),
METADATA_MISSING_OPTIONAL_FOLDERS("Missing folder %s in package"),
METADATA_UNSUPPORTED_ENTRY("Following entry not supported in TOSCA.meta %s"),
@@ -68,6 +69,9 @@ public enum Messages {
METADATA_NO_ENTRY_DEFINITIONS("TOSCA.meta must contain Entry Definitions"),
METADATA_INVALID_ENTRY_DEFINITIONS("TOSCA.meta must contain key:value entries"),
FAILED_TO_VALIDATE_METADATA("Failed to validate metadata file"),
+ ARTIFACT_INVALID_SIGNATURE("Invalid signature '%s' provided for artifact '%s'"),
+ ARTIFACT_SIGNATURE_VALIDATION_ERROR(
+ "Could not validate signature '%s' provided for artifact '%s' with certificate '%s': %s"),
FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"),
ZIP_NOT_EXIST("Zip file doesn't exist"),
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
index cc13879b96..db5be60149 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
@@ -33,6 +33,13 @@ public class FileContentHandler {
private Map<String, byte[]> files = new HashMap<>();
+ public FileContentHandler() {
+ }
+
+ public FileContentHandler(final FileContentHandler other) {
+ addAll(other);
+ }
+
/**
* Gets file content as stream.
*
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/etsi/ETSIServiceImpl.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/etsi/ETSIServiceImpl.java
index ca60577b29..d6b1194b81 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/etsi/ETSIServiceImpl.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/etsi/ETSIServiceImpl.java
@@ -23,11 +23,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
import static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import java.io.IOException;
import java.io.InputStream;
@@ -203,18 +203,18 @@ public class ETSIServiceImpl implements ETSIService {
private boolean hasMetaMandatoryEntries(final ToscaMetadata toscaMetadata) {
final Map<String, String> metaDataEntries = toscaMetadata.getMetaEntries();
- return metaDataEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS) && metaDataEntries
- .containsKey(TOSCA_META_ETSI_ENTRY_MANIFEST)
- && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_CHANGE_LOG);
+ return metaDataEntries.containsKey(ENTRY_DEFINITIONS.getName()) && metaDataEntries
+ .containsKey(ETSI_ENTRY_MANIFEST.getName())
+ && metaDataEntries.containsKey(ETSI_ENTRY_CHANGE_LOG.getName());
}
private boolean isMetaFilePresent(Map<String, byte[]> handler) {
- return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME);
+ return handler.containsKey(TOSCA_META_PATH_FILE_NAME.getName()) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME);
}
public ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST));
+ Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
return getResourceType(manifest);
}
@@ -231,7 +231,7 @@ public class ETSIServiceImpl implements ETSIService {
public Manifest getManifest(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- return getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST));
+ return getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
}
private Manifest getManifest(FileContentHandler handler, String manifestLocation) throws IOException {
@@ -244,16 +244,16 @@ public class ETSIServiceImpl implements ETSIService {
public Path getOriginalManifestPath(final FileContentHandler handler) throws IOException {
final ToscaMetadata metadata = getOriginalMetadata(handler);
- final String originalMetadataPath = metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST);
+ final String originalMetadataPath = metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName());
final Path path = Paths.get(originalMetadataPath);
return path.getParent() == null ? Paths.get("") : path.getParent();
}
private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException {
ToscaMetadata metadata;
- if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) {
+ if (handler.containsFile(TOSCA_META_PATH_FILE_NAME.getName())) {
metadata = OnboardingToscaMetadata
- .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
+ .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName()));
} else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
metadata = OnboardingToscaMetadata
.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
index 0b0c6e42f9..fa1de6751c 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
@@ -22,6 +22,27 @@
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
+import static org.openecomp.core.converter.datatypes.Constants.mainStName;
+import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+
+import java.io.File;
+import java.util.ArrayList;
+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 java.util.regex.Pattern;
import org.apache.commons.collections.MapUtils;
import org.onap.sdc.tosca.datatypes.model.Import;
import org.onap.sdc.tosca.datatypes.model.NodeType;
@@ -41,39 +62,13 @@ 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.File;
-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.Objects;
-import java.util.Optional;
-import java.util.regex.Pattern;
-
-import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
-import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
-import static org.openecomp.core.converter.datatypes.Constants.mainStName;
-import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
-
public abstract class AbstractToscaConverter implements ToscaConverter {
- @Override
- public abstract ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException;
-
public abstract void convertTopologyTemplate(ServiceTemplate serviceTemplate,
ServiceTemplateReaderService readerService);
protected void handleMetadataFile(Map<String, byte[]> csarFiles) {
- byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME);
+ byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME.getName());
if (bytes != null) {
csarFiles.put(TOSCA_META_ORIG_PATH_FILE_NAME, bytes);
}
@@ -251,7 +246,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
}
protected boolean isMetadataFile(String fileName) {
- return fileName.equals(TOSCA_META_PATH_FILE_NAME);
+ return fileName.equals(TOSCA_META_PATH_FILE_NAME.getName());
}
protected boolean isGlobalServiceTemplate(String fileName) {
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
index ce7024015b..4be9379c1e 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
@@ -22,6 +22,15 @@
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.logging.api.Logger;
@@ -30,15 +39,6 @@ import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
@@ -96,8 +96,8 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException {
try {
ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(
- contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
- return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
+ contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName()));
+ return toscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName());
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new IOException(e.getMessage());
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
index 1de91f9549..783636b3d9 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
@@ -34,22 +34,10 @@ public class CSARConstants {
public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/",
"Licenses/", "TOSCA-Metadata/");
public static final String ARTIFACTS_FOLDER = "Artifacts";
-
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_FILE_VERSION_ENTRY = "TOSCA-Meta-File-Version";
- public static final String TOSCA_META_CSAR_VERSION_ENTRY = "CSAR-Version";
- public static final String TOSCA_META_CREATED_BY_ENTRY = "Created-By";
- public static final String TOSCA_META_ENTRY_DEFINITIONS ="Entry-Definitions";
- public static final String TOSCA_META_ETSI_ENTRY_MANIFEST = "ETSI-Entry-Manifest";
- public static final String TOSCA_META_ETSI_ENTRY_CHANGE_LOG = "ETSI-Entry-Change-Log";
- public static final String TOSCA_META_ETSI_ENTRY_TESTS = "ETSI-Entry-Tests";
- public static final String TOSCA_META_ETSI_ENTRY_LICENSES = "ETSI-Entry-Licenses";
- public static final String TOSCA_META_ETSI_ENTRY_CERTIFICATE = "ETSI-Entry-Certificate";
public static final ImmutableSet<String> ELIGIBLE_FILES =
of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
-
public static final ImmutableSet<String> MANIFEST_PNF_METADATA =
of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(),
PNFD_ARCHIVE_VERSION.getToken());
@@ -58,8 +46,6 @@ public class CSARConstants {
VNF_PACKAGE_VERSION.getToken());
public static final int MANIFEST_METADATA_LIMIT = 4;
public static final String TOSCA_META_ORIG_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta.original";
-
- public static final String TOSCA_META_FILE_VERSION = "1.0";
public static final String CSAR_VERSION_1_0 = "1.0";
public static final String CSAR_VERSION_1_1 = "1.1";
public static final ImmutableSet<String> NON_FILE_IMPORT_ATTRIBUTES =
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
index 3fc55adb51..20bcf84aa2 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.tosca.csar;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.Optional;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
@@ -36,8 +37,8 @@ import java.util.List;
import java.util.Map;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
public class OnboardingToscaMetadata implements ToscaMetadata {
@@ -77,7 +78,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
}
}
- if (!meta.metaEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS)) {
+ if (!meta.metaEntries.containsKey(ENTRY_DEFINITIONS.getName())) {
meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(
Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage())));
}
@@ -90,7 +91,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
@Override
public List<ErrorMessage> getErrors() {
- return ImmutableList.copyOf(errors);
+ return ImmutableList.copyOf(errors);
}
@@ -101,5 +102,16 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
}
return ImmutableMap.copyOf(metaEntries);
}
+
+ @Override
+ public boolean hasEntry(final String entry) {
+ return metaEntries.containsKey(entry);
+
+ }
+
+ @Override
+ public Optional<String> getEntry(final ToscaMetaEntry entry) {
+ return Optional.ofNullable(metaEntries.get(entry.getName()));
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
new file mode 100644
index 0000000000..56dabc5dc2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
@@ -0,0 +1,52 @@
+/*
+ *(===========LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * (===============================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * (===========LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.tosca.csar;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum ToscaMetaEntry {
+ TOSCA_META_PATH_FILE_NAME("TOSCA-Metadata/TOSCA.meta"),
+ TOSCA_META_FILE_VERSION_ENTRY("TOSCA-Meta-File-Version"),
+ CSAR_VERSION_ENTRY("CSAR-Version"),
+ CREATED_BY_ENTRY("Created-By"),
+ ENTRY_DEFINITIONS("Entry-Definitions"),
+ ENTRY_EVENTS("Entry-Events"),
+ ETSI_ENTRY_MANIFEST("ETSI-Entry-Manifest"),
+ ETSI_ENTRY_CHANGE_LOG("ETSI-Entry-Change-Log"),
+ ETSI_ENTRY_TESTS("ETSI-Entry-Tests"),
+ ETSI_ENTRY_LICENSES("ETSI-Entry-Licenses"),
+ ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate"),
+ TOSCA_META_FILE_VERSION("1.0");
+
+ private final String name;
+
+ ToscaMetaEntry(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static Optional<ToscaMetaEntry> parse(final String name) {
+ return Arrays.stream(values()).filter(toscaMetaEntry -> toscaMetaEntry.getName().equals(name)).findFirst();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
index a26e5195a5..c02c2f31c6 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
@@ -20,27 +20,48 @@
package org.openecomp.sdc.tosca.csar;
+import java.util.Optional;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import java.util.List;
import java.util.Map;
public interface ToscaMetadata {
+
/**
- * checks if metadata file is valid
- * @return
+ * Checks if metadata file is valid.
+ *
+ * @return {@code true} if the metadata is valid, {@code false} otherwise
*/
boolean isValid();
/**
- * List of errors occured during manifest parsing
- * @return
+ * Gets the list of errors occurred during manifest parsing.
+ *
+ * @return the list of errors
*/
List<ErrorMessage> getErrors();
/**
- * Metadata entries of block_0
- * @return
+ * Metadata entries of block_0.
+ *
+ * @return a map representing the entries
*/
Map<String, String> getMetaEntries();
+
+ /**
+ * Checks if the entry exists.
+ *
+ * @param entry the entry name.
+ * @return {@code true} if the entry exists, {@code false} otherwise.
+ */
+ boolean hasEntry(String entry);
+
+ /**
+ * Get the entry value if it exists.
+ *
+ * @param entry the entry to retrieve the value.
+ * @return an optional with the entry value if it exists.
+ */
+ Optional<String> getEntry(ToscaMetaEntry entry);
}
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 a0545fdd94..bbbcb202ef 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
@@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
index 29b083853a..7c0d1271fb 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
@@ -16,6 +16,11 @@
package org.openecomp.sdc.tosca.services.impl;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
+
import org.apache.commons.io.IOUtils;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -46,14 +51,10 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
private static final String ARTIFACTS_FOLDER_NAME = "Artifacts";
//todo currently duplicated, to be changed when external artifacts are separated from internal
private static final String TOSCA_META_FOLDER_NAME = "TOSCA-Metadata";
- private static final String TOSCA_META_FILE_VERSION = "TOSCA-Meta-File-Version";
private static final String TOSCA_META_FILE_VERSION_VALUE = "1.0";
private static final String TOSCA_META_FILE_NAME = "TOSCA.meta";
- private static final String CSAR_VERSION = "CSAR-Version";
private static final String CSAR_VERSION_VALUE = "1.1";
- private static final String CREATED_BY = "Created-By";
private static final String CREATED_BY_VALUE = "ASDC Onboarding portal";
- private static final String ENTRY_DEFINITIONS = "Entry-Definitions";
private static final String META_FILE_DELIMITER = ":";
private static final String SPACE = " ";
private static final String FILE_SEPARATOR = File.separator;
@@ -86,11 +87,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
@Override
public String createMetaFile(String entryDefinitionsFileName) {
- return TOSCA_META_FILE_VERSION + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE
+ return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE
+ System.lineSeparator()
- + CSAR_VERSION + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator()
- + CREATED_BY + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator()
- + ENTRY_DEFINITIONS + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME
+ + CSAR_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator()
+ + CREATED_BY_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator()
+ + ENTRY_DEFINITIONS.getName() + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME
+ FILE_SEPARATOR
+ entryDefinitionsFileName;
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
index 936371990a..51cdfa990d 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
@@ -24,9 +24,9 @@ package org.openecomp.sdc.tosca.csar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
import java.io.IOException;
import java.io.InputStream;
@@ -43,7 +43,7 @@ public class MetadataParsingTest {
.getResourceAsStream("/vspmanager.csar/metadata/Invalidtosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
assertFalse(onboardingToscaMetadata.isValid());
- assertNull(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS));
+ assertNull(onboardingToscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName()));
}
}
@@ -52,7 +52,8 @@ public class MetadataParsingTest {
try (InputStream is = getClass()
.getResourceAsStream("/vspmanager.csar/metadata/Validtosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS), "Definitions/MainServiceTemplate.yaml");
+ assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
+ ENTRY_DEFINITIONS.getName()));
}
}
@@ -80,9 +81,10 @@ public class MetadataParsingTest {
try (InputStream is = getClass()
.getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS), "Definitions/MainServiceTemplate.yaml");
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST), "MainServiceTemplate.mf");
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_CHANGE_LOG), "change.log");
+ assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
+ ENTRY_DEFINITIONS.getName()));
+ assertEquals("MainServiceTemplate.mf", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
+ assertEquals("change.log", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_CHANGE_LOG.getName()));
}
}