aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src')
-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
7 files changed, 113 insertions, 40 deletions
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()));
}
}