Search in sources :

Example 1 with ClickHouseSinkRequest

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

the class InlongStreamSinkTransfer method createClickHouseRequest.

private static SinkRequest createClickHouseRequest(StreamSink streamSink, InlongStreamInfo streamInfo) {
    ClickHouseSinkRequest clickHouseSinkRequest = new ClickHouseSinkRequest();
    ClickHouseSink clickHouseSink = (ClickHouseSink) streamSink;
    clickHouseSinkRequest.setSinkName(clickHouseSink.getSinkName());
    clickHouseSinkRequest.setDatabaseName(clickHouseSink.getDatabaseName());
    clickHouseSinkRequest.setSinkType(clickHouseSink.getSinkType().name());
    clickHouseSinkRequest.setJdbcUrl(clickHouseSink.getJdbcUrl());
    DefaultAuthentication defaultAuthentication = clickHouseSink.getAuthentication();
    AssertUtil.notNull(defaultAuthentication, String.format("Clickhouse storage:%s must be authenticated", clickHouseSink.getDatabaseName()));
    clickHouseSinkRequest.setUsername(defaultAuthentication.getUserName());
    clickHouseSinkRequest.setPassword(defaultAuthentication.getPassword());
    clickHouseSinkRequest.setTableName(clickHouseSink.getTableName());
    clickHouseSinkRequest.setDistributedTable(clickHouseSink.getDistributedTable());
    clickHouseSinkRequest.setFlushInterval(clickHouseSink.getFlushInterval());
    clickHouseSinkRequest.setFlushRecordNumber(clickHouseSink.getFlushRecordNumber());
    clickHouseSinkRequest.setKeyFieldNames(clickHouseSink.getKeyFieldNames());
    clickHouseSinkRequest.setPartitionKey(clickHouseSink.getPartitionKey());
    clickHouseSinkRequest.setPartitionStrategy(clickHouseSink.getPartitionStrategy());
    clickHouseSinkRequest.setWriteMaxRetryTimes(clickHouseSink.getWriteMaxRetryTimes());
    clickHouseSinkRequest.setInlongGroupId(streamInfo.getInlongGroupId());
    clickHouseSinkRequest.setInlongStreamId(streamInfo.getInlongStreamId());
    clickHouseSinkRequest.setProperties(clickHouseSink.getProperties());
    clickHouseSinkRequest.setEnableCreateResource(clickHouseSink.isNeedCreated() ? 1 : 0);
    if (CollectionUtils.isNotEmpty(clickHouseSink.getSinkFields())) {
        List<SinkFieldRequest> fieldRequests = createSinkFieldRequests(streamSink.getSinkFields());
        clickHouseSinkRequest.setFieldList(fieldRequests);
    }
    return clickHouseSinkRequest;
}
Also used : ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest) DefaultAuthentication(org.apache.inlong.manager.client.api.auth.DefaultAuthentication) SinkFieldRequest(org.apache.inlong.manager.common.pojo.sink.SinkFieldRequest) ClickHouseSink(org.apache.inlong.manager.client.api.sink.ClickHouseSink)

Example 2 with ClickHouseSinkRequest

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

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

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

the class ClickHouseStreamSinkServiceTest method saveSink.

@Before
public void saveSink() {
    streamServiceTest.saveInlongStream(globalGroupId, globalStreamId, globalOperator);
    ClickHouseSinkRequest sinkInfo = new ClickHouseSinkRequest();
    sinkInfo.setInlongGroupId(globalGroupId);
    sinkInfo.setInlongStreamId(globalStreamId);
    sinkInfo.setSinkName(sinkName);
    sinkInfo.setSinkType(Constant.SINK_CLICKHOUSE);
    sinkInfo.setJdbcUrl(ckJdbcUrl);
    sinkInfo.setUsername(ckUsername);
    sinkInfo.setDatabaseName(ckDatabaseName);
    sinkInfo.setTableName(ckTableName);
    sinkInfo.setEnableCreateResource(Constant.DISABLE_CREATE_RESOURCE);
    sinkId = sinkService.save(sinkInfo, globalOperator);
}
Also used : ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest) Before(org.junit.Before)

Example 5 with ClickHouseSinkRequest

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

the class ClickHouseStreamSinkServiceTest method testGetAndUpdate.

@Test
public void testGetAndUpdate() {
    SinkResponse response = sinkService.get(sinkId, Constant.SINK_CLICKHOUSE);
    Assert.assertEquals(globalGroupId, response.getInlongGroupId());
    ClickHouseSinkResponse kafkaSinkResponse = (ClickHouseSinkResponse) response;
    kafkaSinkResponse.setEnableCreateResource(Constant.ENABLE_CREATE_RESOURCE);
    ClickHouseSinkRequest request = CommonBeanUtils.copyProperties(kafkaSinkResponse, ClickHouseSinkRequest::new);
    boolean result = sinkService.update(request, globalOperator);
    Assert.assertTrue(result);
}
Also used : ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) ClickHouseSinkResponse(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse) ClickHouseSinkResponse(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest) InlongStreamServiceTest(org.apache.inlong.manager.service.core.impl.InlongStreamServiceTest)

Aggregations

ClickHouseSinkRequest (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest)5 Date (java.util.Date)2 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)2 ClickHouseSinkDTO (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkDTO)2 StreamSinkEntity (org.apache.inlong.manager.dao.entity.StreamSinkEntity)2 DefaultAuthentication (org.apache.inlong.manager.client.api.auth.DefaultAuthentication)1 ClickHouseSink (org.apache.inlong.manager.client.api.sink.ClickHouseSink)1 SinkFieldRequest (org.apache.inlong.manager.common.pojo.sink.SinkFieldRequest)1 SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)1 ClickHouseSinkResponse (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse)1 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)1 InlongStreamServiceTest (org.apache.inlong.manager.service.core.impl.InlongStreamServiceTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1