aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/common/transaction
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/common/transaction')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java124
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java96
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java86
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java101
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java298
14 files changed, 0 insertions, 1163 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java
deleted file mode 100644
index d7a0f4b8d1..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-
-public interface ICommitHandler extends IDBType {
- DBActionCodeEnum doCommit();
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java
deleted file mode 100644
index 20763d04f8..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-public interface IDBAction {
- <T> T doAction();
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java
deleted file mode 100644
index 3aa2e9a9d7..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-
-public interface IDBType {
- DBTypeEnum getDBType();
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
deleted file mode 100644
index b964321c8a..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionCodeEnum;
-
-public interface ITransactionSdnc {
- TransactionCodeEnum finishTransaction();
-
- Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData);
-
- <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction);
-
- <T> Either<T, TransactionCodeEnum> invokeJanusGraphAction(boolean isLastAction, IDBAction dbAction);
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
deleted file mode 100644
index 4022655e67..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Stack;
-
-public abstract class RollbackHandler implements IDBType {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = LoggerFactory.getLogger(RollbackHandler.class.getName());
- private Stack<IDBAction> dbActionRollbacks;
-
- private Integer transactionId;
- private String userId, actionType;
-
- protected RollbackHandler(Integer transactionId, String userId, String actionType) {
- if (isRollbackForPersistenceData()) {
- dbActionRollbacks = new Stack<>();
- }
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
- }
-
- public MethodActivationStatusEnum addRollbackAction(IDBAction rollbackAction) {
- MethodActivationStatusEnum result = MethodActivationStatusEnum.SUCCESS;
- if (isRollbackForPersistenceData()) {
- dbActionRollbacks.push(rollbackAction);
- } else {
- result = MethodActivationStatusEnum.NOT_ALLOWED;
- }
- return result;
- }
-
- public DBActionCodeEnum doRollback() {
- DBActionCodeEnum result;
-
- try {
- if (isRollbackForPersistenceData()) {
- result = doPersistenceDataRollback();
- } else {
- log.debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- result = doNonPersistenceDataRollback();
- }
- if (result != DBActionCodeEnum.SUCCESS) {
- log.error(LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
- log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
- }
-
- } catch (Exception e) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- log.error(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
- log.debug(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType, e);
- log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
- }
-
- return result;
- }
-
- private <T> DBActionCodeEnum doPersistenceDataRollback() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- while (!dbActionRollbacks.empty()) {
- log.debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- IDBAction rollbackAction = dbActionRollbacks.pop();
- T rollbackResult = rollbackAction.doAction();
- if (!isRollbackResultValid()) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- }
- return result;
- }
-
- /**
- * Override for specific logic
- *
- * @param <T>
- */
- public <T> boolean isRollbackResultValid() {
- return true;
- }
-
- /**
- * Override for specific logic
- */
- public DBActionCodeEnum doNonPersistenceDataRollback() {
- return DBActionCodeEnum.SUCCESS;
- }
-
- protected abstract boolean isRollbackForPersistenceData();
-
- /**
- * Only Used for Unit Tests !
- */
- // TODO test using slf4j-test and remove this
- public static void setLog(Logger log) {
- RollbackHandler.log = log;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
deleted file mode 100644
index 60f89ce012..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.api;
-
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-
-public final class TransactionUtils {
-
- private TransactionUtils() {
-
- }
-
- public enum DBTypeEnum {
- ELASTIC_SEARCH, JANUSGRAPH, MYSTERY, SWIFT
- }
-
- public enum TransactionCodeEnum {
- ROLLBACK_SUCCESS, ROLLBACK_FAILED, SUCCESS, COMMIT_FAILED, MULTIPLE_LAST_ACTION, INTERNAL_ERROR, UNALLOWED_METHOD_USAGE, PREPARE_ROLLBACK_FAILED, TRANSACTION_CLOSED
- }
-
- public enum TransactionStatusEnum {
- OPEN, CLOSED, FAILED_ROLLBACK
- }
-
- public enum DBActionCodeEnum {
- SUCCESS, FAIL_GENERAL, FAIL_MULTIPLE_LAST_ACTION
- }
-
- public enum ESActionTypeEnum {
- ADD_ARTIFACT, UPDATE_ARTIFACT, REMOVE_ARTIFACT
- }
-
- public enum ActionTypeEnum {
- ADD_ARTIFACT, REMOVE_ARTIFACT, UPDATE_ARTIFACT, CREATE_RESOURCE, UPDATE_RESOURCE, DELETE_RESOURCE
- }
-
- public static final int MAX_SIZE_TRANSACTION_LIST = 1000;
-
- public static final int TRANSACTION_ID_RESET_LIMIT = MAX_SIZE_TRANSACTION_LIST * 10;
-
- public static final String TRANSACTION_MARKER_STR = "TRANSACTION_MARKER";
-
- public static final String DUMMY_USER = "udummy";
-
- public static final Marker TRANSACTION_MARKER = MarkerFactory.getMarker(TRANSACTION_MARKER_STR);
-
- public static class LogMessages {
- public static final String PRE_INVOKE_ACTION = "About to add Action to SdncTransaction ID:{} for DB:{}, user:{}, action:{}";
- public static final String INVOKE_ACTION = "invoking Action in SdncTransactionID:{}, on DB:{}, user:{}, action:{}";
- public static final String COMMIT_ACTION_ALL_DB = "Starting Commit for SdncTransactionID:{} for all DBs, user:{}, action:{}";
- public static final String COMMIT_ACTION_SPECIFIC_DB = "Starting Commit for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
- public static final String COMMIT_ON_CLOSED_TRANSACTION = "Commit failed for SdncTransactionID:{} Transaction is in status:{}, user:{}, action:{}";
- public static final String ACTION_ON_CLOSED_TRANSACTION = "Action failed for SdncTransactionID:{} Transaction is already closed, user:{}, action:{}";
- public static final String DOUBLE_FINISH_FLAG_ACTION = "Transaction with SdncTransactionID:{} on DB:{} was called multiple times with last action flag, user:{}, action:{}";
- public static final String DB_ACTION_FAILED_WITH_EXCEPTION = "Action on DB:{} has failed for SdncTransactionID:{}, message:{}, user:{}, action:{}";
- public static final String ROLLBACK_SUCCEEDED_GENERAL = "Transaction rollback succeeded for SdncTransactionID:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_GENERAL = "Transaction rollback failed for SdncTransactionID:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_ON_DB = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, exception message:{}, user:{}, action:{}";
- public static final String ROLLBACK_PERSISTENT_ACTION = "About To Rollback Action on DB{} for TransactionID:{} ... user:{}, action:{}";
- public static final String ROLLBACK_NON_PERSISTENT_ACTION = "About To Rollback Actions on DB{} for TransactionID:{} ... user:{}, action:{}";
- public static final String CREATE_ROLLBACK_HANDLER = "creating new Rollback Handler For DB:{} in SdncTransaction ID:{}, user:{}, action:{}";
- public static final String FAILED_CREATE_ROLLBACK = "failed to create new Rollback action For DB:{} with SdncTransactionID:{}, user:{}, action:{}";
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
deleted file mode 100644
index bd638249b2..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
-import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.IDBAction;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
-
-public class ESAction implements IDBAction {
-
- private static final Logger log = Logger.getLogger(CsarUtils.class.getName());
-
- private ESCatalogDAO esCatalogDao;
- private ESArtifactData artifactData;
- private ESActionTypeEnum esActionType;
-
- public ESAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
- this.esCatalogDao = esCatalogDao;
- this.artifactData = artifactData;
- this.esActionType = esActiontype;
- }
-
- @Override
- public DBActionCodeEnum doAction() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- try {
- if (esActionType == ESActionTypeEnum.ADD_ARTIFACT || esActionType == ESActionTypeEnum.UPDATE_ARTIFACT) {
- esCatalogDao.writeArtifact(artifactData);
- } else if (esActionType == ESActionTypeEnum.REMOVE_ARTIFACT) {
- esCatalogDao.deleteArtifact(artifactData.getId());
- }
-
- } catch (ResourceDAOException daoException) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- log.error("#doAction - {}, es action failed with error : ", result, daoException);
- }
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
deleted file mode 100644
index da1db80d2c..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-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.transaction.api.TransactionUtils.ESActionTypeEnum;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-
-public class ESRollbackHandler extends RollbackHandler {
-
- private static final Logger log = Logger.getLogger(CsarUtils.class.getName());
-
- public ESRollbackHandler(Integer transactionId, String userId, String actionType) {
- super(transactionId, userId, actionType);
- }
-
- public DBTypeEnum getDBType() {
- return DBTypeEnum.ELASTIC_SEARCH;
- }
-
- protected boolean isRollbackForPersistenceData() {
- return true;
- }
-
- public boolean isRollbackResultValid(DBActionCodeEnum rollbackResult) {
- return rollbackResult == DBActionCodeEnum.SUCCESS;
- }
-
- public Either<ESAction, MethodActivationStatusEnum> buildEsRollbackAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
- Either<ESAction, MethodActivationStatusEnum> result;
-
- try {
- ESAction esRollbackAction = null;
- Either<ESArtifactData, ResourceUploadStatus> either = esCatalogDao.getArtifact(artifactData.getId());
-
- switch (esActiontype) {
- case ADD_ARTIFACT:
-
- if (either.isRight() && either.right().value() == ResourceUploadStatus.NOT_EXIST) {
- esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.REMOVE_ARTIFACT);
- }
- break;
- case REMOVE_ARTIFACT:
- if (either.isLeft()) {
- esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.ADD_ARTIFACT);
- }
- break;
- case UPDATE_ARTIFACT:
-
- if (either.isLeft()) {
- ESArtifactData originalArtifactData = either.left().value();
- esRollbackAction = new ESAction(esCatalogDao, originalArtifactData, ESActionTypeEnum.UPDATE_ARTIFACT);
- }
- break;
-
- }
- if (esRollbackAction != null) {
- result = Either.left(esRollbackAction);
- } else {
- result = Either.right(MethodActivationStatusEnum.FAILED);
- }
- } catch (Exception e) {
- result = Either.right(MethodActivationStatusEnum.FAILED);
- log.error("#buildEsRollbackAction - {}, es rollback failed with error: ", result, e);
- }
-
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java
deleted file mode 100644
index dad79b5f76..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.common.transaction.api.ICommitHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-
-public class JanusGraphCommitHandler implements ICommitHandler {
-
- private JanusGraphGenericDao janusGraphGenericDao;
-
- public JanusGraphCommitHandler(JanusGraphGenericDao janusGraphGenericDao) {
- this.janusGraphGenericDao = janusGraphGenericDao;
- }
-
- @Override
- public DBActionCodeEnum doCommit() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- JanusGraphOperationStatus janusGraphStatus = janusGraphGenericDao.commit();
- if (janusGraphStatus != JanusGraphOperationStatus.OK) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- return result;
- }
-
- @Override
- public DBTypeEnum getDBType() {
- return DBTypeEnum.JANUSGRAPH;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java
deleted file mode 100644
index ed2633fa11..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-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;
-
-public class JanusGraphRollbackHandler extends RollbackHandler {
-
- private JanusGraphGenericDao janusGraphGenericDao;
-
- public JanusGraphRollbackHandler(Integer transactionId, String userId, String actionType, JanusGraphGenericDao janusGraphGenericDao) {
- super(transactionId, userId, actionType);
- this.janusGraphGenericDao = janusGraphGenericDao;
- }
-
- public DBTypeEnum getDBType() {
- return DBTypeEnum.JANUSGRAPH;
- }
-
- protected boolean isRollbackForPersistenceData() {
- return false;
- }
-
- public DBActionCodeEnum doNonPersistenceDataRollback() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- JanusGraphOperationStatus janusGraphStatus = janusGraphGenericDao.rollback();
- if (janusGraphStatus != JanusGraphOperationStatus.OK) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
deleted file mode 100644
index abe4c3743f..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.mngr;
-
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.ICommitHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
-
-import java.util.List;
-
-public class CommitManager {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = Logger.getLogger(CommitManager.class);
- private List<ICommitHandler> commitHandlers;
- private Integer transactionId;
- private String userId, actionType;
-
- CommitManager(Integer transactionId, String userId, String actionType, List<ICommitHandler> commitHandlers) {
- this.commitHandlers = commitHandlers;
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
-
- }
-
- public DBActionCodeEnum transactionCommit() {
- log.debug(LogMessages.COMMIT_ACTION_ALL_DB, transactionId, userId, actionType);
- DBActionCodeEnum commitResult = DBActionCodeEnum.SUCCESS;
- ICommitHandler lastHandler = null;
- try {
- for (ICommitHandler handler : commitHandlers) {
- lastHandler = handler;
- log.debug(LogMessages.COMMIT_ACTION_SPECIFIC_DB, transactionId, handler.getDBType().name(), userId, actionType);
- DBActionCodeEnum commitCode = handler.doCommit();
- if (commitCode == DBActionCodeEnum.FAIL_GENERAL) {
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit on DB " + handler.getDBType().name());
- log.debug("Commit failed for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
- commitResult = DBActionCodeEnum.FAIL_GENERAL;
- break;
- }
- log.debug("Commit succeeded for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit - on DB " + getDBName(lastHandler));
- log.debug("Commit failed for SdncTransactionID:{} on DB:{}, Exception message:{}", transactionId, getDBName(lastHandler), e.getMessage(), e);
- log.info(TransactionUtils.TRANSACTION_MARKER, "Commit failed for SdncTransactionID:{} on DB:{}", transactionId, getDBName(lastHandler));
- commitResult = DBActionCodeEnum.FAIL_GENERAL;
- }
- return commitResult;
- }
-
- private String getDBName(ICommitHandler lastHandler) {
- String dbName = "Unknown";
- if (lastHandler != null) {
- dbName = lastHandler.getDBType().name();
- }
- return dbName;
- }
-
- // TODO test using slf4j-test and remove this
- static void setLog(Logger log) {
- CommitManager.log = log;
- }
-}
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
deleted file mode 100644
index 5e51615164..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.mngr;
-
-import fj.P;
-import fj.data.Either;
-import fj.data.HashMap;
-import fj.data.List;
-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;
-
-public class RollbackManager {
- 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, Iterable<RollbackHandler> rollbackHandlers) {
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
- this.rollbackHandlersMap = HashMap.from(List.iterableList(rollbackHandlers).map(i -> P.p(i.getDBType(), i)));
- }
-
- public DBActionCodeEnum transactionRollback() {
- 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.contains(rollbackHandler.getDBType())) {
- result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED);
- } else {
- rollbackHandlersMap.set(rollbackHandler.getDBType(), rollbackHandler);
- result = Either.left(rollbackHandler);
- }
- return result;
-
- }
-
- protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(final DBTypeEnum dbType) {
-
- RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) {
-
- @Override
- public DBTypeEnum getDBType() {
- return dbType;
- }
-
- @Override
- protected boolean isRollbackForPersistenceData() {
- return true;
- }
- };
- return addRollbackHandler(rollbackHandler);
- }
-
- protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) {
- // 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
deleted file mode 100644
index 78264484fb..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.mngr;
-
-import com.google.common.collect.EvictingQueue;
-import com.google.common.collect.Queues;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-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;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.util.Queue;
-import java.util.concurrent.atomic.AtomicInteger;
-
-@Component("transactionManager")
-public class TransactionManager {
-
- private static final Logger log = Logger.getLogger(TransactionManager.class.getName());
-
- private AtomicInteger transactionIDCounter = new AtomicInteger(0);
-
- private Queue<ITransactionSdnc> transactions;
- @Resource
- private ESCatalogDAO esCatalogDao;
- @Resource
- private JanusGraphGenericDao janusGraphGenericDao;
-
- /**
- * userId and actionType parameters are used only for logging purposes.
- */
- public ITransactionSdnc getTransaction(String userId, ActionTypeEnum actionType) {
- if (transactions == null) {
- init();
- }
- log.debug("TransactionManager creating new SdncTransaction");
- ITransactionSdnc tx = new TransactionSdncImpl(generateTransactionID(), userId, actionType, esCatalogDao,
- janusGraphGenericDao);
- transactions.add(tx);
-
- return tx;
-
- }
-
- private Integer generateTransactionID() {
- boolean generatedSuccessfully = false;
- int nextId = 0;
-
- while (!generatedSuccessfully) {
- int prevId = transactionIDCounter.get();
- if (prevId > TransactionUtils.TRANSACTION_ID_RESET_LIMIT) {
- resetTransactionId();
- }
- nextId = prevId + 1;
- generatedSuccessfully = transactionIDCounter.compareAndSet(prevId, nextId);
- }
- return nextId;
- }
-
- private void resetTransactionId() {
-
- boolean resetSuccessfully = false;
- while (!resetSuccessfully) {
- int prevId = transactionIDCounter.get();
- resetSuccessfully = transactionIDCounter.compareAndSet(prevId, 0);
- }
-
- }
-
- private synchronized void init() {
- if (transactions == null) {
- log.info("TransactionManager Initialized");
- EvictingQueue<ITransactionSdnc> queue = EvictingQueue
- .<ITransactionSdnc>create(TransactionUtils.MAX_SIZE_TRANSACTION_LIST);
- // make thread-safe
- transactions = Queues.synchronizedQueue(queue);
- }
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
deleted file mode 100644
index 93a2c9db82..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.common.transaction.mngr;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.*;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.*;
-import org.openecomp.sdc.common.transaction.impl.ESAction;
-import org.openecomp.sdc.common.transaction.impl.ESRollbackHandler;
-import org.openecomp.sdc.common.transaction.impl.JanusGraphCommitHandler;
-import org.openecomp.sdc.common.transaction.impl.JanusGraphRollbackHandler;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class TransactionSdncImpl implements ITransactionSdnc {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = Logger.getLogger(TransactionSdncImpl.class);
- private boolean lastActionAlreadyCalled;
- private RollbackManager rollbackManager;
- private CommitManager commitManager;
- private ESCatalogDAO esCatalogDao;
- private JanusGraphGenericDao janusGraphGenericDao;
- private Integer transactionId;
- private TransactionStatusEnum status;
- private String userId, actionType;
-
- TransactionSdncImpl(Integer transactionId, String userId, ActionTypeEnum actionTypeEnum, ESCatalogDAO esCatalogDao, JanusGraphGenericDao janusGraphGenericDao) {
- this.esCatalogDao = esCatalogDao;
- this.janusGraphGenericDao = janusGraphGenericDao;
- this.transactionId = transactionId;
- this.userId = userId;
- actionType = actionTypeEnum.name();
- rollbackManager = new RollbackManager(transactionId, userId, actionType, initRollbackHandlers());
- commitManager = new CommitManager(transactionId, userId, actionType, initCommitHandlers());
- status = TransactionStatusEnum.OPEN;
-
- }
-
- private List<ICommitHandler> initCommitHandlers() {
- List<ICommitHandler> commitHandlers = new ArrayList<>();
- commitHandlers.add(new JanusGraphCommitHandler(janusGraphGenericDao));
- return commitHandlers;
- }
-
- private List<RollbackHandler> initRollbackHandlers() {
- List<RollbackHandler> rolebackHandlers = new ArrayList<>();
- rolebackHandlers.add(new JanusGraphRollbackHandler(transactionId, userId, actionType,
- janusGraphGenericDao));
- rolebackHandlers.add(new ESRollbackHandler(transactionId, userId, actionType));
- return rolebackHandlers;
- }
-
- private <T> Either<T, TransactionCodeEnum> invokeAction(boolean isLastAction, IDBAction dbAction, DBTypeEnum dbType) {
-
- Either<T, DBActionCodeEnum> actionResult;
- log.debug(LogMessages.INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
- if (isLastAction) {
- actionResult = getLastActionResult(dbAction, dbType);
- } else {
- actionResult = getActionResult(dbAction, dbType);
- }
-
- Either<T, TransactionCodeEnum> result;
- boolean isRollbackNedded = actionResult.isRight();
- if (isRollbackNedded) {
- TransactionCodeEnum transactionCode = transactionRollback();
- result = Either.right(transactionCode);
- } else {
- result = Either.left(actionResult.left().value());
- }
- return result;
- }
-
- private TransactionCodeEnum transactionRollback() {
-
- TransactionCodeEnum result;
- DBActionCodeEnum transactionRollback = rollbackManager.transactionRollback();
- if (transactionRollback == DBActionCodeEnum.SUCCESS) {
- result = TransactionCodeEnum.ROLLBACK_SUCCESS;
- log.info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
-
- } else {
- result = TransactionCodeEnum.ROLLBACK_FAILED;
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit for transaction " + transactionId);
-
- log.info(LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
- }
- return result;
- }
-
- public <T> Either<T, TransactionCodeEnum> invokeJanusGraphAction(boolean isLastAction, IDBAction dbAction) {
- Either<T, TransactionCodeEnum> result;
- if (status == TransactionStatusEnum.OPEN) {
- result = invokeAction(isLastAction, dbAction, DBTypeEnum.JANUSGRAPH);
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- public <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction) {
-
- Either<T, TransactionCodeEnum> result;
- MethodActivationStatusEnum addingHandlerResult;
- if (status == TransactionStatusEnum.OPEN) {
- log.debug(LogMessages.PRE_INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
- Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.getRollbackHandler(dbType);
-
- if (eitherRollbackHandler.isLeft()) {
- RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
- addingHandlerResult = rollbackHandler.addRollbackAction(dbRollbackAction);
- } else {
- addingHandlerResult = addToNewRollbackHandler(dbType, dbRollbackAction);
- }
-
- if (addingHandlerResult == MethodActivationStatusEnum.SUCCESS) {
- result = invokeAction(isLastAction, dbAction, dbType);
- } else {
- result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
- }
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private MethodActivationStatusEnum addToNewRollbackHandler(DBTypeEnum dbType, IDBAction dbRollbackAction) {
- log.debug(LogMessages.CREATE_ROLLBACK_HANDLER, dbType.name(), transactionId, userId, actionType);
- MethodActivationStatusEnum result;
-
- Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.createRollbackHandler(dbType);
- if (eitherRollbackHandler.isRight()) {
- result = eitherRollbackHandler.right().value();
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - addToNewRollbackHandler");
- log.info(LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
- } else {
- RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
- rollbackHandler.addRollbackAction(dbRollbackAction);
- result = MethodActivationStatusEnum.SUCCESS;
- }
-
- return result;
- }
-
- public Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData) {
-
- Either<DBActionCodeEnum, TransactionCodeEnum> result;
- if (status == TransactionStatusEnum.OPEN) {
- Either<RollbackHandler, MethodActivationStatusEnum> eitherEsHandler = rollbackManager.getRollbackHandler(DBTypeEnum.ELASTIC_SEARCH);
- if (eitherEsHandler.isRight()) {
- result = Either.right(TransactionCodeEnum.INTERNAL_ERROR);
- } else {
- ESRollbackHandler esHandler = (ESRollbackHandler) eitherEsHandler.left().value();
-
- Either<ESAction, MethodActivationStatusEnum> eitherEsRollbackAction = esHandler.buildEsRollbackAction(esCatalogDao, artifactData, esActiontype);
- if (eitherEsRollbackAction.isLeft()) {
- esHandler.addRollbackAction(eitherEsRollbackAction.left().value());
- result = invokeAction(isLastAction, new ESAction(esCatalogDao, artifactData, esActiontype), DBTypeEnum.ELASTIC_SEARCH);
- } else {
- result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
- }
-
- }
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private <T> void updateTransactionStatus(Either<T, TransactionCodeEnum> result) {
- if (result.isRight()) {
- updateTransactionStatus(result.right().value());
- }
-
- }
-
- private <T> Either<T, TransactionCodeEnum> handleActionOnClosedTransaction() {
- Either<T, TransactionCodeEnum> result = Either.right(TransactionCodeEnum.TRANSACTION_CLOSED);
- log.debug(LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
- return result;
- }
-
- private <T> Either<T, DBActionCodeEnum> getLastActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
- Either<T, DBActionCodeEnum> result;
- if (isLastActionAlreadyCalled()) {
- result = Either.right(DBActionCodeEnum.FAIL_MULTIPLE_LAST_ACTION);
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getLastActionResult");
- log.debug(LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
- } else {
- setLastActionAlreadyCalled(true);
- result = getActionResult(dataBaseAction, dbType);
- }
- return result;
- }
-
- private <T> Either<T, DBActionCodeEnum> getActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
- Either<T, DBActionCodeEnum> result;
- try {
- T doAction = dataBaseAction.doAction();
- result = Either.left(doAction);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getActionResult");
- log.debug(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType, e);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType);
-
- result = Either.right(DBActionCodeEnum.FAIL_GENERAL);
- }
- return result;
- }
-
- public TransactionCodeEnum finishTransaction() {
- TransactionCodeEnum result;
- if (status == TransactionStatusEnum.OPEN) {
- DBActionCodeEnum transactionCommit = commitManager.transactionCommit();
- if (transactionCommit == DBActionCodeEnum.SUCCESS) {
- result = TransactionCodeEnum.SUCCESS;
- status = TransactionStatusEnum.CLOSED;
- } else {
- result = transactionRollback();
- }
- } else {
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - finishTransaction");
- log.debug(LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
- result = TransactionCodeEnum.TRANSACTION_CLOSED;
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private void updateTransactionStatus(TransactionCodeEnum result) {
- switch (result) {
- case SUCCESS:
- status = TransactionStatusEnum.CLOSED;
- break;
- case ROLLBACK_SUCCESS:
- status = TransactionStatusEnum.CLOSED;
- break;
- case ROLLBACK_FAILED:
- status = TransactionStatusEnum.FAILED_ROLLBACK;
- break;
- default:
- break;
- }
-
- }
-
- private boolean isLastActionAlreadyCalled() {
- return lastActionAlreadyCalled;
- }
-
- private void setLastActionAlreadyCalled(boolean lastAction) {
- this.lastActionAlreadyCalled = lastAction;
- }
-
- // TODO test using slf4j-test and remove this
- static void setLog(Logger log) {
- TransactionSdncImpl.log = log;
- }
-
- TransactionStatusEnum getStatus() {
- return status;
- }
-}