Fix for locked component 81/107981/2
authoraribeiro <anderson.ribeiro@est.tech>
Wed, 20 May 2020 08:31:52 +0000 (09:31 +0100)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Tue, 26 May 2020 10:41:36 +0000 (10:41 +0000)
After add, update or remove node_filter the component was left locked on SDC

Issue-ID: SDC-3072
Change-Id: I27058760704bd6261619946becda3612a6386432
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java

index 42e8d9b..a7c926e 100644 (file)
@@ -24,6 +24,12 @@ package org.openecomp.sdc.be.components.impl;
 
 import com.google.gson.JsonElement;
 import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -88,13 +94,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
 import org.openecomp.sdc.exception.ResponseFormat;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-
 public abstract class BaseBusinessLogic {
 
     private static final String FAILED_TO_LOCK_COMPONENT_ERROR = "Failed to lock component {} error - {}";
@@ -236,9 +235,19 @@ public abstract class BaseBusinessLogic {
 
     protected void lockComponent(String componentId, Component component, String ecompErrorContext) {
         ActionStatus lock = lockElement(componentId, component, ecompErrorContext);
-        if ( lock!= ActionStatus.OK ) {
+        if (lock!= ActionStatus.OK) {
+            logAndThrowComponentException(lock, component.getUniqueId(), component.getName());
+        }
+    }
+
+    protected ActionStatus lockComponentAndReturnStatus(final String componentId,
+                                                        final Component component,
+                                                        final String ecompErrorContext) {
+        final ActionStatus lock = lockElement(componentId, component, ecompErrorContext);
+        if (lock!= ActionStatus.OK) {
             logAndThrowComponentException(lock, component.getUniqueId(), component.getName());
         }
+        return ActionStatus.OK;
     }
 
     protected void lockComponent(String componentId, Component component, boolean needLock, String ecompErrorContext) {
index 4e4c5d5..bd29e9a 100644 (file)
@@ -2676,13 +2676,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
             return Either.right(booleanResponseFormatEither.right().value());
         }
 
-        Either<CINodeFilterDataDefinition, StorageOperationStatus> result;
+        Either<CINodeFilterDataDefinition, StorageOperationStatus> result = null;
 
-        Either<Boolean, ResponseFormat> lockResult = null;
         CINodeFilterDataDefinition serviceFilterResult = null;
+        ActionStatus lockStatus = null;
         try {
             if (lock) {
-                lockComponent(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
+                lockStatus = lockComponentAndReturnStatus(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
             }
 
             Optional<ComponentInstance> componentInstanceOptional = storedService.getComponentInstanceById(componentInstanceId);
@@ -2711,7 +2711,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
 
             }
 
-            if (result.isRight()) {
+            if (result != null && result.isRight()) {
                 janusGraphDao.rollback();
                 return Either.right(componentsUtils.getResponseFormat(
                         componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.SERVICE),
@@ -2728,7 +2728,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
 
         } finally {
-            if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+            if (ActionStatus.OK == lockStatus) {
                 graphLockOperation.unlockComponent(storedService.getUniqueId(), NodeTypeEnum.Service);
             }
         }