diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
55 files changed, 1102 insertions, 1622 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AbstractOnboardingManifest.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AbstractOnboardingManifest.java index 372517c5f9..b24804be54 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AbstractOnboardingManifest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AbstractOnboardingManifest.java @@ -15,7 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.csar; import com.google.common.collect.ImmutableList; @@ -106,7 +105,6 @@ abstract class AbstractOnboardingManifest implements Manifest { errors.add(Messages.MANIFEST_EMPTY.getErrorMessage()); return; } - processMetadata(); processBody(); } @@ -133,8 +131,7 @@ abstract class AbstractOnboardingManifest implements Manifest { throw new IOException("Manifest Input Stream cannot be null."); } final ImmutableList.Builder<String> builder = ImmutableList.builder(); - try (final BufferedReader bufferedReader = new BufferedReader( - new InputStreamReader(manifestAsStream, StandardCharsets.UTF_8.newDecoder()))) { + try (final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(manifestAsStream, StandardCharsets.UTF_8.newDecoder()))) { bufferedReader.lines().forEach(builder::add); } return builder.build(); @@ -147,8 +144,7 @@ abstract class AbstractOnboardingManifest implements Manifest { * @return {@code true} if the line is a 'metadata' entry, {@code false} otherwise. */ protected boolean isMetadata(final String line) { - return line.trim() - .equals(ManifestTokenType.METADATA.getToken() + ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR.getToken()); + return line.trim().equals(ManifestTokenType.METADATA.getToken() + ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR.getToken()); } /** @@ -187,7 +183,7 @@ abstract class AbstractOnboardingManifest implements Manifest { * Reports a manifest invalid line error. * * @param lineNumber the line number - * @param line the line + * @param line the line */ protected void reportInvalidLine(final int lineNumber, final String line) { errors.add(Messages.MANIFEST_INVALID_LINE.formatMessage(lineNumber, line)); @@ -197,7 +193,7 @@ abstract class AbstractOnboardingManifest implements Manifest { * Reports a manifest error occurred in the current line. * * @param message The error message - * @param params The message params + * @param params The message params */ protected void reportError(final Messages message, final Object... params) { reportError(currentLineNumber, getCurrentLine().orElse(""), message, params); @@ -207,12 +203,11 @@ abstract class AbstractOnboardingManifest implements Manifest { * Reports a manifest error occurred in the specified line. * * @param lineNumber The line number - * @param line The line - * @param message The error message - * @param params The message params + * @param line The line + * @param message The error message + * @param params The message params */ - protected void reportError(final int lineNumber, final String line, final Messages message, - final Object... params) { + protected void reportError(final int lineNumber, final String line, final Messages message, final Object... params) { errors.add(Messages.MANIFEST_ERROR_WITH_LINE.formatMessage(message.formatMessage(params), lineNumber, line)); } @@ -240,12 +235,10 @@ abstract class AbstractOnboardingManifest implements Manifest { } currentLine = null; } - if (getCurrentLine().isPresent()) { currentLineNumber++; currentLine = null; } - return getCurrentLine(); } @@ -259,8 +252,7 @@ abstract class AbstractOnboardingManifest implements Manifest { } /** - * Reads the current line entry name. The entry name and value must be separated by {@link - * ManifestTokenType#ATTRIBUTE_VALUE_SEPARATOR}. + * Reads the current line entry name. The entry name and value must be separated by {@link ManifestTokenType#ATTRIBUTE_VALUE_SEPARATOR}. * * @return the entry value */ @@ -269,7 +261,6 @@ abstract class AbstractOnboardingManifest implements Manifest { if (line.isPresent()) { return readEntryName(line.get()); } - return Optional.empty(); } @@ -290,13 +281,11 @@ abstract class AbstractOnboardingManifest implements Manifest { if (StringUtils.isEmpty(attribute)) { return Optional.empty(); } - return Optional.of(attribute); } /** - * Reads the current line entry value. The entry name and value must be separated by {@link - * ManifestTokenType#ATTRIBUTE_VALUE_SEPARATOR}. + * Reads the current line entry value. The entry name and value must be separated by {@link ManifestTokenType#ATTRIBUTE_VALUE_SEPARATOR}. * * @return the entry value */ @@ -305,7 +294,6 @@ abstract class AbstractOnboardingManifest implements Manifest { if (line.isPresent()) { return readEntryValue(line.get()); } - return Optional.empty(); } @@ -326,13 +314,11 @@ abstract class AbstractOnboardingManifest implements Manifest { if (StringUtils.isEmpty(value)) { return Optional.empty(); } - return Optional.of(value); } /** - * Adds a entry to the metadata map. Only accepts new entries. If the entry is duplicated a manifest error is - * reported. + * Adds a entry to the metadata map. Only accepts new entries. If the entry is duplicated a manifest error is reported. * * @param entry the metadata entry * @param value the entry value @@ -343,7 +329,6 @@ abstract class AbstractOnboardingManifest implements Manifest { reportError(Messages.MANIFEST_METADATA_DUPLICATED_ENTRY, entry); return false; } - metadata.put(entry, value); return true; } @@ -388,7 +373,6 @@ abstract class AbstractOnboardingManifest implements Manifest { if (MapUtils.isEmpty(sourceAndChecksumMap)) { return Optional.empty(); } - return Optional.of(ImmutableMap.copyOf(sourceAndChecksumMap)); } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AlgorithmDigest.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AlgorithmDigest.java index 8ce0fb650b..409842e946 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AlgorithmDigest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/AlgorithmDigest.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import lombok.AllArgsConstructor; @@ -28,6 +27,7 @@ import lombok.Getter; @Getter @AllArgsConstructor public class AlgorithmDigest { + private final String hashAlgorithm; private final String digest; } 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 845d36cb4c..cd83cc816b 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 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.csar; import static com.google.common.collect.ImmutableSet.of; @@ -23,37 +22,32 @@ import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_ARCHIVE_VERSIO import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_NAME; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_PROVIDER; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_RELEASE_DATE_TIME; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFD_ID; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFM_INFO; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PACKAGE_VERSION; -import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_SOFTWARE_VERSION; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PRODUCT_NAME; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PROVIDER_ID; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_RELEASE_DATE_TIME; -import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFD_ID; -import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFM_INFO; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_SOFTWARE_VERSION; import com.google.common.collect.ImmutableSet; public class CSARConstants { - public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/", - "Licenses/", "TOSCA-Metadata/"); + 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 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()); - public static final ImmutableSet<String> MANIFEST_PNF_METADATA_VERSION_3 = - of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(), - PNFD_ARCHIVE_VERSION.getToken(), COMPATIBLE_SPECIFICATION_VERSIONS.getToken()); - public static final ImmutableSet<String> MANIFEST_VNF_METADATA = - of(VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), VNF_RELEASE_DATE_TIME.getToken(), - VNF_PACKAGE_VERSION.getToken()); - public static final ImmutableSet<String> MANIFEST_VNF_METADATA_VERSION_3 = - of(COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), VNFD_ID.getToken(), VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), VNF_RELEASE_DATE_TIME.getToken(), - VNF_PACKAGE_VERSION.getToken(), VNF_SOFTWARE_VERSION.getToken(), VNFM_INFO.getToken()); + 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()); + public static final ImmutableSet<String> MANIFEST_PNF_METADATA_VERSION_3 = of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), + PNFD_RELEASE_DATE_TIME.getToken(), PNFD_ARCHIVE_VERSION.getToken(), COMPATIBLE_SPECIFICATION_VERSIONS.getToken()); + public static final ImmutableSet<String> MANIFEST_VNF_METADATA = of(VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), + VNF_RELEASE_DATE_TIME.getToken(), VNF_PACKAGE_VERSION.getToken()); + public static final ImmutableSet<String> MANIFEST_VNF_METADATA_VERSION_3 = of(COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), VNFD_ID.getToken(), + VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), VNF_RELEASE_DATE_TIME.getToken(), VNF_PACKAGE_VERSION.getToken(), + VNF_SOFTWARE_VERSION.getToken(), VNFM_INFO.getToken()); public static final int MANIFEST_METADATA_LIMIT = 4; public static final int MANIFEST_VNF_METADATA_LIMIT_VERSION_3 = 8; public static final int MANIFEST_PNF_METADATA_LIMIT_VERSION_3 = 5; @@ -62,13 +56,11 @@ public class CSARConstants { public static final String CSAR_VERSION_1_1 = "1.1"; public static final String ETSI_VERSION_2_6_1 = "2.6.1"; public static final String ETSI_VERSION_2_7_1 = "2.7.1"; - public static final ImmutableSet<String> NON_FILE_IMPORT_ATTRIBUTES = - ImmutableSet.of("repository", "namespace_uri", "namespace_prefix"); + public static final ImmutableSet<String> NON_FILE_IMPORT_ATTRIBUTES = ImmutableSet.of("repository", "namespace_uri", "namespace_prefix"); public static final String TOSCA_TYPE_PNF = "pnf"; public static final String TOSCA_TYPE_VNF = "vnf"; public static final String TOSCA_MANIFEST_FILE_EXT = "mf"; private CSARConstants() { - } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/Manifest.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/Manifest.java index 31b04f0d8b..d87850ac4b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/Manifest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/Manifest.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import java.io.InputStream; @@ -29,44 +28,51 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; public interface Manifest { /** - * This Method will parse manifest, extracting fields mandatory/non-mandatory, - * if error occurred it's recorded and will be used for deciding if manifest is valid + * This Method will parse manifest, extracting fields mandatory/non-mandatory, if error occurred it's recorded and will be used for deciding if + * manifest is valid + * * @param is manifest file input stream */ void parse(InputStream is); /** * Returns if manifest is valid + * * @return true/false */ boolean isValid(); /** * Metadata section of manifest + * * @return */ Map<String, String> getMetadata(); /** * Source section of manifest + * * @return */ List<String> getSources(); /** * Validation errors of manifest + * * @return */ List<String> getErrors(); /** * non mano section of manifest sol004 #4.3.7 + * * @return */ Map<String, List<String>> getNonManoSources(); /** * Gets the type based on the metadata of manifest file (VF/PNF) + * * @return enum for type values */ Optional<ResourceTypeEnum> getType(); @@ -75,15 +81,15 @@ public interface Manifest { /** * Gets the CMS manifest signature if present in manifest - * @return - * the CMS manifest signature. + * + * @return the CMS manifest signature. */ Optional<String> getCmsSignature(); /** * Gets the Map of source path and it correspondent checksum. - * @return - * The source and checksum map. + * + * @return The source and checksum map. */ Optional<Map<String, AlgorithmDigest>> getSourceAndChecksumMap(); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java index 7caa09f954..9b6b34f755 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java @@ -17,13 +17,13 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import java.util.Arrays; import java.util.Optional; public enum ManifestTokenType { + // @formatter:off ALGORITHM("Algorithm"), ATTRIBUTE_VALUE_SEPARATOR(":"), CMS_BEGIN("-----BEGIN CMS-----"), @@ -46,7 +46,7 @@ public enum ManifestTokenType { SIGNATURE("Signature"), CERTIFICATE("Certificate"), COMPATIBLE_SPECIFICATION_VERSIONS("compatible_specification_versions"); - + // @formatter:on private final String token; @@ -54,14 +54,14 @@ public enum ManifestTokenType { this.token = token; } - public String getToken() { - return token; - } - public static Optional<ManifestTokenType> parse(final String token) { return Arrays.stream(values()).filter(it -> it.getToken() != null && it.getToken().equals(token)).findFirst(); } + public String getToken() { + return token; + } + public boolean isMetadataEntry() { return isMetadataVnfEntry() || isMetadataPnfEntry(); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ONAPManifestOnboarding.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ONAPManifestOnboarding.java index 02ee12db13..ee6cc5f9f4 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ONAPManifestOnboarding.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ONAPManifestOnboarding.java @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import com.google.common.collect.ImmutableList; @@ -43,7 +42,6 @@ public class ONAPManifestOnboarding extends AbstractOnboardingManifest { return; } currentLine = readNextNonEmptyLine(); - while (currentLine.isPresent() && continueToProcess) { final String line = currentLine.get(); final String entry = readEntryName(line).orElse(null); @@ -54,7 +52,6 @@ public class ONAPManifestOnboarding extends AbstractOnboardingManifest { if (value == null) { reportInvalidLine(); } - final ManifestTokenType tokenType = ManifestTokenType.parse(entry).orElse(null); if (tokenType == ManifestTokenType.SOURCE) { sources.add(value); @@ -70,5 +67,4 @@ public class ONAPManifestOnboarding extends AbstractOnboardingManifest { protected void processBody() { //no implementation } - } 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 20bcf84aa2..bc104335f5 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 @@ -17,101 +17,96 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS; + 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; -import java.io.InputStream; import java.io.IOException; -import org.apache.commons.io.IOUtils; - +import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - -import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; -import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR; -import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; public class OnboardingToscaMetadata implements ToscaMetadata { - private Map<String, String> metaEntries; - private List<ErrorMessage> errors; + private Map<String, String> metaEntries; + private List<ErrorMessage> errors; - private OnboardingToscaMetadata(){ - metaEntries = new HashMap<>(); - errors = new ArrayList<>(); - } - - /** - * Method parses input stream of meta file, only block_0 is parsed, the rest of metadata ignored - * @param st meta file input stream - * @return OnboardingToscaMetadata instance - * @throws IOException - */ - public static ToscaMetadata parseToscaMetadataFile(InputStream st) throws IOException { - if(st == null) { - throw new IOException(Messages.METADATA_PARSER_INTERNAL.getErrorMessage()); + private OnboardingToscaMetadata() { + metaEntries = new HashMap<>(); + errors = new ArrayList<>(); } - OnboardingToscaMetadata meta = new OnboardingToscaMetadata(); - List<String> metadataLines = IOUtils.readLines(st, "utf-8"); - for (String line : metadataLines) { - line = line.trim(); - if (line.isEmpty()) { + + /** + * Method parses input stream of meta file, only block_0 is parsed, the rest of metadata ignored + * + * @param st meta file input stream + * @return OnboardingToscaMetadata instance + * @throws IOException + */ + public static ToscaMetadata parseToscaMetadataFile(InputStream st) throws IOException { + if (st == null) { + throw new IOException(Messages.METADATA_PARSER_INTERNAL.getErrorMessage()); + } + OnboardingToscaMetadata meta = new OnboardingToscaMetadata(); + List<String> metadataLines = IOUtils.readLines(st, "utf-8"); + for (String line : metadataLines) { + line = line.trim(); + if (line.isEmpty()) { + return meta; + } + String[] entry = line.split(ATTRIBUTE_VALUE_SEPARATOR.getToken()); + //No empty keys allowed, no empty values allowed + if (entry.length < 2 || entry[0].isEmpty()) { + meta.errors.add( + new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(Messages.METADATA_INVALID_ENTRY_DEFINITIONS.getErrorMessage(), line))); + //want to get all error lines in meta file block_0, no breaking loop + } else { + meta.metaEntries.put(entry[0].trim(), entry[1].trim()); + } + } + if (!meta.metaEntries.containsKey(ENTRY_DEFINITIONS.getName())) { + meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()))); + } return meta; - } - String[] entry = line.split(ATTRIBUTE_VALUE_SEPARATOR.getToken()); - //No empty keys allowed, no empty values allowed - if (entry.length < 2 || entry[0].isEmpty()) { - meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters( - Messages.METADATA_INVALID_ENTRY_DEFINITIONS.getErrorMessage(), line))); - //want to get all error lines in meta file block_0, no breaking loop - } else { - meta.metaEntries.put(entry[0].trim(), entry[1].trim()); - } } - if (!meta.metaEntries.containsKey(ENTRY_DEFINITIONS.getName())) { - meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters( - Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()))); + @Override + public boolean isValid() { + return errors.isEmpty(); } - return meta; - } - @Override public boolean isValid(){ - return errors.isEmpty(); - } - - @Override - public List<ErrorMessage> getErrors() { - return ImmutableList.copyOf(errors); - } - - - @Override - public Map<String, String> getMetaEntries() { - if (!isValid()){ - return Collections.emptyMap(); + @Override + public List<ErrorMessage> getErrors() { + return ImmutableList.copyOf(errors); } - return ImmutableMap.copyOf(metaEntries); - } - @Override - public boolean hasEntry(final String entry) { - return metaEntries.containsKey(entry); + @Override + public Map<String, String> getMetaEntries() { + if (!isValid()) { + return Collections.emptyMap(); + } + 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())); - } + @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/SOL004ManifestOnboarding.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java index 97f562979f..0d4deca6c0 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java @@ -18,7 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1; @@ -27,17 +26,15 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_L import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_LIMIT_VERSION_3; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS; +import com.vdurmont.semver4j.Semver; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; import java.util.Optional; - import org.apache.commons.lang.StringUtils; import org.openecomp.sdc.common.errors.Messages; -import com.vdurmont.semver4j.Semver; - /** * Processes a SOL004 Manifest. */ @@ -86,7 +83,6 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { getCurrentLine().ifPresent(line -> reportInvalidLine()); break; } - switch (manifestTokenType) { case CMS_BEGIN: readCmsSignature(); @@ -158,7 +154,6 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { if (manifestTokenType != ManifestTokenType.SOURCE) { break; } - final String value = readCurrentEntryValue().orElse(null); if (!StringUtils.isEmpty(value)) { nonManoSourceList.add(value); @@ -166,7 +161,6 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { reportError(Messages.MANIFEST_EMPTY_NON_MANO_SOURCE); break; } - readNextNonEmptyLine(); } return nonManoSourceList; @@ -182,10 +176,9 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { return; } final StringBuilder cmsSignatureBuilder = new StringBuilder(); - cmsSignatureBuilder.append(currentLine).append("\n"); Optional<String> currentLine = readNextNonEmptyLine(); - if(!getCurrentLine().isPresent()) { + if (!getCurrentLine().isPresent()) { return; } while (currentLine.isPresent()) { @@ -196,12 +189,10 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { cmsSignatureBuilder.append(currentLine.get()).append("\n"); currentLine = readNextNonEmptyLine(); } - if (currentLine.isPresent()) { cmsSignature = cmsSignatureBuilder.toString(); readNextNonEmptyLine(); } - if (getCurrentLine().isPresent()) { reportError(Messages.MANIFEST_SIGNATURE_LAST_ENTRY); continueToProcess = false; @@ -237,32 +228,28 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { reportError(Messages.MANIFEST_NO_METADATA); return false; } - String key = metadata.keySet().stream().filter(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k)) - .findFirst().orElse(null); + String key = metadata.keySet().stream().filter(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k)).findFirst().orElse(null); final ManifestTokenType firstManifestEntryTokenType = ManifestTokenType.parse(key).orElse(null); if (firstManifestEntryTokenType == null) { reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, key); return false; } for (final Entry<String, String> manifestEntry : metadata.entrySet()) { - final ManifestTokenType manifestEntryTokenType = ManifestTokenType.parse(manifestEntry.getKey()) - .orElse(null); + final ManifestTokenType manifestEntryTokenType = ManifestTokenType.parse(manifestEntry.getKey()).orElse(null); if (manifestEntryTokenType == null) { reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, manifestEntry.getKey()); return false; } - if ((firstManifestEntryTokenType.isMetadataVnfEntry() && !manifestEntryTokenType.isMetadataVnfEntry()) - || (firstManifestEntryTokenType.isMetadataPnfEntry() && !manifestEntryTokenType.isMetadataPnfEntry())) { + if ((firstManifestEntryTokenType.isMetadataVnfEntry() && !manifestEntryTokenType.isMetadataVnfEntry()) || ( + firstManifestEntryTokenType.isMetadataPnfEntry() && !manifestEntryTokenType.isMetadataPnfEntry())) { reportError(Messages.MANIFEST_METADATA_UNEXPECTED_ENTRY_TYPE); return false; } } - if (metadata.entrySet().size() != getMaxAllowedManifestMetaEntries()) { reportError(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT, getMaxAllowedManifestMetaEntries()); return false; } - return true; } @@ -278,10 +265,8 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { if (manifestTokenType != ManifestTokenType.SOURCE) { return; } - final String sourceLine = currentLine.get(); final String sourcePath = readEntryValue(sourceLine).orElse(null); - if (sourcePath == null) { reportError(Messages.MANIFEST_EXPECTED_SOURCE_PATH); return; @@ -293,13 +278,12 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { } /** - * Processes entries {@link ManifestTokenType#ALGORITHM} and {@link ManifestTokenType#HASH} of a {@link - * ManifestTokenType#SOURCE} entry. + * Processes entries {@link ManifestTokenType#ALGORITHM} and {@link ManifestTokenType#HASH} of a {@link ManifestTokenType#SOURCE} entry. * * @param sourcePath the source path related to the algorithm entry. */ private void readAlgorithmEntry(final String sourcePath) { - Optional<String> currentLine = getCurrentLine(); + Optional<String> currentLine = getCurrentLine(); if (!currentLine.isPresent()) { return; } @@ -319,14 +303,12 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { continueToProcess = false; return; } - currentLine = readNextNonEmptyLine(); if (!currentLine.isPresent() || detectLineEntry().orElse(null) != ManifestTokenType.HASH) { reportError(Messages.MANIFEST_EXPECTED_HASH_ENTRY); continueToProcess = false; return; } - final String hashLine = currentLine.get(); final String hash = readEntryValue(hashLine).orElse(null); if (hash == null) { @@ -339,13 +321,12 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { } /** - * Processes entries {@link ManifestTokenType#SIGNATURE} and {@link ManifestTokenType#CERTIFICATE} of a {@link - * ManifestTokenType#SOURCE} entry. + * Processes entries {@link ManifestTokenType#SIGNATURE} and {@link ManifestTokenType#CERTIFICATE} of a {@link ManifestTokenType#SOURCE} entry. * * @param sourcePath the source path related to the algorithm entry. */ private void readSignatureEntry(final String sourcePath) { - Optional<String> currentLine = getCurrentLine(); + Optional<String> currentLine = getCurrentLine(); if (!currentLine.isPresent()) { return; } @@ -365,13 +346,11 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { continueToProcess = false; return; } - currentLine = readNextNonEmptyLine(); if (!currentLine.isPresent() || detectLineEntry().orElse(null) != ManifestTokenType.CERTIFICATE) { sourceAndSignatureMap.put(sourcePath, new SignatureData(signatureFile, null)); return; } - final String certLine = currentLine.get(); final String certFile = readEntryValue(certLine).orElse(null); if (certFile == null) { @@ -385,23 +364,22 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest { private int getMaxAllowedManifestMetaEntries() { if (maxAllowedMetaEntries == 0) { - boolean isVersion3 = metadata.containsKey(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()) - && !getHighestCompatibleVersion().isLowerThan(ETSI_VERSION_2_7_1); + boolean isVersion3 = + metadata.containsKey(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()) && !getHighestCompatibleVersion().isLowerThan(ETSI_VERSION_2_7_1); //Both PNF and VNF share attribute COMPATIBLE_SPECIFICATION_VERSIONS - if (isVersion3) - maxAllowedMetaEntries = metadata.keySet().stream() - .anyMatch(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k) - && isMetadataEntry(k) && ManifestTokenType.parse(k).get().isMetadataPnfEntry()) - ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3; - else + if (isVersion3) { + maxAllowedMetaEntries = metadata.keySet().stream().anyMatch( + k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k) && isMetadataEntry(k) && ManifestTokenType.parse(k).get() + .isMetadataPnfEntry()) ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3; + } else { maxAllowedMetaEntries = MAX_ALLOWED_MANIFEST_META_ENTRIES; + } } return maxAllowedMetaEntries; } private Semver getHighestCompatibleVersion() { - return Arrays.asList(metadata.get(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()).split(",")) - .stream().map(Semver::new).max((v1, v2) -> v1.compareTo(v2)) - .orElse(new Semver(ETSI_VERSION_2_6_1)); + return Arrays.asList(metadata.get(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()).split(",")).stream().map(Semver::new) + .max((v1, v2) -> v1.compareTo(v2)).orElse(new Semver(ETSI_VERSION_2_6_1)); } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SignatureData.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SignatureData.java index 74277a627f..a4e04f22db 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SignatureData.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SignatureData.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import lombok.AllArgsConstructor; @@ -29,6 +28,7 @@ import org.springframework.lang.Nullable; @Getter @AllArgsConstructor public class SignatureData { + private final String signatureFile; @Nullable private final String certificateFile; 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 index 3b669543fd..9219c77bea 100644 --- 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 @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * (===========LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; import java.util.Arrays; @@ -30,6 +29,7 @@ import lombok.Getter; @AllArgsConstructor @Getter public enum ToscaMetaEntry { + // @formatter:off TOSCA_META_FILE_VERSION_ENTRY("TOSCA-Meta-File-Version"), CSAR_VERSION_ENTRY("CSAR-Version"), CREATED_BY_ENTRY("Created-By"), @@ -40,6 +40,7 @@ public enum ToscaMetaEntry { ETSI_ENTRY_LICENSES("ETSI-Entry-Licenses"), ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate"), OTHER_DEFINITIONS("Other-Definitions"); + // @formatter:on private final String name; 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 c02c2f31c6..483afb7710 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 @@ -17,14 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - 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; +import java.util.Optional; +import org.openecomp.sdc.datatypes.error.ErrorMessage; public interface ToscaMetadata { diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadataFileInfo.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadataFileInfo.java index 9d2a95f992..91a8121d3f 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadataFileInfo.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadataFileInfo.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.csar; public class ToscaMetadataFileInfo { @@ -25,7 +24,5 @@ public class ToscaMetadataFileInfo { public static final String TOSCA_META_FILE_VERSION_1_0 = "1.0"; private ToscaMetadataFileInfo() { - } - } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java index cc11144102..f80869630c 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,11 +25,7 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaArtifactType { - private static Configuration config = ConfigurationManager.lookup(); - - public static final String ARTIFACT_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ARTIFACT_TYPE); - public static final String NATIVE_DEPLOYMENT = "tosca.artifacts.Deployment"; - + private static Configuration config = ConfigurationManager.lookup(); + public static final String ARTIFACT_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ARTIFACT_TYPE); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaCapabilityType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaCapabilityType.java index 8be3433998..4840bc8f4e 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaCapabilityType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaCapabilityType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,11 +25,6 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaCapabilityType { - private static Configuration config = ConfigurationManager.lookup(); - - private static final String CAPABILITY_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_CAPABILITY_TYPE); - //TOSCA native types public static final String NATIVE_ROOT = "tosca.capabilities.Root"; public static final String NATIVE_NODE = "tosca.capabilities.Node"; @@ -43,12 +37,12 @@ public class ToscaCapabilityType { public static final String NATIVE_ATTACHMENT = "tosca.capabilities.Attachment"; public static final String NATIVE_NETWORK_LINKABLE = "tosca.capabilities.network.Linkable"; public static final String NATIVE_NFV_METRIC = "tosca.capabilities.nfv.Metric"; - + private static Configuration config = ConfigurationManager.lookup(); + private static final String CAPABILITY_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_CAPABILITY_TYPE); //Additional types public static final String METRIC = CAPABILITY_PREFIX + "Metric"; public static final String METRIC_CEILOMETER = CAPABILITY_PREFIX + "metric.Ceilometer"; public static final String METRIC_SNMP_TRAP = CAPABILITY_PREFIX + "metric.SnmpTrap"; public static final String METRIC_SNMP_POLLING = CAPABILITY_PREFIX + "metric.SnmpPolling"; public static final String FABRIC_CONFIGURATION = CAPABILITY_PREFIX + "FabricConfiguration"; - } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaDataType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaDataType.java index a034b9ad38..48d6a37492 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaDataType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaDataType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,77 +25,54 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaDataType { - private static Configuration config = ConfigurationManager.lookup(); - - private static final String DATA_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_DATA_TYPE); - //TOSCA native types public static final String NATIVE_ROOT = "tosca.datatypes.Root"; public static final String NATIVE_NETWORK_NETWORK_INFO = "tosca.datatypes.network.NetworkInfo"; public static final String NATIVE_NETWORK_PORT_INFO = "tosca.datatypes.network.PortInfo"; - + private static Configuration config = ConfigurationManager.lookup(); + private static final String DATA_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_DATA_TYPE); //Additional types - public static final String NOVA_SERVER_PORT_EXTRA_PROPERTIES = - DATA_TYPE_PREFIX + "heat.novaServer.network.PortExtraProperties"; + public static final String NOVA_SERVER_PORT_EXTRA_PROPERTIES = DATA_TYPE_PREFIX + "heat.novaServer.network.PortExtraProperties"; public static final String NETWORK_ADDRESS_PAIR = DATA_TYPE_PREFIX + "heat.network.AddressPair"; public static final String NEUTRON_PORT_FIXED_IPS = DATA_TYPE_PREFIX + "heat.neutron.port.FixedIps"; public static final String CONTRAIL_NETWORK_RULE = DATA_TYPE_PREFIX + "heat.contrail.network.rule.Rule"; - public static final String CONTRAIL_NETWORK_RULE_LIST = - DATA_TYPE_PREFIX + "heat.contrail.network.rule.RuleList"; - public static final String CONTRAIL_NETWORK_RULE_PORT_PAIRS = - DATA_TYPE_PREFIX + "heat.contrail.network.rule.PortPairs"; - public static final String CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK = - DATA_TYPE_PREFIX + "heat.contrail.network.rule.VirtualNetwork"; - public static final String CONTRAILV2_NETWORK_RULE = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.Rule"; - public static final String CONTRAILV2_NETWORK_RULE_LIST = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.RuleList"; - public static final String CONTRAILV2_NETWORK_RULE_SRC_PORT_PAIRS = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.SrcPortPairs"; - public static final String CONTRAILV2_NETWORK_RULE_DST_PORT_PAIRS = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.DstPortPairs"; - public static final String CONTRAILV2_NETWORK_RULE_DST_VIRTUAL_NETWORK = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.DstVirtualNetwork"; - public static final String CONTRAILV2_NETWORK_RULE_SRC_VIRTUAL_NETWORK = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.SrcVirtualNetwork"; + public static final String CONTRAIL_NETWORK_RULE_LIST = DATA_TYPE_PREFIX + "heat.contrail.network.rule.RuleList"; + public static final String CONTRAIL_NETWORK_RULE_PORT_PAIRS = DATA_TYPE_PREFIX + "heat.contrail.network.rule.PortPairs"; + public static final String CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK = DATA_TYPE_PREFIX + "heat.contrail.network.rule.VirtualNetwork"; + public static final String CONTRAILV2_NETWORK_RULE = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.Rule"; + public static final String CONTRAILV2_NETWORK_RULE_LIST = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.RuleList"; + public static final String CONTRAILV2_NETWORK_RULE_SRC_PORT_PAIRS = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.SrcPortPairs"; + public static final String CONTRAILV2_NETWORK_RULE_DST_PORT_PAIRS = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.DstPortPairs"; + public static final String CONTRAILV2_NETWORK_RULE_DST_VIRTUAL_NETWORK = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.DstVirtualNetwork"; + public static final String CONTRAILV2_NETWORK_RULE_SRC_VIRTUAL_NETWORK = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.SrcVirtualNetwork"; public static final String CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_PROPERTIES = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.interface.Properties"; - public static final String CONTRAILV2_NETWORK_RULE_ACTION_LIST = - DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.ActionList"; - public static final String CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.IpamRefData"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.interface.Properties"; + public static final String CONTRAILV2_NETWORK_RULE_ACTION_LIST = DATA_TYPE_PREFIX + "heat.contrailV2.network.rule.ActionList"; + public static final String CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA = DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.IpamRefData"; public static final String CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET_LIST = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.ref.data.IpamSubnetList"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.ref.data.IpamSubnetList"; public static final String CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.ref.data.IpamSubnet"; - public static final String CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.RefData"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.ref.data.IpamSubnet"; + public static final String CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA = DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.RefData"; public static final String CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA_SEQUENCE = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.RefDataSequence"; - public static final String NOVA_SERVER_NETWORK_ADDRESS_INFO = - DATA_TYPE_PREFIX + "heat.novaServer.network.AddressInfo"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.network.rule.RefDataSequence"; + public static final String NOVA_SERVER_NETWORK_ADDRESS_INFO = DATA_TYPE_PREFIX + "heat.novaServer.network.AddressInfo"; public static final String NEUTRON_SUBNET = DATA_TYPE_PREFIX + "heat.network.neutron.Subnet"; public static final String NETWORK_ALLOCATION_POOL = DATA_TYPE_PREFIX + "heat.network.AllocationPool"; public static final String NETWORK_HOST_ROUTE = DATA_TYPE_PREFIX + "heat.network.subnet.HostRoute"; - public static final String SUBSTITUTION_FILTERING = - DATA_TYPE_PREFIX + "heat.substitution.SubstitutionFiltering"; - public static final String NEUTRON_SECURITY_RULES_RULE = - DATA_TYPE_PREFIX + "heat.network.neutron.SecurityRules.Rule"; - public static final String CONTRAIL_STATIC_ROUTE = - DATA_TYPE_PREFIX + "heat.network.contrail.port.StaticRoute"; - public static final String CONTRAIL_ADDRESS_PAIR = - DATA_TYPE_PREFIX + "heat.network.contrail.AddressPair"; - public static final String CONTRAIL_INTERFACE_DATA = - DATA_TYPE_PREFIX + "heat.network.contrail.InterfaceData"; + public static final String SUBSTITUTION_FILTERING = DATA_TYPE_PREFIX + "heat.substitution.SubstitutionFiltering"; + public static final String NEUTRON_SECURITY_RULES_RULE = DATA_TYPE_PREFIX + "heat.network.neutron.SecurityRules.Rule"; + public static final String CONTRAIL_STATIC_ROUTE = DATA_TYPE_PREFIX + "heat.network.contrail.port.StaticRoute"; + public static final String CONTRAIL_ADDRESS_PAIR = DATA_TYPE_PREFIX + "heat.network.contrail.AddressPair"; + public static final String CONTRAIL_INTERFACE_DATA = DATA_TYPE_PREFIX + "heat.network.contrail.InterfaceData"; public static final String CONTRAILV2_VIRTUAL_MACHINE_SUB_INTERFACE_PROPERTIES = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.Properties"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.Properties"; public static final String CONTRAILV2_VIRTUAL_MACHINE_SUB_INTERFACE_MAC_ADDRESS = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.MacAddress"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.MacAddress"; public static final String CONTRAILV2_VIRTUAL_MACHINE_SUB_INTERFACE_ADDRESS_PAIRS = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPairs"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPairs"; public static final String CONTRAILV2_VIRTUAL_MACHINE_SUB_INTERFACE_ADDRESS_PAIR = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPair"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPair"; public static final String CONTRAILV2_VIRTUAL_MACHINE_SUB_INTERFACE_ADDRESS_PAIR_IP = - DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPairIp"; + DATA_TYPE_PREFIX + "heat.contrailV2.virtual.machine.subInterface.AddressPairIp"; } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaElementTypes.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaElementTypes.java index 7aa3e04ad7..35edbb35cf 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaElementTypes.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaElementTypes.java @@ -7,9 +7,9 @@ * 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. @@ -17,16 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; -public enum ToscaElementTypes { - CAPABILITY_TYPE, - NODE_TYPE, - ARTIFACT_TYPE, - DATA_TYPE, - INTERFACE_TYPE, - RELATIONSHIP_TYPE, - GROUP_TYPE, - POLICY_TYPE -} +public enum ToscaElementTypes {CAPABILITY_TYPE, NODE_TYPE, ARTIFACT_TYPE, DATA_TYPE, INTERFACE_TYPE, RELATIONSHIP_TYPE, GROUP_TYPE, POLICY_TYPE} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFlatData.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFlatData.java index 04663071b7..729b25d419 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFlatData.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFlatData.java @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.datatypes; import java.util.ArrayList; import java.util.List; - import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -30,7 +28,6 @@ public class ToscaFlatData { private Object flatEntity; private ToscaElementTypes elementType; - @Setter(AccessLevel.NONE) private List<String> inheritanceHierarchyType; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFunctions.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFunctions.java index 5dbd05aada..43e061319c 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFunctions.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaFunctions.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import lombok.AllArgsConstructor; @@ -33,30 +32,24 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum ToscaFunctions { - + // @formatter:off // Intrinsic functions, section 4.3 in TOSCA 1.3 CONCAT("concat"), JOIN("join"), // since 1.2 TOKEN("token"), - // Property functions, section 4.4 in TOSCA 1.3 - GET_INPUT("get_input"), - GET_PROPERTY("get_property"), - + GET_INPUT("get_input"), GET_PROPERTY("get_property"), // Attribute functions, section 4.5 in TOSCA 1.3 GET_ATTRIBUTE("get_attribute"), - // Operation functions, section 4.6 in TOSCA 1.3 GET_OPERATION_OUTPUT("get_operation_output"), - // Navigation functions, section 4.7 in TOSCA 1.3 GET_NODES_OF_TYPE("get_nodes_of_type"), - // Artifact functions, section 4.8 in TOSCA 1.3 GET_ARTIFACT("get_artifact"), - // non TOSCA-compliant function GET_POLICY("get_policy"); + // @formatter:of private String functionName; } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaGroupType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaGroupType.java index 92c2fc5402..fa891c09a9 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaGroupType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaGroupType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,14 +25,10 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaGroupType { - private static Configuration config = ConfigurationManager.lookup(); - - private static final String GROUP_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_GROUP_TYPE); - //TOSCA native types public static final String NATIVE_ROOT = "tosca.groups.Root"; - + private static Configuration config = ConfigurationManager.lookup(); + private static final String GROUP_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_GROUP_TYPE); //Additional types public static final String HEAT_STACK = GROUP_TYPE_PREFIX + "heat.HeatStack"; } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java index 4e74708e42..5db99e7e01 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -21,9 +20,8 @@ import org.onap.config.api.ConfigurationManager; public class ToscaInterfaceType { - private static Configuration config = ConfigurationManager.lookup(); - //TOSCA native types public static final String NATIVE_ROOT = " tosca.interfaces.Root"; public static final String NATIVE_LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard"; + private static Configuration config = ConfigurationManager.lookup(); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java index d03aa19c64..a0355f4b4d 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.datatypes; import lombok.AccessLevel; @@ -25,22 +24,7 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ToscaNodeType { - private static Configuration config = ConfigurationManager.lookup(); - - public static final String VFC_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_VFC); - public static final String CP_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_CP); - public static final String EXTERNAL_CP_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_EXTERNAL_CP); - public static final String NETWORK_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_NETWORK); - public static final String ABSTRACT_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_ABSTARCT); - public static final String RULE_NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_RULE); - public static final String NODE_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX); + private static final Configuration config = ConfigurationManager.lookup(); //TOSCA native types public static final String NATIVE_COMPUTE = "tosca.nodes.Compute"; @@ -48,58 +32,48 @@ public class ToscaNodeType { public static final String NATIVE_BLOCK_STORAGE = "tosca.nodes.BlockStorage"; public static final String NATIVE_NETWORK = "tosca.nodes.network.Network"; public static final String NATIVE_NETWORK_PORT = "tosca.nodes.network.Port"; - + public static final String ABSTRACT_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_ABSTARCT); + public static final String NESTED_HEAT_RESOURCE_TYPE_PREFIX = ABSTRACT_NODE_TYPE_PREFIX + "heat."; + public static final String VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX = NESTED_HEAT_RESOURCE_TYPE_PREFIX + "subinterface."; + public static final String COMPUTE_TYPE_PREFIX = "org.openecomp.resource.vfc.compute.nodes.heat"; + public static final String VFC_TYPE_PREFIX = "org.openecomp.resource.vfc.nodes.heat"; + public static final String GROUP_TYPE_PREFIX = "org.openecomp.groups"; + public static final String VFC_INSTANCE_GROUP = ".VfcInstanceGroup"; + public static final String VFC_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_VFC); //Additional types public static final String NOVA_SERVER = VFC_NODE_TYPE_PREFIX + "heat.nova.Server"; public static final String CINDER_VOLUME = VFC_NODE_TYPE_PREFIX + "heat.cinder.Volume"; public static final String COMPUTE = VFC_NODE_TYPE_PREFIX + "Compute"; public static final String CONTRAIL_COMPUTE = VFC_NODE_TYPE_PREFIX + "heat.contrail.Compute"; - - public static final String NEUTRON_SECURITY_RULES = - RULE_NODE_TYPE_PREFIX + "heat.network.neutron.SecurityRules"; - public static final String CONTRAILV2_NETWORK_RULE = - RULE_NODE_TYPE_PREFIX + "heat.network.contrailV2.NetworkRules"; - public static final String CONTRAIL_NETWORK_RULE = - RULE_NODE_TYPE_PREFIX + "heat.network.contrail.NetworkRules"; - - public static final String NEUTRON_NET = NETWORK_NODE_TYPE_PREFIX + "heat.network.neutron.Net"; - public static final String CONTRAILV2_VIRTUAL_NETWORK = - NETWORK_NODE_TYPE_PREFIX + "heat.network.contrailV2.VirtualNetwork"; - public static final String CONTRAIL_VIRTUAL_NETWORK = - NETWORK_NODE_TYPE_PREFIX + "heat.network.contrail.VirtualNetwork"; - public static final String NETWORK = NETWORK_NODE_TYPE_PREFIX + "network.Network"; - + public static final String CP_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_CP); public static final String NEUTRON_PORT = CP_NODE_TYPE_PREFIX + "heat.network.neutron.Port"; - public static final String CONTRAILV2_VIRTUAL_MACHINE_INTERFACE = - CP_NODE_TYPE_PREFIX + "heat.contrailV2.VirtualMachineInterface"; + public static final String CONTRAILV2_VIRTUAL_MACHINE_INTERFACE = CP_NODE_TYPE_PREFIX + "heat.contrailV2.VirtualMachineInterface"; public static final String CONTRAIL_PORT = CP_NODE_TYPE_PREFIX + "heat.network.contrail.Port"; public static final String NETWORK_PORT = CP_NODE_TYPE_PREFIX + "network.Port"; - public static final String CONTRAILV2_VLAN_SUB_INTERFACE = CP_NODE_TYPE_PREFIX - + "heat.network.v2.contrailV2.VLANSubInterface"; - public static final String NESTED_HEAT_RESOURCE_TYPE_PREFIX = ABSTRACT_NODE_TYPE_PREFIX + "heat."; - public static final String VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX = - NESTED_HEAT_RESOURCE_TYPE_PREFIX + "subinterface."; + public static final String CONTRAILV2_VLAN_SUB_INTERFACE = CP_NODE_TYPE_PREFIX + "heat.network.v2.contrailV2.VLANSubInterface"; + public static final String EXTERNAL_CP_NODE_TYPE_PREFIX = config + .getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_EXTERNAL_CP); //Port Mirroring external node types public static final String EXTERNAL_CP = EXTERNAL_CP_NODE_TYPE_PREFIX + "extCP"; - public static final String EXTERNAL_CONTRAIL_PORT = EXTERNAL_CP_NODE_TYPE_PREFIX - + "extContrailCP"; - public static final String EXTERNAL_VMI_PORT = EXTERNAL_CP_NODE_TYPE_PREFIX - + "extVirtualMachineInterfaceCP"; + public static final String EXTERNAL_CONTRAIL_PORT = EXTERNAL_CP_NODE_TYPE_PREFIX + "extContrailCP"; + public static final String EXTERNAL_VMI_PORT = EXTERNAL_CP_NODE_TYPE_PREFIX + "extVirtualMachineInterfaceCP"; public static final String EXTERNAL_NEUTRON_PORT = EXTERNAL_CP_NODE_TYPE_PREFIX + "extNeutronCP"; - + public static final String NETWORK_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_NETWORK); + public static final String NEUTRON_NET = NETWORK_NODE_TYPE_PREFIX + "heat.network.neutron.Net"; + public static final String CONTRAILV2_VIRTUAL_NETWORK = NETWORK_NODE_TYPE_PREFIX + "heat.network.contrailV2.VirtualNetwork"; + public static final String CONTRAIL_VIRTUAL_NETWORK = NETWORK_NODE_TYPE_PREFIX + "heat.network.contrail.VirtualNetwork"; + public static final String NETWORK = NETWORK_NODE_TYPE_PREFIX + "network.Network"; public static final String ABSTRACT_SUBSTITUTE = ABSTRACT_NODE_TYPE_PREFIX + "AbstractSubstitute"; public static final String VFC_ABSTRACT_SUBSTITUTE = ABSTRACT_NODE_TYPE_PREFIX + "VFC"; - public static final String CONTRAIL_ABSTRACT_SUBSTITUTE = - ABSTRACT_NODE_TYPE_PREFIX + "contrail.AbstractSubstitute"; + public static final String CONTRAIL_ABSTRACT_SUBSTITUTE = ABSTRACT_NODE_TYPE_PREFIX + "contrail.AbstractSubstitute"; public static final String COMPLEX_VFC_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "ComplexVFC"; //Questionnaire to Tosca Types public static final String VNF_CONFIG_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "VnfConfiguration"; public static final String MULTIFLAVOR_VFC_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "MultiFlavorVFC"; - public static final String MULTIDEPLOYMENTFLAVOR_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX - + "MultiDeploymentFlavor.CVFC"; - public static final String COMPUTE_TYPE_PREFIX = "org.openecomp.resource.vfc.compute.nodes.heat"; - public static final String VFC_TYPE_PREFIX = "org.openecomp.resource.vfc.nodes.heat"; - public static final String GROUP_TYPE_PREFIX = "org.openecomp.groups"; - public static final String VFC_INSTANCE_GROUP = ".VfcInstanceGroup"; + public static final String MULTIDEPLOYMENTFLAVOR_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "MultiDeploymentFlavor.CVFC"; + public static final String RULE_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_RULE); + public static final String NEUTRON_SECURITY_RULES = RULE_NODE_TYPE_PREFIX + "heat.network.neutron.SecurityRules"; + public static final String CONTRAILV2_NETWORK_RULE = RULE_NODE_TYPE_PREFIX + "heat.network.contrailV2.NetworkRules"; + public static final String CONTRAIL_NETWORK_RULE = RULE_NODE_TYPE_PREFIX + "heat.network.contrail.NetworkRules"; + public static final String NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX); } - diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaPolicyType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaPolicyType.java index 39383f1ef8..90af85053b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaPolicyType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaPolicyType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,14 +25,10 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaPolicyType { - private static Configuration config = ConfigurationManager.lookup(); - - private static final String POLICY_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_POLICY_TYPE); - //TOSCA native types public static final String NATIVE_PLACEMENT = "tosca.policy.placement"; - + private static Configuration config = ConfigurationManager.lookup(); + private static final String POLICY_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_POLICY_TYPE); //Additional types public static final String PLACEMENT_ANTILOCATE = POLICY_TYPE_PREFIX + "placement.Antilocate"; public static final String PLACEMENT_COLOCATE = POLICY_TYPE_PREFIX + "placement.Colocate"; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaRelationshipType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaRelationshipType.java index 370911b1ad..8d1860d9c1 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaRelationshipType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaRelationshipType.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import org.onap.config.api.Configuration; @@ -26,18 +25,13 @@ import org.openecomp.sdc.tosca.services.ConfigConstants; public class ToscaRelationshipType { - private static Configuration config = ConfigurationManager.lookup(); - - private static final String RELATIONSHIP_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_RELATIONSHIP_TYPE); - public static final String NATIVE_ROOT = "tosca.relationships.Root"; public static final String NATIVE_ATTACHES_TO = "tosca.relationships.AttachesTo"; public static final String NATIVE_DEPENDS_ON = "tosca.relationships.DependsOn"; public static final String NATIVE_NETWORK_LINK_TO = "tosca.relationships.network.LinksTo"; public static final String NATIVE_NETWORK_BINDS_TO = "tosca.relationships.network.BindsTo"; - public static final String CINDER_VOLUME_ATTACHES_TO = - RELATIONSHIP_TYPE_PREFIX + "VolumeAttachesTo"; + private static Configuration config = ConfigurationManager.lookup(); + private static final String RELATIONSHIP_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_RELATIONSHIP_TYPE); + public static final String CINDER_VOLUME_ATTACHES_TO = RELATIONSHIP_TYPE_PREFIX + "VolumeAttachesTo"; public static final String ATTACHES_TO = RELATIONSHIP_TYPE_PREFIX + "AttachesTo"; - } 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 bbbcb202ef..90e1d2e863 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 @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; import java.util.Collections; @@ -50,6 +49,16 @@ public class ToscaServiceModel implements AsdcModel { private String entryDefinitionServiceTemplate; /** + * Gets cloned service model. + * + * @param toscaServiceModel the tosca service model + * @return the cloned service model + */ + public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) { + return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel)); + } + + /** * Gets service templates. * * @return the service templates @@ -59,26 +68,13 @@ public class ToscaServiceModel implements AsdcModel { } public Optional<ServiceTemplate> getServiceTemplate(String serviceTemplateName) { - return MapUtils.isEmpty(this.serviceTemplates) ? Optional.empty() - : Optional.of(this.serviceTemplates.get(serviceTemplateName)); + return MapUtils.isEmpty(this.serviceTemplates) ? Optional.empty() : Optional.of(this.serviceTemplates.get(serviceTemplateName)); } - public void addServiceTemplate(String serviceTemplateName, - ServiceTemplate serviceTemplate) { + public void addServiceTemplate(String serviceTemplateName, ServiceTemplate serviceTemplate) { if (MapUtils.isEmpty(serviceTemplates)) { serviceTemplates = new HashMap<>(); } - serviceTemplates.put(serviceTemplateName, serviceTemplate); } - - /** - * Gets cloned service model. - * - * @param toscaServiceModel the tosca service model - * @return the cloned service model - */ - public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) { - return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel)); - } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaTopologyTemplateElements.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaTopologyTemplateElements.java index ae067cd393..1ac8b67a13 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaTopologyTemplateElements.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaTopologyTemplateElements.java @@ -7,9 +7,9 @@ * 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. @@ -17,14 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes; -public enum ToscaTopologyTemplateElements { - NODE_TEMPLATE, - RELATIONSHIP_TEMPLATE, - GROUP, - POLICY, - WORKFLOW -} - +public enum ToscaTopologyTemplateElements {NODE_TEMPLATE, RELATIONSHIP_TEMPLATE, GROUP, POLICY, WORKFLOW} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/extend/ToscaAnnotationType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/extend/ToscaAnnotationType.java index c66896d771..3406879858 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/extend/ToscaAnnotationType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/extend/ToscaAnnotationType.java @@ -13,22 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.datatypes.extend; import org.onap.config.api.Configuration; import org.onap.config.api.ConfigurationManager; import org.openecomp.sdc.tosca.services.ConfigConstants; - public class ToscaAnnotationType { - private static Configuration config = ConfigurationManager.lookup(); - public static final String ANNOTATION_TYPE_PREFIX = - config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ANNOTATION_TYPE); - - public static final String SOURCE = - ANNOTATION_TYPE_PREFIX + "Source"; - + private static Configuration config = ConfigurationManager.lookup(); + public static final String ANNOTATION_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ANNOTATION_TYPE); + public static final String SOURCE = ANNOTATION_TYPE_PREFIX + "Source"; } - diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Old1610ServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Old1610ServiceTemplate.java index 883aabba6f..90ea0e20c1 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Old1610ServiceTemplate.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Old1610ServiceTemplate.java @@ -7,9 +7,9 @@ * 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. @@ -17,144 +17,139 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.datatypes.model; -import org.onap.sdc.tosca.datatypes.model.*; - import java.util.Map; +import org.onap.sdc.tosca.datatypes.model.ArtifactType; +import org.onap.sdc.tosca.datatypes.model.CapabilityType; +import org.onap.sdc.tosca.datatypes.model.DataType; +import org.onap.sdc.tosca.datatypes.model.GroupType; +import org.onap.sdc.tosca.datatypes.model.Import; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.onap.sdc.tosca.datatypes.model.PolicyType; +import org.onap.sdc.tosca.datatypes.model.RelationshipType; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; /** * Created by Talio on 3/30/2017. */ public class Old1610ServiceTemplate { - private String tosca_definitions_version; - private Map<String, String> metadata; - private String description; - private Map<String, Import> imports; - private Map<String, ArtifactType> artifact_types; - private Map<String, DataType> data_types; - private Map<String, CapabilityType> capability_types; - private Map<String, Object> interface_types; - private Map<String, RelationshipType> relationship_types; - private Map<String, NodeType> node_types; - private Map<String, GroupType> group_types; - private Map<String, PolicyType> policy_types; - private TopologyTemplate topology_template; - - public String getTosca_definitions_version() { - return tosca_definitions_version; - } - - public void setTosca_definitions_version(String tosca_definitions_version) { - this.tosca_definitions_version = tosca_definitions_version; - } - - public Map<String, String> getMetadata() { - return metadata; - } - - public void setMetadata(Map<String, String> metadata) { - this.metadata = metadata; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - - public Map<String, Import> getImports() { - return this.imports; - } - - public void setImports( - Map<String, Import> imports) { - this.imports = imports; - } - - public Map<String, ArtifactType> getArtifact_types() { - return artifact_types; - } - - public void setArtifact_types( - Map<String, ArtifactType> artifact_types) { - this.artifact_types = artifact_types; - } - - public Map<String, DataType> getData_types() { - return data_types; - } - - public void setData_types( - Map<String, DataType> data_types) { - this.data_types = data_types; - } - - public Map<String, CapabilityType> getCapability_types() { - return capability_types; - } - - public void setCapability_types( - Map<String, CapabilityType> capability_types) { - this.capability_types = capability_types; - } - - public Map<String, Object> getInterface_types() { - return interface_types; - } - - public void setInterface_types(Map<String, Object> interface_types) { - this.interface_types = interface_types; - } - - public Map<String, RelationshipType> getRelationship_types() { - return relationship_types; - } - - public void setRelationship_types( - Map<String, RelationshipType> relationship_types) { - this.relationship_types = relationship_types; - } - - public Map<String, NodeType> getNode_types() { - return node_types; - } - - public void setNode_types( - Map<String, NodeType> node_types) { - this.node_types = node_types; - } - - public Map<String, GroupType> getGroup_types() { - return group_types; - } - - public void setGroup_types( - Map<String, GroupType> group_types) { - this.group_types = group_types; - } - - public Map<String, PolicyType> getPolicy_types() { - return policy_types; - } - - public void setPolicy_types( - Map<String, PolicyType> policy_types) { - this.policy_types = policy_types; - } - - public TopologyTemplate getTopology_template() { - return topology_template; - } - - public void setTopology_template( - TopologyTemplate topology_template) { - this.topology_template = topology_template; - } -} + private String tosca_definitions_version; + private Map<String, String> metadata; + private String description; + private Map<String, Import> imports; + private Map<String, ArtifactType> artifact_types; + private Map<String, DataType> data_types; + private Map<String, CapabilityType> capability_types; + private Map<String, Object> interface_types; + private Map<String, RelationshipType> relationship_types; + private Map<String, NodeType> node_types; + private Map<String, GroupType> group_types; + private Map<String, PolicyType> policy_types; + private TopologyTemplate topology_template; + + public String getTosca_definitions_version() { + return tosca_definitions_version; + } + + public void setTosca_definitions_version(String tosca_definitions_version) { + this.tosca_definitions_version = tosca_definitions_version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, Import> getImports() { + return this.imports; + } + + public void setImports(Map<String, Import> imports) { + this.imports = imports; + } + + public Map<String, ArtifactType> getArtifact_types() { + return artifact_types; + } + + public void setArtifact_types(Map<String, ArtifactType> artifact_types) { + this.artifact_types = artifact_types; + } + + public Map<String, DataType> getData_types() { + return data_types; + } + + public void setData_types(Map<String, DataType> data_types) { + this.data_types = data_types; + } + + public Map<String, CapabilityType> getCapability_types() { + return capability_types; + } + + public void setCapability_types(Map<String, CapabilityType> capability_types) { + this.capability_types = capability_types; + } + + public Map<String, Object> getInterface_types() { + return interface_types; + } + + public void setInterface_types(Map<String, Object> interface_types) { + this.interface_types = interface_types; + } + + public Map<String, RelationshipType> getRelationship_types() { + return relationship_types; + } + + public void setRelationship_types(Map<String, RelationshipType> relationship_types) { + this.relationship_types = relationship_types; + } + + public Map<String, NodeType> getNode_types() { + return node_types; + } + + public void setNode_types(Map<String, NodeType> node_types) { + this.node_types = node_types; + } + + public Map<String, GroupType> getGroup_types() { + return group_types; + } + + public void setGroup_types(Map<String, GroupType> group_types) { + this.group_types = group_types; + } + + public Map<String, PolicyType> getPolicy_types() { + return policy_types; + } + + public void setPolicy_types(Map<String, PolicyType> policy_types) { + this.policy_types = policy_types; + } + + public TopologyTemplate getTopology_template() { + return topology_template; + } + public void setTopology_template(TopologyTemplate topology_template) { + this.topology_template = topology_template; + } +} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java index aa5c537397..7e9e843a3a 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -25,20 +24,16 @@ import org.openecomp.sdc.common.errors.ErrorCode; public class CreateInterfaceObjectErrorBuilder { - private static final String COULD_NOT_CREATE_OBJECT_MSG = - "Could not create %s from %s. Reason - %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + private static final String COULD_NOT_CREATE_OBJECT_MSG = "Could not create %s from %s. Reason - %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - public CreateInterfaceObjectErrorBuilder(String interfaceClassName, - String interfaceId, - String reason) { - builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage( - String.format(COULD_NOT_CREATE_OBJECT_MSG, interfaceClassName, interfaceId, reason)); - } + public CreateInterfaceObjectErrorBuilder(String interfaceClassName, String interfaceId, String reason) { + builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(COULD_NOT_CREATE_OBJECT_MSG, interfaceClassName, interfaceId, reason)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java index c22fdbc07f..606763db8b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,26 +17,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; public class CreateInterfaceOperationObjectErrorBuilder { - private static final String COULD_NOT_CREATE_OBJECT_MSG = - "Could not create Operation from %s. Reason - %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - public CreateInterfaceOperationObjectErrorBuilder(String operationId, - String reason) { - builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage( - String.format(COULD_NOT_CREATE_OBJECT_MSG, operationId, reason)); - } + private static final String COULD_NOT_CREATE_OBJECT_MSG = "Could not create Operation from %s. Reason - %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + public CreateInterfaceOperationObjectErrorBuilder(String operationId, String reason) { + builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(COULD_NOT_CREATE_OBJECT_MSG, operationId, reason)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidAddActionNullEntityErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidAddActionNullEntityErrorBuilder.java index 68d7da1b36..43f76fdab6 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidAddActionNullEntityErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidAddActionNullEntityErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -25,25 +24,22 @@ import org.openecomp.sdc.common.errors.ErrorCode; public class InvalidAddActionNullEntityErrorBuilder { - private static final String INVALID_ACTION_NULL_ENTITY_ERR_MSG = - "Invalid action, can't add '%s' to '%s', '%s' entity is NULL."; - - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - - /** - * Invalid Action Error builder. - * @param addedData Added data - * @param updatedEntity Updated Entity - */ - public InvalidAddActionNullEntityErrorBuilder(String addedData, String updatedEntity) { - builder.withId(ToscaErrorCodes.TOSCA_INVALID_ADD_ACTION_NULL_ENTITY); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage( - String.format(INVALID_ACTION_NULL_ENTITY_ERR_MSG, addedData, updatedEntity, updatedEntity)); - } - - public ErrorCode build() { - return builder.build(); - } - + private static final String INVALID_ACTION_NULL_ENTITY_ERR_MSG = "Invalid action, can't add '%s' to '%s', '%s' entity is NULL."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Invalid Action Error builder. + * + * @param addedData Added data + * @param updatedEntity Updated Entity + */ + public InvalidAddActionNullEntityErrorBuilder(String addedData, String updatedEntity) { + builder.withId(ToscaErrorCodes.TOSCA_INVALID_ADD_ACTION_NULL_ENTITY); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_ACTION_NULL_ENTITY_ERR_MSG, addedData, updatedEntity, updatedEntity)); + } + + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidRequirementAssignmentErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidRequirementAssignmentErrorBuilder.java index 1947ce950b..3f50b28646 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidRequirementAssignmentErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidRequirementAssignmentErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -25,24 +24,22 @@ import org.openecomp.sdc.common.errors.ErrorCode; public class InvalidRequirementAssignmentErrorBuilder { - private static final String INVALID_REQ_ASSIGNMENT_ERR_ID = "INVALID_REQ_ASSIGNMENT_ERR_ID"; - private static final String INVALID_REQ_ASSIGNMENT_ERR_MSG = - "Invalid Requirement Assignment, Node value is NULL, Requirement ID '%s'."; - - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - - /** - * Invalid Requirement Assignment Error Builder. - * @param requirementId. - */ - public InvalidRequirementAssignmentErrorBuilder(String requirementId) { - builder.withId(INVALID_REQ_ASSIGNMENT_ERR_ID); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_REQ_ASSIGNMENT_ERR_MSG, requirementId)); - } - - public ErrorCode build() { - return builder.build(); - } - + private static final String INVALID_REQ_ASSIGNMENT_ERR_ID = "INVALID_REQ_ASSIGNMENT_ERR_ID"; + private static final String INVALID_REQ_ASSIGNMENT_ERR_MSG = "Invalid Requirement Assignment, Node value is NULL, Requirement ID '%s'."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Invalid Requirement Assignment Error Builder. + * + * @param requirementId. + */ + public InvalidRequirementAssignmentErrorBuilder(String requirementId) { + builder.withId(INVALID_REQ_ASSIGNMENT_ERR_ID); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_REQ_ASSIGNMENT_ERR_MSG, requirementId)); + } + + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaFile.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaFile.java index 1bea2bbce6..d7a8ceb90b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaFile.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaFile.java @@ -17,17 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; - public class InvalidToscaFile { - private static final String INVALID_TOSCA_FILE = - "Tosca file '%s' is not following TOSCA spec, can't be parsed. Related error - '%s'"; + private static final String INVALID_TOSCA_FILE = "Tosca file '%s' is not following TOSCA spec, can't be parsed. Related error - '%s'"; private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); /** diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaMetaFile.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaMetaFile.java index 54e22c97ae..5b03ceba43 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaMetaFile.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/InvalidToscaMetaFile.java @@ -17,13 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; - public class InvalidToscaMetaFile { private static final String INVALID_TOSCA_META_FILE = "Missing data - TOSCA.meta file must include '%s' data."; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaElementTypeNotFoundErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaElementTypeNotFoundErrorBuilder.java index dd33bf79a2..5b486ea513 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaElementTypeNotFoundErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaElementTypeNotFoundErrorBuilder.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -23,28 +22,28 @@ import org.openecomp.sdc.common.errors.ErrorCode; * The type Tosca data type not found error builder. */ public class ToscaElementTypeNotFoundErrorBuilder { - private static final String ENTRY_NOT_FOUND_MSG = - "Entity Type '%s' or one of its derivedFrom type hierarchy, " - + "is not defined in tosca service model"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca data type not found error builder. - * - * @param elementType element type - */ - public ToscaElementTypeNotFoundErrorBuilder(String elementType) { - builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, elementType)); - } + private static final String ENTRY_NOT_FOUND_MSG = + "Entity Type '%s' or one of its derivedFrom type hierarchy, " + "is not defined in tosca service model"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Tosca data type not found error builder. + * + * @param elementType element type + */ + public ToscaElementTypeNotFoundErrorBuilder(String elementType) { + builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, elementType)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaEntryDefinitionWasNotFound.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaEntryDefinitionWasNotFound.java index bb34d3a485..2b259cc6ce 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaEntryDefinitionWasNotFound.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaEntryDefinitionWasNotFound.java @@ -17,13 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; - public class ToscaEntryDefinitionWasNotFound { private static final String ENTRY_DEFINITION_WAS_NOT_FOUND = "TOSCA Entry Definition was not found"; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java index aec4091e68..eed9742fa8 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java @@ -17,28 +17,22 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; class ToscaErrorCodes { - private ToscaErrorCodes() { - throw new IllegalStateException("Utility class"); - } - - static final String INVALID_SUBSTITUTE_NODE_TEMPLATE = "INVALID_SUBSTITUTE_NODE_TEMPLATE"; - static final String INVALID_SUBSTITUTION_SERVICE_TEMPLATE = - "INVALID_SUBSTITUTION_SERVICE_TEMPLATE"; - static final String TOSCA_ENTRY_NOT_FOUND = "TOSCA_ENTRY_NOT_FOUND"; - static final String MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP = - "MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP"; - static final String TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE = - "TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE"; - static final String TOSCA_INVALID_ADD_ACTION_NULL_ENTITY = "TOSCA_INVALID_ADD_ACTION_NULL_ENTITY"; - static final String INVALID_INTERFACE_VALUE = "INVALID_INTERFACE_VALUE"; - static final String INVALID_TOSCA_FILE = "INVALID_TOSCA_FILE"; - static final String INVALID_TOSCA_META_FILE = "INVALID_TOSCA_META_FILE"; - static final String INVALID_TOSCA_ENTRY_DEF_WAS_NOT_FOUND = "INVALID_TOSCA_ENTRY_DEF_WAS_NOT_FOUND"; - + static final String INVALID_SUBSTITUTE_NODE_TEMPLATE = "INVALID_SUBSTITUTE_NODE_TEMPLATE"; + static final String INVALID_SUBSTITUTION_SERVICE_TEMPLATE = "INVALID_SUBSTITUTION_SERVICE_TEMPLATE"; + static final String TOSCA_ENTRY_NOT_FOUND = "TOSCA_ENTRY_NOT_FOUND"; + static final String MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP = "MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP"; + static final String TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE = "TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE"; + static final String TOSCA_INVALID_ADD_ACTION_NULL_ENTITY = "TOSCA_INVALID_ADD_ACTION_NULL_ENTITY"; + static final String INVALID_INTERFACE_VALUE = "INVALID_INTERFACE_VALUE"; + static final String INVALID_TOSCA_FILE = "INVALID_TOSCA_FILE"; + static final String INVALID_TOSCA_META_FILE = "INVALID_TOSCA_META_FILE"; + static final String INVALID_TOSCA_ENTRY_DEF_WAS_NOT_FOUND = "INVALID_TOSCA_ENTRY_DEF_WAS_NOT_FOUND"; + private ToscaErrorCodes() { + throw new IllegalStateException("Utility class"); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaFileNotFoundErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaFileNotFoundErrorBuilder.java index b06cd1f625..fa07f61424 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaFileNotFoundErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaFileNotFoundErrorBuilder.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -23,27 +22,27 @@ import org.openecomp.sdc.common.errors.ErrorCode; * The Tosca file not found error builder. */ public class ToscaFileNotFoundErrorBuilder { - private static final String ENTRY_NOT_FOUND_MSG = - "Tosca file '%s' was not found in tosca service model"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca file not found error builder. - * - * @param fileName the file name - */ - public ToscaFileNotFoundErrorBuilder(String fileName) { - builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, fileName)); - } + private static final String ENTRY_NOT_FOUND_MSG = "Tosca file '%s' was not found in tosca service model"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Tosca file not found error builder. + * + * @param fileName the file name + */ + public ToscaFileNotFoundErrorBuilder(String fileName) { + builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, fileName)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidEntryNotFoundErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidEntryNotFoundErrorBuilder.java index 7e05d18755..4495eb9c2d 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidEntryNotFoundErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidEntryNotFoundErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -27,29 +26,29 @@ import org.openecomp.sdc.common.errors.ErrorCode; * The type Tosca invalid entry not found error builder. */ public class ToscaInvalidEntryNotFoundErrorBuilder { - // - private static final String ENTRY_NOT_FOUND_MSG = - "Invalid Tosca model data, missing '%s' entry for '%s' id %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca invalid entry not found error builder. - * - * @param entryName the entry name - * @param entryId the entry id - */ - public ToscaInvalidEntryNotFoundErrorBuilder(String entryName, String entryId) { - builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, entryName, entryName, entryId)); - } + // + private static final String ENTRY_NOT_FOUND_MSG = "Invalid Tosca model data, missing '%s' entry for '%s' id %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Tosca invalid entry not found error builder. + * + * @param entryName the entry name + * @param entryId the entry id + */ + public ToscaInvalidEntryNotFoundErrorBuilder(String entryName, String entryId) { + builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, entryName, entryName, entryId)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java index 5ba8a59d7d..b6c444a1d5 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -25,17 +24,16 @@ import org.openecomp.sdc.common.errors.ErrorCode; public class ToscaInvalidInterfaceValueErrorBuilder { - private static final String INVALID_INTERFACE_MSG = - "Cannot create interface object. reason - %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + private static final String INVALID_INTERFACE_MSG = "Cannot create interface object. reason - %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - public ToscaInvalidInterfaceValueErrorBuilder(String reason) { - builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_INTERFACE_MSG, reason)); - } + public ToscaInvalidInterfaceValueErrorBuilder(String reason) { + builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_INTERFACE_MSG, reason)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplateErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplateErrorBuilder.java index bab2e77c75..b41ea13668 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplateErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplateErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,39 +17,37 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; - /** * The type Tosca invalid substitute node template error builder. */ public class ToscaInvalidSubstituteNodeTemplateErrorBuilder { - private static final String INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG = - "Invalid substitute node template, directives with substitutable value must be defined." - + " node template id %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca invalid substitute node template error builder. - * - * @param nodeTemplateId the node template id - */ - public ToscaInvalidSubstituteNodeTemplateErrorBuilder(String nodeTemplateId) { - builder.withId(ToscaErrorCodes.TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG, nodeTemplateId)); - } + private static final String INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG = + "Invalid substitute node template, directives with substitutable value must be defined." + " node template id %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Tosca invalid substitute node template error builder. + * + * @param nodeTemplateId the node template id + */ + public ToscaInvalidSubstituteNodeTemplateErrorBuilder(String nodeTemplateId) { + builder.withId(ToscaErrorCodes.TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG, nodeTemplateId)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder.java index 90c681efc9..dac2a7cd99 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,43 +17,39 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.tosca.services.ToscaConstants; - /** * The type Tosca invalid substitute node template properties error builder. */ public class ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder { - private static final String INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG = - "Invalid Substitute Node Template %s, mandatory map property %s with mandatory " - + "key %s must be defined."; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + private static final String INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG = + "Invalid Substitute Node Template %s, mandatory map property %s with mandatory " + "key %s must be defined."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca invalid substitute node template properties error builder. - * - * @param nodeTemplateId the node template id - */ - public ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(String nodeTemplateId) { - builder.withId(ToscaErrorCodes.INVALID_SUBSTITUTE_NODE_TEMPLATE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG, nodeTemplateId, - ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, - ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME)); - } + /** + * Instantiates a new Tosca invalid substitute node template properties error builder. + * + * @param nodeTemplateId the node template id + */ + public ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(String nodeTemplateId) { + builder.withId(ToscaErrorCodes.INVALID_SUBSTITUTE_NODE_TEMPLATE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_SUBSTITUTE_NODE_TEMPLATE_MSG, nodeTemplateId, ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, + ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstitutionServiceTemplateErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstitutionServiceTemplateErrorBuilder.java index c240992597..70de61432a 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstitutionServiceTemplateErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidSubstitutionServiceTemplateErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,41 +17,37 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; - /** * The type Tosca invalid substitution service template error builder. */ public class ToscaInvalidSubstitutionServiceTemplateErrorBuilder { - private static final String INVALID_SUBSTITUTION_SERVICE_TEMPLATE_MSG = - "Invalid Substitution Service Template %s, missing mandatory file 'Node type' " - + "in substitution mapping."; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + private static final String INVALID_SUBSTITUTION_SERVICE_TEMPLATE_MSG = + "Invalid Substitution Service Template %s, missing mandatory file 'Node type' " + "in substitution mapping."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca invalid substitution service template error builder. - * - * @param serviceTemplateFileName the service template file name - */ - public ToscaInvalidSubstitutionServiceTemplateErrorBuilder(String serviceTemplateFileName) { - builder.withId(ToscaErrorCodes.INVALID_SUBSTITUTION_SERVICE_TEMPLATE); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage( - String.format(INVALID_SUBSTITUTION_SERVICE_TEMPLATE_MSG, serviceTemplateFileName)); - } + /** + * Instantiates a new Tosca invalid substitution service template error builder. + * + * @param serviceTemplateFileName the service template file name + */ + public ToscaInvalidSubstitutionServiceTemplateErrorBuilder(String serviceTemplateFileName) { + builder.withId(ToscaErrorCodes.INVALID_SUBSTITUTION_SERVICE_TEMPLATE); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_SUBSTITUTION_SERVICE_TEMPLATE_MSG, serviceTemplateFileName)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaMissingSubstitutionMappingForReqCapErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaMissingSubstitutionMappingForReqCapErrorBuilder.java index c41e2fa137..2902d209a0 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaMissingSubstitutionMappingForReqCapErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaMissingSubstitutionMappingForReqCapErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -28,50 +27,44 @@ import org.openecomp.sdc.common.errors.ErrorCode; */ public class ToscaMissingSubstitutionMappingForReqCapErrorBuilder { - private static final String MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP_MSG = - "Invalid Substitution, Missing Substitution Mapping for %s with Id %s."; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - - /** - * Instantiates a new Tosca missing substitution mapping for req cap error builder. - * - * @param exposedEntry the exposed entry - * @param id the id - */ - public ToscaMissingSubstitutionMappingForReqCapErrorBuilder(MappingExposedEntry exposedEntry, - String id) { - builder.withId(ToscaErrorCodes.MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String - .format(MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP_MSG, exposedEntry.getDisplayName(), id)); - } + private static final String MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP_MSG = "Invalid Substitution, Missing Substitution Mapping for %s with Id %s."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Instantiates a new Tosca missing substitution mapping for req cap error builder. + * + * @param exposedEntry the exposed entry + * @param id the id + */ + public ToscaMissingSubstitutionMappingForReqCapErrorBuilder(MappingExposedEntry exposedEntry, String id) { + builder.withId(ToscaErrorCodes.MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(MISSING_SUBSTITUTION_MAPPING_FOR_REQ_CAP_MSG, exposedEntry.getDisplayName(), id)); + } - /** - * The enum Mapping exposed entry. - */ - public enum MappingExposedEntry { + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } - CAPABILITY("Capability"), - REQUIREMENT("Requirement"),; + /** + * The enum Mapping exposed entry. + */ + public enum MappingExposedEntry { + CAPABILITY("Capability"), REQUIREMENT("Requirement"); - private String displayName; + private String displayName; - MappingExposedEntry(String displayName) { - this.displayName = displayName; - } + MappingExposedEntry(String displayName) { + this.displayName = displayName; + } - public String getDisplayName() { - return displayName; + public String getDisplayName() { + return displayName; + } } - - } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaNodeTypeNotFoundErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaNodeTypeNotFoundErrorBuilder.java index 1a2c124f4f..37a16516a9 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaNodeTypeNotFoundErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaNodeTypeNotFoundErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -27,28 +26,28 @@ import org.openecomp.sdc.common.errors.ErrorCode; * The type Tosca node type not found error builder. */ public class ToscaNodeTypeNotFoundErrorBuilder { - private static final String ENTRY_NOT_FOUND_MSG = - "NodeType '%s' or one of its derivedFrom node type hierarchy, " - + "is not defined in tosca service model"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Tosca node type not found error builder. - * - * @param nodeType the node type - */ - public ToscaNodeTypeNotFoundErrorBuilder(String nodeType) { - builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, nodeType)); - } + private static final String ENTRY_NOT_FOUND_MSG = + "NodeType '%s' or one of its derivedFrom node type hierarchy, " + "is not defined in tosca service model"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Tosca node type not found error builder. + * + * @param nodeType the node type + */ + public ToscaNodeTypeNotFoundErrorBuilder(String nodeType) { + builder.withId(ToscaErrorCodes.TOSCA_ENTRY_NOT_FOUND); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(ENTRY_NOT_FOUND_MSG, nodeType)); + } - /** - * Build error code. - * - * @return the error code - */ - public ErrorCode build() { - return builder.build(); - } + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarCreationErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarCreationErrorBuilder.java index 42e38a854a..bc34f1128f 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarCreationErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarCreationErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.exceptions; import org.openecomp.sdc.common.errors.BaseErrorBuilder; @@ -25,16 +24,15 @@ import org.openecomp.sdc.common.errors.ErrorCategory; public class CsarCreationErrorBuilder extends BaseErrorBuilder { - private static final String MANDATORY_PROPERTY_IS_MISSING_MSG = - "Failed to create CSAR file from ToscaServiceModel"; - private static final String ZIP_FILE_CREATION = "ZIP_FILE_CREATION"; + private static final String MANDATORY_PROPERTY_IS_MISSING_MSG = "Failed to create CSAR file from ToscaServiceModel"; + private static final String ZIP_FILE_CREATION = "ZIP_FILE_CREATION"; - /** - * Constructor. - */ - public CsarCreationErrorBuilder() { - getErrorCodeBuilder().withId(ZIP_FILE_CREATION); - getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); - getErrorCodeBuilder().withMessage(MANDATORY_PROPERTY_IS_MISSING_MSG); - } + /** + * Constructor. + */ + public CsarCreationErrorBuilder() { + getErrorCodeBuilder().withId(ZIP_FILE_CREATION); + getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); + getErrorCodeBuilder().withMessage(MANDATORY_PROPERTY_IS_MISSING_MSG); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarMissingEntryPointErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarMissingEntryPointErrorBuilder.java index 94dd138d03..b7bfa07369 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarMissingEntryPointErrorBuilder.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/CsarMissingEntryPointErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.exceptions; import org.openecomp.sdc.common.errors.BaseErrorBuilder; @@ -25,17 +24,16 @@ import org.openecomp.sdc.common.errors.ErrorCategory; public class CsarMissingEntryPointErrorBuilder extends BaseErrorBuilder { - private static final String MANDATORY_PROPERTY_IS_MISSING_MSG = - "Failed to create CSAR file from ToscaServiceModel,missing mandatory " - + "EntryDefinitionServiceTemplate "; - private static final String ZIP_FILE_CREATION = "ZIP_FILE_CREATION__MISSING_ENTRY_DEFINITION"; + private static final String MANDATORY_PROPERTY_IS_MISSING_MSG = + "Failed to create CSAR file from ToscaServiceModel,missing mandatory " + "EntryDefinitionServiceTemplate "; + private static final String ZIP_FILE_CREATION = "ZIP_FILE_CREATION__MISSING_ENTRY_DEFINITION"; - /** - * Constructor. - */ - public CsarMissingEntryPointErrorBuilder() { - getErrorCodeBuilder().withId(ZIP_FILE_CREATION); - getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); - getErrorCodeBuilder().withMessage(MANDATORY_PROPERTY_IS_MISSING_MSG); - } + /** + * Constructor. + */ + public CsarMissingEntryPointErrorBuilder() { + getErrorCodeBuilder().withId(ZIP_FILE_CREATION); + getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); + getErrorCodeBuilder().withMessage(MANDATORY_PROPERTY_IS_MISSING_MSG); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/OnboardingManifestInstantiationException.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/OnboardingManifestInstantiationException.java index c637623926..f3b578265b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/OnboardingManifestInstantiationException.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/exceptions/OnboardingManifestInstantiationException.java @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.exceptions; /** @@ -28,4 +27,4 @@ public class OnboardingManifestInstantiationException extends RuntimeException { public OnboardingManifestInstantiationException(String message, Throwable e) { super(message, e); } -}
\ No newline at end of file +} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java index 8666da9833..863d396585 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java @@ -13,31 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services; public class ConfigConstants { - //namespaces - public static final String NAMESPACE = "ToscaModel"; - - //keys - public static final String PREFIX = "tosca.entity.namespace.prefix"; - public static final String PREFIX_CAPABILITY_TYPE = PREFIX + ".capabilityType"; - public static final String PREFIX_DATA_TYPE = PREFIX + ".dataType"; - public static final String PREFIX_GROUP_TYPE = PREFIX + ".groupType"; - public static final String PREFIX_POLICY_TYPE = PREFIX + ".policyType"; - public static final String PREFIX_ARTIFACT_TYPE = PREFIX + ".artifactType"; - public static final String PREFIX_RELATIONSHIP_TYPE = PREFIX + ".relationshipType"; - public static final String PREFIX_ANNOTATION_TYPE = PREFIX + ".annotationType"; - public static final String PREFIX_NODE_TYPE_VFC = PREFIX + ".nodeType.vfc"; - public static final String PREFIX_NODE_TYPE_NETWORK = PREFIX + ".nodeType.network"; - public static final String PREFIX_NODE_TYPE_CP = PREFIX + ".nodeType.connectionPoint"; - public static final String PREFIX_NODE_TYPE_EXTERNAL_CP = PREFIX + ".nodeType" - + ".external.connectionPoint"; - public static final String PREFIX_NODE_TYPE_ABSTARCT = PREFIX + ".nodeType.abstract"; - public static final String PREFIX_NODE_TYPE_RULE = PREFIX + ".nodeType.rule"; + //namespaces + public static final String NAMESPACE = "ToscaModel"; + //keys + public static final String PREFIX = "tosca.entity.namespace.prefix"; + public static final String PREFIX_CAPABILITY_TYPE = PREFIX + ".capabilityType"; + public static final String PREFIX_DATA_TYPE = PREFIX + ".dataType"; + public static final String PREFIX_GROUP_TYPE = PREFIX + ".groupType"; + public static final String PREFIX_POLICY_TYPE = PREFIX + ".policyType"; + public static final String PREFIX_ARTIFACT_TYPE = PREFIX + ".artifactType"; + public static final String PREFIX_RELATIONSHIP_TYPE = PREFIX + ".relationshipType"; + public static final String PREFIX_ANNOTATION_TYPE = PREFIX + ".annotationType"; + public static final String PREFIX_NODE_TYPE_VFC = PREFIX + ".nodeType.vfc"; + public static final String PREFIX_NODE_TYPE_NETWORK = PREFIX + ".nodeType.network"; + public static final String PREFIX_NODE_TYPE_CP = PREFIX + ".nodeType.connectionPoint"; + public static final String PREFIX_NODE_TYPE_EXTERNAL_CP = PREFIX + ".nodeType" + ".external.connectionPoint"; + public static final String PREFIX_NODE_TYPE_ABSTARCT = PREFIX + ".nodeType.abstract"; + public static final String PREFIX_NODE_TYPE_RULE = PREFIX + ".nodeType.rule"; - private ConfigConstants() { - } + private ConfigConstants() { + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java index 22b6eb847e..f60e823916 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services; import java.io.ByteArrayInputStream; @@ -30,7 +29,6 @@ import java.util.ListIterator; import java.util.Map; import java.util.Objects; import java.util.Optional; - import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -84,13 +82,10 @@ public class DataModelUtil { * @param serviceTemplate the service template * @param substitutionMapping the substitution mapping */ - public static void addSubstitutionMapping(ServiceTemplate serviceTemplate, - SubstitutionMapping substitutionMapping) { + public static void addSubstitutionMapping(ServiceTemplate serviceTemplate, SubstitutionMapping substitutionMapping) { if (serviceTemplate == null) { - throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE) - .build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE).build()); } - if (serviceTemplate.getTopology_template() == null) { serviceTemplate.setTopology_template(new TopologyTemplate()); } @@ -117,15 +112,11 @@ public class DataModelUtil { * @param substitutionMappingRequirementId the substitution mapping requirement id * @param substitutionMappingRequirementList the substitution mapping requirement list */ - public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate, - String substitutionMappingRequirementId, + public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate, String substitutionMappingRequirementId, List<String> substitutionMappingRequirementList) { if (serviceTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements", SERVICE_TEMPLATE) - .build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements", SERVICE_TEMPLATE).build()); } - if (serviceTemplate.getTopology_template() == null) { serviceTemplate.setTopology_template(new TopologyTemplate()); } @@ -135,9 +126,8 @@ public class DataModelUtil { if (serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements() == null) { serviceTemplate.getTopology_template().getSubstitution_mappings().setRequirements(new HashMap<>()); } - serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements() - .put(substitutionMappingRequirementId, substitutionMappingRequirementList); + .put(substitutionMappingRequirementId, substitutionMappingRequirementList); } /** @@ -147,14 +137,11 @@ public class DataModelUtil { * @param substitutionMappingCapabilityId the substitution mapping capability id * @param substitutionMappingCapabilityList the substitution mapping capability list */ - public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate, - String substitutionMappingCapabilityId, + public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate, String substitutionMappingCapabilityId, List<String> substitutionMappingCapabilityList) { if (serviceTemplate == null) { - throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities", - SERVICE_TEMPLATE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities", SERVICE_TEMPLATE).build()); } - if (serviceTemplate.getTopology_template() == null) { serviceTemplate.setTopology_template(new TopologyTemplate()); } @@ -164,9 +151,8 @@ public class DataModelUtil { if (serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities() == null) { serviceTemplate.getTopology_template().getSubstitution_mappings().setCapabilities(new HashMap<>()); } - serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities() - .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList); + .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList); } /** @@ -176,11 +162,10 @@ public class DataModelUtil { * @return the service template node templates and empty map if not present */ public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) { - if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template()) - || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) { + if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template()) || MapUtils + .isEmpty(serviceTemplate.getTopology_template().getNode_templates())) { return new HashMap<>(); } - return serviceTemplate.getTopology_template().getNode_templates(); } @@ -191,11 +176,10 @@ public class DataModelUtil { * @return the service template groups and empty map if not present */ public static Map<String, GroupDefinition> getGroups(ServiceTemplate serviceTemplate) { - if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template()) - || MapUtils.isEmpty(serviceTemplate.getTopology_template().getGroups())) { + if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template()) || MapUtils + .isEmpty(serviceTemplate.getTopology_template().getGroups())) { return new HashMap<>(); } - return serviceTemplate.getTopology_template().getGroups(); } @@ -206,11 +190,9 @@ public class DataModelUtil { * @param nodeTemplateId the node template id * @param nodeTemplate the node template */ - public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId, - NodeTemplate nodeTemplate) { + public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId, NodeTemplate nodeTemplate) { if (serviceTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -233,16 +215,12 @@ public class DataModelUtil { if (MapUtils.isEmpty(capabilities)) { return; } - if (nodeType == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build()); } - if (MapUtils.isEmpty(nodeType.getCapabilities())) { nodeType.setCapabilities(new HashMap<>()); } - for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) { nodeType.getCapabilities().put(entry.getKey(), entry.getValue()); } @@ -258,19 +236,14 @@ public class DataModelUtil { if (MapUtils.isEmpty(capabilities)) { return; } - if (nodeType == null) { - throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE) - .build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build()); } - if (MapUtils.isEmpty(nodeType.getCapabilities())) { nodeType.setCapabilities(new HashMap<>()); } - if (MapUtils.isNotEmpty(capabilities)) { nodeType.setCapabilities(new HashMap<>()); - for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) { nodeType.getCapabilities().put(entry.getKey(), entry.getValue()); } @@ -284,11 +257,9 @@ public class DataModelUtil { * @param policyId the policy id * @param policyDefinition the policy definition */ - public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId, - PolicyDefinition policyDefinition) { + public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId, PolicyDefinition policyDefinition) { if (serviceTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -318,20 +289,16 @@ public class DataModelUtil { serviceTemplate.getNode_types().put(nodeTypeId, nodeType); } - public static void addDataType(final ServiceTemplate serviceTemplate, final String key, - final DataType nodeTypeValue) { + public static void addDataType(final ServiceTemplate serviceTemplate, final String key, final DataType nodeTypeValue) { if (serviceTemplate == null) { throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Data Type", SERVICE_TEMPLATE).build()); } - if (serviceTemplate.getData_types() == null) { serviceTemplate.setData_types(new HashMap<>()); } - serviceTemplate.getData_types().put(key, nodeTypeValue); } - /** * Add relationship template. * @@ -342,8 +309,7 @@ public class DataModelUtil { public static void addRelationshipTemplate(ServiceTemplate serviceTemplate, String relationshipTemplateId, RelationshipTemplate relationshipTemplate) { if (serviceTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE).build()); } if (serviceTemplate.getTopology_template() == null) { serviceTemplate.setTopology_template(new TopologyTemplate()); @@ -351,8 +317,7 @@ public class DataModelUtil { if (serviceTemplate.getTopology_template().getRelationship_templates() == null) { serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>()); } - serviceTemplate.getTopology_template().getRelationship_templates() - .put(relationshipTemplateId, relationshipTemplate); + serviceTemplate.getTopology_template().getRelationship_templates().put(relationshipTemplateId, relationshipTemplate); } /** @@ -362,17 +327,13 @@ public class DataModelUtil { * @param requirementId the requirement id * @param requirementAssignment the requirement assignment */ - public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId, - RequirementAssignment requirementAssignment) { + public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId, RequirementAssignment requirementAssignment) { if (nodeTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", - "Node Template").build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template").build()); } if (requirementAssignment.getNode() == null) { throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build()); } - Map<String, RequirementAssignment> requirement = new HashMap<>(); requirement.put(requirementId, requirementAssignment); nodeTemplate.addRequirements(requirement); @@ -401,7 +362,7 @@ public class DataModelUtil { */ public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getNode_templates() == null) { + || serviceTemplate.getTopology_template().getNode_templates() == null) { return null; } return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId); @@ -428,8 +389,7 @@ public class DataModelUtil { * @param requirementDefinitionId the requirement definition id * @return the requirement definition */ - public static Optional<RequirementDefinition> getRequirementDefinition(NodeType nodeType, - String requirementDefinitionId) { + public static Optional<RequirementDefinition> getRequirementDefinition(NodeType nodeType, String requirementDefinitionId) { if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) { return Optional.empty(); } @@ -442,18 +402,16 @@ public class DataModelUtil { * @param requirementsDefinitionList requirement definition list * @param requirementKey requirement key */ - public static Optional<RequirementDefinition> getRequirementDefinition( - List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) { + public static Optional<RequirementDefinition> getRequirementDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList, + String requirementKey) { if (CollectionUtils.isEmpty(requirementsDefinitionList)) { return Optional.empty(); } - ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) { if (requirementMap.containsKey(requirementKey)) { - RequirementDefinition requirementDefinition = toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(requirementMap.get(requirementKey)), - RequirementDefinition.class); + RequirementDefinition requirementDefinition = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementMap.get(requirementKey)), RequirementDefinition.class); return Optional.of(requirementDefinition); } } @@ -467,8 +425,7 @@ public class DataModelUtil { * @param capabilityDefinitionId the capability definition id * @return the capability definition */ - public static Optional<CapabilityDefinition> getCapabilityDefinition(NodeType nodeType, - String capabilityDefinitionId) { + public static Optional<CapabilityDefinition> getCapabilityDefinition(NodeType nodeType, String capabilityDefinitionId) { if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) { return Optional.empty(); } @@ -482,13 +439,10 @@ public class DataModelUtil { * @param groupName the group name * @param group the group */ - public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate, String groupName, - GroupDefinition group) { + public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate, String groupName, GroupDefinition group) { if (serviceTemplate == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE).build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE).build()); } - TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { topologyTemplate = new TopologyTemplate(); @@ -501,7 +455,6 @@ public class DataModelUtil { Map<String, GroupDefinition> groups = new HashMap<>(); serviceTemplate.getTopology_template().setGroups(groups); } - serviceTemplate.getTopology_template().getGroups().put(groupName, group); } @@ -514,16 +467,13 @@ public class DataModelUtil { */ public static void addGroupMember(ServiceTemplate serviceTemplate, String groupName, String groupMemberId) { TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); - if (Objects.isNull(topologyTemplate) || topologyTemplate.getGroups() == null - || topologyTemplate.getGroups().get(groupName) == null) { + if (Objects.isNull(topologyTemplate) || topologyTemplate.getGroups() == null || topologyTemplate.getGroups().get(groupName) == null) { return; } - GroupDefinition groupDefinition = topologyTemplate.getGroups().get(groupName); if (CollectionUtils.isEmpty(groupDefinition.getMembers())) { groupDefinition.setMembers(new ArrayList<>()); } - if (!groupDefinition.getMembers().contains(groupMemberId)) { groupDefinition.getMembers().add(groupMemberId); } @@ -540,9 +490,8 @@ public class DataModelUtil { * @param defaultVal the default val * @return the property definition */ - public static ParameterDefinition createParameterDefinition(String type, String description, Boolean required, - List<Constraint> constraints, EntrySchema entrySchema, - Object defaultVal) { + public static ParameterDefinition createParameterDefinition(String type, String description, Boolean required, List<Constraint> constraints, + EntrySchema entrySchema, Object defaultVal) { ParameterDefinition paramDef = new ParameterDefinition(); paramDef.setType(type); paramDef.setDescription(description); @@ -562,8 +511,7 @@ public class DataModelUtil { * @param occurrences the occurrences * @return the requirement definition */ - public static RequirementDefinition createRequirement(String capability, String node, String relationship, - Object[] occurrences) { + public static RequirementDefinition createRequirement(String capability, String node, String relationship, Object[] occurrences) { RequirementDefinition requirementDefinition = new RequirementDefinition(); requirementDefinition.setCapability(capability); requirementDefinition.setNode(node); @@ -586,7 +534,6 @@ public class DataModelUtil { if (Objects.isNull(type) && Objects.isNull(description) && CollectionUtils.isEmpty(constraints)) { return null; } - EntrySchema entrySchema = new EntrySchema(); entrySchema.setType(type); entrySchema.setDescription(description); @@ -602,8 +549,7 @@ public class DataModelUtil { * @param nestedPropertyName the nested property name * @return the map */ - public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName, int indexInTheList, - String... nestedPropertyName) { + public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName, int indexInTheList, String... nestedPropertyName) { List<Object> propertyList = new ArrayList<>(); propertyList.add(inputPropertyListName); propertyList.add(indexInTheList); @@ -625,7 +571,6 @@ public class DataModelUtil { if (propertyDefinition == null) { return null; } - ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt(); parameterDefinition.setType(propertyDefinition.getType()); parameterDefinition.setDescription(propertyDefinition.getDescription()); @@ -633,8 +578,8 @@ public class DataModelUtil { parameterDefinition.set_default(propertyDefinition.get_default()); parameterDefinition.setStatus(propertyDefinition.getStatus()); parameterDefinition.setConstraints(propertyDefinition.getConstraints()); - parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null : - propertyDefinition.getEntry_schema().clone()); + parameterDefinition + .setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null : propertyDefinition.getEntry_schema().clone()); parameterDefinition.setHidden(false); parameterDefinition.setImmutable(false); return parameterDefinition; @@ -647,8 +592,7 @@ public class DataModelUtil { * @param outputValue the output value * @return the parameter definition ext */ - public static ParameterDefinitionExt convertAttributeDefToParameterDef(AttributeDefinition attributeDefinition, - Map<String, List> outputValue) { + public static ParameterDefinitionExt convertAttributeDefToParameterDef(AttributeDefinition attributeDefinition, Map<String, List> outputValue) { if (attributeDefinition == null) { return null; } @@ -660,7 +604,7 @@ public class DataModelUtil { public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) { return serviceTemplate.getTopology_template().getNode_templates() != null - && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null; + && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null; } /** @@ -670,13 +614,10 @@ public class DataModelUtil { * @param parameterDefinitionId the parameter definition id * @param parameterDefinition the parameter definition */ - public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate, - String parameterDefinitionId, + public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate, String parameterDefinitionId, ParameterDefinition parameterDefinition) { if (Objects.isNull(serviceTemplate)) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter", SERVICE_TEMPLATE) - .build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter", SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -696,13 +637,10 @@ public class DataModelUtil { * @param parameterDefinitionId the parameter definition id * @param parameterDefinition the parameter definition */ - public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate, - String parameterDefinitionId, + public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate, String parameterDefinitionId, ParameterDefinition parameterDefinition) { if (Objects.isNull(serviceTemplate)) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter", SERVICE_TEMPLATE) - .build()); + throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter", SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -729,7 +667,6 @@ public class DataModelUtil { if (requirementList == null) { requirementList = new ArrayList<>(); } - for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) { CommonMethods.mergeEntryInList(entry.getKey(), entry.getValue(), requirementList); } @@ -745,7 +682,6 @@ public class DataModelUtil { return null; } List<Map<String, RequirementAssignment>> templateRequirements = nodeTemplate.getRequirements(); - Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>(); if (CollectionUtils.isEmpty(templateRequirements)) { return nodeTemplateRequirementsAssignment; @@ -753,8 +689,8 @@ public class DataModelUtil { ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) { for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap.entrySet()) { - RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()), RequirementAssignment.class)); + RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()), RequirementAssignment.class)); nodeTemplateRequirementsAssignment.put(requirementEntry.getKey(), requirementAssignment); } } @@ -779,8 +715,8 @@ public class DataModelUtil { Map<String, RequirementAssignment> requirement = reqListIterator.next(); Map<String, RequirementAssignment> concreteRequirement = new HashMap<>(); for (Map.Entry<String, RequirementAssignment> reqEntry : requirement.entrySet()) { - RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()), RequirementAssignment.class)); + RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()), RequirementAssignment.class)); concreteRequirement.put(reqEntry.getKey(), requirementAssignment); concreteRequirementList.add(concreteRequirement); reqListIterator.remove(); @@ -799,19 +735,17 @@ public class DataModelUtil { * @param requirementsAssignmentList requirement definition list * @param requirementKey requirement key */ - public static Optional<List<RequirementAssignment>> getRequirementAssignment( - List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) { + public static Optional<List<RequirementAssignment>> getRequirementAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList, + String requirementKey) { if (CollectionUtils.isEmpty(requirementsAssignmentList)) { return Optional.empty(); } - List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>(); for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) { if (requirementMap.containsKey(requirementKey)) { ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(requirementMap.get(requirementKey)), - RequirementAssignment.class)); + RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementMap.get(requirementKey)), RequirementAssignment.class)); matchRequirementAssignmentList.add(requirementAssignment); } } @@ -827,12 +761,10 @@ public class DataModelUtil { * @param requirementsDefinitionList requirement definition list * @param requirementKey requirement key */ - public static void removeRequirementsDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList, - String requirementKey) { + public static void removeRequirementsDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) { if (requirementsDefinitionList == null) { return; } - List<Map<String, RequirementDefinition>> mapToBeRemoved = new ArrayList<>(); for (Map<String, RequirementDefinition> reqMap : requirementsDefinitionList) { reqMap.remove(requirementKey); @@ -851,12 +783,10 @@ public class DataModelUtil { * @param requirementsAssignmentList requirement Assignment list * @param requirementKey requirement key */ - public static void removeRequirementsAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList, - String requirementKey) { + public static void removeRequirementsAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) { if (requirementsAssignmentList == null) { return; } - List<Map<String, RequirementAssignment>> mapToBeRemoved = new ArrayList<>(); for (Map<String, RequirementAssignment> reqMap : requirementsAssignmentList) { reqMap.remove(requirementKey); @@ -869,7 +799,6 @@ public class DataModelUtil { } } - /** * Remove requirement assignment. * @@ -884,19 +813,14 @@ public class DataModelUtil { if (nodeTemplateRequirements == null) { return; } - ListIterator<Map<String, RequirementAssignment>> iter = nodeTemplateRequirements.listIterator(); while (iter.hasNext()) { Map<String, RequirementAssignment> reqMap = iter.next(); RequirementAssignment requirementAssignment = reqMap.get(requirementKey); if (requirementAssignment != null) { boolean isDesiredRequirementAssignment = toscaAnalyzerService - .isDesiredRequirementAssignment(requirementAssignment, - requirementAssignmentToBeDeleted - .getCapability(), - requirementAssignmentToBeDeleted.getNode(), - requirementAssignmentToBeDeleted - .getRelationship()); + .isDesiredRequirementAssignment(requirementAssignment, requirementAssignmentToBeDeleted.getCapability(), + requirementAssignmentToBeDeleted.getNode(), requirementAssignmentToBeDeleted.getRelationship()); if (isDesiredRequirementAssignment) { iter.remove(); } @@ -946,7 +870,7 @@ public class DataModelUtil { */ public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate, String outputParameterId) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getOutputs() == null) { + || serviceTemplate.getTopology_template().getOutputs() == null) { return null; } return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId); @@ -959,8 +883,7 @@ public class DataModelUtil { * @return the input parameters */ public static Map<String, ParameterDefinition> getInputParameters(ServiceTemplate serviceTemplate) { - if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getInputs() == null) { + if (serviceTemplate == null || serviceTemplate.getTopology_template() == null || serviceTemplate.getTopology_template().getInputs() == null) { return null; } return serviceTemplate.getTopology_template().getInputs(); @@ -974,7 +897,7 @@ public class DataModelUtil { */ public static Map<String, RelationshipTemplate> getRelationshipTemplates(ServiceTemplate serviceTemplate) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getRelationship_templates() == null) { + || serviceTemplate.getTopology_template().getRelationship_templates() == null) { return null; } return serviceTemplate.getTopology_template().getRelationship_templates(); @@ -1001,11 +924,10 @@ public class DataModelUtil { * @param nodeTemplateId node template id * @return node template properties */ - public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate, - String nodeTemplateId) { + public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate, String nodeTemplateId) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getNode_templates() == null - || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) { + || serviceTemplate.getTopology_template().getNode_templates() == null + || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) { return null; } return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId).getProperties(); @@ -1022,11 +944,9 @@ public class DataModelUtil { if (Objects.isNull(nodeTemplate)) { return; } - if (MapUtils.isEmpty(nodeTemplate.getProperties())) { nodeTemplate.setProperties(new HashMap<>()); } - nodeTemplate.getProperties().put(propertyKey, propertyValue); } @@ -1038,13 +958,12 @@ public class DataModelUtil { */ public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) { + || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) { return null; } return serviceTemplate.getTopology_template().getSubstitution_mappings(); } - /** * Compare two requirement assignment objects for equality. * @@ -1053,8 +972,8 @@ public class DataModelUtil { * @return true if objects are equal and false otherwise */ public static boolean compareRequirementAssignment(RequirementAssignment first, RequirementAssignment second) { - return (first.getCapability().equals(second.getCapability()) && first.getNode().equals(second.getNode()) - && first.getRelationship().equals(second.getRelationship())); + return (first.getCapability().equals(second.getCapability()) && first.getNode().equals(second.getNode()) && first.getRelationship() + .equals(second.getRelationship())); } /** @@ -1138,15 +1057,13 @@ public class DataModelUtil { * @param mapping the mapping * @return the substitution mapping */ - public static SubstitutionMapping createSubstitutionTemplateSubMapping(String nodeTypeKey, - NodeType substitutionNodeType, + public static SubstitutionMapping createSubstitutionTemplateSubMapping(String nodeTypeKey, NodeType substitutionNodeType, Map<String, Map<String, List<String>>> mapping) { SubstitutionMapping substitutionMapping = new SubstitutionMapping(); substitutionMapping.setNode_type(nodeTypeKey); - substitutionMapping.setCapabilities(manageCapabilityMapping(substitutionNodeType.getCapabilities(), - mapping.get(ToscaConstants.CAPABILITY))); - substitutionMapping.setRequirements( - manageRequirementMapping(substitutionNodeType.getRequirements(), mapping.get(ToscaConstants.REQUIREMENT))); + substitutionMapping.setCapabilities(manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get(ToscaConstants.CAPABILITY))); + substitutionMapping + .setRequirements(manageRequirementMapping(substitutionNodeType.getRequirements(), mapping.get(ToscaConstants.REQUIREMENT))); return substitutionMapping; } @@ -1158,8 +1075,7 @@ public class DataModelUtil { * @param capabilityProperties the capability properties * @param capabilityAttributes the capability attributes */ - public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId, - Map<String, Object> capabilityProperties, + public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId, Map<String, Object> capabilityProperties, Map<String, Object> capabilityAttributes) { Map<String, CapabilityAssignment> capabilities = nodeTemplate.getCapabilities(); if (Objects.isNull(capabilities)) { @@ -1172,9 +1088,8 @@ public class DataModelUtil { nodeTemplate.setCapabilities(capabilities); } - private static Map<String, List<String>> manageRequirementMapping( - List<Map<String, RequirementDefinition>> requirementList, - Map<String, List<String>> requirementSubstitutionMapping) { + private static Map<String, List<String>> manageRequirementMapping(List<Map<String, RequirementDefinition>> requirementList, + Map<String, List<String>> requirementSubstitutionMapping) { if (requirementList == null) { return null; } @@ -1196,7 +1111,6 @@ public class DataModelUtil { if (capabilities == null) { return null; } - Map<String, List<String>> capabilityMapping = new HashMap<>(); String capabilityKey; List<String> capabilityMap; @@ -1208,8 +1122,7 @@ public class DataModelUtil { return capabilityMapping; } - public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType, - List<Map<String, RequirementDefinition>> requirementsList, + public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType, List<Map<String, RequirementDefinition>> requirementsList, String templateName) { if (CollectionUtils.isEmpty(requirementsList)) { return; @@ -1217,7 +1130,6 @@ public class DataModelUtil { if (substitutionNodeType.getRequirements() == null) { substitutionNodeType.setRequirements(new ArrayList<>()); } - for (Map<String, RequirementDefinition> requirementDef : requirementsList) { for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) { Map<String, RequirementDefinition> requirementMap = new HashMap<>(); @@ -1228,8 +1140,7 @@ public class DataModelUtil { } public static boolean isNodeTemplateSectionMissingFromServiceTemplate(ServiceTemplate serviceTemplate) { - return Objects.isNull(serviceTemplate.getTopology_template()) || MapUtils.isEmpty( - serviceTemplate.getTopology_template().getNode_templates()); + return Objects.isNull(serviceTemplate.getTopology_template()) || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates()); } /** @@ -1239,15 +1150,12 @@ public class DataModelUtil { * @param relationshipId the relationship id * @return the relationship template */ - public static Optional<RelationshipTemplate> getRelationshipTemplate(ServiceTemplate serviceTemplate, - String relationshipId) { + public static Optional<RelationshipTemplate> getRelationshipTemplate(ServiceTemplate serviceTemplate, String relationshipId) { if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getRelationship_templates() == null - || serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId) == null) { + || serviceTemplate.getTopology_template().getRelationship_templates() == null + || serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId) == null) { return Optional.empty(); } return Optional.of(serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId)); } - - } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java index b21d847a07..b15f32644a 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java @@ -13,78 +13,76 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services; -import org.onap.sdc.tosca.datatypes.model.*; -import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; -import org.openecomp.sdc.tosca.datatypes.ToscaFlatData; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; - import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; +import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType; +import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; +import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; +import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; +import org.openecomp.sdc.tosca.datatypes.ToscaFlatData; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; public interface ToscaAnalyzerService { /* node template with type equal to node type or derived from node type */ - Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, - ToscaServiceModel toscaServiceModel); + Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, ToscaServiceModel toscaServiceModel); Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate> serviceTemplates); - boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel); + boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel); boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel); + ToscaServiceModel toscaServiceModel); - boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel); + boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel); boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel); + ToscaServiceModel toscaServiceModel); List<RequirementAssignment> getRequirements(NodeTemplate nodeTemplate, String requirementId); Optional<NodeTemplate> getNodeTemplateById(ServiceTemplate serviceTemplate, String nodeTemplateId); - Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId, - NodeTemplate substitutableNodeTemplate); + Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId, NodeTemplate substitutableNodeTemplate); Map<String, NodeTemplate> getSubstitutableNodeTemplates(ServiceTemplate serviceTemplate); Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(String substituteServiceTemplateFileName, - ServiceTemplate substituteServiceTemplate, - String requirementId); + ServiceTemplate substituteServiceTemplate, + String requirementId); /* match only for the input which is not null */ - boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability, String node, - String relationship); + boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability, String node, String relationship); - ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String type, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaModel); + ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String type, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel); boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate); - NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, - String nodeTypeDerivedFromValue); + NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, String nodeTypeDerivedFromValue); - boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId, - RequirementAssignment requirementAssignment); + boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId, RequirementAssignment requirementAssignment); Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(ServiceTemplate substitutionServiceTemplate); Map<String, CapabilityDefinition> calculateExposedCapabilities(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, - Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap); + Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap); List<Map<String, RequirementDefinition>> calculateExposedRequirements(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList, - Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment); + Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment); ToscaServiceModel loadToscaCsarPackage(byte[] toscaCsarPackage); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java index ea9a6cde04..509553db8d 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services; - - public class ToscaConstants { //TOSCA Requirement Ids @@ -27,13 +24,10 @@ public class ToscaConstants { public static final String LOCAL_STORAGE_REQUIREMENT_ID = "local_storage"; public static final String NETWORK_REQUIREMENT_ID = "network"; public static final String PORT_REQUIREMENT_ID = "port"; - //TOSCA Capability Ids public static final String PORT_MIRRORING_CAPABILITY_ID = "port_mirroring"; - //TOSCA Annotation Ids public static final String SOURCE_ANNOTATION_ID = "source"; - //General public static final String TOSCA_DEFINITIONS_VERSION = "tosca_simple_yaml_1_0_0"; public static final String MODELABLE_ENTITY_NAME_SELF = "SELF"; @@ -66,15 +60,14 @@ public class ToscaConstants { // properties valid values public static final String HEAT_SOURCE_TYPE = "HEAT"; public static final String CONTRAIL_SERVICE_INSTANCE_IND = "contrail_service_instance_ind"; - static final String ST_METADATA_FILE_NAME = "filename"; public static final String MANDATORY_PROPERTY_NAME = "mandatory"; public static final String HEAT_NODE_TYPE_SUFFIX = "heat."; public static final String CAPABILITY = "capability"; public static final String REQUIREMENT = "requirement"; public static final String SERVICE_TEMPLATE_FILE_POSTFIX = "ServiceTemplate.yaml"; + static final String ST_METADATA_FILE_NAME = "filename"; private ToscaConstants() { //Hiding the implicit public constructor } - } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java index 7ec2fffa2b..334ff6f567 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java @@ -7,9 +7,9 @@ * 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. @@ -17,18 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.services; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; public interface ToscaFileOutputService { - byte[] createOutputFile(ToscaServiceModel toscaServiceModel, - FileContentHandler externalArtifacts); - String createMetaFile(String entryDefinitionsFileName); + byte[] createOutputFile(ToscaServiceModel toscaServiceModel, FileContentHandler externalArtifacts); - String getArtifactsFolderName(); + String createMetaFile(String entryDefinitionsFileName); + String getArtifactsFolderName(); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java index 7c8e48ac88..66230250d5 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.services; import java.util.Collections; @@ -26,7 +25,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; - import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.collections4.MapUtils; @@ -66,11 +64,9 @@ public class ToscaUtil { if (metadata.get(ToscaConstants.ST_METADATA_FILE_NAME) != null) { return metadata.get(ToscaConstants.ST_METADATA_FILE_NAME); } else if (metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) != null) { - return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) - + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; + return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; } - return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; - + return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; } public static String getServiceTemplateFileName(String templateName) { @@ -79,59 +75,41 @@ public class ToscaUtil { return getServiceTemplateFileName(metadata); } - public static Optional<String> getSubstitutableGroupMemberId(String heatFileName, - ServiceTemplate serviceTemplate) { - - Map<String, NodeTemplate> nodeTemplates = - DataModelUtil.getNodeTemplates(serviceTemplate); - + public static Optional<String> getSubstitutableGroupMemberId(String heatFileName, ServiceTemplate serviceTemplate) { + Map<String, NodeTemplate> nodeTemplates = DataModelUtil.getNodeTemplates(serviceTemplate); if (MapUtils.isEmpty(nodeTemplates)) { return Optional.empty(); } - String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName); - for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) { - String subServiceTemplateName = - getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry); - - if (Objects.nonNull(subServiceTemplateName) - && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)) { + String subServiceTemplateName = getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry); + if (Objects.nonNull(subServiceTemplateName) && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)) { return Optional.of(nodeTemplateEntry.getKey()); } } - return Optional.empty(); } - private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt, - String subServiceTemplateName) { + private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt, String subServiceTemplateName) { return subServiceTemplateName.startsWith(heatFileNameWithoutExt); } - private static String getSubstitutionServiceTemplateNameFromProperties( - Map.Entry<String, NodeTemplate> nodeTemplateEntry) { + private static String getSubstitutionServiceTemplateNameFromProperties(Map.Entry<String, NodeTemplate> nodeTemplateEntry) { Map<String, Object> properties = - nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() : - nodeTemplateEntry.getValue().getProperties(); - + nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() : nodeTemplateEntry.getValue().getProperties(); Map<String, Object> serviceTemplateFilter = - properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) ? - (Map<String, Object>) properties.get(ToscaConstants - .SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap(); - + properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) ? (Map<String, Object>) properties + .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap(); return (String) serviceTemplateFilter.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME); } - /** * Add service template to map with key file name. * * @param serviceTemplateMap the service template map * @param serviceTemplate the service template */ - public static void addServiceTemplateToMapWithKeyFileName( - Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) { + public static void addServiceTemplateToMapWithKeyFileName(Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) { serviceTemplateMap.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate); } } 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 3ce9badea0..c5deee4ebd 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 @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services.impl; import java.io.ByteArrayInputStream; @@ -91,18 +90,58 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { private static final String TOSCA_META_FILE = "TOSCA-Metadata/TOSCA.meta"; private static final String ENTRY_DEFINITIONS = "Entry-Definitions"; + private static boolean isFile(String currentEntryName) { + return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/")); + } + + private static boolean evaluateRequirementFulfillment(RequirementDefinition requirementDefinition) { + Object[] occurrences = requirementDefinition.getOccurrences(); + if (occurrences == null) { + requirementDefinition.setOccurrences(new Object[]{1, 1}); + return false; + } + if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { + return false; + } + if (occurrences[1].equals(1)) { + return true; + } + occurrences[1] = (Integer) occurrences[1] - 1; + return false; + } + + private static boolean evaluateCapabilityFulfillment(CapabilityDefinition capabilityDefinition) { + Object[] occurrences = capabilityDefinition.getOccurrences(); + if (occurrences == null) { + capabilityDefinition.setOccurrences(new Object[]{1, ToscaConstants.UNBOUNDED}); + return false; + } + if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { + return false; + } + if (occurrences[1].equals(1)) { + return true; + } + occurrences[1] = (Integer) occurrences[1] - 1; + return false; + } + + private static boolean isPrimitiveType(String toscaType) { + return (toscaType.equals(PropertyType.STRING.getDisplayName()) || toscaType.equals(PropertyType.INTEGER.getDisplayName()) || toscaType + .equals(PropertyType.FLOAT.getDisplayName())); + } + @Override public List<Map<String, RequirementDefinition>> calculateExposedRequirements( - List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList, - Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) { - + List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList, + Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) { if (nodeTypeRequirementsDefinitionList == null) { return Collections.emptyList(); } for (Map.Entry<String, RequirementAssignment> entry : nodeTemplateRequirementsAssignment.entrySet()) { if (entry.getValue().getNode() != null) { - Optional<RequirementDefinition> requirementDefinition = - DataModelUtil.getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry.getKey()); + Optional<RequirementDefinition> requirementDefinition = DataModelUtil + .getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry.getKey()); RequirementDefinition cloneRequirementDefinition; if (requirementDefinition.isPresent()) { cloneRequirementDefinition = requirementDefinition.get().clone(); @@ -122,7 +161,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); FileContentHandler artifactFiles = new FileContentHandler(); - try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(toscaCsarPackage))) { ZipEntry zipEntry; while ((zipEntry = inputZipStream.getNextEntry()) != null) { @@ -144,7 +182,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (StringUtils.isEmpty(toscaServiceModel.getEntryDefinitionServiceTemplate())) { handleToscaCsarWithoutToscaMetadata(toscaServiceModel); } - } catch (IOException | ZipSlipException exc) { throw new SdcRuntimeException(exc.getMessage(), exc); } @@ -172,22 +209,16 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { toscaServiceModel.setEntryDefinitionServiceTemplate(entryDefinition); } - void loadToscaYamlFile(ToscaServiceModel toscaServiceModel, ToscaExtensionYamlUtil toscaExtensionYamlUtil, - byte[] fileContent, String fileFullName) { + void loadToscaYamlFile(ToscaServiceModel toscaServiceModel, ToscaExtensionYamlUtil toscaExtensionYamlUtil, byte[] fileContent, + String fileFullName) { try { - ServiceTemplate serviceTemplate = - toscaExtensionYamlUtil.yamlToObject(new String(fileContent), ServiceTemplate.class); + ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(new String(fileContent), ServiceTemplate.class); toscaServiceModel.addServiceTemplate(fileFullName, serviceTemplate); - } catch (Exception exc) { throw new CoreException(new InvalidToscaFile(fileFullName, exc.getMessage()).build()); } } - private static boolean isFile(String currentEntryName) { - return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/")); - } - private boolean isYamlFile(String fileName) { return fileName.endsWith("yaml") || fileName.endsWith("yml"); } @@ -198,57 +229,33 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } private void updateMinMaxOccurencesForNodeTypeRequirement(Map.Entry<String, RequirementAssignment> entry, - Map<String, RequirementDefinition> nodeTypeRequirementsMap) { + Map<String, RequirementDefinition> nodeTypeRequirementsMap) { Object max = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null - && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 - ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1; + && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ? nodeTypeRequirementsMap.get(entry.getKey()) + .getOccurrences()[1] : 1; Object min = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null - && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 - ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1; - nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[] {min, max}); + && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ? nodeTypeRequirementsMap.get(entry.getKey()) + .getOccurrences()[0] : 1; + nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[]{min, max}); } - private void updateRequirementDefinition( - List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList, - Map.Entry<String, RequirementAssignment> entry, RequirementDefinition cloneRequirementDefinition) { + private void updateRequirementDefinition(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList, + Map.Entry<String, RequirementAssignment> entry, RequirementDefinition cloneRequirementDefinition) { if (!evaluateRequirementFulfillment(cloneRequirementDefinition)) { - CommonMethods - .mergeEntryInList(entry.getKey(), cloneRequirementDefinition, nodeTypeRequirementsDefinitionList); + CommonMethods.mergeEntryInList(entry.getKey(), cloneRequirementDefinition, nodeTypeRequirementsDefinitionList); } else { DataModelUtil.removeRequirementsDefinition(nodeTypeRequirementsDefinitionList, entry.getKey()); } } - private static boolean evaluateRequirementFulfillment(RequirementDefinition requirementDefinition) { - Object[] occurrences = requirementDefinition.getOccurrences(); - if (occurrences == null) { - requirementDefinition.setOccurrences(new Object[] {1, 1}); - return false; - } - if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { - return false; - } - - if (occurrences[1].equals(1)) { - return true; - } - occurrences[1] = (Integer) occurrences[1] - 1; - return false; - } - @Override - public Map<String, CapabilityDefinition> calculateExposedCapabilities( - Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, - Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) { - + public Map<String, CapabilityDefinition> calculateExposedCapabilities(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, + Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) { String capabilityKey; String capability; String node; - for (Map.Entry<String, Map<String, RequirementAssignment>> entry : fullFilledRequirementsDefinitionMap - .entrySet()) { + for (Map.Entry<String, Map<String, RequirementAssignment>> entry : fullFilledRequirementsDefinitionMap.entrySet()) { for (Map.Entry<String, RequirementAssignment> fullFilledEntry : entry.getValue().entrySet()) { - - capability = fullFilledEntry.getValue().getCapability(); node = fullFilledEntry.getValue().getNode(); capabilityKey = capability + "_" + node; @@ -256,12 +263,10 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (capabilityDefinition != null) { CapabilityDefinition clonedCapabilityDefinition = capabilityDefinition.clone(); nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityDefinition.clone()); - updateNodeTypeCapabilitiesDefinition(nodeTypeCapabilitiesDefinition, capabilityKey, - clonedCapabilityDefinition); + updateNodeTypeCapabilitiesDefinition(nodeTypeCapabilitiesDefinition, capabilityKey, clonedCapabilityDefinition); } } } - Map<String, CapabilityDefinition> exposedCapabilitiesDefinition = new HashMap<>(); for (Map.Entry<String, CapabilityDefinition> entry : nodeTypeCapabilitiesDefinition.entrySet()) { exposedCapabilitiesDefinition.put(entry.getKey(), entry.getValue()); @@ -269,8 +274,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return exposedCapabilitiesDefinition; } - private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, - String capabilityKey, CapabilityDefinition clonedCapabilityDefinition) { + private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, String capabilityKey, + CapabilityDefinition clonedCapabilityDefinition) { if (evaluateCapabilityFulfillment(clonedCapabilityDefinition)) { nodeTypeCapabilitiesDefinition.remove(capabilityKey); } else { @@ -278,40 +283,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } } - private static boolean evaluateCapabilityFulfillment(CapabilityDefinition capabilityDefinition) { - - Object[] occurrences = capabilityDefinition.getOccurrences(); - if (occurrences == null) { - capabilityDefinition.setOccurrences(new Object[] {1, ToscaConstants.UNBOUNDED}); - return false; - } - if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { - return false; - } - - if (occurrences[1].equals(1)) { - return true; - } - occurrences[1] = (Integer) occurrences[1] - 1; - return false; - } - /* node template with type equal to node type or derived from node type */ @Override - public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, - ToscaServiceModel toscaServiceModel) { + public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, ToscaServiceModel toscaServiceModel) { Map<String, NodeTemplate> nodeTemplates = new HashMap<>(); - - if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils.isNotEmpty( - serviceTemplate.getTopology_template().getNode_templates())) { - for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template() - .getNode_templates().entrySet()) { + if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils + .isNotEmpty(serviceTemplate.getTopology_template().getNode_templates())) { + for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template().getNode_templates().entrySet()) { if (isTypeOf(nodeTemplateEntry.getValue(), nodeType, serviceTemplate, toscaServiceModel)) { nodeTemplates.put(nodeTemplateEntry.getKey(), nodeTemplateEntry.getValue()); } - } } return nodeTemplates; @@ -320,38 +303,31 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { @Override public Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate> serviceTemplates) { Optional<Map<String, NodeType>> nodeTypeMap = serviceTemplates.stream().map(ServiceTemplate::getNode_types) - .filter(nodeTypes -> Objects.nonNull(nodeTypes) - && nodeTypes - .containsKey( - nodeTypeKey)) - .findFirst(); + .filter(nodeTypes -> Objects.nonNull(nodeTypes) && nodeTypes.containsKey(nodeTypeKey)).findFirst(); return nodeTypeMap.map(stringNodeTypeMap -> stringNodeTypeMap.get(nodeTypeKey)); } @Override - public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel) { + public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { return isTypeOf(nodeTemplate, nodeType, GET_NODE_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel); } @Override - public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { - return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate, - toscaServiceModel); + public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel) { + return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel); } @Override public boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel) { + ToscaServiceModel toscaServiceModel) { return isTypeOf(parameterDefinition, dataType, GET_DATA_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel); } @Override - public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { - return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate, - toscaServiceModel); + public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel) { + return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel); } @Override @@ -361,8 +337,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (requirementList != null) { requirementList.stream().filter(reqMap -> reqMap.get(requirementId) != null).forEach(reqMap -> { ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - RequirementAssignment reqAssignment = toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(reqMap.get(requirementId)), RequirementAssignment.class); + RequirementAssignment reqAssignment = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqMap.get(requirementId)), RequirementAssignment.class); requirements.add(reqAssignment); }); } @@ -371,53 +347,43 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { @Override public Optional<NodeTemplate> getNodeTemplateById(ServiceTemplate serviceTemplate, String nodeTemplateId) { - if ((serviceTemplate.getTopology_template() != null) && ( - serviceTemplate.getTopology_template().getNode_templates() != null) && ( - serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) { + if ((serviceTemplate.getTopology_template() != null) && (serviceTemplate.getTopology_template().getNode_templates() != null) && ( + serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) { return Optional.of(serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)); } return Optional.empty(); } @Override - public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId, - NodeTemplate substitutableNodeTemplate) { + public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId, NodeTemplate substitutableNodeTemplate) { if (!isSubstitutableNodeTemplate(substitutableNodeTemplate)) { return Optional.empty(); } - - if (substitutableNodeTemplate.getProperties() != null && - substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) - != null) { - Object serviceTemplateFilter = - substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + if (substitutableNodeTemplate.getProperties() != null + && substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) != null) { + Object serviceTemplateFilter = substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); if (serviceTemplateFilter instanceof Map) { - Object substituteServiceTemplate = - ((Map) serviceTemplateFilter).get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME); + Object substituteServiceTemplate = ((Map) serviceTemplateFilter).get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME); handleNoSubstituteServiceTemplate(substituteNodeTemplateId, substituteServiceTemplate); return Optional.of(substituteServiceTemplate.toString()); } } - throw new CoreException( - new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build()); + throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build()); } private void handleNoSubstituteServiceTemplate(String substituteNodeTemplateId, Object substituteServiceTemplate) { if (substituteServiceTemplate == null) { - throw new CoreException( - new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build()); + throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build()); } } @Override public Map<String, NodeTemplate> getSubstitutableNodeTemplates(ServiceTemplate serviceTemplate) { Map<String, NodeTemplate> substitutableNodeTemplates = new HashMap<>(); - if (serviceTemplate == null || serviceTemplate.getTopology_template() == null - || serviceTemplate.getTopology_template().getNode_templates() == null) { + || serviceTemplate.getTopology_template().getNode_templates() == null) { return substitutableNodeTemplates; } - Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) { String nodeTemplateId = entry.getKey(); @@ -426,24 +392,23 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { substitutableNodeTemplates.put(nodeTemplateId, nodeTemplate); } } - return substitutableNodeTemplates; } @Override - public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq( - String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate, String requirementId) { + public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(String substituteServiceTemplateFileName, + ServiceTemplate substituteServiceTemplate, + String requirementId) { if (isSubstitutionServiceTemplate(substituteServiceTemplateFileName, substituteServiceTemplate)) { - Map<String, List<String>> substitutionMappingRequirements = - substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements(); + Map<String, List<String>> substitutionMappingRequirements = substituteServiceTemplate.getTopology_template().getSubstitution_mappings() + .getRequirements(); if (substitutionMappingRequirements != null) { List<String> requirementMapping = substitutionMappingRequirements.get(requirementId); if (requirementMapping != null && !requirementMapping.isEmpty()) { String mappedNodeTemplateId = requirementMapping.get(0); - Optional<NodeTemplate> mappedNodeTemplate = - getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId); - mappedNodeTemplate.orElseThrow(() -> new CoreException( - new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build())); + Optional<NodeTemplate> mappedNodeTemplate = getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId); + mappedNodeTemplate.orElseThrow( + () -> new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build())); Map.Entry<String, NodeTemplate> mappedNodeTemplateEntry = new Map.Entry<String, NodeTemplate>() { @Override public String getKey() { @@ -471,47 +436,36 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { match only for the input which is not null */ @Override - public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability, - String node, String relationship) { + public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability, String node, String relationship) { if (isSameCapability(requirementAssignment, capability)) { return false; } - if (isSameRequirement(requirementAssignment, node)) { return false; } - if (isSameRelationship(requirementAssignment, relationship)) { return false; } - return !(capability == null && node == null && relationship == null); - } private boolean isSameRelationship(RequirementAssignment requirementAssignment, String relationship) { - return relationship != null && (requirementAssignment.getRelationship() == null || !requirementAssignment - .getRelationship() - .equals(relationship)); + return relationship != null && (requirementAssignment.getRelationship() == null || !requirementAssignment.getRelationship() + .equals(relationship)); } private boolean isSameRequirement(RequirementAssignment requirementAssignment, String node) { - return node != null && (requirementAssignment.getNode() == null || !requirementAssignment.getNode() - .equals(node)); + return node != null && (requirementAssignment.getNode() == null || !requirementAssignment.getNode().equals(node)); } private boolean isSameCapability(RequirementAssignment requirementAssignment, String capability) { - return capability != null && (requirementAssignment.getCapability() == null || !requirementAssignment - .getCapability() - .equals(capability)); + return capability != null && (requirementAssignment.getCapability() == null || !requirementAssignment.getCapability().equals(capability)); } @Override - public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaModel) { + public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel) { ToscaFlatData flatData = new ToscaFlatData(); flatData.setElementType(elementType); - switch (elementType) { case CAPABILITY_TYPE: flatData.setFlatEntity(new CapabilityType()); @@ -525,87 +479,69 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { default: throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported"); } - - boolean isEntityFound = - scanAnFlatEntity(elementType, typeId, flatData, serviceTemplate, toscaModel, new ArrayList<>(), 0); + boolean isEntityFound = scanAnFlatEntity(elementType, typeId, flatData, serviceTemplate, toscaModel, new ArrayList<>(), 0); if (!isEntityFound) { throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build()); } - return flatData; } @Override public boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate) { - return nodeTemplate.getDirectives() != null && nodeTemplate.getDirectives().contains( - ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE); + return nodeTemplate.getDirectives() != null && nodeTemplate.getDirectives().contains(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE); } - private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch, - String getTypesMethodName, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, - Set<String> analyzedImportFiles) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Map<String, T> searchableTypes = - (Map<String, T>) serviceTemplate.getClass().getMethod(getTypesMethodName).invoke(serviceTemplate); - + private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch, String getTypesMethodName, + ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, + Set<String> analyzedImportFiles) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Map<String, T> searchableTypes = (Map<String, T>) serviceTemplate.getClass().getMethod(getTypesMethodName).invoke(serviceTemplate); if (!MapUtils.isEmpty(searchableTypes)) { T typeObject = searchableTypes.get(typeToSearch); if (Objects.nonNull(typeObject)) { - String derivedFromTypeVal = - (String) typeObject.getClass().getMethod(GET_DERIVED_FROM_METHOD_NAME).invoke(typeObject); + String derivedFromTypeVal = (String) typeObject.getClass().getMethod(GET_DERIVED_FROM_METHOD_NAME).invoke(typeObject); if (Objects.equals(derivedFromTypeVal, typeToMatch)) { return Optional.of(true); } else if (Objects.isNull(derivedFromTypeVal) || isTypeIsToscaRoot(derivedFromTypeVal)) { return Optional.of(false); } else { - return isTypeExistInServiceTemplateHierarchy(typeToMatch, derivedFromTypeVal, getTypesMethodName, - serviceTemplate, toscaServiceModel, null); + return isTypeExistInServiceTemplateHierarchy(typeToMatch, derivedFromTypeVal, getTypesMethodName, serviceTemplate, + toscaServiceModel, null); } } else { - return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, - toscaServiceModel, analyzedImportFiles); + return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel, analyzedImportFiles); } } - return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel, - analyzedImportFiles); + return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel, analyzedImportFiles); } private Optional<Boolean> isTypeExistInImports(String typeToMatch, String typeToSearch, String getTypesMethodName, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned) - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { List<Map<String, Import>> imports = serviceTemplate.getImports(); if (CollectionUtils.isEmpty(imports)) { return Optional.empty(); } - Set<String> createdFilesScanned = createFilesScannedSet(filesScanned); - for (Map<String, Import> map : imports) { ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - Import anImport = toscaExtensionYamlUtil - .yamlToObject(toscaExtensionYamlUtil.objectToYaml(map.values().iterator().next()), - Import.class); + Import anImport = toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(map.values().iterator().next()), Import.class); handleImportWithNoFileEntry(anImport); String importFile = anImport.getFile(); - ServiceTemplate template = toscaServiceModel.getServiceTemplates() - .get(fetchFullFileNameForImport(importFile, - serviceTemplate.getMetadata() == null ? null : - serviceTemplate.getMetadata().get("filename"), - serviceTemplate, toscaServiceModel)); - if (Objects.isNull(template) || createdFilesScanned - .contains(ToscaUtil.getServiceTemplateFileName(template))) { + ServiceTemplate template = toscaServiceModel.getServiceTemplates().get( + fetchFullFileNameForImport(importFile, serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"), + serviceTemplate, toscaServiceModel)); + if (Objects.isNull(template) || createdFilesScanned.contains(ToscaUtil.getServiceTemplateFileName(template))) { continue; } else { createdFilesScanned.add(ToscaUtil.getServiceTemplateFileName(template)); } - Optional<Boolean> typeExistInServiceTemplateHierarchy = - isTypeExistInServiceTemplateHierarchy(typeToMatch, typeToSearch, getTypesMethodName, template, - toscaServiceModel, createdFilesScanned); + Optional<Boolean> typeExistInServiceTemplateHierarchy = isTypeExistInServiceTemplateHierarchy(typeToMatch, typeToSearch, + getTypesMethodName, template, toscaServiceModel, createdFilesScanned); if (typeExistInServiceTemplateHierarchy.isPresent() && (typeExistInServiceTemplateHierarchy.get())) { createdFilesScanned.clear(); return Optional.of(true); } - } return Optional.of(false); } @@ -628,29 +564,21 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return (type.contains(TOSCA_DOT) && type.contains(DOT_ROOT)); } - private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName, - ServiceTemplate substituteServiceTemplate) { + private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate) { if (substituteServiceTemplate != null && substituteServiceTemplate.getTopology_template() != null - && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) { + && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) { if (substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getNode_type() == null) { - throw new CoreException( - new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName) - .build()); + throw new CoreException(new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName).build()); } return true; } return false; - } - private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned, - int rootScanStartInx) { - - - boolean entityFound = - enrichEntityFromCurrentServiceTemplate(elementType, typeId, flatData, serviceTemplate, toscaModel, - filesScanned, rootScanStartInx); + private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) { + boolean entityFound = enrichEntityFromCurrentServiceTemplate(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, + rootScanStartInx); if (!entityFound) { List<Map<String, Import>> imports = serviceTemplate.getImports(); if (CollectionUtils.isEmpty(imports)) { @@ -661,25 +589,21 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (found) { return true; } - found = isFlatEntity(importMap, flatData, serviceTemplate, filesScanned, toscaModel, elementType, - typeId); + found = isFlatEntity(importMap, flatData, serviceTemplate, filesScanned, toscaModel, elementType, typeId); } return found; } return true; } - private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate, - List<String> filesScanned, ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) { + private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate, List<String> filesScanned, + ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) { boolean found = false; ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); for (Object importObject : importMap.values()) { - Import importServiceTemplate = toscaExtensionYamlUtil - .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importObject), - Import.class); + Import importServiceTemplate = toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(importObject), Import.class); String fileName = fetchFullFileNameForImport(importServiceTemplate.getFile(), - serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"), - serviceTemplate, toscaModel); + serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"), serviceTemplate, toscaModel); if (filesScanned.contains(fileName)) { return false; } else { @@ -689,28 +613,24 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (Objects.isNull(template)) { throw new CoreException(new ToscaFileNotFoundErrorBuilder(fileName).build()); } - found = scanAnFlatEntity(elementType, typeId, flatData, template, toscaModel, filesScanned, - filesScanned.size()); + found = scanAnFlatEntity(elementType, typeId, flatData, template, toscaModel, filesScanned, filesScanned.size()); } return found; } - String fetchFullFileNameForImport(String importServiceTemplateFile, String currentMetadatafileName, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { - Optional<Map.Entry<String, ServiceTemplate>> serviceTemplateEntry = - toscaServiceModel.getServiceTemplates().entrySet().stream() - .filter(entry -> entry.getValue() == serviceTemplate).findFirst(); + String fetchFullFileNameForImport(String importServiceTemplateFile, String currentMetadatafileName, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel) { + Optional<Map.Entry<String, ServiceTemplate>> serviceTemplateEntry = toscaServiceModel.getServiceTemplates().entrySet().stream() + .filter(entry -> entry.getValue() == serviceTemplate).findFirst(); if (!serviceTemplateEntry.isPresent()) { if (importServiceTemplateFile.contains("../")) { return importServiceTemplateFile.replace("../", ""); } else if (currentMetadatafileName != null && currentMetadatafileName.indexOf('/') != -1) { - return currentMetadatafileName.substring(0, currentMetadatafileName.indexOf('/')) + "/" - + importServiceTemplateFile; + return currentMetadatafileName.substring(0, currentMetadatafileName.indexOf('/')) + "/" + importServiceTemplateFile; } else { return importServiceTemplateFile; } } - Path currentPath = Paths.get(serviceTemplateEntry.get().getKey()).getParent(); if (currentPath == null) { currentPath = Paths.get(""); @@ -718,52 +638,43 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return currentPath.resolve(importServiceTemplateFile).normalize().toString().replaceAll("\\\\", "/"); } - private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId, - ToscaFlatData flatData, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, - List<String> filesScanned, int rootScanStartInx) { + private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, + ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned, + int rootScanStartInx) { switch (elementType) { case CAPABILITY_TYPE: - if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx)) { + if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) { return false; } break; case NODE_TYPE: - if (enrichNodeTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx)) { + if (enrichNodeTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) { return false; } break; case DATA_TYPE: - if (enrichDataTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx)) { + if (enrichDataTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) { return false; } break; default: throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported"); } - return true; - - } - private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned, - int rootScanStartInx) { + private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) { String derivedFrom; if (serviceTemplate.getNode_types() != null && serviceTemplate.getNode_types().containsKey(typeId)) { - filesScanned.clear(); flatData.addInheritanceHierarchyType(typeId); NodeType targetNodeType = (NodeType) flatData.getFlatEntity(); NodeType sourceNodeType = serviceTemplate.getNode_types().get(typeId); derivedFrom = sourceNodeType.getDerived_from(); if (derivedFrom != null) { - boolean isEntityFound = - scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx); + boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, + rootScanStartInx); if (!isEntityFound) { throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build()); } @@ -775,21 +686,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return false; } - private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned, - int rootScanStartInx) { + private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) { String derivedFrom; if (serviceTemplate.getData_types() != null && serviceTemplate.getData_types().containsKey(typeId)) { - filesScanned.clear(); flatData.addInheritanceHierarchyType(typeId); DataType targetDataType = (DataType) flatData.getFlatEntity(); DataType sourceDataType = serviceTemplate.getData_types().get(typeId); derivedFrom = sourceDataType.getDerived_from(); if (derivedFrom != null && !isPrimitiveType(derivedFrom)) { - boolean isEntityFound = - scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx); + boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, + rootScanStartInx); if (!isEntityFound) { throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build()); } @@ -801,28 +709,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return false; } - private static boolean isPrimitiveType(String toscaType) { - return (toscaType.equals(PropertyType.STRING.getDisplayName()) || toscaType.equals(PropertyType.INTEGER - .getDisplayName()) - || toscaType.equals(PropertyType.FLOAT.getDisplayName())); - } - - private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, - ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned, - int rootScanStartInx) { + private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate, + ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) { String derivedFrom; - if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types() - .containsKey(typeId)) { - + if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types().containsKey(typeId)) { filesScanned.clear(); flatData.addInheritanceHierarchyType(typeId); CapabilityType targetCapabilityType = (CapabilityType) flatData.getFlatEntity(); CapabilityType sourceCapabilityType = serviceTemplate.getCapability_types().get(typeId); derivedFrom = sourceCapabilityType.getDerived_from(); if (derivedFrom != null) { - boolean isEntityFound = - scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, - rootScanStartInx); + boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned, + rootScanStartInx); if (!isEntityFound) { throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build()); } @@ -838,18 +736,12 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { targetNodeType.setDerived_from(sourceNodeType.getDerived_from()); targetNodeType.setDescription(sourceNodeType.getDescription()); targetNodeType.setVersion(sourceNodeType.getVersion()); - targetNodeType - .setProperties(CommonMethods.mergeMaps(targetNodeType.getProperties(), sourceNodeType.getProperties())); + targetNodeType.setProperties(CommonMethods.mergeMaps(targetNodeType.getProperties(), sourceNodeType.getProperties())); combineNodeTypeInterfaceInfo(sourceNodeType, targetNodeType); - targetNodeType - .setArtifacts(CommonMethods.mergeMaps(targetNodeType.getArtifacts(), sourceNodeType.getArtifacts())); - targetNodeType - .setAttributes(CommonMethods.mergeMaps(targetNodeType.getAttributes(), sourceNodeType.getAttributes())); - targetNodeType.setCapabilities( - CommonMethods.mergeMaps(targetNodeType.getCapabilities(), sourceNodeType.getCapabilities())); - targetNodeType.setRequirements( - CommonMethods.mergeListsOfMap(targetNodeType.getRequirements(), sourceNodeType.getRequirements())); - + targetNodeType.setArtifacts(CommonMethods.mergeMaps(targetNodeType.getArtifacts(), sourceNodeType.getArtifacts())); + targetNodeType.setAttributes(CommonMethods.mergeMaps(targetNodeType.getAttributes(), sourceNodeType.getAttributes())); + targetNodeType.setCapabilities(CommonMethods.mergeMaps(targetNodeType.getCapabilities(), sourceNodeType.getCapabilities())); + targetNodeType.setRequirements(CommonMethods.mergeListsOfMap(targetNodeType.getRequirements(), sourceNodeType.getRequirements())); } private void combineNodeTypeInterfaceInfo(NodeType sourceNodeType, NodeType targetNodeType) { @@ -868,22 +760,19 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { Map<String, Object> combineInterfaces = new HashMap<>(); for (Map.Entry<String, Object> sourceInterfaceDefEntry : sourceNodeType.getInterfaces().entrySet()) { String interfaceName = sourceInterfaceDefEntry.getKey(); - if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces() - .containsKey(interfaceName)) { - combineInterfaces.put(interfaceName, combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(), - targetNodeType.getInterfaces().get(interfaceName))); + if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces().containsKey(interfaceName)) { + combineInterfaces.put(interfaceName, + combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(), targetNodeType.getInterfaces().get(interfaceName))); } else { combineInterfaces.put(sourceInterfaceDefEntry.getKey(), sourceInterfaceDefEntry.getValue()); } } - for (Map.Entry<String, Object> targetInterfaceDefEntry : targetNodeType.getInterfaces().entrySet()) { String interfaceName = targetInterfaceDefEntry.getKey(); if (!sourceNodeType.getInterfaces().containsKey(interfaceName)) { combineInterfaces.put(targetInterfaceDefEntry.getKey(), targetInterfaceDefEntry.getValue()); } } - return Optional.of(combineInterfaces); } @@ -891,16 +780,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if ((MapUtils.isEmpty(sourceNodeType.getInterfaces()) && MapUtils.isEmpty(targetNodeType.getInterfaces()))) { return Optional.empty(); } - if (MapUtils.isEmpty(sourceNodeType.getInterfaces()) && !MapUtils.isEmpty(targetNodeType.getInterfaces())) { return Optional.of(targetNodeType.getInterfaces()); } - if (!MapUtils.isEmpty(sourceNodeType.getInterfaces()) && MapUtils.isEmpty(targetNodeType.getInterfaces())) { return Optional.of(sourceNodeType.getInterfaces()); } return Optional.empty(); - } private Object combineInterfaceDefinition(Object sourceInterfaceDefType, Object targetInterfaceDefType) { @@ -909,9 +795,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { InterfaceDefinitionType combineInterface = new InterfaceDefinitionType(); combineInterface.setType(sourceInterface.getType()); combineInterface.setInputs(CommonMethods.mergeMaps(targetInterface.getInputs(), sourceInterface.getInputs())); - combineInterface.setOperations( - CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations())); - + combineInterface.setOperations(CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations())); Optional<Object> interfaceDefObject = combineInterface.convertInterfaceDefinitionTypeToToscaObj(); if (!interfaceDefObject.isPresent()) { throw new SdcRuntimeException("Illegal Statement"); @@ -923,22 +807,15 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { targetDataType.setDerived_from(sourceDataType.getDerived_from()); targetDataType.setDescription(sourceDataType.getDescription()); targetDataType.setVersion(sourceDataType.getVersion()); - targetDataType - .setProperties(CommonMethods.mergeMaps(targetDataType.getProperties(), sourceDataType.getProperties())); - targetDataType.setConstraints( - CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints())); + targetDataType.setProperties(CommonMethods.mergeMaps(targetDataType.getProperties(), sourceDataType.getProperties())); + targetDataType.setConstraints(CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints())); } private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType, CapabilityType targetCapabilityType) { - - targetCapabilityType.setAttributes( - CommonMethods.mergeMaps(targetCapabilityType.getAttributes(), sourceCapabilityType.getAttributes())); - targetCapabilityType.setProperties( - CommonMethods.mergeMaps(targetCapabilityType.getProperties(), sourceCapabilityType.getProperties())); - targetCapabilityType.setValid_source_types(CommonMethods - .mergeLists(targetCapabilityType.getValid_source_types(), - sourceCapabilityType.getValid_source_types())); - + targetCapabilityType.setAttributes(CommonMethods.mergeMaps(targetCapabilityType.getAttributes(), sourceCapabilityType.getAttributes())); + targetCapabilityType.setProperties(CommonMethods.mergeMaps(targetCapabilityType.getProperties(), sourceCapabilityType.getProperties())); + targetCapabilityType.setValid_source_types( + CommonMethods.mergeLists(targetCapabilityType.getValid_source_types(), sourceCapabilityType.getValid_source_types())); if (StringUtils.isNotEmpty(sourceCapabilityType.getDerived_from())) { targetCapabilityType.setDerived_from(sourceCapabilityType.getDerived_from()); } @@ -948,11 +825,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { if (StringUtils.isNotEmpty(sourceCapabilityType.getVersion())) { targetCapabilityType.setVersion(sourceCapabilityType.getVersion()); } - - } - /* * Create node type according to the input substitution service template, while the substitution * service template can be mappted to this node type, for substitution mapping. @@ -962,8 +836,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { * @return the node type */ @Override - public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, - String nodeTypeDerivedFromValue) { + public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, String nodeTypeDerivedFromValue) { NodeType substitutionNodeType = new NodeType(); substitutionNodeType.setDerived_from(nodeTypeDerivedFromValue); substitutionNodeType.setDescription(substitutionServiceTemplate.getDescription()); @@ -973,21 +846,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } @Override - public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties( - ServiceTemplate substitutionServiceTemplate) { + public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(ServiceTemplate substitutionServiceTemplate) { Map<String, PropertyDefinition> substitutionNodeTypeProperties = new HashMap<>(); Map<String, ParameterDefinition> properties = substitutionServiceTemplate.getTopology_template().getInputs(); if (properties == null) { return null; } - PropertyDefinition propertyDefinition; String toscaPropertyName; for (Map.Entry<String, ParameterDefinition> entry : properties.entrySet()) { toscaPropertyName = entry.getKey(); propertyDefinition = new PropertyDefinition(); - ParameterDefinition parameterDefinition = - substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName); + ParameterDefinition parameterDefinition = substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName); propertyDefinition.setType(parameterDefinition.getType()); propertyDefinition.setDescription(parameterDefinition.getDescription()); propertyDefinition.set_default(parameterDefinition.get_default()); @@ -1009,9 +879,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { return substitutionNodeTypeProperties; } - - private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes( - ServiceTemplate substitutionServiceTemplate) { + private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(ServiceTemplate substitutionServiceTemplate) { Map<String, AttributeDefinition> substitutionNodeTypeAttributes = new HashMap<>(); Map<String, ParameterDefinition> attributes = substitutionServiceTemplate.getTopology_template().getOutputs(); if (attributes == null) { @@ -1019,12 +887,10 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } AttributeDefinition attributeDefinition; String toscaAttributeName; - for (Map.Entry<String, ParameterDefinition> entry : attributes.entrySet()) { attributeDefinition = new AttributeDefinition(); toscaAttributeName = entry.getKey(); - ParameterDefinition parameterDefinition = - substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName); + ParameterDefinition parameterDefinition = substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName); if (parameterDefinition.getType() != null && !parameterDefinition.getType().isEmpty()) { attributeDefinition.setType(parameterDefinition.getType()); } else { @@ -1050,36 +916,29 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { * @return true if the requirement already exists and false otherwise */ @Override - public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId, - RequirementAssignment requirementAssignment) { + public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId, RequirementAssignment requirementAssignment) { List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate.getRequirements(); return nodeTemplateRequirements != null && nodeTemplateRequirements.stream().anyMatch( - requirement -> requirement.containsKey(requirementId) && DataModelUtil.compareRequirementAssignment( - requirementAssignment, requirement.get(requirementId))); + requirement -> requirement.containsKey(requirementId) && DataModelUtil + .compareRequirementAssignment(requirementAssignment, requirement.get(requirementId))); } private <T> boolean isTypeOf(T object, String type, String getTypesMethodName, ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel) { + ToscaServiceModel toscaServiceModel) { if (object == null) { return false; } - try { String objectType = (String) object.getClass().getMethod(GET_TYPE_METHOD_NAME).invoke(object); if (Objects.equals(objectType, type)) { return true; } - - Optional<Boolean> typeExistInServiceTemplateHierarchy = - isTypeExistInServiceTemplateHierarchy(type, objectType, getTypesMethodName, serviceTemplate, - toscaServiceModel, null); - return typeExistInServiceTemplateHierarchy.orElseThrow( - () -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build())); - + Optional<Boolean> typeExistInServiceTemplateHierarchy = isTypeExistInServiceTemplateHierarchy(type, objectType, getTypesMethodName, + serviceTemplate, toscaServiceModel, null); + return typeExistInServiceTemplateHierarchy + .orElseThrow(() -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build())); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new SdcRuntimeException(e); } } } - - 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 7c0d1271fb..90047aa6df 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 @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.tosca.services.impl; import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY; @@ -21,6 +20,15 @@ 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 java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.core.utilities.file.FileContentHandler; @@ -33,135 +41,108 @@ import org.openecomp.sdc.tosca.exceptions.CsarCreationErrorBuilder; import org.openecomp.sdc.tosca.exceptions.CsarMissingEntryPointErrorBuilder; import org.openecomp.sdc.tosca.services.ToscaFileOutputService; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - - public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { - static final String EXTERNAL_ARTIFACTS_FOLDER_NAME = "Artifacts"; - private static final String DEFINITIONS_FOLDER_NAME = "Definitions"; - 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_VALUE = "1.0"; - private static final String TOSCA_META_FILE_NAME = "TOSCA.meta"; - private static final String CSAR_VERSION_VALUE = "1.1"; - private static final String CREATED_BY_VALUE = "ASDC Onboarding portal"; - private static final String META_FILE_DELIMITER = ":"; - private static final String SPACE = " "; - private static final String FILE_SEPARATOR = File.separator; - private static final Logger logger = LoggerFactory.getLogger(ToscaFileOutputServiceCsarImpl.class); - - @Override - public byte[] createOutputFile(ToscaServiceModel toscaServiceModel, - FileContentHandler externalArtifacts) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(baos))) { - packDefinitions(zos, toscaServiceModel.getServiceTemplates()); - FileContentHandler artifactFiles = toscaServiceModel.getArtifactFiles(); - if (artifactFiles != null && !artifactFiles.isEmpty()) { - packArtifacts(zos, artifactFiles); - } - if (toscaServiceModel.getEntryDefinitionServiceTemplate() == null) { - throw new CoreException(new CsarMissingEntryPointErrorBuilder().build()); - } - createAndPackToscaMetaFile(zos, toscaServiceModel.getEntryDefinitionServiceTemplate()); - if (externalArtifacts != null) { - packExternalArtifacts(zos, externalArtifacts); - } - } catch (IOException ex) { - throw new CoreException(new CsarCreationErrorBuilder().build(), ex); + static final String EXTERNAL_ARTIFACTS_FOLDER_NAME = "Artifacts"; + private static final String DEFINITIONS_FOLDER_NAME = "Definitions"; + 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_VALUE = "1.0"; + private static final String TOSCA_META_FILE_NAME = "TOSCA.meta"; + private static final String CSAR_VERSION_VALUE = "1.1"; + private static final String CREATED_BY_VALUE = "ASDC Onboarding portal"; + private static final String META_FILE_DELIMITER = ":"; + private static final String SPACE = " "; + private static final String FILE_SEPARATOR = File.separator; + private static final Logger logger = LoggerFactory.getLogger(ToscaFileOutputServiceCsarImpl.class); + + @Override + public byte[] createOutputFile(ToscaServiceModel toscaServiceModel, FileContentHandler externalArtifacts) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(baos))) { + packDefinitions(zos, toscaServiceModel.getServiceTemplates()); + FileContentHandler artifactFiles = toscaServiceModel.getArtifactFiles(); + if (artifactFiles != null && !artifactFiles.isEmpty()) { + packArtifacts(zos, artifactFiles); + } + if (toscaServiceModel.getEntryDefinitionServiceTemplate() == null) { + throw new CoreException(new CsarMissingEntryPointErrorBuilder().build()); + } + createAndPackToscaMetaFile(zos, toscaServiceModel.getEntryDefinitionServiceTemplate()); + if (externalArtifacts != null) { + packExternalArtifacts(zos, externalArtifacts); + } + } catch (IOException ex) { + throw new CoreException(new CsarCreationErrorBuilder().build(), ex); + } + return baos.toByteArray(); } - return baos.toByteArray(); - } - - - @Override - public String createMetaFile(String entryDefinitionsFileName) { - return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE - + System.lineSeparator() - + 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; - } - - @Override - public String getArtifactsFolderName() { - return ARTIFACTS_FOLDER_NAME; - } - private void createAndPackToscaMetaFile(ZipOutputStream zos, String entryDefinitionsFileName) - throws IOException { - String metaFile = createMetaFile(entryDefinitionsFileName); - zos.putNextEntry( - new ZipEntry(TOSCA_META_FOLDER_NAME + FILE_SEPARATOR + TOSCA_META_FILE_NAME)); - writeBytesToZip(zos, new ByteArrayInputStream(metaFile.getBytes())); - } - - private void packDefinitions(ZipOutputStream zos, Map<String, ServiceTemplate> serviceTemplates) - throws IOException { - for (Map.Entry<String, ServiceTemplate> serviceTemplate : serviceTemplates.entrySet()) { - String fileName = serviceTemplate.getKey(); - zos.putNextEntry(new ZipEntry(DEFINITIONS_FOLDER_NAME + FILE_SEPARATOR + fileName)); - writeBytesToZip(zos, - FileUtils.convertToInputStream(serviceTemplate.getValue(), FileUtils.FileExtension.YAML)); + @Override + public String createMetaFile(String entryDefinitionsFileName) { + return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE + System.lineSeparator() + + 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; } - } - private void packExternalArtifacts(ZipOutputStream zos, FileContentHandler externalArtifacts) { + @Override + public String getArtifactsFolderName() { + return ARTIFACTS_FOLDER_NAME; + } - for (String filenameIncludingPath : externalArtifacts.getFileList()) { - try { - zos.putNextEntry(new ZipEntry(filenameIncludingPath)); - writeBytesToZip(zos, externalArtifacts.getFileContentAsStream(filenameIncludingPath)); + private void createAndPackToscaMetaFile(ZipOutputStream zos, String entryDefinitionsFileName) throws IOException { + String metaFile = createMetaFile(entryDefinitionsFileName); + zos.putNextEntry(new ZipEntry(TOSCA_META_FOLDER_NAME + FILE_SEPARATOR + TOSCA_META_FILE_NAME)); + writeBytesToZip(zos, new ByteArrayInputStream(metaFile.getBytes())); + } - } catch (IOException ex) { - throw new RuntimeException(ex); - } finally { - try { - zos.closeEntry(); - } catch (IOException ignore) { - logger.debug(ignore.getMessage(), ignore); + private void packDefinitions(ZipOutputStream zos, Map<String, ServiceTemplate> serviceTemplates) throws IOException { + for (Map.Entry<String, ServiceTemplate> serviceTemplate : serviceTemplates.entrySet()) { + String fileName = serviceTemplate.getKey(); + zos.putNextEntry(new ZipEntry(DEFINITIONS_FOLDER_NAME + FILE_SEPARATOR + fileName)); + writeBytesToZip(zos, FileUtils.convertToInputStream(serviceTemplate.getValue(), FileUtils.FileExtension.YAML)); } - } } - } - - private void packArtifacts(ZipOutputStream zos, FileContentHandler artifacts) { - - for (String fileName : artifacts.getFileList()) { - try { - zos.putNextEntry(new ZipEntry(ARTIFACTS_FOLDER_NAME + FILE_SEPARATOR + fileName)); - writeBytesToZip(zos, artifacts.getFileContentAsStream(fileName)); - - } catch (IOException ex) { - throw new RuntimeException(ex); - } finally { - try { - zos.closeEntry(); - } catch (IOException ignore) { - logger.debug(ignore.getMessage(), ignore); + private void packExternalArtifacts(ZipOutputStream zos, FileContentHandler externalArtifacts) { + for (String filenameIncludingPath : externalArtifacts.getFileList()) { + try { + zos.putNextEntry(new ZipEntry(filenameIncludingPath)); + writeBytesToZip(zos, externalArtifacts.getFileContentAsStream(filenameIncludingPath)); + } catch (IOException ex) { + throw new RuntimeException(ex); + } finally { + try { + zos.closeEntry(); + } catch (IOException ignore) { + logger.debug(ignore.getMessage(), ignore); + } + } } - } } - } + private void packArtifacts(ZipOutputStream zos, FileContentHandler artifacts) { + for (String fileName : artifacts.getFileList()) { + try { + zos.putNextEntry(new ZipEntry(ARTIFACTS_FOLDER_NAME + FILE_SEPARATOR + fileName)); + writeBytesToZip(zos, artifacts.getFileContentAsStream(fileName)); + } catch (IOException ex) { + throw new RuntimeException(ex); + } finally { + try { + zos.closeEntry(); + } catch (IOException ignore) { + logger.debug(ignore.getMessage(), ignore); + } + } + } + } - private void writeBytesToZip(ZipOutputStream zos, InputStream is) throws IOException { - if(is != null){ - IOUtils.copy(is, zos); + private void writeBytesToZip(ZipOutputStream zos, InputStream is) throws IOException { + if (is != null) { + IOUtils.copy(is, zos); + } } - } } |