Search in sources :

Example 1 with ClickHouseSinkDTO

use of org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO 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 2 with ClickHouseSinkDTO

use of org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO 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 3 with ClickHouseSinkDTO

use of org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO in project incubator-inlong by apache.

the class ClickHouseStreamSinkOperation method getFromEntity.

@Override
public <T> T getFromEntity(StreamSinkEntity entity, Supplier<T> target) {
    T result = target.get();
    if (entity == null) {
        return result;
    }
    String existType = entity.getSinkType();
    Preconditions.checkTrue(Constant.SINK_CLICKHOUSE.equals(existType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_CLICKHOUSE, existType));
    ClickHouseSinkDTO dto = ClickHouseSinkDTO.getFromJson(entity.getExtParams());
    CommonBeanUtils.copyProperties(entity, result, true);
    CommonBeanUtils.copyProperties(dto, result, true);
    return result;
}
Also used : ClickHouseSinkDTO(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO)

Aggregations

ClickHouseSinkDTO (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO)3 Date (java.util.Date)2 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)2 ClickHouseSinkRequest (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest)2 StreamSinkEntity (org.apache.inlong.manager.dao.entity.StreamSinkEntity)2