Search in sources :

Example 1 with KafkaSinkRequest

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;
}
Also used : KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) KafkaSink(org.apache.inlong.manager.client.api.sink.KafkaSink) SinkFieldRequest(org.apache.inlong.manager.common.pojo.sink.SinkFieldRequest)

Example 2 with 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;
}
Also used : KafkaSinkDTO(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkDTO) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Date(java.util.Date) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 3 with KafkaSinkRequest

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);
}
Also used : KafkaSinkDTO(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkDTO) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) Date(java.util.Date)

Example 4 with KafkaSinkRequest

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);
}
Also used : KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) Before(org.junit.Before)

Example 5 with KafkaSinkRequest

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);
}
Also used : SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) KafkaSinkResponse(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse) KafkaSinkResponse(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse) KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest) InlongStreamServiceTest(org.apache.inlong.manager.service.core.impl.InlongStreamServiceTest)

Aggregations

KafkaSinkRequest (org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest)5 Date (java.util.Date)2 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)2 KafkaSinkDTO (org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkDTO)2 StreamSinkEntity (org.apache.inlong.manager.dao.entity.StreamSinkEntity)2 KafkaSink (org.apache.inlong.manager.client.api.sink.KafkaSink)1 SinkFieldRequest (org.apache.inlong.manager.common.pojo.sink.SinkFieldRequest)1 SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)1 KafkaSinkResponse (org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse)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