Search in sources :

Example 6 with BusinessException

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

the class IcebergStreamSinkOperation method updateOpt.

@Override
public void updateOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_ICEBERG.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_ICEBERG, sinkType));
    StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
    Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
    IcebergSinkRequest icebergSinkRequest = (IcebergSinkRequest) request;
    CommonBeanUtils.copyProperties(icebergSinkRequest, entity, true);
    try {
        IcebergSinkDTO dto = IcebergSinkDTO.getFromRequest(icebergSinkRequest);
        entity.setExtParams(objectMapper.writeValueAsString(dto));
    } catch (Exception e) {
        throw new BusinessException(ErrorCodeEnum.SINK_INFO_INCORRECT.getMessage());
    }
    entity.setPreviousStatus(entity.getStatus());
    entity.setStatus(EntityStatus.GROUP_CONFIG_ING.getCode());
    entity.setModifier(operator);
    entity.setModifyTime(new Date());
    sinkMapper.updateByPrimaryKeySelective(entity);
    boolean onlyAdd = EntityStatus.SINK_CONFIG_SUCCESSFUL.getCode().equals(entity.getPreviousStatus());
    this.updateFieldOpt(onlyAdd, icebergSinkRequest);
    LOGGER.info("success to update sink of type={}", sinkType);
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) IcebergSinkRequest(org.apache.inlong.manager.common.pojo.sink.iceberg.IcebergSinkRequest) IcebergSinkDTO(org.apache.inlong.manager.common.pojo.sink.iceberg.IcebergSinkDTO) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) Date(java.util.Date)

Example 7 with BusinessException

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

the class KafkaStreamSourceOperation method setTargetEntity.

@Override
protected void setTargetEntity(SourceRequest request, StreamSourceEntity targetEntity) {
    KafkaSourceRequest sourceRequest = (KafkaSourceRequest) request;
    CommonBeanUtils.copyProperties(sourceRequest, targetEntity, true);
    try {
        KafkaSourceDTO dto = KafkaSourceDTO.getFromRequest(sourceRequest);
        targetEntity.setExtParams(objectMapper.writeValueAsString(dto));
    } catch (Exception e) {
        throw new BusinessException(ErrorCodeEnum.SOURCE_INFO_INCORRECT.getMessage());
    }
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) KafkaSourceRequest(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceRequest) KafkaSourceDTO(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceDTO) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 8 with BusinessException

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

the class KafkaStreamSinkOperation method saveOpt.

@Override
public Integer saveOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_KAFKA.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
    KafkaSinkRequest kafkaSinkRequest = (KafkaSinkRequest) request;
    StreamSinkEntity entity = CommonBeanUtils.copyProperties(kafkaSinkRequest, StreamSinkEntity::new);
    entity.setStatus(EntityStatus.SINK_NEW.getCode());
    entity.setIsDeleted(EntityStatus.UN_DELETED.getCode());
    entity.setCreator(operator);
    entity.setModifier(operator);
    Date now = new Date();
    entity.setCreateTime(now);
    entity.setModifyTime(now);
    // get the ext params
    KafkaSinkDTO dto = KafkaSinkDTO.getFromRequest(kafkaSinkRequest);
    try {
        entity.setExtParams(objectMapper.writeValueAsString(dto));
    } catch (Exception e) {
        throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED);
    }
    sinkMapper.insert(entity);
    Integer sinkId = entity.getId();
    request.setId(sinkId);
    this.saveFieldOpt(request);
    return sinkId;
}
Also used : KafkaSinkDTO(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkDTO) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Date(java.util.Date) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 9 with BusinessException

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

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

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