From 1803aa8530b53d9f22dc5815155dd3abdfd99b5a Mon Sep 17 00:00:00 2001 From: aribeiro Date: Wed, 20 May 2020 09:31:52 +0100 Subject: Fix for locked component 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 --- .../sdc/be/components/impl/BaseBusinessLogic.java | 25 +++++++++++++++------- .../be/components/impl/ServiceBusinessLogic.java | 10 ++++----- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 42e8d9bad1..a7c926e0f7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -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) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index 4e4c5d5027..bd29e9ab81 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -2676,13 +2676,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { return Either.right(booleanResponseFormatEither.right().value()); } - Either result; + Either result = null; - Either 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 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); } } -- cgit 1.2.3-korg