summaryrefslogtreecommitdiffstats
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/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java44
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java27
3 files changed, 65 insertions, 13 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index cbbd5eeef6..8f5b2b6355 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2545,3 +2545,10 @@ errors:
messageId: "SVC4153"
}
+ #-----------SVC4154---------------------------
+ CSAR_TOSCA_IMPORTS_ERROR: {
+ code: 500,
+ message: "Error: An error has occurred while including the default TOSCA imports in the CSAR",
+ messageId: "SVC4154"
+ }
+
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 3756ac5a3c..823ddc48ff 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
@@ -31,6 +31,7 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -76,6 +77,8 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.ToscaModelImportCassandraDao;
+import org.openecomp.sdc.be.data.model.ToscaImportByModel;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -169,6 +172,8 @@ public class CsarUtils {
private ToscaExportHandler toscaExportUtils;
@Autowired(required = false)
private List<CsarEntryGenerator> generators;
+ @Autowired(required = false)
+ private ToscaModelImportCassandraDao toscaModelImportCassandraDao;
private String versionFirstThreeOctets;
public CsarUtils() {
@@ -426,16 +431,21 @@ public class CsarUtils {
if (zipOutputStreamOrResponseFormat != null && zipOutputStreamOrResponseFormat.isRight()) {
return zipOutputStreamOrResponseFormat;
}
- //retrieve SDC.zip from Cassandra
- Either<byte[], ResponseFormat> latestSchemaFilesFromCassandra = getLatestSchemaFilesFromCassandra();
- if (latestSchemaFilesFromCassandra.isRight()) {
- log.error("Error retrieving SDC Schema files from cassandra");
- return Either.right(latestSchemaFilesFromCassandra.right().value());
+ if (component.getModel() == null) {
+ //retrieve SDC.zip from Cassandra
+ Either<byte[], ResponseFormat> latestSchemaFiles = getLatestSchemaFilesFromCassandra();
+ if (latestSchemaFiles.isRight()) {
+ log.error("Error retrieving SDC Schema files from cassandra");
+ return Either.right(latestSchemaFiles.right().value());
+ }
+ final byte[] schemaFileZip = latestSchemaFiles.left().value();
+ final List<String> nodesFromPackage = findNonRootNodesFromPackage(dependencies);
+ //add files from retrieved SDC.zip to Definitions folder in CSAR
+ addSchemaFilesFromCassandra(zip, schemaFileZip, nodesFromPackage);
+ } else {
+ //retrieve schema files by model from Cassandra
+ addSchemaFilesByModel(zip, component.getModel());
}
- final byte[] schemaFileZip = latestSchemaFilesFromCassandra.left().value();
- final List<String> nodesFromPackage = findNonRootNodesFromPackage(dependencies);
- //add files from retrieved SDC.zip to Definitions folder in CSAR
- addSchemaFilesFromCassandra(zip, schemaFileZip, nodesFromPackage);
Either<CsarDefinition, ResponseFormat> collectedComponentCsarDefinition = collectComponentCsarDefinition(component);
if (collectedComponentCsarDefinition.isRight()) {
return Either.right(collectedComponentCsarDefinition.right().value());
@@ -799,6 +809,22 @@ public class CsarUtils {
.bind(iff(List::isEmpty, () -> schemaFileFetchError(fto), s -> Either.left(s.iterator().next().getPayloadAsArray())));
}
+ private void addSchemaFilesByModel(final ZipOutputStream zipOutputStream, final String model) {
+ try {
+ final List<ToscaImportByModel> schemaImportsByModel = toscaModelImportCassandraDao.findAllByModel(model);
+ for (ToscaImportByModel toscaImportByModel : schemaImportsByModel) {
+ final ZipEntry zipEntry = new ZipEntry(DEFINITIONS_PATH + toscaImportByModel.getFullPath());
+ zipOutputStream.putNextEntry(zipEntry);
+ final byte[] content = toscaImportByModel.getContent().getBytes(StandardCharsets.UTF_8);
+ zipOutputStream.write(content, 0, content.length);
+ zipOutputStream.closeEntry();
+ }
+ } catch (IOException e) {
+ log.error("Error while writing the schema files by model to the CSAR " + "{}", e);
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.CSAR_TOSCA_IMPORTS_ERROR));
+ }
+ }
+
private F<CassandraOperationStatus, ResponseFormat> schemaFilesFetchDBError(String firstThreeOctets) {
return cos -> {
log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}. Please fix DB table accordingly.", firstThreeOctets,
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 8b8c3153cf..b70d676200 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
@@ -47,6 +47,7 @@ import java.util.stream.Collectors;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
@@ -55,7 +56,9 @@ import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.cassandra.ToscaModelImportCassandraDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.data.model.ToscaImportByModel;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
@@ -168,6 +171,7 @@ public class ToscaExportHandler {
private OutputConverter outputConverter;
private InterfaceLifecycleOperation interfaceLifecycleOperation;
private InterfacesOperationsConverter interfacesOperationsConverter;
+ private ToscaModelImportCassandraDao toscaModelImportCassandraDao;
@Autowired
public ToscaExportHandler(final ApplicationDataTypeCache applicationDataTypeCache,
@@ -180,7 +184,8 @@ public class ToscaExportHandler {
final InputConverter inputConverter,
final OutputConverter outputConverter,
final InterfaceLifecycleOperation interfaceLifecycleOperation,
- final InterfacesOperationsConverter interfacesOperationsConverter) {
+ final InterfacesOperationsConverter interfacesOperationsConverter,
+ final ToscaModelImportCassandraDao toscaModelImportCassandraDao) {
this.applicationDataTypeCache = applicationDataTypeCache;
this.toscaOperationFacade = toscaOperationFacade;
this.capabilityRequirementConverter = capabilityRequirementConverter;
@@ -192,6 +197,7 @@ public class ToscaExportHandler {
this.outputConverter = outputConverter;
this.interfaceLifecycleOperation = interfaceLifecycleOperation;
this.interfacesOperationsConverter = interfacesOperationsConverter;
+ this.toscaModelImportCassandraDao = toscaModelImportCassandraDao;
}
public static String getInterfaceFilename(String artifactName) {
@@ -211,7 +217,7 @@ public class ToscaExportHandler {
}
public Either<ToscaRepresentation, ToscaError> exportComponentInterface(final Component component, final boolean isAssociatedComponent) {
- final List<Map<String, Map<String, String>>> imports = new ArrayList<>(getDefaultToscaImportConfig());
+ final List<Map<String, Map<String, String>>> imports = new ArrayList<>(getDefaultToscaImports(component.getModel()));
if (CollectionUtils.isEmpty(imports)) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
@@ -274,7 +280,7 @@ public class ToscaExportHandler {
}
public Either<ToscaTemplate, ToscaError> convertToToscaTemplate(final Component component) {
- final List<Map<String, Map<String, String>>> defaultToscaImportConfig = getDefaultToscaImportConfig();
+ final List<Map<String, Map<String, String>>> defaultToscaImportConfig = getDefaultToscaImports(component.getModel());
if (CollectionUtils.isEmpty(defaultToscaImportConfig)) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
@@ -297,6 +303,19 @@ public class ToscaExportHandler {
}
}
+ public List<Map<String, Map<String, String>>> getDefaultToscaImports(final String model) {
+ if (model == null) {
+ return getDefaultToscaImportConfig();
+ }
+ final List<ToscaImportByModel> importsByModel = toscaModelImportCassandraDao.findAllByModel(model);
+ final List<Map<String, Map<String, String>>> importList = new ArrayList<>();
+ for(ToscaImportByModel toscaImportByModel: importsByModel) {
+ final String fileName = FilenameUtils.getBaseName(toscaImportByModel.getFullPath());
+ importList.add(Map.of(fileName, Map.of("file", toscaImportByModel.getFullPath())));
+ }
+ return importList;
+ }
+
private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component, toscaNode);
if (importsRes.isRight()) {
@@ -508,7 +527,7 @@ public class ToscaExportHandler {
}
private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component, ToscaTemplate toscaTemplate) {
- final List<Map<String, Map<String, String>>> defaultToscaImportConfig = getDefaultToscaImportConfig();
+ final List<Map<String, Map<String, String>>> defaultToscaImportConfig = getDefaultToscaImports(component.getModel());
if (CollectionUtils.isEmpty(defaultToscaImportConfig)) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);