Search in sources :

Example 1 with SinkType

use of org.apache.inlong.manager.common.enums.SinkType in project incubator-inlong by apache.

the class StreamSinkServiceImpl method listByCondition.

@Override
public PageInfo<? extends SinkListResponse> listByCondition(SinkPageRequest request) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("begin to list sink page by " + request);
    }
    Preconditions.checkNotNull(request.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
    PageHelper.startPage(request.getPageNum(), request.getPageSize());
    List<StreamSinkEntity> entityPage = sinkMapper.selectByCondition(request);
    Map<SinkType, Page<StreamSinkEntity>> sinkMap = Maps.newHashMap();
    for (StreamSinkEntity streamSink : entityPage) {
        SinkType sinkType = SinkType.forType(streamSink.getSinkType());
        sinkMap.computeIfAbsent(sinkType, k -> new Page<>()).add(streamSink);
    }
    List<SinkListResponse> sinkListResponses = Lists.newArrayList();
    for (Map.Entry<SinkType, Page<StreamSinkEntity>> entry : sinkMap.entrySet()) {
        SinkType sinkType = entry.getKey();
        StreamSinkOperation operation = operationFactory.getInstance(sinkType);
        PageInfo<? extends SinkListResponse> pageInfo = operation.getPageInfo(entry.getValue());
        sinkListResponses.addAll(pageInfo.getList());
    }
    // Encapsulate the paging query results into the PageInfo object to obtain related paging information
    PageInfo<? extends SinkListResponse> pageInfo = PageInfo.of(sinkListResponses);
    LOGGER.debug("success to list sink page");
    return pageInfo;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) EntityStatus(org.apache.inlong.manager.common.enums.EntityStatus) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) Date(java.util.Date) SinkPageRequest(org.apache.inlong.manager.common.pojo.sink.SinkPageRequest) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SinkBriefResponse(org.apache.inlong.manager.common.pojo.sink.SinkBriefResponse) ArrayList(java.util.ArrayList) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) Lists(com.google.common.collect.Lists) Preconditions(org.apache.inlong.manager.common.util.Preconditions) CollectionUtils(org.apache.commons.collections.CollectionUtils) CommonOperateService(org.apache.inlong.manager.service.CommonOperateService) CreateStreamWorkflowDefinition(org.apache.inlong.manager.service.workflow.stream.CreateStreamWorkflowDefinition) Service(org.springframework.stereotype.Service) Map(java.util.Map) CallerRunsPolicy(java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy) ProcessName(org.apache.inlong.manager.service.workflow.ProcessName) ExecutorService(java.util.concurrent.ExecutorService) StreamSinkEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper) GroupState(org.apache.inlong.manager.common.enums.GroupState) Logger(org.slf4j.Logger) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) SinkApproveDTO(org.apache.inlong.manager.common.pojo.sink.SinkApproveDTO) PageHelper(com.github.pagehelper.PageHelper) PageInfo(com.github.pagehelper.PageInfo) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) Maps(com.google.common.collect.Maps) ErrorCodeEnum(org.apache.inlong.manager.common.enums.ErrorCodeEnum) Constant(org.apache.inlong.manager.common.enums.Constant) TimeUnit(java.util.concurrent.TimeUnit) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) WorkflowService(org.apache.inlong.manager.service.workflow.WorkflowService) Page(com.github.pagehelper.Page) StreamSinkFieldEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSinkFieldEntityMapper) CommonBeanUtils(org.apache.inlong.manager.common.util.CommonBeanUtils) Collections(java.util.Collections) SinkType(org.apache.inlong.manager.common.enums.SinkType) Transactional(org.springframework.transaction.annotation.Transactional) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Page(com.github.pagehelper.Page) SinkType(org.apache.inlong.manager.common.enums.SinkType) Map(java.util.Map)

Example 2 with SinkType

use of org.apache.inlong.manager.common.enums.SinkType in project incubator-inlong by apache.

the class InlongParser method parseStreamList.

