summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-05-05 14:36:38 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-28 07:48:07 +0000
commit9f7430db214092bba954fa07fd3e72e333116cfa (patch)
tree0c7f688aa95e5280315a7b5736569a8ed5dbd0fc /catalog-be/src/main
parent6909f0c827bb46180fafc9d306d500e032ae7e0b (diff)
Allow global types generation
This change allows to configure which global type file will be added to the generated CSAR Issue-ID: SDC-3021 Change-Id: I83c0c3f317c4a4e5e8dbf22cb3dbd47e63562d3a Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java1
-rw-r--r--catalog-be/src/main/resources/config/configuration.yaml12
3 files changed, 53 insertions, 17 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index 492ebcf0e4..478cf28d2e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -115,6 +115,7 @@ public class CsarUtils {
private static final Logger log = Logger.getLogger(CsarUtils.class);
private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(CsarUtils.class.getName());
private static final String PATH_DELIMITER = "/";
+ public static final String NODES_YML = "nodes.yml";
@Autowired
private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
@Autowired
@@ -129,6 +130,8 @@ public class CsarUtils {
@Autowired(required = false)
private List<CsarEntryGenerator> generators;
+ private static final List<String> globalCsarImports = ConfigurationManager.getConfigurationManager()
+ .getConfiguration().getGlobalCsarImports();
private static final String CONFORMANCE_LEVEL = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel();
private static final String SDC_VERSION = ExternalConfiguration.getAppVersion();
public static final String ARTIFACTS_PATH = "Artifacts/";
@@ -537,34 +540,45 @@ public class CsarUtils {
}).left().map(content -> new Tuple2<>(content, new ZipEntry(DEFINITIONS_PATH + fileName)));
}
- private void addSchemaFilesFromCassandra(final ZipOutputStream zip,
+ /**
+ * Writes to a CSAR zip from casandra schema data
+ *
+ * @param zipOutputStream stores the input stream content
+ * @param schemaFileZip zip data from Cassandra
+ * @param nodesFromPackage list of all nodes found on the onboarded package
+ * @param isHeatPackage true if the onboardead package is a Heat package
+ */
+ private void addSchemaFilesFromCassandra(final ZipOutputStream zipOutputStream,
final byte[] schemaFileZip,
final List<String> nodesFromPackage) {
final int initSize = 2048;
log.debug("Starting copy from Schema file zip to CSAR zip");
- try (final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final BufferedOutputStream bos = new BufferedOutputStream(out, initSize)) {
+ try (final ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ final BufferedOutputStream bufferedOutputStream =
+ new BufferedOutputStream(byteArrayOutputStream, initSize)) {
ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
+ while ((entry = zipInputStream.getNextEntry()) != null) {
ZipUtils.checkForZipSlipInRead(entry);
final String entryName = entry.getName();
int readSize = initSize;
final byte[] entryData = new byte[initSize];
- if (entryName.equalsIgnoreCase("nodes.yml")) {
- handleNode(zipStream, out, nodesFromPackage);
- } else {
- while ((readSize = zipStream.read(entryData, 0, readSize)) != -1) {
- bos.write(entryData, 0, readSize);
+ if (shouldZipEntryBeHandled(entryName)) {
+ if (NODES_YML.equalsIgnoreCase(entryName)) {
+ handleNode(zipInputStream, byteArrayOutputStream, nodesFromPackage);
+ } else {
+ while ((readSize = zipInputStream.read(entryData, 0, readSize)) != -1) {
+ bufferedOutputStream.write(entryData, 0, readSize);
+ }
+ bufferedOutputStream.flush();
}
- bos.flush();
+ byteArrayOutputStream.flush();
+ zipOutputStream.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
+ zipOutputStream.write(byteArrayOutputStream.toByteArray());
+ zipOutputStream.flush();
+ byteArrayOutputStream.reset();
}
- out.flush();
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
- zip.write(out.toByteArray());
- zip.flush();
- out.reset();
}
} catch (final Exception e) {
log.error("Error while writing the SDC schema file to the CSAR", e);
@@ -574,6 +588,17 @@ public class CsarUtils {
}
/**
+ * Checks if the zip entry should or should not be added to the CSAR based on the given global type list
+ *
+ * @param entryName the zip entry name
+ * @return true if the zip entry should be handled
+ */
+ private boolean shouldZipEntryBeHandled(final String entryName) {
+ return globalCsarImports.stream()
+ .anyMatch(entry -> entry.contains(entryName));
+ }
+
+ /**
* Handles the nodes.yml zip entry, updating the nodes.yml to avoid duplicated nodes on it.
*
* @param zipInputStream the zip entry to be read
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 1ca087d38a..0a51e5901b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -249,7 +249,6 @@ public class ToscaExportHandler {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
}
-
log.trace("start tosca export for {}", component.getUniqueId());
String toscaVersion = null;
if (component instanceof Resource) {
diff --git a/catalog-be/src/main/resources/config/configuration.yaml b/catalog-be/src/main/resources/config/configuration.yaml
index b56c243093..3e34e2176f 100644
--- a/catalog-be/src/main/resources/config/configuration.yaml
+++ b/catalog-be/src/main/resources/config/configuration.yaml
@@ -91,6 +91,18 @@ defaultImports:
- annotations:
file: annotations.yml
+# Global CSAR Import Files
+globalCsarImports:
+ - annotations.yml
+ - artifacts.yml
+ - capabilities.yml
+ - data.yml
+ - groups.yml
+ - interfaces.yml
+ - nodes.yml
+ - policies.yml
+ - relationships.yml
+
# Users
users:
tom: passwd