aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java13
2 files changed, 29 insertions, 44 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
index 0641524038..99e0da0116 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
@@ -20,68 +20,54 @@
package org.openecomp.sdc.common.transaction.mngr;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.openecomp.sdc.common.transaction.api.RollbackHandler;
import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
+import fj.P;
import fj.data.Either;
+import fj.data.HashMap;
+import fj.data.List;
public class RollbackManager {
- private Map<DBTypeEnum, RollbackHandler> rollBackHandlersMap;
- private Integer transactionId;
- private String userId, actionType;
+ private final HashMap<DBTypeEnum, RollbackHandler> rollbackHandlersMap;
+ private final Integer transactionId;
+ private final String userId;
+ private final String actionType;
- RollbackManager(Integer transactionId, String userId, String actionType, List<RollbackHandler> roleBackHandlers) {
+ RollbackManager(Integer transactionId, String userId, String actionType, Iterable<RollbackHandler> rollbackHandlers) {
this.transactionId = transactionId;
this.userId = userId;
this.actionType = actionType;
- rollBackHandlersMap = new HashMap<>();
- for (RollbackHandler handler : roleBackHandlers) {
- rollBackHandlersMap.put(handler.getDBType(), handler);
- }
-
+ this.rollbackHandlersMap = HashMap.from(List.iterableList(rollbackHandlers).map(i -> P.p(i.getDBType(), i)));
}
public DBActionCodeEnum transactionRollback() {
- DBActionCodeEnum rollbackResult = DBActionCodeEnum.SUCCESS;
- Iterator<RollbackHandler> handlersItr = rollBackHandlersMap.values().iterator();
- while (handlersItr.hasNext()) {
- RollbackHandler handler = handlersItr.next();
- DBActionCodeEnum rollbackCode = handler.doRollback();
- if (rollbackCode == DBActionCodeEnum.FAIL_GENERAL) {
- rollbackResult = DBActionCodeEnum.FAIL_GENERAL;
- }
- }
-
- return rollbackResult;
+ List<DBActionCodeEnum> results = rollbackHandlersMap.values().map(RollbackHandler::doRollback);
+ boolean failure = results.exists(r -> r == DBActionCodeEnum.FAIL_GENERAL);
+ return failure ? DBActionCodeEnum.FAIL_GENERAL : DBActionCodeEnum.SUCCESS;
}
protected Either<RollbackHandler, MethodActivationStatusEnum> addRollbackHandler(RollbackHandler rollbackHandler) {
Either<RollbackHandler, MethodActivationStatusEnum> result;
- if (rollBackHandlersMap.containsKey(rollbackHandler.getDBType())) {
+ if (rollbackHandlersMap.contains(rollbackHandler.getDBType())) {
result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED);
} else {
- rollBackHandlersMap.put(rollbackHandler.getDBType(), rollbackHandler);
+ rollbackHandlersMap.set(rollbackHandler.getDBType(), rollbackHandler);
result = Either.left(rollbackHandler);
}
return result;
}
- protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(DBTypeEnum dbType) {
+ protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(final DBTypeEnum dbType) {
- final DBTypeEnum dbTypeFinal = dbType;
RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) {
@Override
public DBTypeEnum getDBType() {
- return dbTypeFinal;
+ return dbType;
}
@Override
@@ -89,19 +75,13 @@ public class RollbackManager {
return true;
}
};
- Either<RollbackHandler, MethodActivationStatusEnum> result = addRollbackHandler(rollbackHandler);
-
- return result;
+ return addRollbackHandler(rollbackHandler);
}
protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) {
- Either<RollbackHandler, MethodActivationStatusEnum> result;
- if (rollBackHandlersMap.containsKey(dbType)) {
- result = Either.left(rollBackHandlersMap.get(dbType));
- } else {
- result = Either.right(MethodActivationStatusEnum.NOT_FOUND);
- }
- return result;
+ // need to swap here because the uses of Either in SDC appears to be opposite of convention
+ // by convention left is failure; in SDC right is failure
+ return rollbackHandlersMap.get(dbType).toEither(MethodActivationStatusEnum.NOT_FOUND).swap();
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
index c401586383..c05431ac7f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
@@ -20,14 +20,13 @@
package org.openecomp.sdc.common.transaction.mngr;
-import java.util.List;
+import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Resource;
import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.common.datastructure.CapList;
import org.openecomp.sdc.common.transaction.api.ITransactionSdnc;
import org.openecomp.sdc.common.transaction.api.TransactionUtils;
import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum;
@@ -35,6 +34,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import com.google.common.collect.EvictingQueue;
+import com.google.common.collect.Queues;
+
@Component("transactionManager")
public class TransactionManager {
@@ -42,7 +44,7 @@ public class TransactionManager {
private AtomicInteger transactionIDCounter = new AtomicInteger(0);
- private List<ITransactionSdnc> transactions;
+ private Queue<ITransactionSdnc> transactions;
@Resource
private ESCatalogDAO esCatalogDao;
@Resource
@@ -91,7 +93,10 @@ public class TransactionManager {
private synchronized void init() {
if (transactions == null) {
log.info("TransactionManager Initialized");
- transactions = new CapList<>(TransactionUtils.MAX_SIZE_TRANSACTION_LIST);
+ EvictingQueue<ITransactionSdnc> queue = EvictingQueue
+ .<ITransactionSdnc>create(TransactionUtils.MAX_SIZE_TRANSACTION_LIST);
+ // make thread-safe
+ transactions = Queues.synchronizedQueue(queue);
}
}