public static List<FullStreamResponse> parseStreamList(Response response) {
    Object data = response.getData();
    JsonObject pageInfoJson = GsonUtil.fromJson(GsonUtil.toJson(data), JsonObject.class);
    JsonArray fullStreamArray = pageInfoJson.getAsJsonArray("list");
    List<FullStreamResponse> list = Lists.newArrayList();
    for (int i = 0; i < fullStreamArray.size(); i++) {
        JsonObject fullStreamJson = (JsonObject) fullStreamArray.get(i);
        FullStreamResponse fullStreamResponse = GsonUtil.fromJson(fullStreamJson.toString(), FullStreamResponse.class);
        list.add(fullStreamResponse);
        // Parse sourceResponse in each stream
        JsonArray sourceJsonArr = fullStreamJson.getAsJsonArray(SOURCE_INFO);
        List<SourceResponse> sourceResponses = Lists.newArrayList();
        fullStreamResponse.setSourceInfo(sourceResponses);
        for (int j = 0; j < sourceJsonArr.size(); j++) {
            JsonObject sourceJson = (JsonObject) sourceJsonArr.get(i);
            String type = sourceJson.get(SOURCE_TYPE).getAsString();
            SourceType sourceType = SourceType.forType(type);
            switch(sourceType) {
                case BINLOG:
                    BinlogSourceResponse binlogSourceResponse = GsonUtil.fromJson(sourceJson.toString(), BinlogSourceResponse.class);
                    sourceResponses.add(binlogSourceResponse);
                    break;
                case KAFKA:
                    KafkaSourceResponse kafkaSourceResponse = GsonUtil.fromJson(sourceJson.toString(), KafkaSourceResponse.class);
                    sourceResponses.add(kafkaSourceResponse);
                    break;
                default:
                    throw new RuntimeException(String.format("Unsupport sourceType=%s for Inlong", sourceType));
            }
        }
        // Parse sinkResponse in each stream
        JsonArray sinkJsonArr = fullStreamJson.getAsJsonArray(SINK_INFO);
        List<SinkResponse> sinkResponses = Lists.newArrayList();
        fullStreamResponse.setSinkInfo(sinkResponses);
        for (int j = 0; j < sinkJsonArr.size(); j++) {
            JsonObject sinkJson = (JsonObject) sinkJsonArr.get(i);
            String type = sinkJson.get(SINK_TYPE).getAsString();
            SinkType sinkType = SinkType.forType(type);
            switch(sinkType) {
                case HIVE:
                    HiveSinkResponse hiveSinkResponse = GsonUtil.fromJson(sinkJson.toString(), HiveSinkResponse.class);
                    sinkResponses.add(hiveSinkResponse);
                    break;
                case KAFKA:
                    KafkaSinkResponse kafkaSinkResponse = GsonUtil.fromJson(sinkJson.toString(), KafkaSinkResponse.class);
                    sinkResponses.add(kafkaSinkResponse);
                    break;
                case ICEBERG:
                    IcebergSinkResponse icebergSinkResponse = GsonUtil.fromJson(sinkJson.toString(), IcebergSinkResponse.class);
                    sinkResponses.add(icebergSinkResponse);
                    break;
                case CLICKHOUSE:
                    ClickHouseSinkResponse clickHouseSinkResponse = GsonUtil.fromJson(sinkJson.toString(), ClickHouseSinkResponse.class);
                    sinkResponses.add(clickHouseSinkResponse);
                    break;
                default:
                    throw new RuntimeException(String.format("Unsupport sinkType=%s for Inlong", sinkType));
            }
        }
    }
    return list;
}
Also used : BinlogSourceResponse(org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceResponse) SourceResponse(org.apache.inlong.manager.common.pojo.source.SourceResponse) KafkaSourceResponse(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceResponse) SourceType(org.apache.inlong.manager.common.enums.SourceType) JsonObject(com.google.gson.JsonObject) BinlogSourceResponse(org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceResponse) ClickHouseSinkResponse(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse) JsonArray(com.google.gson.JsonArray) KafkaSourceResponse(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceResponse) ClickHouseSinkResponse(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse) KafkaSinkResponse(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse) IcebergSinkResponse(org.apache.inlong.manager.common.pojo.sink.iceberg.IcebergSinkResponse) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) HiveSinkResponse(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse) KafkaSinkResponse(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse) HiveSinkResponse(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse) FullStreamResponse(org.apache.inlong.manager.common.pojo.stream.FullStreamResponse) JsonObject(com.google.gson.JsonObject) SinkType(org.apache.inlong.manager.common.enums.SinkType) IcebergSinkResponse(org.apache.inlong.manager.common.pojo.sink.iceberg.IcebergSinkResponse)

Example 3 with SinkType

use of org.apache.inlong.manager.common.enums.SinkType in project incubator-inlong by apache.

the class InlongStreamSinkTransfer method parseStreamSink.

public static StreamSink parseStreamSink(SinkResponse sinkResponse, StreamSink streamSink) {
    String type = sinkResponse.getSinkType();
    SinkType sinkType = SinkType.forType(type);
    StreamSink streamSinkResult;
    if (sinkType == SinkType.HIVE) {
        streamSinkResult = parseHiveSink((HiveSinkResponse) sinkResponse, streamSink);
    } else if (sinkType == SinkType.KAFKA) {
        streamSinkResult = parseKafkaSink((KafkaSinkResponse) sinkResponse, streamSink);
    } else if (sinkType == SinkType.CLICKHOUSE) {
        streamSinkResult = parseClickHouseSink((ClickHouseSinkResponse) sinkResponse, streamSink);
    } else {
        throw new IllegalArgumentException(String.format("Unsupport sink type : %s for Inlong", sinkType));
    }
    return streamSinkResult;
}
Also used : HiveSinkResponse(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse) StreamSink(org.apache.inlong.manager.client.api.StreamSink) ClickHouseSinkResponse(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse) SinkType(org.apache.inlong.manager.common.enums.SinkType)

Example 4 with SinkType

use of org.apache.inlong.manager.common.enums.SinkType in project incubator-inlong by apache.

the class InlongStreamSinkTransfer method createSinkRequest.

public static SinkRequest createSinkRequest(StreamSink streamSink, InlongStreamInfo streamInfo) {
    SinkType sinkType = streamSink.getSinkType();
    SinkRequest sinkRequest;
    if (sinkType == SinkType.HIVE) {
        sinkRequest = createHiveRequest(streamSink, streamInfo);
    } else if (sinkType == SinkType.KAFKA) {
        sinkRequest = createKafkaRequest(streamSink, streamInfo);
    } else if (sinkType == SinkType.CLICKHOUSE) {
        sinkRequest = createClickHouseRequest(streamSink, streamInfo);
    } else {
        throw new IllegalArgumentException(String.format("Unsupport sink type : %s for Inlong", sinkType));
    }
    return sinkRequest;
}
Also used : SinkType(org.apache.inlong.manager.common.enums.SinkType) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) KafkaSinkRequest(org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest) HiveSinkRequest(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest) ClickHouseSinkRequest(org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest)

Aggregations

SinkType (org.apache.inlong.manager.common.enums.SinkType)4 SinkRequest (org.apache.inlong.manager.common.pojo.sink.SinkRequest)2 SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)2 ClickHouseSinkResponse (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse)2 HiveSinkResponse (org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse)2 Page (com.github.pagehelper.Page)1 PageHelper (com.github.pagehelper.PageHelper)1 PageInfo (com.github.pagehelper.PageInfo)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1