From 95b22d8d074f294e997c27d79d369b0eb3bee9e2 Mon Sep 17 00:00:00 2001 From: davsad Date: Fri, 16 Jul 2021 09:44:22 +0100 Subject: Disable locking during deployment Issue-ID: SDC-3643 Signed-off-by: davsad Change-Id: I1a04c253d70bf5aebf33bba7b2b9f83bd559ae64 --- .../model/operations/api/IGraphLockOperation.java | 2 ++ .../model/operations/impl/GraphLockOperation.java | 23 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGraphLockOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGraphLockOperation.java index 21288168b3..3e4152728d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGraphLockOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGraphLockOperation.java @@ -30,4 +30,6 @@ public interface IGraphLockOperation { StorageOperationStatus lockComponentByName(String name, NodeTypeEnum nodeType); StorageOperationStatus unlockComponentByName(String name, String componentId, NodeTypeEnum nodeType); + + boolean disableLocking(final boolean disable); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GraphLockOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GraphLockOperation.java index 0106cd3529..bc49c8aaec 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GraphLockOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GraphLockOperation.java @@ -27,17 +27,17 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Component; +import lombok.NoArgsConstructor; + @Component("graph-lock-operation") +@NoArgsConstructor public class GraphLockOperation implements IGraphLockOperation { private static final Logger log = Logger.getLogger(GraphLockOperation.class.getName()); + private boolean disable = false; @javax.annotation.Resource private JanusGraphGenericDao janusGraphGenericDao; - public GraphLockOperation() { - super(); - } - /* * (non-Javadoc) * @@ -48,7 +48,7 @@ public class GraphLockOperation implements IGraphLockOperation { log.info("lock resource with id {}", componentId); JanusGraphOperationStatus lockElementStatus = null; try { - lockElementStatus = janusGraphGenericDao.lockElement(componentId, nodeType); + lockElementStatus = disable ? JanusGraphOperationStatus.OK : janusGraphGenericDao.lockElement(componentId, nodeType); } catch (Exception e) { lockElementStatus = JanusGraphOperationStatus.ALREADY_LOCKED; } @@ -62,13 +62,13 @@ public class GraphLockOperation implements IGraphLockOperation { */ @Override public StorageOperationStatus unlockComponent(String componentId, NodeTypeEnum nodeType) { - JanusGraphOperationStatus lockElementStatus = janusGraphGenericDao.releaseElement(componentId, nodeType); + JanusGraphOperationStatus lockElementStatus = disable ? JanusGraphOperationStatus.OK : janusGraphGenericDao.releaseElement(componentId, nodeType); return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus); } @Override public StorageOperationStatus unlockComponentByName(String name, String componentId, NodeTypeEnum nodeType) { - JanusGraphOperationStatus lockElementStatus = janusGraphGenericDao.releaseElement(name, nodeType); + JanusGraphOperationStatus lockElementStatus = disable ? JanusGraphOperationStatus.OK : janusGraphGenericDao.releaseElement(name, nodeType); return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus); } @@ -77,10 +77,17 @@ public class GraphLockOperation implements IGraphLockOperation { log.info("lock resource with name {}", name); JanusGraphOperationStatus lockElementStatus = null; try { - lockElementStatus = janusGraphGenericDao.lockElement(name, nodeType); + lockElementStatus = disable ? JanusGraphOperationStatus.OK : janusGraphGenericDao.lockElement(name, nodeType); } catch (Exception e) { lockElementStatus = JanusGraphOperationStatus.ALREADY_LOCKED; } return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus); } + + @Override + public boolean disableLocking(boolean disable) { + log.info("Toggling disable locking from {} to {}", this.disable, disable); + this.disable = disable; + return this.disable; + } } -- cgit 1.2.3-korg