use of org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest in project incubator-inlong by apache.
the class InlongStreamSinkTransfer method createKafkaRequest.
private static SinkRequest createKafkaRequest(StreamSink streamSink, InlongStreamInfo streamInfo) {
KafkaSinkRequest kafkaSinkRequest = new KafkaSinkRequest();
KafkaSink kafkaSink = (KafkaSink) streamSink;
kafkaSinkRequest.setSinkName(streamSink.getSinkName());
kafkaSinkRequest.setAddress(kafkaSink.getAddress());
kafkaSinkRequest.setTopicName(kafkaSink.getTopicName());
kafkaSinkRequest.setSinkType(kafkaSink.getSinkType().name());
kafkaSinkRequest.setInlongGroupId(streamInfo.getInlongGroupId());
kafkaSinkRequest.setInlongStreamId(streamInfo.getInlongStreamId());
kafkaSinkRequest.setSerializationType(kafkaSink.getDataFormat().name());
kafkaSinkRequest.setEnableCreateResource(kafkaSink.isNeedCreated() ? 1 : 0);
kafkaSinkRequest.setProperties(kafkaSink.getProperties());
if (CollectionUtils.isNotEmpty(kafkaSink.getSinkFields())) {
List<SinkFieldRequest> fieldRequests = createSinkFieldRequests(kafkaSink.getSinkFields());
kafkaSinkRequest.setFieldList(fieldRequests);
}
return kafkaSinkRequest;
}
use of org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest 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;
}
use of org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest in project incubator-inlong by apache.
the class KafkaStreamSinkOperation method updateOpt.
@Override
public void updateOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_KAFKA.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_KAFKA, sinkType));
StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
KafkaSinkRequest kafkaSinkRequest = (KafkaSinkRequest) request;
CommonBeanUtils.copyProperties(kafkaSinkRequest, entity, true);
try {
KafkaSinkDTO dto = KafkaSinkDTO.getFromRequest(kafkaSinkRequest);
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, kafkaSinkRequest);
LOGGER.info("success to update sink of type={}", sinkType);
}
use of org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest in project incubator-inlong by apache.
the class KafkaStreamSinkServiceTest method saveSink.
@Before
public void saveSink() {
streamServiceTest.saveInlongStream(globalGroupId, globalStreamId, globalOperator);
KafkaSinkRequest sinkInfo = new KafkaSinkRequest();
sinkInfo.setInlongGroupId(globalGroupId);
sinkInfo.setInlongStreamId(globalStreamId);
sinkInfo.setSinkType(Constant.SINK_KAFKA);
sinkInfo.setSinkName(sinkName);
sinkInfo.setSerializationType(serializationType);
sinkInfo.setAddress(bootstrapServers);
sinkInfo.setTopicName(topicName);
sinkInfo.setEnableCreateResource(Constant.DISABLE_CREATE_RESOURCE);
kafkaSinkId = sinkService.save(sinkInfo, globalOperator);
}
use of org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest in project incubator-inlong by apache.
the class KafkaStreamSinkServiceTest method testGetAndUpdate.
@Test
public void testGetAndUpdate() {
SinkResponse response = sinkService.get(kafkaSinkId, Constant.SINK_KAFKA);
Assert.assertEquals(globalGroupId, response.getInlongGroupId());
KafkaSinkResponse kafkaSinkResponse = (KafkaSinkResponse) response;
kafkaSinkResponse.setEnableCreateResource(Constant.ENABLE_CREATE_RESOURCE);
KafkaSinkRequest request = CommonBeanUtils.copyProperties(kafkaSinkResponse, KafkaSinkRequest::new);
boolean result = sinkService.update(request, globalOperator);
Assert.assertTrue(result);
}
Aggregations