aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-06-03 10:50:07 -0400
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-04 14:46:29 +0000
commit5886110d78dfd3bf95a506c67a194716056cf8a2 (patch)
tree28a072a762ef8d1bdacda1f36cfa1dcf0afcdaec /catalog-model
parent032525a375681fb18cc498d8daed9d73faa21ec3 (diff)
Rewrite of `cloneToscaElementForCertify` to remove NPE
- Modularized `cloneToscaElementForCertify` in smaller, less complex parts (`updateEdgesDeleteNotCertifiedVersionsAndHandlePreviousVersions`) Issue-ID: SDC-2967 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I7f9e8a9e337147fd48c1c4c742eff5abf7ebacf8
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java71
1 files changed, 46 insertions, 25 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
index 9c588d9596..bf899631aa 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
@@ -330,11 +330,11 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
modifier, majorVersion);
});
} catch (Exception e) {
- CommonUtility
- .addRecordToLog(log, LogLevelEnum.DEBUG,
+ return Either.right(
+ logDebugMessageAndReturnStorageOperationStatus(StorageOperationStatus.GENERAL_ERROR,
"Exception occurred during certification tosca element {}.",
- toscaElementId, e);
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ toscaElementId, e)
+ );
}
}
@@ -877,29 +877,50 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
return nextVersionToscaElementVertex;
}
- private Either<GraphVertex, StorageOperationStatus> cloneToscaElementForCertify(GraphVertex toscaElementVertex, GraphVertex modifierVertex, Integer majorVersion) {
- Either<GraphVertex, StorageOperationStatus> result;
- Either<List<GraphVertex>, StorageOperationStatus> deleteResult = null;
- GraphVertex clonedToscaElement = null;
- result = getToscaElementOperation(toscaElementVertex.getLabel()).cloneToscaElement(toscaElementVertex, cloneGraphVertexForCertify(toscaElementVertex, modifierVertex, majorVersion), modifierVertex);
- if (result.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to clone tosca element {} for certification. Sattus is {}. ", toscaElementVertex.getUniqueId(), result.right().value());
+ private Either<GraphVertex, StorageOperationStatus> cloneToscaElementForCertify(GraphVertex toscaElementVertex,
+ GraphVertex modifierVertex, Integer majorVersion) {
+ return getToscaElementOperation(toscaElementVertex.getLabel())
+ .cloneToscaElement(
+ toscaElementVertex,
+ cloneGraphVertexForCertify(toscaElementVertex, modifierVertex, majorVersion),
+ modifierVertex)
+ .right().map(status ->
+ logDebugMessageAndReturnStorageOperationStatus(status,
+ "Failed to clone tosca element {} for certification. Status is {}. ",
+ toscaElementVertex.getUniqueId(), status))
+ .left().bind(clonedToscaElement ->
+ updateEdgesDeleteNotCertifiedVersionsAndHandlePreviousVersions(
+ clonedToscaElement, toscaElementVertex, majorVersion
+ ));
+ }
+
+ private Either<GraphVertex, StorageOperationStatus> updateEdgesDeleteNotCertifiedVersionsAndHandlePreviousVersions(
+ GraphVertex clonedToscaElement,
+ GraphVertex toscaElementVertex,
+ Integer majorVersion
+ ) {
+ StorageOperationStatus updateEdgeToCatalog = updateEdgeToCatalogRoot(clonedToscaElement, toscaElementVertex);
+ if (updateEdgeToCatalog != StorageOperationStatus.OK) {
+ return Either.right(updateEdgeToCatalog);
} else {
- clonedToscaElement = result.left().value();
- StorageOperationStatus updateEdgeToCatalog = updateEdgeToCatalogRoot(clonedToscaElement, toscaElementVertex);
- if (updateEdgeToCatalog != StorageOperationStatus.OK) {
- return Either.right(updateEdgeToCatalog);
- }
- deleteResult = deleteAllPreviousNotCertifiedVersions(toscaElementVertex);
- if (deleteResult.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete all previous npt certified versions of tosca element {}. Status is {}. ", toscaElementVertex.getUniqueId(), deleteResult.right().value());
- result = Either.right(deleteResult.right().value());
+ Either<List<GraphVertex>, StorageOperationStatus> deleteResultEither =
+ deleteAllPreviousNotCertifiedVersions(toscaElementVertex);
+
+ if (deleteResultEither == null) {
+ return Either.right(
+ logDebugMessageAndReturnStorageOperationStatus(StorageOperationStatus.GENERAL_ERROR,
+ "Failed to delete all previous not certified versions of tosca element {}. Null value returned.",
+ toscaElementVertex.getUniqueId()));
+ } else {
+ return deleteResultEither
+ .right().map(status ->
+ logDebugMessageAndReturnStorageOperationStatus(status,
+ "Failed to delete all previous not certified versions of tosca element {}. Status is {}. ",
+ toscaElementVertex.getUniqueId(), status))
+ .left().bind(deleteResult ->
+ handlePreviousVersionRelation(clonedToscaElement, deleteResult, majorVersion));
}
}
- if (result.isLeft()) {
- result = handlePreviousVersionRelation(clonedToscaElement, deleteResult.left().value(), majorVersion);
- }
- return result;
}
private Either<GraphVertex, StorageOperationStatus> handlePreviousVersionRelation(GraphVertex clonedToscaElement, List<GraphVertex> deletedVersions, Integer majorVersion) {
@@ -970,7 +991,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
result = Either.left(previosVersions);
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occured during deleteng all tosca elements by UUID {} and name {}. {} ", uuid, componentName, e.getMessage());
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occurred during deleting all tosca elements by UUID {} and name {}. {} ", uuid, componentName, e.getMessage());
}
return result;
}