summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-07-14 21:06:58 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-15 13:16:16 +0000
commitee8876059c520d97bf068734b25a02365d7fe1ea (patch)
tree46176fc6a016818c6d17dd0ac20054ec884e7802 /catalog-model/src/main/java
parente4055451d3fbfe1fba35dcf546907ad432f6b4fc (diff)
Support Outputs during Import Service
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I4d58576b70ef738d6fa7545cd268ec030b43f95c Issue-ID: SDC-4051
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java15
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java58
4 files changed, 61 insertions, 21 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
index 3d2125471d..ae0c2c0632 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
@@ -18,7 +18,6 @@
*/
package org.openecomp.sdc.be.model;
-import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -29,17 +28,18 @@ import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
@NoArgsConstructor
public class OutputDefinition extends AttributeDefinition {
- private List<ComponentInstanceAttribute> attributes;
+ private ComponentInstanceAttribute attribute;
public OutputDefinition(final AttributeDataDefinition attributeDataDefinition) {
super(attributeDataDefinition);
}
- public OutputDefinition(AttributeDefinition propertyDefinition) {
- super(propertyDefinition);
+ public OutputDefinition(AttributeDefinition attributeDefinition) {
+ super(attributeDefinition);
}
public OutputDefinition(final OutputDefinition outputDefinition) {
super(outputDefinition);
+ this.attribute = outputDefinition.getAttribute();
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
index 9ea74ea565..6af88e1215 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterProp
public class ParsedToscaYamlInfo {
Map<String, InputDefinition> inputs;
+ Map<String, OutputDefinition> outputs;
Map<String, UploadComponentInstanceInfo> instances;
Map<String, GroupDefinition> groups;
Map<String, PolicyDefinition> policies;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
index 7742cbfe0e..dcd801168a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
@@ -583,6 +583,21 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return StorageOperationStatus.OK;
}
+ public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex,
+ final Map<String, ? extends AttributeDataDefinition> outputs,
+ final String id) {
+ if (MapUtils.isNotEmpty(outputs)) {
+ outputs.values().stream().filter(e -> e.getUniqueId() == null)
+ .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
+ final Either<GraphVertex, StorageOperationStatus> associateElementToData
+ = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs);
+ if (associateElementToData.isRight()) {
+ return associateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
fillCommonMetadata(nodeTypeVertex, topologyTemplate);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index cf1b23ec88..7c34da89f0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -148,6 +148,8 @@ public class ToscaOperationFacade {
private static final String VF = "VF";
private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
private static final String COMPONENT_CREATED_SUCCESSFULLY = "Component created successfully!!!";
+ private static final String INPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY = "Inputs associated to component successfully!";
+ private static final String OUTPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY = "Outputs associated to component successfully!";
private static final String COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR = "Couldn't fetch component with and unique id {}, error: {}";
private static final Logger log = Logger.getLogger(ToscaOperationFacade.class.getName());
@Autowired
@@ -1362,7 +1364,7 @@ public class ToscaOperationFacade {
.collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
StorageOperationStatus status = topologyTemplateOperation.associateInputsToComponent(vertex, inputsMap, componentId);
if (StorageOperationStatus.OK == status) {
- log.debug(COMPONENT_CREATED_SUCCESSFULLY);
+ log.debug(INPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY);
List<InputDefinition> inputsResList = null;
if (inputsMap != null && !inputsMap.isEmpty()) {
inputsResList = inputsMap.values().stream().map(InputDefinition::new).collect(Collectors.toList());
@@ -1372,6 +1374,28 @@ public class ToscaOperationFacade {
return Either.right(status);
}
+ public Either<List<OutputDefinition>, StorageOperationStatus> createAndAssociateOutputs(final Map<String, OutputDefinition> outputs,
+ final String componentId) {
+ final Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ final GraphVertex vertex = getVertexEither.left().value();
+ final Map<String, OutputDefinition> outputsMap = outputs.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> new OutputDefinition(e.getValue())));
+ final StorageOperationStatus status = topologyTemplateOperation.associateOutputsToComponent(vertex, outputsMap, componentId);
+ if (StorageOperationStatus.OK == status) {
+ log.debug(OUTPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY);
+ List<OutputDefinition> outputsResList = null;
+ if (MapUtils.isNotEmpty(outputsMap)) {
+ outputsResList = outputsMap.values().stream().map(OutputDefinition::new).collect(Collectors.toList());
+ }
+ return Either.left(outputsResList);
+ }
+ return Either.right(status);
+ }
+
public Either<List<InputDefinition>, StorageOperationStatus> addInputsToComponent(Map<String, InputDefinition> inputs, String componentId) {
Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getVertexEither.isRight()) {
@@ -1526,7 +1550,7 @@ public class ToscaOperationFacade {
GraphVertex vertex = getVertexEither.left().value();
List<AttributeDataDefinition> outputsAsDataDef = outputs.stream().map(AttributeDataDefinition::new).collect(Collectors.toList());
StorageOperationStatus status = topologyTemplateOperation
- .updateToscaDataOfToscaElement(vertex, EdgeLabelEnum.OUTPUTS, VertexTypeEnum.OUTPUTS, outputsAsDataDef, JsonPresentationFields.NAME);
+ .updateToscaDataOfToscaElement(vertex, EdgeLabelEnum.OUTPUTS, VertexTypeEnum.OUTPUTS, outputsAsDataDef, JsonPresentationFields.NAME);
if (StorageOperationStatus.OK == status) {
log.debug(COMPONENT_CREATED_SUCCESSFULLY);
List<OutputDefinition> outputsResList = null;
@@ -1671,33 +1695,33 @@ public class ToscaOperationFacade {
}
public Either<Map<String, List<ComponentInstanceOutput>>, StorageOperationStatus> addComponentInstanceOutputsToComponent(
- Component containerComponent, Map<String, List<ComponentInstanceOutput>> instProperties) {
- requireNonNull(instProperties);
+ Component containerComponent, Map<String, List<ComponentInstanceOutput>> instOutputs) {
+ requireNonNull(instOutputs);
StorageOperationStatus status;
- for (final Entry<String, List<ComponentInstanceOutput>> entry : instProperties.entrySet()) {
- final List<ComponentInstanceOutput> props = entry.getValue();
+ for (final Entry<String, List<ComponentInstanceOutput>> entry : instOutputs.entrySet()) {
+ final List<ComponentInstanceOutput> outputs = entry.getValue();
final String componentInstanceId = entry.getKey();
- if (!isEmpty(props)) {
- for (final ComponentInstanceOutput property : props) {
- final List<ComponentInstanceOutput> componentInstancesInputs = containerComponent.getComponentInstancesOutputs()
+ if (!isEmpty(outputs)) {
+ for (final ComponentInstanceOutput output : outputs) {
+ final List<ComponentInstanceOutput> componentInstanceOutputs = containerComponent.getComponentInstancesOutputs()
.get(componentInstanceId);
- final Optional<ComponentInstanceOutput> instanceProperty = componentInstancesInputs.stream()
- .filter(p -> p.getName().equals(property.getName())).findAny();
- if (instanceProperty.isPresent()) {
- status = updateComponentInstanceOutput(containerComponent, componentInstanceId, property);
+ final Optional<ComponentInstanceOutput> componentInstanceOutput = componentInstanceOutputs.stream()
+ .filter(p -> p.getName().equals(output.getName())).findAny();
+ if (componentInstanceOutput.isPresent()) {
+ status = updateComponentInstanceOutput(containerComponent, componentInstanceId, output);
} else {
- status = addComponentInstanceOutput(containerComponent, componentInstanceId, property);
+ status = addComponentInstanceOutput(containerComponent, componentInstanceId, output);
}
if (status != StorageOperationStatus.OK) {
- log.debug("Failed to update instance input {} for instance {} error {} ", property, componentInstanceId, status);
+ log.debug("Failed to update instance output {} for instance {} error {} ", output, componentInstanceId, status);
return Either.right(status);
} else {
- log.trace("instance input {} for instance {} updated", property, componentInstanceId);
+ log.trace("instance output {} for instance {} updated", output, componentInstanceId);
}
}
}
}
- return Either.left(instProperties);
+ return Either.left(instOutputs);
}
public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(