use of org.apache.inlong.manager.common.exceptions.WorkflowListenerException in project incubator-inlong by apache.
the class CreatePulsarTopicForStreamTaskListener method listen.
@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
String groupId = form.getInlongGroupId();
String streamId = form.getInlongStreamId();
InlongGroupInfo groupInfo = groupService.get(groupId);
InlongStreamEntity streamEntity = streamMapper.selectByIdentifier(groupId, streamId);
if (groupInfo == null || streamEntity == null) {
throw new WorkflowListenerException("inlong group or inlong stream not found with groupId=" + groupId + ", streamId=" + streamId);
}
log.info("begin to create pulsar topic for groupId={}, streamId={}", groupId, streamId);
PulsarClusterInfo globalCluster = commonOperateService.getPulsarClusterInfo(groupInfo.getMiddlewareType());
try (PulsarAdmin globalPulsarAdmin = PulsarUtils.getPulsarAdmin(globalCluster)) {
List<String> pulsarClusters = PulsarUtils.getPulsarClusters(globalPulsarAdmin);
for (String cluster : pulsarClusters) {
String serviceUrl = PulsarUtils.getServiceUrl(globalPulsarAdmin, cluster);
PulsarClusterInfo pulsarClusterInfo = PulsarClusterInfo.builder().token(globalCluster.getToken()).adminUrl(serviceUrl).build();
String pulsarTopic = streamEntity.getMqResourceObj();
this.createTopic(groupInfo, pulsarTopic, pulsarClusterInfo);
}
} catch (Exception e) {
log.error("create pulsar topic error for groupId={}, streamId={}", groupId, streamId, e);
throw new WorkflowListenerException("create pulsar topic error for groupId=" + groupId + ", streamId=" + streamId);
}
log.info("success to create pulsar topic for groupId={}, streamId={}", groupId, streamId);
return ListenerResult.success();
}
use of org.apache.inlong.manager.common.exceptions.WorkflowListenerException 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.exceptions.WorkflowListenerException in project incubator-inlong by apache.
the class GroupCancelProcessListener method listen.
@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
NewGroupProcessForm form = (NewGroupProcessForm) context.getProcessForm();
// After canceling the approval, the status becomes [Waiting to submit]
String groupId = form.getInlongGroupId();
// Only the [Wait approval] status allowed the canceling operation
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
if (entity == null) {
throw new WorkflowListenerException("inlong group not found with group id=" + groupId);
}
if (!Objects.equals(GroupState.TO_BE_APPROVAL.getCode(), entity.getStatus())) {
throw new WorkflowListenerException("current status was not allowed to cancel business");
}
// After canceling the approval, the status becomes [Waiting to submit]
String username = context.getApplicant();
groupMapper.updateStatus(groupId, GroupState.TO_BE_SUBMIT.getCode(), username);
return ListenerResult.success();
}
use of org.apache.inlong.manager.common.exceptions.WorkflowListenerException in project incubator-inlong by apache.
the class GroupPassTaskListener method listen.
@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
// Save the data format selected at the time of approval and the cluster information of the inlong stream
InlongGroupApproveForm form = (InlongGroupApproveForm) context.getActionContext().getForm();
InlongGroupApproveRequest approveInfo = form.getGroupApproveInfo();
// Only the [Wait approval] status allowed the passing operation
String groupId = approveInfo.getInlongGroupId();
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
if (entity == null) {
throw new WorkflowListenerException("inlong group not found with group id=" + groupId);
}
if (!Objects.equals(GroupState.TO_BE_APPROVAL.getCode(), entity.getStatus())) {
throw new WorkflowListenerException("inlong group status is [wait_approval], not allowed to approve again");
}
// Save the inlong group information after approval
groupService.updateAfterApprove(approveInfo, context.getApplicant());
// Save inlong stream information after approval
List<InlongStreamApproveRequest> streamApproveInfoList = form.getStreamApproveInfoList();
streamService.updateAfterApprove(streamApproveInfoList, context.getApplicant());
return ListenerResult.success();
}
use of org.apache.inlong.manager.common.exceptions.WorkflowListenerException in project incubator-inlong by apache.
the class GroupRejectProcessListener method listen.
@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
NewGroupProcessForm form = (NewGroupProcessForm) context.getProcessForm();
// Only the [Wait approval] status allowed the rejecting operation
String groupId = form.getInlongGroupId();
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
if (entity == null) {
throw new WorkflowListenerException("inlong group not found with group id=" + groupId);
}
if (!Objects.equals(GroupState.TO_BE_APPROVAL.getCode(), entity.getStatus())) {
throw new WorkflowListenerException("current status was not allowed to reject inlong group");
}
// After reject, update inlong group status to [GROUP_APPROVE_REJECT]
String username = context.getApplicant();
groupService.updateStatus(groupId, GroupState.APPROVE_REJECTED.getCode(), username);
return ListenerResult.success();
}
Aggregations