Search in sources :

Example 1 with InlongGroupInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupInfo in project incubator-inlong by apache.

the class InlongGroupTransfer method createGroupInfo.

public static InlongGroupInfo createGroupInfo(InlongGroupConf groupConf) {
    InlongGroupInfo groupInfo = new InlongGroupInfo();
    AssertUtil.hasLength(groupConf.getGroupName(), "GroupName should not be empty");
    groupInfo.setName(groupConf.getGroupName());
    groupInfo.setCnName(groupConf.getCnName());
    groupInfo.setDescription(groupConf.getDescription());
    groupInfo.setZookeeperEnabled(groupConf.isZookeeperEnabled() ? 1 : 0);
    groupInfo.setDailyRecords(groupConf.getDailyRecords().intValue());
    groupInfo.setPeakRecords(groupConf.getPeakRecords().intValue());
    groupInfo.setMaxLength(groupConf.getMaxLength());
    groupInfo.setProxyClusterId(groupConf.getProxyClusterId());
    MqBaseConf mqConf = groupConf.getMqBaseConf();
    MqType mqType = MqType.NONE;
    if (null != mqConf) {
        mqType = mqConf.getType();
        groupInfo.setMiddlewareType(mqType.name());
    }
    groupInfo.setInCharges(groupConf.getOperator());
    groupInfo.setExtList(Lists.newArrayList());
    groupInfo.setCreator(groupConf.getOperator());
    if (mqType == MqType.PULSAR || mqType == MqType.TDMQ_PULSAR) {
        PulsarBaseConf pulsarBaseConf = (PulsarBaseConf) mqConf;
        groupInfo.setMqResourceObj(pulsarBaseConf.getNamespace());
        InlongGroupPulsarInfo pulsarInfo = createPulsarInfo(pulsarBaseConf);
        groupInfo.setMqExtInfo(pulsarInfo);
        List<InlongGroupExtInfo> extInfos = createPulsarExtInfo(pulsarBaseConf);
        groupInfo.getExtList().addAll(extInfos);
        groupInfo.setTopicPartitionNum(pulsarBaseConf.getTopicPartitionNum());
    } else if (mqType == MqType.TUBE) {
        TubeBaseConf tubeBaseConf = (TubeBaseConf) mqConf;
        List<InlongGroupExtInfo> extInfos = createTubeExtInfo(tubeBaseConf);
        groupInfo.setMqResourceObj(tubeBaseConf.getGroupName());
        groupInfo.getExtList().addAll(extInfos);
        groupInfo.setTopicPartitionNum(tubeBaseConf.getTopicPartitionNum());
    }
    SortBaseConf sortBaseConf = groupConf.getSortBaseConf();
    SortType sortType = sortBaseConf.getType();
    if (sortType == SortType.FLINK) {
        FlinkSortBaseConf flinkSortBaseConf = (FlinkSortBaseConf) sortBaseConf;
        List<InlongGroupExtInfo> sortExtInfos = createFlinkExtInfo(flinkSortBaseConf);
        groupInfo.getExtList().addAll(sortExtInfos);
    } else if (sortType == SortType.USER_DEFINED) {
        UserDefinedSortConf udf = (UserDefinedSortConf) sortBaseConf;
        List<InlongGroupExtInfo> sortExtInfos = createUserDefinedSortExtInfo(udf);
        groupInfo.getExtList().addAll(sortExtInfos);
    } else {
    // todo local
    }
    return groupInfo;
}
Also used : UserDefinedSortConf(org.apache.inlong.manager.client.api.UserDefinedSortConf) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) FlinkSortBaseConf(org.apache.inlong.manager.client.api.FlinkSortBaseConf) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) SortType(org.apache.inlong.manager.client.api.SortBaseConf.SortType) PulsarBaseConf(org.apache.inlong.manager.client.api.PulsarBaseConf) TubeBaseConf(org.apache.inlong.manager.client.api.TubeBaseConf) ArrayList(java.util.ArrayList) List(java.util.List) MqBaseConf(org.apache.inlong.manager.client.api.MqBaseConf) MqType(org.apache.inlong.manager.common.enums.MqType) SortBaseConf(org.apache.inlong.manager.client.api.SortBaseConf) FlinkSortBaseConf(org.apache.inlong.manager.client.api.FlinkSortBaseConf)

Example 2 with InlongGroupInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupInfo in project incubator-inlong by apache.

the class AbstractSourceOperateListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws Exception {
    log.info("Delete data source for context={}", context);
    InlongGroupInfo groupInfo = getGroupInfo(context.getProcessForm());
    final String groupId = groupInfo.getInlongGroupId();
    List<StreamBriefResponse> streamBriefResponses = streamService.getBriefList(groupId);
    streamBriefResponses.forEach(streamBriefResponse -> operateStreamSources(groupId, streamBriefResponse.getInlongStreamId(), context.getApplicant()));
    return ListenerResult.success();
}
Also used : StreamBriefResponse(org.apache.inlong.manager.common.pojo.stream.StreamBriefResponse) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)

Example 3 with InlongGroupInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupInfo 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();
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) 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)

Example 4 with InlongGroupInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupInfo 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 5 with InlongGroupInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupInfo in project incubator-inlong by apache.

the class TubeEventSelector method accept.

@Override
public boolean accept(WorkflowContext context) {
    ProcessForm processForm = context.getProcessForm();
    if (!(processForm instanceof GroupResourceProcessForm)) {
        return false;
    }
    GroupResourceProcessForm form = (GroupResourceProcessForm) processForm;
    InlongGroupInfo groupInfo = form.getGroupInfo();
    if (Constant.MIDDLEWARE_TUBE.equalsIgnoreCase(groupInfo.getMiddlewareType())) {
        return true;
    }
    log.warn("not need to create tube resource for groupId={}, as the middleware type is {}", groupInfo.getMiddlewareType(), form.getInlongGroupId());
    return false;
}
Also used : GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)

Aggregations

InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)42 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)18 Test (org.junit.Test)11 ProcessResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessResponse)10 WorkflowResult (org.apache.inlong.manager.common.pojo.workflow.WorkflowResult)10 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)10 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)9 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)8 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)8 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)6 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)6 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)6 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)5 List (java.util.List)4 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)4 ServiceTask (org.apache.inlong.manager.workflow.definition.ServiceTask)4 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)4 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)4 TaskEventListener (org.apache.inlong.manager.workflow.event.task.TaskEventListener)4 InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)3