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();
}
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 "";
}
Aggregations