use of org.apache.inlong.manager.common.pojo.source.SourceListResponse in project incubator-inlong by apache.
the class InlongParser method parseSourceList.
public static PageInfo<SourceListResponse> parseSourceList(Response response) {
Object data = response.getData();
String pageInfoJson = GsonUtil.toJson(data);
PageInfo<SourceListResponse> pageInfo = GsonUtil.fromJson(pageInfoJson, new TypeToken<PageInfo<SourceListResponse>>() {
}.getType());
if (pageInfo.getList() != null && !pageInfo.getList().isEmpty()) {
SourceListResponse sourceListResponse = pageInfo.getList().get(0);
SourceType sourceType = SourceType.forType(sourceListResponse.getSourceType());
if (sourceType == BINLOG) {
return GsonUtil.fromJson(pageInfoJson, new TypeToken<PageInfo<BinlogSourceListResponse>>() {
}.getType());
}
if (sourceType == KAFKA) {
return GsonUtil.fromJson(pageInfoJson, new TypeToken<PageInfo<KafkaSourceListResponse>>() {
}.getType());
}
throw new IllegalArgumentException(String.format("Unsupported sourceType=%s for Inlong", sourceType));
} else {
return new PageInfo<>();
}
}
use of org.apache.inlong.manager.common.pojo.source.SourceListResponse in project incubator-inlong by apache.
the class InnerInlongManagerClient method listSources.
public List<SourceListResponse> listSources(String groupId, String streamId, String sourceType) {
final String path = HTTP_PATH + "/source/list";
String url = formatUrl(path);
url = String.format("%s&inlongGroupId=%s&inlongStreamId=%s", url, groupId, streamId);
if (StringUtils.isNotEmpty(sourceType)) {
url = String.format("%s&sourceType=%s", url, sourceType);
}
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<SourceListResponse> sourceListResponsePageInfo = InlongParser.parseSourceList(responseBody);
return sourceListResponsePageInfo.getList();
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong source list failed with ex:%s", e.getMessage()), e);
}
}
use of org.apache.inlong.manager.common.pojo.source.SourceListResponse in project incubator-inlong by apache.
the class DefaultInlongStreamBuilder method initOrUpdateSource.
private int initOrUpdateSource(SourceRequest sourceRequest) {
String sourceType = sourceRequest.getSourceType();
if (SourceType.KAFKA.name().equals(sourceType) || SourceType.BINLOG.name().equals(sourceType)) {
List<SourceListResponse> responses = managerClient.listSources(sourceRequest.getInlongGroupId(), sourceRequest.getInlongStreamId(), sourceRequest.getSourceType());
if (CollectionUtils.isEmpty(responses)) {
String sourceIndex = managerClient.createSource(sourceRequest);
return Double.valueOf(sourceIndex).intValue();
} else {
SourceListResponse sourceListResponse = null;
for (SourceListResponse response : responses) {
if (response.getSourceName().equals(sourceRequest.getSourceName())) {
sourceListResponse = response;
break;
}
}
if (sourceListResponse == null) {
String sourceIndex = managerClient.createSource(sourceRequest);
return Double.valueOf(sourceIndex).intValue();
}
sourceRequest.setId(sourceListResponse.getId());
Pair<Boolean, String> updateMsg = managerClient.updateSource(sourceRequest);
if (updateMsg.getKey()) {
return sourceListResponse.getId();
} else {
throw new RuntimeException(String.format("Update source:%s failed with ex:%s", GsonUtil.toJson(sourceRequest), updateMsg.getValue()));
}
}
} else {
throw new IllegalArgumentException(String.format("Unsupported source type:%s", sourceType));
}
}
use of org.apache.inlong.manager.common.pojo.source.SourceListResponse in project incubator-inlong by apache.
the class StreamSourceServiceImpl method listByCondition.
@Override
public PageInfo<? extends SourceListResponse> listByCondition(SourcePageRequest request) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("begin to list source page by " + request);
}
Preconditions.checkNotNull(request.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
PageHelper.startPage(request.getPageNum(), request.getPageSize());
List<StreamSourceEntity> entityPage = sourceMapper.selectByCondition(request);
// Encapsulate the paging query results into the PageInfo object to obtain related paging information
Map<SourceType, Page<StreamSourceEntity>> sourceMap = Maps.newHashMap();
for (StreamSourceEntity streamSource : entityPage) {
SourceType sourceType = SourceType.forType(streamSource.getSourceType());
sourceMap.computeIfAbsent(sourceType, k -> new Page<>()).add(streamSource);
}
List<SourceListResponse> sourceListResponses = Lists.newArrayList();
for (Map.Entry<SourceType, Page<StreamSourceEntity>> entry : sourceMap.entrySet()) {
SourceType sourceType = entry.getKey();
StreamSourceOperation operation = operationFactory.getInstance(sourceType);
PageInfo<? extends SourceListResponse> pageInfo = operation.getPageInfo(entry.getValue());
sourceListResponses.addAll(pageInfo.getList());
}
PageInfo<? extends SourceListResponse> pageInfo = PageInfo.of(sourceListResponses);
LOGGER.debug("success to list source page");
return pageInfo;
}
Aggregations