summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-04-09 13:30:04 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-04-13 12:51:49 +0000
commit88a3a7f6952fc5da7008b318be55636d784b3717 (patch)
tree01a72b88ba611b8fc75f21ddf0e8b212e365e590 /catalog-be/src
parentae8fe8b1deb89995ff844f7019c3e570e9c8c948 (diff)
Fix 'Unable to delete declared outputs'
Change-Id: I11cd688f4c3ad25cbcb32e9f9b3dee782fc70fa7 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3557
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java77
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java55
5 files changed, 4 insertions, 162 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java
index 9b3487dbc9..47fd74e8ce 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java
@@ -20,32 +20,24 @@
package org.openecomp.sdc.be.components.attribute;
import fj.data.Either;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetOutputValueDataDefinition;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
@org.springframework.stereotype.Component
public class ComponentAttributeDeclarator extends DefaultAttributeDeclarator<Component, AttributeDataDefinition> {
private final ToscaOperationFacade toscaOperationFacade;
- private final AttributeBusinessLogic attributeBusinessLogic;
- public ComponentAttributeDeclarator(final ComponentsUtils componentsUtils, final AttributeOperation attributeOperation,
- final ToscaOperationFacade toscaOperationFacade, final AttributeBusinessLogic attributeBusinessLogic) {
-// super(componentsUtils, attributeOperation);
+ public ComponentAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade) {
this.toscaOperationFacade = toscaOperationFacade;
- this.attributeBusinessLogic = attributeBusinessLogic;
}
@Override
@@ -75,12 +67,7 @@ public class ComponentAttributeDeclarator extends DefaultAttributeDeclarator<Com
@Override
public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, final OutputDefinition output) {
- AttributeDefinition attributeDefinition = new AttributeDefinition(output);
- // TODO - do we need this one
- if (attributeBusinessLogic.isAttributeUsedByOperation(component, attributeDefinition)) {
- return StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION;
- }
- Optional<AttributeDefinition> attributeToUpdateCandidate = getDeclaredAttributeByOutputId(component, output.getUniqueId());
+ final Optional<AttributeDefinition> attributeToUpdateCandidate = getDeclaredAttributeByOutputId(component, output.getUniqueId());
if (attributeToUpdateCandidate.isPresent()) {
AttributeDefinition attributeToUpdate = attributeToUpdateCandidate.get();
return unDeclareOutput(component, output, attributeToUpdate);
@@ -90,7 +77,6 @@ public class ComponentAttributeDeclarator extends DefaultAttributeDeclarator<Com
private StorageOperationStatus unDeclareOutput(final Component component, final OutputDefinition output,
final AttributeDefinition attributeToUpdate) {
- prepareValueBeforeDelete(output, attributeToUpdate, Collections.emptyList());
attributeToUpdate.setValue(output.getDefaultValue());
Either<AttributeDefinition, StorageOperationStatus> status = toscaOperationFacade.updateAttributeOfComponent(component, attributeToUpdate);
if (status.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java
index 0882edaa4f..4c75624ec1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java
@@ -27,14 +27,12 @@ import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
@org.springframework.stereotype.Component
@@ -44,10 +42,8 @@ public class ComponentInstanceAttributeDeclarator extends DefaultAttributeDeclar
private ToscaOperationFacade toscaOperationFacade;
private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
- public ComponentInstanceAttributeDeclarator(final ComponentsUtils componentsUtils, final AttributeOperation attributeOperation,
- final ToscaOperationFacade toscaOperationFacade,
+ public ComponentInstanceAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade,
final ComponentInstanceBusinessLogic componentInstanceBusinessLogic) {
-// super(componentsUtils, attributeOperation);
this.toscaOperationFacade = toscaOperationFacade;
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
}
@@ -79,8 +75,6 @@ public class ComponentInstanceAttributeDeclarator extends DefaultAttributeDeclar
if (CollectionUtils.isEmpty(componentInstancePropertiesDeclaredAsInput)) {
return StorageOperationStatus.OK;
}
- componentInstancePropertiesDeclaredAsInput
- .forEach(cmptInstanceProperty -> prepareValueBeforeDelete(output, cmptInstanceProperty, cmptInstanceProperty.getPath()));
return toscaOperationFacade
.updateComponentInstanceAttributes(component, componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(),
componentInstancePropertiesDeclaredAsInput);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java
index 989cc97069..9ad7c2a9e3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java
@@ -28,14 +28,12 @@ import java.util.Map;
import java.util.Optional;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
@org.springframework.stereotype.Component
@@ -45,10 +43,8 @@ public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttribute
private final ToscaOperationFacade toscaOperationFacade;
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
- public ComponentInstanceOutputAttributeDeclarator(final ComponentsUtils componentsUtils, final AttributeOperation attributeOperation,
- final ToscaOperationFacade toscaOperationFacade,
+ public ComponentInstanceOutputAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade,
final ComponentInstanceBusinessLogic componentInstanceBusinessLogic) {
-// super(componentsUtils, attributeOperation);
this.toscaOperationFacade = toscaOperationFacade;
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
}
@@ -79,8 +75,6 @@ public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttribute
if (isEmpty(componentInstanceInputsByInputId)) {
return StorageOperationStatus.OK;
}
- componentInstanceInputsByInputId
- .forEach(cmptInstanceInput -> prepareValueBeforeDelete(output, cmptInstanceInput, cmptInstanceInput.getPath()));
return toscaOperationFacade.updateComponentInstanceOutputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(),
componentInstanceInputsByInputId);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
index 915959b7cd..62f4211925 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
@@ -49,14 +49,12 @@ import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.yaml.snakeyaml.Yaml;
public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends PropertiesOwner, ATTRIBUTETYPE extends AttributeDataDefinition> implements
AttributeDeclarator {
private static final Logger log = Logger.getLogger(DefaultAttributeDeclarator.class);
- private static final short LOOP_PROTECTION_LEVEL = 10;
private static final String UNDERSCORE = "_";
private final Gson gson = new Gson();
@@ -287,65 +285,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
return lhm1;
}
- Either<OutputDefinition, ResponseFormat> prepareValueBeforeDelete(final OutputDefinition inputForDelete, final AttributeDataDefinition inputValue,
- final List<String> pathOfComponentInstances) {
- final Either<OutputDefinition, ResponseFormat> deleteEither = prepareValueBeforeDelete(inputForDelete, inputValue);
-// Either<String, JanusGraphOperationStatus> findDefaultValue = propertyOperation
-
-// .findDefaultValueFromSecondPosition(pathOfComponentInstances, inputValue.getUniqueId(),
-
-// (String) inputValue.get_default());
-
-// if (findDefaultValue.isRight()) {
-
-// deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils
-
-// .convertFromStorageResponse(
-
-// DaoStatusConverter.convertJanusGraphStatusToStorageStatus(findDefaultValue.right().value()))));
-
-// return deleteEither;
-
-//
-
-// }
-
-// String defaultValue = findDefaultValue.left().value();
-
-// inputValue.set_default(defaultValue);
-
-// log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
- return deleteEither;
- }
-
- private Either<OutputDefinition, ResponseFormat> prepareValueBeforeDelete(final OutputDefinition outputForDelete,
- final AttributeDataDefinition outputValue) {
- final Either<OutputDefinition, ResponseFormat> deleteEither = Either.left(outputForDelete);
- String value = outputValue.getValue();
- final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value);
- resetOutputName(mappedToscaTemplate, outputForDelete.getName());
- value = "";
- if (MapUtils.isNotEmpty(mappedToscaTemplate)) {
- final Either result = cleanNestedMap(mappedToscaTemplate, true);
- Map modifiedMappedToscaTemplate = mappedToscaTemplate;
- if (result.isLeft()) {
- modifiedMappedToscaTemplate = (Map) result.left().value();
- } else {
- log.warn("Map cleanup failed -> {}", result.right().value()); //continue, don't break operation
- }
- value = gson.toJson(modifiedMappedToscaTemplate);
- }
- outputValue.setValue(value);
- final List<GetOutputValueDataDefinition> getInputsValues = outputValue.getGetOutputValues();
- if (getInputsValues != null && !getInputsValues.isEmpty()) {
- final Optional<GetOutputValueDataDefinition> op = getInputsValues.stream()
- .filter(gi -> gi.getOutputId().equals(outputForDelete.getUniqueId())).findAny();
- op.ifPresent(getInputsValues::remove);
- }
- outputValue.setGetOutputValues(getInputsValues);
- return deleteEither;
- }
-
private void resetOutputName(final Map<String, Object> lhm1, final String outputName) {
for (final Map.Entry<String, Object> entry : lhm1.entrySet()) {
final String key = entry.getKey();
@@ -361,22 +300,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
}
}
- private Either cleanNestedMap(Map mappedToscaTemplate, final boolean deepClone) {
- if (MapUtils.isNotEmpty(mappedToscaTemplate)) {
- if (deepClone) {
- if (!(mappedToscaTemplate instanceof HashMap)) {
- return Either.right("expecting mappedToscaTemplate as HashMap ,recieved " + mappedToscaTemplate.getClass().getSimpleName());
- } else {
- mappedToscaTemplate = (HashMap) ((HashMap) mappedToscaTemplate).clone();
- }
- }
- return Either.left((Map) cleanEmptyNestedValuesInMap(mappedToscaTemplate, LOOP_PROTECTION_LEVEL));
- } else {
- log.debug("mappedToscaTemplate is empty ");
- return Either.right("mappedToscaTemplate is empty ");
- }
- }
-
/* Mutates the object
* Tail recurse -> traverse the tosca elements and remove nested empty map properties
* this only handles nested maps, other objects are left untouched (even a Set containing a map) since behaviour is unexpected
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
index 3c06e8b818..687a5d56ef 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
@@ -341,59 +341,4 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
return Either.left(status.left().value().getAttributes());
}
- public boolean isAttributeUsedByOperation(Component component, AttributeDefinition propertyDefinitionEntry) {
- // TODO - do we need this one
- return false;
-// // Component's own interfaces
-
-// Map<String, InterfaceDefinition> interfaces = component.getInterfaces();
-
-// if(MapUtils.isNotEmpty(interfaces)){
-
-// for(Map.Entry<String, InterfaceDefinition> interfaceEntry : interfaces.entrySet()) {
-
-// if (isPropertyExistInOperationInterface(propertyDefinitionEntry, interfaceEntry.getValue())) {
-
-// return true;
-
-// }
-
-// }
-
-// }
-
-//
-
-// // Component's child's component interfaces
-
-// if(isPropertyUsedInCIInterfaces(component.getComponentInstancesInterfaces(), propertyDefinitionEntry)){
-
-// return true;
-
-// }
-
-//
-
-// // Component's parent's component interfaces
-
-// Either<List<Component>, StorageOperationStatus> componentList = toscaOperationFacade.getParentComponents(component.getUniqueId());
-
-// if(componentList.isLeft()){
-
-// for (Component parentComponent : componentList.left().value()) {
-
-// if(isPropertyUsedInCIInterfaces(parentComponent.getComponentInstancesInterfaces(), propertyDefinitionEntry)){
-
-// return true;
-
-// }
-
-// }
-
-// }
-
-//
-
-// return false;
- }
}