2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.transaction.impl;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
25 import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
26 import org.openecomp.sdc.be.resources.data.ESArtifactData;
27 import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
28 import org.openecomp.sdc.be.tosca.CsarUtils;
29 import org.openecomp.sdc.common.transaction.api.RollbackHandler;
30 import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
31 import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
32 import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
33 import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class ESRollbackHandler extends RollbackHandler {
39 private static final Logger log = LoggerFactory.getLogger(CsarUtils.class);
41 public ESRollbackHandler(Integer transactionId, String userId, String actionType) {
42 super(transactionId, userId, actionType);
45 public DBTypeEnum getDBType() {
46 return DBTypeEnum.ELASTIC_SEARCH;
49 protected boolean isRollbackForPersistenceData() {
53 public boolean isRollbackResultValid(DBActionCodeEnum rollbackResult) {
54 return rollbackResult == DBActionCodeEnum.SUCCESS;
57 public Either<ESAction, MethodActivationStatusEnum> buildEsRollbackAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
58 Either<ESAction, MethodActivationStatusEnum> result;
61 ESAction esRollbackAction = null;
62 Either<ESArtifactData, ResourceUploadStatus> either = esCatalogDao.getArtifact(artifactData.getId());
64 switch (esActiontype) {
67 if (either.isRight() && either.right().value() == ResourceUploadStatus.NOT_EXIST) {
68 esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.REMOVE_ARTIFACT);
72 if (either.isLeft()) {
73 esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.ADD_ARTIFACT);
78 if (either.isLeft()) {
79 ESArtifactData originalArtifactData = either.left().value();
80 esRollbackAction = new ESAction(esCatalogDao, originalArtifactData, ESActionTypeEnum.UPDATE_ARTIFACT);
85 if (esRollbackAction != null) {
86 result = Either.left(esRollbackAction);
88 result = Either.right(MethodActivationStatusEnum.FAILED);
90 } catch (Exception e) {
91 result = Either.right(MethodActivationStatusEnum.FAILED);
92 log.error("#buildEsRollbackAction - {}, es rollback failed with error: ", result, e);