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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations