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);
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations