Search in sources :

Example 1 with GroupState

use of org.apache.inlong.manager.common.enums.GroupState in project incubator-inlong by apache.

the class CommonOperateService method checkGroupStatus.

/**
 * Check whether the inlong group status is temporary
 *
 * @param groupId Inlong group id
 * @return Inlong group entity, for caller reuse
 */
public InlongGroupEntity checkGroupStatus(String groupId, String operator) {
    InlongGroupEntity inlongGroupEntity = groupMapper.selectByGroupId(groupId);
    Preconditions.checkNotNull(inlongGroupEntity, "groupId is invalid");
    List<String> managers = Arrays.asList(inlongGroupEntity.getInCharges().split(","));
    Preconditions.checkTrue(managers.contains(operator), String.format(ErrorCodeEnum.USER_IS_NOT_MANAGER.getMessage(), operator, managers));
    GroupState state = GroupState.forCode(inlongGroupEntity.getStatus());
    // Add/modify/delete is not allowed under certain group state
    if (GroupState.notAllowedUpdate(state)) {
        LOGGER.error("inlong group status was not allowed to add/update/delete related info");
        throw new BusinessException(ErrorCodeEnum.OPT_NOT_ALLOWED_BY_STATUS);
    }
    return inlongGroupEntity;
}
Also used : InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) GroupState(org.apache.inlong.manager.common.enums.GroupState)

Example 2 with GroupState

use of org.apache.inlong.manager.common.enums.GroupState in project incubator-inlong by apache.

the class InlongGroupServiceImpl method updateStatus.

@Override
@Transactional(rollbackFor = Throwable.class, isolation = Isolation.REPEATABLE_READ)
public boolean updateStatus(String groupId, Integer status, String operator) {
    LOGGER.info("begin to update group status to [{}] by groupId={}, username={}", status, groupId, operator);
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    InlongGroupEntity entity = groupMapper.selectByGroupIdForUpdate(groupId);
    if (entity == null) {
        LOGGER.error("inlong group not found by groupId={}", groupId);
        throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
    }
    GroupState curState = GroupState.forCode(entity.getStatus());
    GroupState nextState = GroupState.forCode(status);
    if (GroupState.notAllowedTransition(curState, nextState)) {
        String errorMsg = String.format("Current state=%s is not allowed to transfer to state=%s", curState, nextState);
        LOGGER.error(errorMsg);
        throw new BusinessException(errorMsg);
    }
    groupMapper.updateStatus(groupId, status, operator);
    LOGGER.info("success to update inlong group status to [{}] for groupId={}", status, groupId);
    return true;
}
Also used : InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) GroupState(org.apache.inlong.manager.common.enums.GroupState) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with GroupState

use of org.apache.inlong.manager.common.enums.GroupState in project incubator-inlong by apache.

the class InlongGroupServiceImpl method delete.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean delete(String groupId, String operator) {
    LOGGER.debug("begin to delete inlong group, groupId={}", groupId);
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
    if (entity == null) {
        LOGGER.error("inlong group not found by groupId={}", groupId);
        throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
    }
    // Determine whether the current status can be deleted
    GroupState curState = GroupState.forCode(entity.getStatus());
    if (GroupState.notAllowedTransition(curState, GroupState.DELETED)) {
        String errMsg = String.format("Current state=%s was not allowed to delete", curState);
        LOGGER.error(errMsg);
        throw new BusinessException(ErrorCodeEnum.GROUP_DELETE_NOT_ALLOWED, errMsg);
    }
    // [DRAFT] [GROUP_WAIT_SUBMIT] status, all associated data can be logically deleted directly
    if (GroupState.isAllowedLogicDel(curState)) {
        // Logically delete inlong streams, data sources and data sink information
        streamService.logicDeleteAll(entity.getInlongGroupId(), operator);
    } else {
        // In other status, you need to delete the associated "inlong stream" first.
        // When deleting a inlong stream, you also need to check whether there are
        // some associated "data source" and "stream sink"
        int count = streamService.selectCountByGroupId(groupId);
        if (count >= 1) {
            LOGGER.error("groupId={} have [{}] inlong streams, deleted failed", groupId, count);
            throw new BusinessException(ErrorCodeEnum.GROUP_HAS_STREAM);
        }
    }
    entity.setIsDeleted(entity.getId());
    entity.setStatus(GroupState.DELETED.getCode());
    entity.setModifier(operator);
    groupMapper.updateByIdentifierSelective(entity);
    // To logically delete the associated extension table
    groupExtMapper.logicDeleteAllByGroupId(groupId);
    // To logically delete the associated pulsar table
    groupPulsarMapper.logicDeleteByGroupId(groupId);
    LOGGER.info("success to delete inlong group and inlong group ext property for groupId={}", groupId);
    return true;
}
Also used : InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) GroupState(org.apache.inlong.manager.common.enums.GroupState) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with GroupState

use of org.apache.inlong.manager.common.enums.GroupState in project incubator-inlong by apache.

the class InlongGroupServiceImpl method checkGroupCanUpdate.

/**
 * Check whether modification is supported under the current inlong group status, and which fields can be modified.
 *
 * @param entity Original inlong group entity.
 * @param groupInfo New inlong group info.
 * @param operator Current operator.
 */
private void checkGroupCanUpdate(InlongGroupEntity entity, InlongGroupRequest groupInfo, String operator) {
    if (entity == null || groupInfo == null) {
        return;
    }
    // Only the person in charges can update
    if (StringUtils.isEmpty(entity.getInCharges())) {
        LOGGER.error("group [{}] has no inCharges", entity.getInlongGroupId());
        throw new BusinessException(ErrorCodeEnum.GROUP_INFO_INCONSISTENT);
    }
    List<String> inCharges = Arrays.asList(entity.getInCharges().split(","));
    if (!inCharges.contains(operator)) {
        LOGGER.error("user [{}] has no privilege for the inlong group", operator);
        throw new BusinessException(ErrorCodeEnum.GROUP_PERMISSION_DENIED);
    }
    // Check whether the current state supports modification
    GroupState curState = GroupState.forCode(entity.getStatus());
    if (GroupState.notAllowedUpdate(curState)) {
        String errMsg = String.format("Current state=%s is not allowed to update", curState);
        LOGGER.error(errMsg);
        throw new BusinessException(ErrorCodeEnum.GROUP_UPDATE_NOT_ALLOWED, errMsg);
    }
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) GroupState(org.apache.inlong.manager.common.enums.GroupState)

Aggregations

GroupState (org.apache.inlong.manager.common.enums.GroupState)4 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)4 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)2