summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java108
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java20
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java4
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ArtifactDataDefinition.java11
4 files changed, 73 insertions, 70 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 65ade9539d..492ebcf0e4 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
@@ -44,6 +44,8 @@ import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
@@ -1114,73 +1116,79 @@ public class CsarUtils {
}
private Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath(final Component mainComponent,
- final ArtifactsInfo currArtifactsInfo,
- final ZipOutputStream zip,
- final String path,
- final boolean isInCertificationRequest) throws IOException {
+ final ArtifactsInfo currArtifactsInfo,
+ final ZipOutputStream zip,
+ final String path,
+ final boolean isInCertificationRequest) throws IOException {
+
final Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> artifactsInfo =
currArtifactsInfo.getArtifactsInfo();
for (final ArtifactGroupTypeEnum artifactGroupTypeEnum : artifactsInfo.keySet()) {
- final String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + PATH_DELIMITER;
+ final String groupTypeFolder =
+ path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + PATH_DELIMITER;
final Map<String, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
for (final String artifactType : artifactTypesMap.keySet()) {
final List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactType);
- String artifactTypeFolder = groupTypeFolder + artifactType + PATH_DELIMITER;
-
- if(ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType) && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
- // Ignore this packaging as BPMN artifacts needs to be packaged in different manner
- continue;
- }
- if (ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType)) {
- artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
- }
+ String artifactTypeFolder = groupTypeFolder + artifactType + PATH_DELIMITER;
- Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition =
- writeArtifactDefinition(mainComponent, zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
+ if (ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType) && path
+ .contains(ARTIFACTS_PATH + RESOURCES_PATH)) {
+ // Ignore this packaging as BPMN artifacts needs to be packaged in different manner
+ continue;
+ }
+ if (ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType)) {
+ artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
+ }
- if (writeArtifactDefinition.isRight()) {
- return writeArtifactDefinition;
+ // TODO: We should not do this but in order to keep this refactoring small enough,
+ // we'll leave this as is for now
+ List<ArtifactDefinition> collect =
+ filterArtifactDefinitionToZip(mainComponent, artifactDefinitionList, isInCertificationRequest)
+ .collect(Collectors.toList());
+ for (ArtifactDefinition ad : collect) {
+ zip.putNextEntry(new ZipEntry(artifactTypeFolder + ad.getArtifactName()));
+ zip.write(ad.getPayloadData());
}
}
}
-
return Either.left(zip);
}
- private Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition(Component mainComponent, ZipOutputStream zip, List<ArtifactDefinition> artifactDefinitionList,
- String artifactPathAndFolder, boolean isInCertificationRequest) throws IOException {
-
- ComponentTypeEnum componentType = mainComponent.getComponentType();
- String heatEnvType = ArtifactTypeEnum.HEAT_ENV.getType();
-
- for (ArtifactDefinition artifactDefinition : artifactDefinitionList) {
- if (!isInCertificationRequest && componentType == ComponentTypeEnum.SERVICE
- && artifactDefinition.getArtifactType().equals(heatEnvType) ||
- //this is placeholder
- (artifactDefinition.getEsId() == null && artifactDefinition.getMandatory())){
- continue;
- }
-
- byte[] payloadData = artifactDefinition.getPayloadData();
- String artifactFileName = artifactDefinition.getArtifactName();
-
- if (payloadData == null) {
- Either<byte[], ActionStatus> fromCassandra = getFromCassandra(artifactDefinition.getEsId());
-
- if (fromCassandra.isRight()) {
- log.debug(ARTIFACT_NAME_UNIQUE_ID, artifactDefinition.getArtifactName(), artifactDefinition.getUniqueId());
- log.debug("Failed to get {} payload from DB reason: {}", artifactFileName, fromCassandra.right().value());
- continue;
- }
- payloadData = fromCassandra.left().value();
- }
- zip.putNextEntry(new ZipEntry(artifactPathAndFolder + artifactFileName));
- zip.write(payloadData);
+ private Stream<ArtifactDefinition> filterArtifactDefinitionToZip(Component mainComponent,
+ List<ArtifactDefinition> artifactDefinitionList, boolean isInCertificationRequest) {
+ return artifactDefinitionList
+ .stream()
+ .filter(shouldBeInZip(isInCertificationRequest, mainComponent))
+ .map(this::fetchPayLoadData)
+ .filter(Either::isLeft)
+ .map(e -> e.left().value());
+ }
+
+ private Predicate<ArtifactDefinition> shouldBeInZip(boolean isInCertificationRequest, Component component) {
+ return artifactDefinition ->
+ !(!isInCertificationRequest
+ && component.isService()
+ && artifactDefinition.isHeatEnvType()
+ || artifactDefinition.hasNoMandatoryEsId());
+ }
+
+ private Either<ArtifactDefinition, ActionStatus> fetchPayLoadData(ArtifactDefinition ad) {
+ byte[] payloadData = ad.getPayloadData();
+ if(payloadData == null) {
+ return getFromCassandra(ad.getEsId())
+ .left().map(pd -> {
+ ad.setPayload(pd);
+ return ad;
+ }).right().map(as -> {
+ log.debug(ARTIFACT_NAME_UNIQUE_ID, ad.getArtifactName(), ad.getUniqueId());
+ log.debug("Failed to get {} payload from DB reason: {}", ad.getArtifactName(), as);
+ return as;
+ });
+ } else {
+ return Either.left(ad);
}
-
- return Either.left(zip);
}
/************************************ Artifacts Structure ******************************************************************/
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
index 3ee2b89047..4fd8a70229 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
@@ -43,6 +43,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import mockit.Deencapsulation;
@@ -781,24 +783,6 @@ public class CsarUtilsTest extends BeConfDependentTest {
}
@Test
- public void testWriteArtifactDefinition() throws IOException {
- Component component = new Service();
- List<ArtifactDefinition> artifactDefinitionList = new ArrayList<>();
- String artifactPathAndFolder = "";
-
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactType(ArtifactTypeEnum.HEAT_ENV.getType());
- artifactDefinitionList.add(artifact);
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "writeArtifactDefinition", component, zip, artifactDefinitionList, artifactPathAndFolder, false);
-
- assertNotNull(output);
- assertTrue(output.isLeft());
- }
- }
-
- @Test
public void testCollectComponentCsarDefinitionWhenComponentIsServiceAndGetToscaElementIsLeft() {
Component component = new Service();
component.setUniqueId("uniqueId");
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index 63194752fc..477d903652 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -286,6 +286,10 @@ public abstract class Component implements PropertiesOwner {
return this.componentMetadataDefinition.getMetadataDataDefinition().getComponentType();
}
+ public boolean isService() {
+ return getComponentType() == ComponentTypeEnum.SERVICE;
+ }
+
public void setComponentType(ComponentTypeEnum componentType) {
this.componentMetadataDefinition.getMetadataDataDefinition().setComponentType(componentType);
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ArtifactDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ArtifactDataDefinition.java
index 7360c03f44..3b52eb97df 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ArtifactDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ArtifactDataDefinition.java
@@ -27,8 +27,7 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-
-//import com.google.gson.reflect.TypeToken;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
public class ArtifactDataDefinition extends ToscaDataDefinition {
@@ -92,6 +91,10 @@ public class ArtifactDataDefinition extends ToscaDataDefinition {
return (String) getToscaPresentationValue(JsonPresentationFields.ARTIFACT_TYPE);
}
+ public boolean isHeatEnvType() {
+ return getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.getType());
+ }
+
public void setArtifactType(String artifactType) {
setToscaPresentationValue(JsonPresentationFields.ARTIFACT_TYPE, artifactType);
@@ -205,6 +208,10 @@ public class ArtifactDataDefinition extends ToscaDataDefinition {
return (String) getToscaPresentationValue(JsonPresentationFields.ES_ID);
}
+ public boolean hasNoMandatoryEsId() {
+ return getEsId() == null && getMandatory();
+ }
+
public void setEsId(String esId) {
setToscaPresentationValue(JsonPresentationFields.ES_ID, esId);
}