Search in sources :

Example 1 with SinkRequest

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

the class InnerInlongManagerClient method createSink.

public String createSink(SinkRequest sinkRequest) {
    String path = HTTP_PATH + "/sink/save";
    final String sink = GsonUtil.toJson(sinkRequest);
    final RequestBody sinkBody = RequestBody.create(MediaType.parse("application/json"), sink);
    final String url = formatUrl(path);
    Request request = new Request.Builder().url(url).method("POST", sinkBody).build();
    Call call = httpClient.newCall(request);
    try {
        Response response = call.execute();
        assert response.body() != null;
        String body = response.body().string();
        AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed: %s", body));
        org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
        AssertUtil.isTrue(responseBody.getErrMsg() == null, String.format("Inlong request failed: %s", responseBody.getErrMsg()));
        return responseBody.getData().toString();
    } catch (Exception e) {
        throw new RuntimeException(String.format("Inlong sink save failed: %s", e.getMessage()), e);
    }
}
Also used : Response(okhttp3.Response) InlongStreamConfigLogListResponse(org.apache.inlong.manager.common.pojo.stream.InlongStreamConfigLogListResponse) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse) InlongGroupListResponse(org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse) InlongGroupResponse(org.apache.inlong.manager.common.pojo.group.InlongGroupResponse) FullStreamResponse(org.apache.inlong.manager.common.pojo.stream.FullStreamResponse) Call(okhttp3.Call) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) Request(okhttp3.Request) InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) InlongGroupRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupRequest) SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) InlongGroupApproveRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest) RequestBody(okhttp3.RequestBody)

Example 2 with SinkRequest

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

the class DefaultInlongStreamBuilder method initOrUpdate.

@Override
public InlongStream initOrUpdate() {
    InlongStreamInfo dataStreamInfo = streamContext.getStreamInfo();
    Pair<Boolean, InlongStreamInfo> existMsg = managerClient.isStreamExists(dataStreamInfo);
    if (existMsg.getKey()) {
        Pair<Boolean, String> updateMsg = managerClient.updateStreamInfo(dataStreamInfo);
        if (updateMsg.getKey()) {
            List<SourceRequest> sourceRequests = Lists.newArrayList(streamContext.getSourceRequests().values());
            for (SourceRequest sourceRequest : sourceRequests) {
                sourceRequest.setId(initOrUpdateSource(sourceRequest));
            }
            List<SinkRequest> sinkRequests = Lists.newArrayList(streamContext.getSinkRequests().values());
            for (SinkRequest sinkRequest : sinkRequests) {
                sinkRequest.setId(initOrUpdateSink(sinkRequest));
            }
        } else {
            throw new RuntimeException(String.format("Update data stream failed:%s", updateMsg.getValue()));
        }
        return inlongStream;
    } else {
        return init();
    }
}
Also used : SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)

Example 3 with SinkRequest

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

the class DefaultInlongStreamBuilder method sink.

@Override
public InlongStreamBuilder sink(StreamSink sink) {
    inlongStream.addSink(sink);
    SinkRequest sinkRequest = InlongStreamSinkTransfer.createSinkRequest(sink, streamContext.getStreamInfo());
    streamContext.setSinkRequest(sinkRequest);
    return this;
}
Also used : SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest)

Example 4 with SinkRequest

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

the class DefaultInlongStreamBuilder method init.

@Override
public InlongStream init() {
    InlongStreamInfo streamInfo = streamContext.getStreamInfo();
    String streamIndex = managerClient.createStreamInfo(streamInfo);
    streamInfo.setId(Double.valueOf(streamIndex).intValue());
    // Create source and update index
    List<SourceRequest> sourceRequests = Lists.newArrayList(streamContext.getSourceRequests().values());
    for (SourceRequest sourceRequest : sourceRequests) {
        String sourceIndex = managerClient.createSource(sourceRequest);
        sourceRequest.setId(Double.valueOf(sourceIndex).intValue());
    }
    // Create sink and update index
    List<SinkRequest> sinkRequests = Lists.newArrayList(streamContext.getSinkRequests().values());
    for (SinkRequest sinkRequest : sinkRequests) {
        String sinkIndex = managerClient.createSink(sinkRequest);
        sinkRequest.setId(Double.valueOf(sinkIndex).intValue());
    }
    return inlongStream;
}
Also used : SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)

