Search in sources :

Example 1 with QueryTubeTopicRequest

use of org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest in project incubator-inlong by apache.

the class CreateTubeGroupTaskListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
    GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
    String groupId = form.getInlongGroupId();
    log.info("try to create consumer group for groupId {}", groupId);
    InlongGroupInfo groupInfo = groupService.get(groupId);
    String topicName = groupInfo.getMqResourceObj();
    int clusterId = Integer.parseInt(commonOperateService.getSpecifiedParam(Constant.CLUSTER_TUBE_CLUSTER_ID));
    QueryTubeTopicRequest queryTubeTopicRequest = QueryTubeTopicRequest.builder().topicName(topicName).clusterId(clusterId).user(groupInfo.getCreator()).build();
    // Query whether the tube topic exists
    boolean topicExist = tubeMqOptService.queryTopicIsExist(queryTubeTopicRequest);
    Integer tryNumber = reTryConfigBean.getMaxAttempts();
    Long delay = reTryConfigBean.getDelay();
    while (!topicExist && --tryNumber > 0) {
        log.info("check whether the tube topic exists, try count={}", tryNumber);
        try {
            Thread.sleep(delay);
            delay *= reTryConfigBean.getMultiplier();
            topicExist = tubeMqOptService.queryTopicIsExist(queryTubeTopicRequest);
        } catch (InterruptedException e) {
            log.error("check the tube topic exists error", e);
        }
    }
    AddTubeConsumeGroupRequest addTubeConsumeGroupRequest = new AddTubeConsumeGroupRequest();
    addTubeConsumeGroupRequest.setClusterId(clusterId);
    addTubeConsumeGroupRequest.setCreateUser(groupInfo.getCreator());
    GroupNameJsonSetBean groupNameJsonSetBean = new GroupNameJsonSetBean();
    groupNameJsonSetBean.setTopicName(topicName);
    String consumeGroupName = "sort_" + topicName + "_group";
    groupNameJsonSetBean.setGroupName(consumeGroupName);
    addTubeConsumeGroupRequest.setGroupNameJsonSet(Collections.singletonList(groupNameJsonSetBean));
    try {
        tubeMqOptService.createNewConsumerGroup(addTubeConsumeGroupRequest);
    } catch (Exception e) {
        throw new WorkflowListenerException("create tube consumer group for groupId=" + groupId + " error", e);
    }
    log.info("finish to create consumer group for {}", groupId);
    return ListenerResult.success();
}
Also used : GroupNameJsonSetBean(org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest.GroupNameJsonSetBean) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) AddTubeConsumeGroupRequest(org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) QueryTubeTopicRequest(org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest)

Example 2 with QueryTubeTopicRequest

use of org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest in project incubator-inlong by apache.

the class TubeMqOptService method createNewTopic.

/**
 * Create new topic
 */
public String createNewTopic(AddTubeMqTopicRequest request) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("Content-Type", "application/json");
    try {
        if (CollectionUtils.isEmpty(request.getAddTopicTasks())) {
            throw new Exception("topic cannot be empty");
        }
        AddTubeMqTopicRequest.AddTopicTasksBean addTopicTasksBean = request.getAddTopicTasks().get(0);
        String clusterIdStr = commonOperateService.getSpecifiedParam(Constant.CLUSTER_TUBE_CLUSTER_ID);
        int clusterId = Integer.parseInt(clusterIdStr);
        QueryTubeTopicRequest topicRequest = QueryTubeTopicRequest.builder().topicName(addTopicTasksBean.getTopicName()).clusterId(clusterId).user(request.getUser()).build();
        String tubeManager = commonOperateService.getSpecifiedParam(Constant.CLUSTER_TUBE_MANAGER);
        TubeManagerResponse response = httpUtils.request(tubeManager + "/v1/topic?method=queryCanWrite", HttpMethod.POST, GSON.toJson(topicRequest), httpHeaders, TubeManagerResponse.class);
        if (response.getErrCode() == 101) {
            // topic already exists
            log.info(" create tube topic  {}  on {} ", GSON.toJson(request), tubeManager + "/v1/task?method=addTopicTask");
            request.setClusterId(clusterId);
            TubeManagerResponse createRsp = httpUtils.request(tubeManager + "/v1/task?method=addTopicTask", HttpMethod.POST, GSON.toJson(request), httpHeaders, TubeManagerResponse.class);
        } else {
            log.warn("topic {} exists in {} ", addTopicTasksBean.getTopicName(), tubeManager);
        }
    } catch (Exception e) {
        log.error("fail to create tube topic " + request.getAddTopicTasks().get(0).getTopicName(), e);
    }
    return "";
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) QueryTubeTopicRequest(org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest) AddTubeMqTopicRequest(org.apache.inlong.manager.common.pojo.tubemq.AddTubeMqTopicRequest) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) TubeManagerResponse(org.apache.inlong.manager.common.pojo.tubemq.TubeManagerResponse)

Aggregations

QueryTubeTopicRequest (org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest)2 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)1 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)1 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)1 AddTubeConsumeGroupRequest (org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest)1 GroupNameJsonSetBean (org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest.GroupNameJsonSetBean)1 AddTubeMqTopicRequest (org.apache.inlong.manager.common.pojo.tubemq.AddTubeMqTopicRequest)1 TubeManagerResponse (org.apache.inlong.manager.common.pojo.tubemq.TubeManagerResponse)1 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)1 HttpHeaders (org.springframework.http.HttpHeaders)1