Search in sources :

Example 1 with AddTubeConsumeGroupRequest

use of org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest 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 AddTubeConsumeGroupRequest

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

the class ConsumptionCompleteProcessListener method createTubeConsumerGroup.

/**
 * Create tube consumer group
 */
private void createTubeConsumerGroup(ConsumptionEntity consumption) {
    AddTubeConsumeGroupRequest addTubeConsumeGroupRequest = new AddTubeConsumeGroupRequest();
    // TODO is cluster id needed?
    addTubeConsumeGroupRequest.setClusterId(1);
    addTubeConsumeGroupRequest.setCreateUser(consumption.getCreator());
    AddTubeConsumeGroupRequest.GroupNameJsonSetBean bean = new AddTubeConsumeGroupRequest.GroupNameJsonSetBean();
    bean.setTopicName(consumption.getTopic());
    bean.setGroupName(consumption.getConsumerGroupId());
    addTubeConsumeGroupRequest.setGroupNameJsonSet(Collections.singletonList(bean));
    try {
        tubeMqOptService.createNewConsumerGroup(addTubeConsumeGroupRequest);
    } catch (Exception e) {
        throw new WorkflowListenerException("failed to create tube consumer group: " + addTubeConsumeGroupRequest);
    }
}
Also used : AddTubeConsumeGroupRequest(org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException)

Aggregations

WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)2 AddTubeConsumeGroupRequest (org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest)2 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)1 GroupNameJsonSetBean (org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest.GroupNameJsonSetBean)1 QueryTubeTopicRequest (org.apache.inlong.manager.common.pojo.tubemq.QueryTubeTopicRequest)1 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)1