aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
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