Search in sources :

Example 1 with SourceListResponse

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<>();
    }
}
Also used : PageInfo(com.github.pagehelper.PageInfo) TypeToken(com.google.common.reflect.TypeToken) SourceType(org.apache.inlong.manager.common.enums.SourceType) JsonObject(com.google.gson.JsonObject) BinlogSourceListResponse(org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceListResponse) KafkaSourceListResponse(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceListResponse) KafkaSourceListResponse(org.apache.inlong.manager.common.pojo.source.kafka.KafkaSourceListResponse) BinlogSourceListResponse(org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceListResponse) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse)

Example 2 with SourceListResponse

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);
    }
}
Also used : 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) 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) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse)

Example 3 with SourceListResponse

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));
    }
}
Also used : SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse)

Example 4 with SourceListResponse

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;
}
Also used : Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) StreamSourceEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSourceEntityMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SourceType(org.apache.inlong.manager.common.enums.SourceType) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Preconditions(org.apache.inlong.manager.common.util.Preconditions) CollectionUtils(org.apache.commons.collections.CollectionUtils) CommonOperateService(org.apache.inlong.manager.service.CommonOperateService) Service(org.springframework.stereotype.Service) Map(java.util.Map) SourceState(org.apache.inlong.manager.common.enums.SourceState) GroupState(org.apache.inlong.manager.common.enums.GroupState) Logger(org.slf4j.Logger) PageHelper(com.github.pagehelper.PageHelper) PageInfo(com.github.pagehelper.PageInfo) SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) Maps(com.google.common.collect.Maps) SourceResponse(org.apache.inlong.manager.common.pojo.source.SourceResponse) ErrorCodeEnum(org.apache.inlong.manager.common.enums.ErrorCodeEnum) Constant(org.apache.inlong.manager.common.enums.Constant) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse) List(java.util.List) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) Page(com.github.pagehelper.Page) SourcePageRequest(org.apache.inlong.manager.common.pojo.source.SourcePageRequest) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) CommonBeanUtils(org.apache.inlong.manager.common.util.CommonBeanUtils) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) SourceType(org.apache.inlong.manager.common.enums.SourceType) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Page(com.github.pagehelper.Page) Map(java.util.Map) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse)

Aggregations

SourceListResponse (org.apache.inlong.manager.common.pojo.source.SourceListResponse)4 PageInfo (com.github.pagehelper.PageInfo)2 SourceType (org.apache.inlong.manager.common.enums.SourceType)2 SourceRequest (org.apache.inlong.manager.common.pojo.source.SourceRequest)2 Page (com.github.pagehelper.Page)1 PageHelper (com.github.pagehelper.PageHelper)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1