use of org.apache.inlong.manager.common.pojo.sink.SinkListResponse in project incubator-inlong by apache.
the class InlongParser method parseSinkList.
public static PageInfo<SinkListResponse> parseSinkList(Response response) {
Object data = response.getData();
String pageInfoJson = GsonUtil.toJson(data);
return GsonUtil.fromJson(pageInfoJson, new TypeToken<PageInfo<SinkListResponse>>() {
}.getType());
}
use of org.apache.inlong.manager.common.pojo.sink.SinkListResponse in project incubator-inlong by apache.
the class DefaultInlongStreamBuilder method initOrUpdateSink.
private int initOrUpdateSink(SinkRequest sinkRequest) {
String sinkType = sinkRequest.getSinkType();
boolean flag = SinkType.HIVE.name().equals(sinkType) || SinkType.KAFKA.name().equals(sinkType) || SinkType.CLICKHOUSE.name().equals(sinkType);
if (flag) {
List<SinkListResponse> responses = managerClient.listSinks(sinkRequest.getInlongGroupId(), sinkRequest.getInlongStreamId(), sinkRequest.getSinkType());
if (CollectionUtils.isEmpty(responses)) {
String sinkIndex = managerClient.createSink(sinkRequest);
return Double.valueOf(sinkIndex).intValue();
} else {
SinkListResponse sinkListResponse = null;
for (SinkListResponse response : responses) {
if (response.getSinkName().equals(sinkRequest.getSinkName())) {
sinkListResponse = response;
break;
}
}
if (sinkListResponse == null) {
String sinkIndex = managerClient.createSink(sinkRequest);
return Double.valueOf(sinkIndex).intValue();
}
sinkRequest.setId(sinkListResponse.getId());
Pair<Boolean, String> updateMsg = managerClient.updateSink(sinkRequest);
if (updateMsg.getKey()) {
return sinkListResponse.getId();
} else {
throw new RuntimeException(String.format("Update sink:%s failed with ex:%s", GsonUtil.toJson(sinkRequest), updateMsg.getValue()));
}
}
} else {
throw new IllegalArgumentException(String.format("Unsupported sink type:%s", sinkType));
}
}
use of org.apache.inlong.manager.common.pojo.sink.SinkListResponse 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;
}
use of org.apache.inlong.manager.common.pojo.sink.SinkListResponse in project incubator-inlong by apache.
the class InnerInlongManagerClient method listSinks.
public List<SinkListResponse> listSinks(String groupId, String streamId, String sinkType) {
final String path = HTTP_PATH + "/sink/list";
String url = formatUrl(path);
url = String.format("%s&inlongGroupId=%s&inlongStreamId=%s", url, groupId, streamId);
if (StringUtils.isNotEmpty(sinkType)) {
url = String.format("%s&sinkType=%s", url, sinkType);
}
Request request = new Request.Builder().get().url(url).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
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()));
PageInfo<SinkListResponse> sinkListResponsePageInfo = InlongParser.parseSinkList(responseBody);
return sinkListResponsePageInfo.getList();
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong storage list failed with ex:%s", e.getMessage()), e);
}
}
Aggregations