Search in sources :

Example 11 with BusinessException

use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.

the class InlongGroupServiceImpl method get.

@Override
public InlongGroupInfo get(String groupId) {
    LOGGER.debug("begin to get inlong group info by 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);
    }
    InlongGroupInfo groupInfo = CommonBeanUtils.copyProperties(entity, InlongGroupInfo::new);
    List<InlongGroupExtEntity> extEntityList = groupExtMapper.selectByGroupId(groupId);
    List<InlongGroupExtInfo> extInfoList = CommonBeanUtils.copyListProperties(extEntityList, InlongGroupExtInfo::new);
    groupInfo.setExtList(extInfoList);
    // If the middleware is Pulsar, we need to encapsulate Pulsar related data
    String mqType = entity.getMiddlewareType();
    if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
        InlongGroupPulsarEntity pulsarEntity = groupPulsarMapper.selectByGroupId(groupId);
        Preconditions.checkNotNull(pulsarEntity, "Pulsar info not found by the groupId=" + groupId);
        InlongGroupPulsarInfo pulsarInfo = CommonBeanUtils.copyProperties(pulsarEntity, InlongGroupPulsarInfo::new);
        pulsarInfo.setMiddlewareType(mqType);
        groupInfo.setMqExtInfo(pulsarInfo);
    }
    // For approved inlong group, encapsulate the cluster address of the middleware
    if (GroupState.CONFIG_SUCCESSFUL == GroupState.forCode(groupInfo.getStatus())) {
        if (Constant.MIDDLEWARE_TUBE.equalsIgnoreCase(mqType)) {
            groupInfo.setTubeMaster(commonOperateService.getSpecifiedParam(Constant.TUBE_MASTER_URL));
        } else if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
            PulsarClusterInfo pulsarCluster = commonOperateService.getPulsarClusterInfo(mqType);
            groupInfo.setPulsarAdminUrl(pulsarCluster.getAdminUrl());
            groupInfo.setPulsarServiceUrl(pulsarCluster.getBrokerServiceUrl());
        }
    }
    LOGGER.debug("success to get inlong group for groupId={}", groupId);
    return groupInfo;
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupExtEntity(org.apache.inlong.manager.dao.entity.InlongGroupExtEntity) InlongGroupPulsarEntity(org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)

Example 12 with BusinessException

use of org.apache.inlong.manager.common.exceptions.BusinessException 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)

Example 13 with BusinessException

use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.

the class SourceDbServiceImpl method saveDetailOpt.

/**
 * Save data source details
 */
@Transactional(rollbackFor = Throwable.class)
int saveDetailOpt(SourceDbDetailInfo detailInfo, String operator) {
    // DB type judgment uniqueness: if the same groupId, streamId, dbName, connectionName
    // correspond to the same data source
    String groupId = detailInfo.getInlongGroupId();
    String streamId = detailInfo.getInlongStreamId();
    String dbName = detailInfo.getDbName();
    String connectionName = detailInfo.getConnectionName();
    Integer count = dbDetailMapper.selectDetailExist(groupId, streamId, dbName, connectionName);
    if (count > 0) {
        LOGGER.error("db source detail already exists, groupId={}, streamId={}, dbName={}, connectionName={}", groupId, streamId, dbName, connectionName);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
    }
    SourceDbDetailEntity dbEntity = CommonBeanUtils.copyProperties(detailInfo, SourceDbDetailEntity::new);
    dbEntity.setStatus(EntityStatus.AGENT_ADD.getCode());
    dbEntity.setCreator(operator);
    dbEntity.setModifier(operator);
    dbEntity.setCreateTime(new Date());
    dbDetailMapper.insertSelective(dbEntity);
    return dbEntity.getId();
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with BusinessException

use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.

the class SourceDbServiceImpl method logicDeleteBasic.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
    LOGGER.info("begin to delete db data source basic, id={}", id);
    Preconditions.checkNotNull(id, "db data source basic's id is null");
    SourceDbBasicEntity entity = dbBasicMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source basic not found by id={}, delete failed", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
    }
    String groupId = entity.getInlongGroupId();
    String streamId = entity.getInlongStreamId();
    // Check if it can be deleted
    this.checkGroupIsTempStatus(groupId);
    // If there are related data source details, it is not allowed to delete
    List<SourceDbDetailEntity> detailEntities = dbDetailMapper.selectByIdentifier(groupId, streamId);
    if (CollectionUtils.isNotEmpty(detailEntities)) {
        LOGGER.error("the data source basic have [{}] details, delete failed", detailEntities.size());
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_DELETE_HAS_DETAIL);
    }
    entity.setIsDeleted(1);
    entity.setModifier(operator);
    int resultCount = dbBasicMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete db data source basic");
    return resultCount >= 0;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with BusinessException

use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.

the class SourceDbServiceImpl method getDetailById.

@Override
public SourceDbDetailInfo getDetailById(Integer id) {
    LOGGER.info("begin to get db data source detail by id={}", id);
    Preconditions.checkNotNull(id, "db data source detail's id is null");
    SourceDbDetailEntity entity = dbDetailMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source detail not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
    }
    SourceDbDetailInfo detailInfo = CommonBeanUtils.copyProperties(entity, SourceDbDetailInfo::new);
    LOGGER.info("success to get db data source detail");
    return detailInfo;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailInfo(org.apache.inlong.manager.common.pojo.source.SourceDbDetailInfo) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity)

Aggregations

BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)58 Date (java.util.Date)20 Transactional (org.springframework.transaction.annotation.Transactional)18 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)14 StreamSinkEntity (org.apache.inlong.manager.dao.entity.StreamSinkEntity)8 InlongStreamEntity (org.apache.inlong.manager.dao.entity.InlongStreamEntity)7 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)6 SourceFileDetailEntity (org.apache.inlong.manager.dao.entity.SourceFileDetailEntity)5 ThirdPartyClusterEntity (org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)5 GroupState (org.apache.inlong.manager.common.enums.GroupState)4 InlongGroupPulsarEntity (org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity)4 SourceDbDetailEntity (org.apache.inlong.manager.dao.entity.SourceDbDetailEntity)4 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)3 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)3 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)3 SourceDbBasicEntity (org.apache.inlong.manager.dao.entity.SourceDbBasicEntity)3 ColumnPositionMappingStrategy (com.opencsv.bean.ColumnPositionMappingStrategy)2 ApiOperation (io.swagger.annotations.ApiOperation)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2