summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-08-09 02:57:47 +0530
committerpriyanshu <pagarwal@amdocs.com>2018-08-09 02:57:47 +0530
commitbe05c17a3824d38d37adaba1a58291f7bd919646 (patch)
tree194f67b92f2a11fe93b3b1dc5fc32d84329ed7a0 /catalog-model/src/main/java/org
parentf0811d5711a03c3b4b3e02ecdce4a2cd0f7f7a35 (diff)
Interface operations Bug Fixes
1. create and modify operation bug fix 2. Get and Delete negative use case handling 3. refactored code Change-Id: I472abb7f487cb0399e63e413e616a03143a1e2ac Issue-ID: SDC-1535 Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java54
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java39
2 files changed, 24 insertions, 69 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
index 3b1b6e506c..18bd13dce3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
@@ -30,7 +30,6 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -38,16 +37,11 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("interfaces-operation")
public class InterfaceOperation extends BaseOperation {
- private static final Logger logger = Logger.getLogger(InterfaceOperation.class.getName());
-
@Autowired
private ArtifactCassandraDao artifactCassandraDao;
@@ -70,7 +64,6 @@ public class InterfaceOperation extends BaseOperation {
getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getToscaElementRes.isRight()) {
TitanOperationStatus status = getToscaElementRes.right().value();
- logger.debug("Failed to get tosca element {} while adding or updating interface. Status is {}. ", componentId, status);
statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
return Either.right(statusRes);
}
@@ -80,7 +73,6 @@ public class InterfaceOperation extends BaseOperation {
}
statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, Arrays.asList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
if (!statusRes.equals(StorageOperationStatus.OK)) {
- logger.debug("Failed to add or update interface of component {}. status is {}", componentId, statusRes);
return Either.right(statusRes);
}
return Either.left(interfaceDefinition);
@@ -103,7 +95,6 @@ public class InterfaceOperation extends BaseOperation {
getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getToscaElementRes.isRight()) {
TitanOperationStatus status = getToscaElementRes.right().value();
- logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", componentId, status);
statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
return Either.right(statusRes);
}
@@ -111,27 +102,20 @@ public class InterfaceOperation extends BaseOperation {
getToscaElementInt = titanDao.getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
if (getToscaElementInt.isRight()) {
TitanOperationStatus status = getToscaElementInt.right().value();
- logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", interfaceDef.getUniqueId(), status);
statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
return Either.right(statusRes);
}
GraphVertex interfaceVertex = getToscaElementInt.left().value();
- if (!isUpdateAction)
- initNewOperation(operation);
- else
- operation.setImplementation(getArtifactImplFromOperation(operation, interfaceDef));
statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, Arrays.asList(operation),
EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION);
if (!statusRes.equals(StorageOperationStatus.OK)) {
- logger.debug("Failed to add or update operation of interface {}. status is {}", interfaceDef.getUniqueId(), statusRes);
return Either.right(statusRes);
}
getUpdatedInterfaceDef(interfaceDef, operation, operation.getUniqueId());
Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef);
if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) {
- logger.debug("Failed to update interface details on component {}. status is {}", componentId, statusRes);
return Either.right(statusRes);
}
@@ -163,7 +147,6 @@ public class InterfaceOperation extends BaseOperation {
String artifactUUID = implementationArtifact.getArtifactUUID();
CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID);
if (cassandraStatus != CassandraOperationStatus.OK) {
- logger.debug("Failed to delete the artifact {} from the database. ", artifactUUID);
return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus));
}
@@ -181,6 +164,10 @@ public class InterfaceOperation extends BaseOperation {
getUpdatedInterfaceDef(interfaceDef, null, operationToDelete);
if (interfaceDef.getOperations().isEmpty()) {
+ status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Arrays.asList(interfaceDef.getUniqueId()));
+ if (status != StorageOperationStatus.OK) {
+ return Either.right(status);
+ }
status = removeToscaDataVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
if (status != StorageOperationStatus.OK) {
return Either.right(status);
@@ -196,17 +183,6 @@ public class InterfaceOperation extends BaseOperation {
return Either.left(operation);
}
- public Either<Operation, StorageOperationStatus> getInterfaceOperation(InterfaceDefinition interfaceDef, String operationToGet) {
- Operation operation = new Operation();
- Optional<Entry<String, Operation>> operationToFetch = interfaceDef.getOperationsMap().entrySet().stream()
- .filter(entry -> entry.getValue().getUniqueId().equals(operationToGet)).findAny();
- if (operationToFetch.isPresent()){
- Map.Entry<String, Operation> stringOperationEntry = operationToFetch.get();
- operation = stringOperationEntry.getValue();
- }
- return Either.left(operation);
- }
-
private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
List<ToscaDataDefinition> toscaDataList, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
if (isUpdate) {
@@ -216,29 +192,9 @@ public class InterfaceOperation extends BaseOperation {
}
}
- private ArtifactDefinition createNewArtifactDefForOperation(){
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- String artifactUUID = UUID.randomUUID().toString();
- artifactDefinition.setArtifactUUID(artifactUUID);
- artifactDefinition.setUniqueId(artifactUUID);
- artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
- artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
- return artifactDefinition;
- }
-
- private ArtifactDataDefinition getArtifactImplFromOperation(Operation operation, InterfaceDefinition interfaceDef){
- Either<Operation, StorageOperationStatus> operationData = getInterfaceOperation(interfaceDef, operation.getUniqueId());
- return operationData.isLeft()? operationData.left().value().getImplementation() : createNewArtifactDefForOperation();
- }
-
- private void initNewOperation(Operation operation){
- operation.setUniqueId(UUID.randomUUID().toString());
- operation.setImplementation(createNewArtifactDefForOperation());
- }
-
private InterfaceDefinition getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){
Map<String, Operation> operationMap = interfaceDef.getOperationsMap();
- if(operation != null && !operation.isEmpty()){
+ if(operation != null){
operationMap.put(operationId, operation);
interfaceDef.setOperationsMap(operationMap);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java
index 249de97d86..5fa64d6ca6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java
@@ -15,8 +15,12 @@
*/
package org.openecomp.sdc.be.model.jsontitan.utils;
+import java.util.Collection;
+import java.util.Formatter;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
@@ -24,10 +28,6 @@ import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-
-import java.util.*;
-import java.util.stream.Collectors;
public class InterfaceUtils {
@@ -47,15 +47,15 @@ public class InterfaceUtils {
}
public static Collection<InterfaceDefinition> getInterfaceDefinitionListFromToscaName(Collection<InterfaceDefinition> interfaces,
- String resourceName) {
+ String resourceName) {
if(CollectionUtils.isEmpty(interfaces)){
return CollectionUtils.EMPTY_COLLECTION;
}
String toscaName = createInterfaceToscaResourceName(resourceName);
return interfaces.stream().filter(
- interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
- .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
+ interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
+ .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
}
public static String createInterfaceToscaResourceName(String resourceName) {
@@ -65,14 +65,13 @@ public class InterfaceUtils {
}
}
- public static void createInputOutput(Operation operation, List<InputDefinition> inputs) throws IllegalStateException {
+ public static void createInputOutput(Operation operation, List<InputDefinition> inputs, List<InputDefinition> outputs) throws IllegalStateException {
ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
if (inputDefinitionListDataDefinition != null) {
return;
}
- List<OperationInputDefinition> listToscaDataDefinition = inputDefinitionListDataDefinition
- .getListToscaDataDefinition();
- List<OperationInputDefinition> convertedInputs = listToscaDataDefinition.stream()
+ List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition();
+ List<OperationInputDefinition> convertedInputs = inputListToscaDataDefinition.stream()
.map(input -> convertInput(input, inputs))
.collect(Collectors.toList());
@@ -80,11 +79,11 @@ public class InterfaceUtils {
if (outputDefinitionListDataDefinition != null) {
return;
}
- List<OperationOutputDefinition> outListToscaDefinition = outputDefinitionListDataDefinition
- .getListToscaDataDefinition();
- List<OperationOutputDefinition> convertedOutputs = outListToscaDefinition.stream()
- .map(operationOutputDefinition -> convertOutput(operationOutputDefinition, inputs) )
- .collect(Collectors.toList());
+ List<OperationOutputDefinition> outputListToscaDataDefinition = outputDefinitionListDataDefinition.getListToscaDataDefinition();
+ List<OperationOutputDefinition> convertedOutputs = outputListToscaDataDefinition.stream()
+ .map(output -> convertOutput(output, outputs) )
+ .collect(Collectors.toList());
+
inputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
inputDefinitionListDataDefinition.getListToscaDataDefinition().addAll(convertedInputs);
outputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
@@ -92,7 +91,7 @@ public class InterfaceUtils {
}
private static OperationInputDefinition convertInput(OperationInputDefinition input,
- List<InputDefinition> inputs) throws IllegalStateException {
+ List<InputDefinition> inputs) throws IllegalStateException {
Optional<InputDefinition> anyInputDefinition = inputs.stream()
.filter(inp -> inp.getUniqueId().equals(input.getUniqueId())).findAny();
if (anyInputDefinition.isPresent()) {
@@ -102,9 +101,9 @@ public class InterfaceUtils {
}
private static OperationOutputDefinition convertOutput(OperationOutputDefinition output,
- List<InputDefinition> outputs) throws IllegalStateException {
+ List<InputDefinition> outputs) throws IllegalStateException {
Optional<InputDefinition> anyOutputDefinition = outputs.stream()
- .filter(inp -> inp.getUniqueId().equals(output.getUniqueId())).findAny();
+ .filter(op -> op.getUniqueId().equals(output.getUniqueId())).findAny();
if (anyOutputDefinition.isPresent()) {
return new OperationOutputDefinition(output.getLabel(),new InputDataDefinition(anyOutputDefinition.get()));
}