Example 5 with SinkRequest

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

the class InlongStreamServiceImpl method saveAll.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean saveAll(FullStreamRequest fullStreamRequest, String operator) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("begin to save all stream page info: {}", fullStreamRequest);
    }
    Preconditions.checkNotNull(fullStreamRequest, "fullStreamRequest is empty");
    InlongStreamInfo streamInfo = fullStreamRequest.getStreamInfo();
    Preconditions.checkNotNull(streamInfo, "inlong stream info is empty");
    // Check whether it can be added: check by lower-level specific services
    // this.checkBizIsTempStatus(streamInfo.getInlongGroupId());
    // 1. Save inlong stream
    this.save(streamInfo, operator);
    // 2.1 Save file data source information
    if (fullStreamRequest.getFileBasicInfo() != null) {
        sourceFileService.saveBasic(fullStreamRequest.getFileBasicInfo(), operator);
    }
    if (CollectionUtils.isNotEmpty(fullStreamRequest.getFileDetailInfoList())) {
        for (SourceFileDetailInfo detailInfo : fullStreamRequest.getFileDetailInfoList()) {
            sourceFileService.saveDetail(detailInfo, operator);
        }
    }
    // 2.2 Save DB data source information
    if (fullStreamRequest.getDbBasicInfo() != null) {
        sourceDbService.saveBasic(fullStreamRequest.getDbBasicInfo(), operator);
    }
    if (CollectionUtils.isNotEmpty(fullStreamRequest.getDbDetailInfoList())) {
        for (SourceDbDetailInfo detailInfo : fullStreamRequest.getDbDetailInfoList()) {
            sourceDbService.saveDetail(detailInfo, operator);
        }
    }
    // 3. Save data sink information
    if (CollectionUtils.isNotEmpty(fullStreamRequest.getSinkInfo())) {
        for (SinkRequest sinkInfo : fullStreamRequest.getSinkInfo()) {
            sinkService.save(sinkInfo, operator);
        }
    }
    LOGGER.info("success to save all stream page info");
    return true;
}
Also used : SourceDbDetailInfo(org.apache.inlong.manager.common.pojo.source.SourceDbDetailInfo) SourceFileDetailInfo(org.apache.inlong.manager.common.pojo.source.SourceFileDetailInfo) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SinkRequest (org.apache.inlong.manager.common.pojo.sink.SinkRequest)7 SourceRequest (org.apache.inlong.manager.common.pojo.source.SourceRequest)4 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)3 Call (okhttp3.Call)2 Request (okhttp3.Request)2 RequestBody (okhttp3.RequestBody)2 Response (okhttp3.Response)2 InlongGroupApproveRequest (org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest)2 InlongGroupListResponse (org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse)2 InlongGroupRequest (org.apache.inlong.manager.common.pojo.group.InlongGroupRequest)2 InlongGroupResponse (org.apache.inlong.manager.common.pojo.group.InlongGroupResponse)2 SinkListResponse (org.apache.inlong.manager.common.pojo.sink.SinkListResponse)2 SourceListResponse (org.apache.inlong.manager.common.pojo.source.SourceListResponse)2 FullStreamResponse (org.apache.inlong.manager.common.pojo.stream.FullStreamResponse)2 InlongStreamApproveRequest (org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest)2 InlongStreamConfigLogListResponse (org.apache.inlong.manager.common.pojo.stream.InlongStreamConfigLogListResponse)2 SinkType (org.apache.inlong.manager.common.enums.SinkType)1 ClickHouseSinkRequest (org.apache.inlong.manager.common.pojo.sink.ck.ClickHouseSinkRequest)1 HiveSinkRequest (org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest)1 KafkaSinkRequest (org.apache.inlong.manager.common.pojo.sink.kafka.KafkaSinkRequest)1