Search in sources :

Example 1 with SinkListResponse

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());
}
Also used : TypeToken(com.google.common.reflect.TypeToken) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) JsonObject(com.google.gson.JsonObject)

Example 2 with SinkListResponse

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

Example 3 with SinkListResponse

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;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) EntityStatus(org.apache.inlong.manager.common.enums.EntityStatus) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) Date(java.util.Date) SinkPageRequest(org.apache.inlong.manager.common.pojo.sink.SinkPageRequest) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SinkBriefResponse(org.apache.inlong.manager.common.pojo.sink.SinkBriefResponse) ArrayList(java.util.ArrayList) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) 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) CreateStreamWorkflowDefinition(org.apache.inlong.manager.service.workflow.stream.CreateStreamWorkflowDefinition) Service(org.springframework.stereotype.Service) Map(java.util.Map) CallerRunsPolicy(java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy) ProcessName(org.apache.inlong.manager.service.workflow.ProcessName) ExecutorService(java.util.concurrent.ExecutorService) StreamSinkEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper) GroupState(org.apache.inlong.manager.common.enums.GroupState) Logger(org.slf4j.Logger) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) SinkApproveDTO(org.apache.inlong.manager.common.pojo.sink.SinkApproveDTO) PageHelper(com.github.pagehelper.PageHelper) PageInfo(com.github.pagehelper.PageInfo) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) Maps(com.google.common.collect.Maps) ErrorCodeEnum(org.apache.inlong.manager.common.enums.ErrorCodeEnum) Constant(org.apache.inlong.manager.common.enums.Constant) TimeUnit(java.util.concurrent.TimeUnit) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) WorkflowService(org.apache.inlong.manager.service.workflow.WorkflowService) Page(com.github.pagehelper.Page) StreamSinkFieldEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSinkFieldEntityMapper) CommonBeanUtils(org.apache.inlong.manager.common.util.CommonBeanUtils) Collections(java.util.Collections) SinkType(org.apache.inlong.manager.common.enums.SinkType) Transactional(org.springframework.transaction.annotation.Transactional) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) StreamSinkEntity(org.apache.inlong.manager.dao.entity.StreamSinkEntity) Page(com.github.pagehelper.Page) SinkType(org.apache.inlong.manager.common.enums.SinkType) Map(java.util.Map)

Example 4 with SinkListResponse

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);
    }
}
Also used : Call(okhttp3.Call) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) 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)

Aggregations

SinkListResponse (org.apache.inlong.manager.common.pojo.sink.SinkListResponse)4 SinkRequest (org.apache.inlong.manager.common.pojo.sink.SinkRequest)2 Page (com.github.pagehelper.Page)1 PageHelper (com.github.pagehelper.PageHelper)1 PageInfo (com.github.pagehelper.PageInfo)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)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 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 CallerRunsPolicy (java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy)1 TimeUnit (java.util.concurrent.TimeUnit)1