Search in sources :

Example 1 with BusinessException

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

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

the class ClickHouseStreamSinkOperation method saveOpt.

@Override
public Integer saveOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_CLICKHOUSE.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
    ClickHouseSinkRequest sinkRequest = (ClickHouseSinkRequest) request;
    StreamSinkEntity entity = CommonBeanUtils.copyProperties(sinkRequest, 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
    ClickHouseSinkDTO dto = ClickHouseSinkDTO.getFromRequest(sinkRequest);
    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 : ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) ClickHouseSinkDTO(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Date(java.util.Date) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 3 with BusinessException

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

the class ClickHouseStreamSinkOperation method updateOpt.

@Override
public void updateOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_CLICKHOUSE.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_CLICKHOUSE, sinkType));
    StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
    Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
    ClickHouseSinkRequest sinkRequest = (ClickHouseSinkRequest) request;
    CommonBeanUtils.copyProperties(sinkRequest, entity, true);
    try {
        ClickHouseSinkDTO dto = ClickHouseSinkDTO.getFromRequest(sinkRequest);
        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, sinkRequest);
    LOGGER.info("success to update sink of type={}", sinkType);
}
Also used : ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) ClickHouseSinkDTO(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) Date(java.util.Date)

Example 4 with BusinessException

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

the class HiveStreamSinkOperation method saveOpt.

@Override
public Integer saveOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_HIVE.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
    HiveSinkRequest hiveRequest = (HiveSinkRequest) request;
    StreamSinkEntity entity = CommonBeanUtils.copyProperties(hiveRequest, 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
    HiveSinkDTO dto = HiveSinkDTO.getFromRequest(hiveRequest);
    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 : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) HiveSinkRequest(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest) HiveSinkDTO(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkDTO) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Date(java.util.Date) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 5 with BusinessException

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

the class HiveStreamSinkOperation method updateOpt.

@Override
public void updateOpt(SinkRequest request, String operator) {
    String sinkType = request.getSinkType();
    Preconditions.checkTrue(Constant.SINK_HIVE.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_HIVE, sinkType));
    StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
    Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
    HiveSinkRequest hiveRequest = (HiveSinkRequest) request;
    CommonBeanUtils.copyProperties(hiveRequest, entity, true);
    try {
        HiveSinkDTO dto = HiveSinkDTO.getFromRequest(hiveRequest);
        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, hiveRequest);
    LOGGER.info("success to update sink of type={}", sinkType);
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) HiveSinkRequest(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest) HiveSinkDTO(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkDTO) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) Date(java.util.Date)

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