aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-06-26 19:53:26 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-07-05 07:56:41 +0000
commitdf10d0be06468d55818fa734321c14827fef61bb (patch)
treedf383e3c85999c362a965a6851bd625622b2d91b /catalog-be/src/main
parent0a6a27ea1abf4fe990ac0b3e204a16dd0aca84c3 (diff)
Clean CsarUtils::MainYamlWithDependencies
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I593dd7bb6a20445899a14da793e8c550e1e14e09 Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java6
5 files changed, 40 insertions, 68 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index d8f85617c0..cac36cbe0e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -396,7 +396,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.exportComponent(parent)
.left().map(toscaRepresentation -> {
log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
- return toscaRepresentation.getMainYaml().getBytes();
+ return toscaRepresentation.getMainYaml();
}).right().map(toscaError -> {
log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), toscaError);
return new ByActionStatusComponentException(componentsUtils.convertFromToscaError(toscaError));
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 291d2bb508..241148b531 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
@@ -253,7 +253,7 @@ public class CsarUtils {
.getToscaArtifacts()
.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
- Either<MainYamlWithDependencies, ResponseFormat> toscaRepresentation =
+ Either<ToscaRepresentation, ResponseFormat> toscaRepresentation =
fetchToscaRepresentation(component, getFromCS, artifactDef);
// This should not be done but in order to keep the refactoring small enough we stop here.
@@ -261,8 +261,8 @@ public class CsarUtils {
byte[] mainYaml;
List<Triple<String, String, Component>> dependencies;
if(toscaRepresentation.isLeft()) {
- mainYaml = toscaRepresentation.left().value().mainYaml;
- dependencies = toscaRepresentation.left().value().dependencies.orElse(null);
+ mainYaml = toscaRepresentation.left().value().getMainYaml();
+ dependencies = toscaRepresentation.left().value().getDependencies().getOrElse(new ArrayList<>());
} else {
return Either.right(toscaRepresentation.right().value());
}
@@ -315,7 +315,7 @@ public class CsarUtils {
return writeAllFilesToCsar(component, collectedComponentCsarDefinition.left().value(), zip, isInCertificationRequest);
}
- private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaRepresentation(
+ private Either<ToscaRepresentation, ResponseFormat> fetchToscaRepresentation(
Component component,
boolean getFromCS,
ArtifactDefinition artifactDef
@@ -326,14 +326,14 @@ public class CsarUtils {
!(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN ||
lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- Either<MainYamlWithDependencies, ResponseFormat> toscaRepresentation =
+ Either<ToscaRepresentation, ResponseFormat> toscaRepresentation =
shouldBeFetchedFromCassandra ?
fetchToscaRepresentation(artifactDef) :
generateToscaRepresentation(component);
return toscaRepresentation.left().bind(iff(
- myd -> !myd.dependencies.isPresent(),
- myd -> fetchToscaTemplateDependencies(myd.mainYaml, component)
+ myd -> !myd.getDependencies().isDefined(),
+ myd -> fetchToscaTemplateDependencies(myd.getMainYaml(), component)
));
}
@@ -341,7 +341,7 @@ public class CsarUtils {
return l -> p.test(l) ? ifTrue.apply(l) : Either.left(l);
}
- private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaTemplateDependencies(
+ private Either<ToscaRepresentation, ResponseFormat> fetchToscaTemplateDependencies(
byte[] mainYml,
Component component
) {
@@ -349,47 +349,21 @@ public class CsarUtils {
log.debug("Failed to retrieve dependencies for component {}, error {}",
component.getUniqueId(), toscaError);
return componentsUtils.getResponseFormat(componentsUtils.convertFromToscaError(toscaError));
- }).left().map(tt -> MainYamlWithDependencies.make(mainYml, tt));
+ }).left().map(tt -> ToscaRepresentation.make(mainYml, tt));
}
- private Either<MainYamlWithDependencies, ResponseFormat> generateToscaRepresentation(Component component) {
+ private Either<ToscaRepresentation, ResponseFormat> generateToscaRepresentation(Component component) {
return toscaExportUtils.exportComponent(component).right().map(toscaError -> {
- log.debug("exportComponent failed", toscaError);
+ log.debug("exportComponent failed {}", toscaError);
return componentsUtils.getResponseFormat(componentsUtils.convertFromToscaError(toscaError));
- }).left().map(MainYamlWithDependencies::make);
+ });
}
- private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaRepresentation(ArtifactDefinition artifactDef) {
+ private Either<ToscaRepresentation, ResponseFormat> fetchToscaRepresentation(ArtifactDefinition artifactDef) {
return getFromCassandra(artifactDef.getEsId()).right().map(as -> {
log.debug(ARTIFACT_NAME_UNIQUE_ID, artifactDef.getArtifactName(), artifactDef.getUniqueId());
return componentsUtils.getResponseFormat(as);
- }).left().map(MainYamlWithDependencies::make);
- }
-
- // TODO: Refactor the ToscaRepresentation class in order to remove the following one
- // This will be done in a separate change
- private static class MainYamlWithDependencies {
-
- private final byte[] mainYaml;
- private final Optional<List<Triple<String, String, Component>>> dependencies;
-
- private MainYamlWithDependencies(byte[] mainYaml,
- Optional<List<Triple<String, String, Component>>> dependencies) {
- this.mainYaml = mainYaml;
- this.dependencies = dependencies;
- }
-
- public static MainYamlWithDependencies make(byte[] mainYaml) {
- return new MainYamlWithDependencies(mainYaml, Optional.empty());
- }
-
- public static MainYamlWithDependencies make(ToscaRepresentation tr) {
- return new MainYamlWithDependencies(tr.getMainYaml().getBytes(), Optional.ofNullable(tr.getDependencies()));
- }
-
- public static MainYamlWithDependencies make(byte[] mainYaml, ToscaTemplate tt) {
- return new MainYamlWithDependencies(mainYaml, Optional.ofNullable(tt.getDependencies()));
- }
+ }).left().map(ToscaRepresentation::make);
}
/**
@@ -686,7 +660,7 @@ public class CsarUtils {
boolean isAssociatedComponent,
ZipWriter zw
) {
- Either<String, ToscaError> yml = toscaExportUtils
+ Either<byte[], ToscaError> yml = toscaExportUtils
.exportComponentInterface(component, isAssociatedComponent)
.left().map(ToscaRepresentation::getMainYaml);
@@ -705,7 +679,7 @@ public class CsarUtils {
if (cassandraId == null || cassandraId.isEmpty()) {
return toscaExportUtils.exportComponent(childComponent)
.right().map(toscaErrorToActionStatus(childComponent))
- .left().map(toscaRepresentation -> toscaRepresentation.getMainYaml().getBytes());
+ .left().map(ToscaRepresentation::getMainYaml);
} else {
return getFromCassandra(cassandraId);
}
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 a492f01953..aa9cd8ce49 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
@@ -170,15 +170,7 @@ public class ToscaExportHandler {
public ToscaExportHandler(){}
public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
-
- Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
- if (toscaTemplateRes.isRight()) {
- return Either.right(toscaTemplateRes.right().value());
- }
-
- ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
- ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
- return Either.left(toscaRepresentation);
+ return convertToToscaTemplate(component).left().map(this::createToscaRepresentation);
}
public Either<ToscaRepresentation, ToscaError> exportComponentInterface(final Component component,
@@ -227,11 +219,7 @@ public class ToscaExportHandler {
sb.append(yamlAsString);
sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
- ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
- toscaRepresentation.setMainYaml(sb.toString());
- toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
-
- return toscaRepresentation;
+ return ToscaRepresentation.make(sb.toString().getBytes(), toscaTemplate);
}
public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
index 49fd91cfed..1ca95576a8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
@@ -20,30 +20,36 @@
package org.openecomp.sdc.be.tosca;
+import io.vavr.control.Option;
+import lombok.Getter;
import org.apache.commons.lang3.tuple.Triple;
import org.openecomp.sdc.be.model.Component;
import java.util.List;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
public class ToscaRepresentation {
- private String mainYaml;
- private List<Triple<String, String, Component>> dependencies;
+ @Getter
+ private final byte[] mainYaml;
- public String getMainYaml() {
- return mainYaml;
- }
+ @Getter
+ private final Option<List<Triple<String, String, Component>>> dependencies;
- public void setMainYaml(String mainYaml) {
+ private ToscaRepresentation(byte[] mainYaml, Option<List<Triple<String, String, Component>>> dependencies) {
this.mainYaml = mainYaml;
+ this.dependencies = dependencies;
}
- public List<Triple<String, String, Component>> getDependencies() {
- return dependencies;
+ public static ToscaRepresentation make(byte[] mainYaml) {
+ return new ToscaRepresentation(mainYaml, Option.none());
}
- public void setDependencies(List<Triple<String, String, Component>> dependancies) {
- this.dependencies = dependancies;
+ public static ToscaRepresentation make(byte[] mainYaml, List<Triple<String, String, Component>> dependencies) {
+ return new ToscaRepresentation(mainYaml, Option.of(dependencies));
}
+ public static ToscaRepresentation make(byte[] mainYaml, ToscaTemplate tt) {
+ return new ToscaRepresentation(mainYaml, Option.of(tt.getDependencies()));
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java
index 4740fb2042..916895fff4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java
@@ -54,10 +54,14 @@ public interface ZipWriter {
*
* @param entryName The entry's name to use in the zip file
*/
- default Function<String, Try<Void>> write(String entryName) {
+ default Function<String, Try<Void>> writeString(String entryName) {
return payload -> write(entryName, payload.getBytes());
}
+ default Function<byte[], Try<Void>> write(String entryName) {
+ return payload -> write(entryName, payload);
+ }
+
/**
* Builds a ZipWriter that outputs the data on a {@link java.util.zip.ZipOutputStream}
* @param zos the target {@link java.util.zip.ZipOutputStream}