Search in sources :

Example 1 with InlongStreamEntity

use of org.apache.inlong.manager.dao.entity.InlongStreamEntity in project incubator-inlong by apache.

the class CreateHiveTableEventSelector method accept.

@Override
public boolean accept(WorkflowContext context) {
    ProcessForm processForm = context.getProcessForm();
    if (!(processForm instanceof GroupResourceProcessForm)) {
        return false;
    }
    GroupResourceProcessForm form = (GroupResourceProcessForm) processForm;
    if (form.getGroupInfo() == null || StringUtils.isEmpty(form.getGroupInfo().getInlongGroupId())) {
        return false;
    }
    String groupId = form.getInlongGroupId();
    List<String> dsForHive = sinkService.getExistsStreamIdList(groupId, Constant.SINK_HIVE, streamMapper.selectByGroupId(groupId).stream().map(InlongStreamEntity::getInlongStreamId).collect(Collectors.toList()));
    if (CollectionUtils.isEmpty(dsForHive)) {
        log.warn("groupId={} streamId={} does not have sink, skip to create hive table ", groupId, form.getInlongStreamId());
        return true;
    }
    return false;
}
Also used : InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)

Example 2 with InlongStreamEntity

use of org.apache.inlong.manager.dao.entity.InlongStreamEntity 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 3 with InlongStreamEntity

use of org.apache.inlong.manager.dao.entity.InlongStreamEntity in project incubator-inlong by apache.

the class CreatePulsarGroupTaskListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
    GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
    String groupId = form.getInlongGroupId();
    InlongGroupInfo groupInfo = groupService.get(groupId);
    if (groupInfo == null) {
        log.error("inlong group not found with groupId={}", groupId);
        throw new WorkflowListenerException("inlong group not found with groupId=" + groupId);
    }
    // For Pulsar, each Stream corresponds to a Topic
    List<InlongStreamEntity> streamEntities = streamMapper.selectByGroupId(groupId);
    if (streamEntities == null || streamEntities.isEmpty()) {
        log.warn("inlong stream is empty for groupId={}, skip to create pulsar subscription", groupId);
        return ListenerResult.success();
    }
    PulsarClusterInfo globalCluster = commonOperateService.getPulsarClusterInfo(groupInfo.getMiddlewareType());
    try (PulsarAdmin globalPulsarAdmin = PulsarUtils.getPulsarAdmin(globalCluster)) {
        String tenant = clusterBean.getDefaultTenant();
        String namespace = groupInfo.getMqResourceObj();
        for (InlongStreamEntity streamEntity : streamEntities) {
            PulsarTopicBean topicBean = new PulsarTopicBean();
            topicBean.setTenant(tenant);
            topicBean.setNamespace(namespace);
            String topic = streamEntity.getMqResourceObj();
            topicBean.setTopicName(topic);
            List<String> pulsarClusters = PulsarUtils.getPulsarClusters(globalPulsarAdmin);
            // Create a subscription in the Pulsar cluster (cross-region), you need to ensure that the Topic exists
            for (String cluster : pulsarClusters) {
                String serviceUrl = PulsarUtils.getServiceUrl(globalPulsarAdmin, cluster);
                PulsarClusterInfo pulsarClusterInfo = PulsarClusterInfo.builder().token(globalCluster.getToken()).adminUrl(serviceUrl).build();
                try (PulsarAdmin pulsarAdmin = PulsarUtils.getPulsarAdmin(pulsarClusterInfo)) {
                    boolean exist = pulsarOptService.topicIsExists(pulsarAdmin, tenant, namespace, topic);
                    if (!exist) {
                        String topicFull = tenant + "/" + namespace + "/" + topic;
                        log.error("topic={} not exists in {}", topicFull, serviceUrl);
                        throw new WorkflowListenerException("topic=" + topicFull + " not exists in " + serviceUrl);
                    }
                    // Consumer naming rules: sortAppName_topicName_consumer_group
                    String subscription = clusterBean.getAppName() + "_" + topic + "_consumer_group";
                    pulsarOptService.createSubscription(pulsarAdmin, topicBean, subscription);
                    // Insert the consumption data into the consumption table
                    consumptionService.saveSortConsumption(groupInfo, topic, subscription);
                }
            }
        }
    } catch (Exception e) {
        log.error("create pulsar subscription error for groupId={}", groupId);
        throw new WorkflowListenerException("create pulsar subscription error: " + e.getMessage());
    }
    log.info("success to create pulsar subscription for groupId={}", groupId);
    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) PulsarTopicBean(org.apache.inlong.manager.common.pojo.pulsar.PulsarTopicBean) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException)

Example 4 with InlongStreamEntity

use of org.apache.inlong.manager.dao.entity.InlongStreamEntity in project incubator-inlong by apache.

the class InlongGroupProcessOperation method genUpdateGroupProcessForm.

private UpdateGroupProcessForm genUpdateGroupProcessForm(String groupId, OperateType operateType) {
    InlongGroupInfo groupInfo = groupService.get(groupId);
    UpdateGroupProcessForm form = new UpdateGroupProcessForm();
    if (OperateType.RESTART == operateType) {
        List<InlongStreamEntity> inlongStreamEntityList = streamMapper.selectByGroupId(groupInfo.getInlongGroupId());
        List<InlongStreamInfo> inlongStreamInfoList = CommonBeanUtils.copyListProperties(inlongStreamEntityList, InlongStreamInfo::new);
        form.setInlongStreamInfoList(inlongStreamInfoList);
    }
    form.setGroupInfo(groupInfo);
    form.setOperateType(operateType);
    return form;
}
Also used : UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)

Example 5 with InlongStreamEntity

use of org.apache.inlong.manager.dao.entity.InlongStreamEntity in project incubator-inlong by apache.

the class InlongStreamServiceImpl method getBriefList.

@Override
public List<StreamBriefResponse> getBriefList(String groupId) {
    LOGGER.debug("begin to get inlong stream brief list by groupId={}", groupId);
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    List<InlongStreamEntity> entityList = streamMapper.selectByGroupId(groupId);
    List<StreamBriefResponse> briefInfoList = CommonBeanUtils.copyListProperties(entityList, StreamBriefResponse::new);
    // Query stream sinks based on groupId and streamId
    for (StreamBriefResponse briefInfo : briefInfoList) {
        String streamId = briefInfo.getInlongStreamId();
        List<SinkBriefResponse> sinkList = sinkService.listBrief(groupId, streamId);
        briefInfo.setSinkList(sinkList);
    }
    LOGGER.info("success to get inlong stream brief list for groupId={}", groupId);
    return briefInfoList;
}
Also used : StreamBriefResponse(org.apache.inlong.manager.common.pojo.stream.StreamBriefResponse) InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity) SinkBriefResponse(org.apache.inlong.manager.common.pojo.sink.SinkBriefResponse)

Aggregations

InlongStreamEntity (org.apache.inlong.manager.dao.entity.InlongStreamEntity)19 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)7 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)5 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)5 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)4 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)4 Transactional (org.springframework.transaction.annotation.Transactional)4 ArrayList (java.util.ArrayList)3 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)3 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)3 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)3 Date (java.util.Date)2 DataProxyConfig (org.apache.inlong.common.pojo.dataproxy.DataProxyConfig)2 PulsarTopicBean (org.apache.inlong.manager.common.pojo.pulsar.PulsarTopicBean)2 Page (com.github.pagehelper.Page)1 PageInfo (com.github.pagehelper.PageInfo)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 DataConfig (org.apache.inlong.common.pojo.agent.DataConfig)1 ThirdPartyClusterDTO (org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterDTO)1