Search in sources :

Example 16 with SinkResponse

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

the class PushSortConfigListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("begin to push sort config by context={}", context);
    }
    GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
    String groupId = form.getGroupInfo().getInlongGroupId();
    InlongGroupInfo groupInfo = groupService.get(groupId);
    // if streamId not null, just push the config belongs to the groupId and the streamId
    String streamId = form.getInlongStreamId();
    List<SinkResponse> sinkResponseList = streamSinkService.listSink(groupId, streamId);
    if (CollectionUtils.isEmpty(sinkResponseList)) {
        LOGGER.warn("Sink not found by groupId={}", groupId);
        return ListenerResult.success();
    }
    for (SinkResponse sinkResponse : sinkResponseList) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("sink info: {}", sinkResponse);
        }
        DataFlowInfo dataFlowInfo = commonOperateService.createDataFlow(groupInfo, sinkResponse);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("try to push config to sort: {}", JsonUtils.toJson(dataFlowInfo));
        }
        Integer sinkId = sinkResponse.getId();
        try {
            String zkUrl = clusterBean.getZkUrl();
            String zkRoot = clusterBean.getZkRoot();
            // push data flow info to zk
            String sortClusterName = clusterBean.getAppName();
            ZkTools.updateDataFlowInfo(dataFlowInfo, sortClusterName, sinkId, zkUrl, zkRoot);
            // add sink id to zk
            ZkTools.addDataFlowToCluster(sortClusterName, sinkId, zkUrl, zkRoot);
        } catch (Exception e) {
            LOGGER.error("push sort config to zookeeper failed, sinkId={} ", sinkId, e);
            throw new WorkflowListenerException("push sort config to zookeeper failed: " + e.getMessage());
        }
    }
    return ListenerResult.success();
}
Also used : SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo)

Example 17 with SinkResponse

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

Aggregations

SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)17 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)8 InlongStreamServiceTest (org.apache.inlong.manager.service.core.impl.InlongStreamServiceTest)8 Test (org.junit.Test)8 SinkFieldResponse (org.apache.inlong.manager.common.pojo.sink.SinkFieldResponse)4 ClickHouseSinkResponse (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkResponse)4 HiveSinkResponse (org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse)4 IcebergSinkResponse (org.apache.inlong.manager.common.pojo.sink.iceberg.IcebergSinkResponse)4 KafkaSinkResponse (org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkResponse)4 StreamSinkEntity (org.apache.inlong.manager.dao.entity.StreamSinkEntity)4 StreamSinkFieldEntity (org.apache.inlong.manager.dao.entity.StreamSinkFieldEntity)4 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)2 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)2 SourceResponse (org.apache.inlong.manager.common.pojo.source.SourceResponse)2 FullStreamResponse (org.apache.inlong.manager.common.pojo.stream.FullStreamResponse)2 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)2 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)2 Page (com.github.pagehelper.Page)1 PageInfo (com.github.pagehelper.PageInfo)1 Lists (com.google.common.collect.Lists)1