Search in sources :

Example 6 with PulsarClusterInfo

use of org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo in project incubator-inlong by apache.

the class ConsumptionCompleteProcessListener method createPulsarTopicMessage.

/**
 * Create Pulsar consumption information, including cross-regional cycle creation of consumption groups
 */
private void createPulsarTopicMessage(ConsumptionEntity entity) {
    String groupId = entity.getInlongGroupId();
    InlongGroupInfo groupInfo = groupService.get(groupId);
    Preconditions.checkNotNull(groupInfo, "inlong group not found for groupId=" + groupId);
    String mqResourceObj = groupInfo.getMqResourceObj();
    Preconditions.checkNotNull(mqResourceObj, "mq resource cannot empty for groupId=" + groupId);
    PulsarClusterInfo globalCluster = commonOperateService.getPulsarClusterInfo(entity.getMiddlewareType());
    try (PulsarAdmin pulsarAdmin = PulsarUtils.getPulsarAdmin(globalCluster)) {
        PulsarTopicBean topicMessage = new PulsarTopicBean();
        String tenant = clusterBean.getDefaultTenant();
        topicMessage.setTenant(tenant);
        topicMessage.setNamespace(mqResourceObj);
        // If cross-regional replication is started, each cluster needs to create consumer groups in cycles
        String consumerGroup = entity.getConsumerGroupId();
        List<String> clusters = PulsarUtils.getPulsarClusters(pulsarAdmin);
        List<String> topics = Arrays.asList(entity.getTopic().split(","));
        this.createPulsarSubscription(pulsarAdmin, consumerGroup, topicMessage, clusters, topics, globalCluster);
    } catch (Exception e) {
        log.error("create pulsar topic failed", e);
        throw new WorkflowListenerException("failed to create pulsar topic for groupId=" + groupId + ", reason: " + e.getMessage());
    }
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) 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) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException)

Example 7 with PulsarClusterInfo

use of org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo in project incubator-inlong by apache.

the class CommonOperateService method getPulsarClusterInfo.

/**
 * Get Pulsar cluster by the given type.
 *
 * @return Pulsar cluster info.
 */
public PulsarClusterInfo getPulsarClusterInfo(String type) {
    ThirdPartyClusterEntity clusterEntity = getMQCluster(type);
    if (clusterEntity == null || StringUtils.isBlank(clusterEntity.getExtParams())) {
        throw new BusinessException("pulsar cluster or pulsar ext params is empty");
    }
    Map<String, String> configParams = JsonUtils.parse(clusterEntity.getExtParams(), Map.class);
    PulsarClusterInfo pulsarClusterInfo = PulsarClusterInfo.builder().brokerServiceUrl(clusterEntity.getUrl()).token(clusterEntity.getToken()).build();
    String adminUrl = configParams.get(Constant.PULSAR_ADMINURL);
    Preconditions.checkNotNull(adminUrl, "adminUrl is empty, check third party cluster table");
    pulsarClusterInfo.setAdminUrl(adminUrl);
    pulsarClusterInfo.setType(clusterEntity.getType());
    return pulsarClusterInfo;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)

Example 8 with PulsarClusterInfo

use of org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo in project incubator-inlong by apache.

the class CommonOperateService method createDataFlow.

/**
 * Create dataflow info for sort.
 */
public DataFlowInfo createDataFlow(InlongGroupInfo groupInfo, SinkResponse sinkResponse) {
    String groupId = sinkResponse.getInlongGroupId();
    String streamId = sinkResponse.getInlongStreamId();
    // TODO Support all source type, include AUTO_PUSH.
    List<SourceResponse> sourceList = streamSourceService.listSource(groupId, streamId);
    if (CollectionUtils.isEmpty(sourceList)) {
        throw new WorkflowListenerException(String.format("Source not found by groupId=%s and streamId=%s", groupId, streamId));
    }
    // Get all field info
    List<FieldInfo> sourceFields = new ArrayList<>();
    List<FieldInfo> sinkFields = new ArrayList<>();
    String partition = null;
    if (SinkType.forType(sinkResponse.getSinkType()) == SinkType.HIVE) {
        HiveSinkResponse hiveSink = (HiveSinkResponse) sinkResponse;
        partition = hiveSink.getPrimaryPartition();
    }
    // TODO Support more than one source and one sink
    final SourceResponse sourceResponse = sourceList.get(0);
    boolean isAllMigration = SourceInfoUtils.isBinlogAllMigration(sourceResponse);
    FieldMappingRule fieldMappingRule = FieldInfoUtils.createFieldInfo(isAllMigration, sinkResponse.getFieldList(), sourceFields, sinkFields, partition);
    // Get source info
    String masterAddress = getSpecifiedParam(Constant.TUBE_MASTER_URL);
    PulsarClusterInfo pulsarCluster = getPulsarClusterInfo(groupInfo.getMiddlewareType());
    InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
    SourceInfo sourceInfo = SourceInfoUtils.createSourceInfo(pulsarCluster, masterAddress, clusterBean, groupInfo, streamInfo, sourceResponse, sourceFields);
    // Get sink info
    SinkInfo sinkInfo = SinkInfoUtils.createSinkInfo(sourceResponse, sinkResponse, sinkFields);
    // Get transformation info
    TransformationInfo transInfo = new TransformationInfo(fieldMappingRule);
    // Get properties
    Map<String, Object> properties = new HashMap<>();
    if (MapUtils.isNotEmpty(sinkResponse.getProperties())) {
        properties.putAll(sinkResponse.getProperties());
    }
    properties.put(Constant.DATA_FLOW_GROUP_ID_KEY, groupId);
    return new DataFlowInfo(sinkResponse.getId(), sourceInfo, transInfo, sinkInfo, properties);
}
Also used : SourceResponse(org.apache.inlong.manager.common.pojo.source.SourceResponse) FieldMappingRule(org.apache.inlong.sort.protocol.transformation.FieldMappingRule) SourceInfo(org.apache.inlong.sort.protocol.source.SourceInfo) HashMap(java.util.HashMap) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) ArrayList(java.util.ArrayList) SinkInfo(org.apache.inlong.sort.protocol.sink.SinkInfo) HiveSinkResponse(org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo) TransformationInfo(org.apache.inlong.sort.protocol.transformation.TransformationInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo)

Example 9 with PulsarClusterInfo

use of org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo in project incubator-inlong by apache.

the class CreatePulsarGroupForStreamTaskListener 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);
    if (groupInfo == null) {
        log.error("inlong group not found with groupId={}", groupId);
        throw new WorkflowListenerException("inlong group not found with groupId=" + groupId);
    }
    InlongStreamEntity streamEntity = streamMapper.selectByIdentifier(groupId, streamId);
    if (streamEntity == null) {
        log.warn("inlong stream is empty for group={}, stream={}, skip to create pulsar group", groupId, streamId);
        return ListenerResult.success();
    }
    PulsarClusterInfo globalCluster = commonOperateService.getPulsarClusterInfo(groupInfo.getMiddlewareType());
    try (PulsarAdmin globalPulsarAdmin = PulsarUtils.getPulsarAdmin(globalCluster)) {
        // Query data sink info based on groupId and streamId
        List<String> sinkTypeList = sinkService.getSinkTypeList(groupId, streamId);
        if (sinkTypeList == null || sinkTypeList.size() == 0) {
            log.warn("sink info is empty for groupId={}, streamId={}, skip to create pulsar group", groupId, streamId);
            return ListenerResult.success();
        }
        PulsarTopicBean topicBean = new PulsarTopicBean();
        topicBean.setTenant(clusterBean.getDefaultTenant());
        topicBean.setNamespace(groupInfo.getMqResourceObj());
        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
        String tenant = clusterBean.getDefaultTenant();
        String namespace = groupInfo.getMqResourceObj();
        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 fullTopic = tenant + "/" + namespace + "/" + topic;
                    log.error("topic={} not exists in {}", fullTopic, pulsarAdmin.getServiceUrl());
                    throw new BusinessException("topic=" + fullTopic + " 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={}, streamId={}", groupId, streamId, e);
        throw new WorkflowListenerException("create pulsar subscription error, reason: " + e.getMessage());
    }
    log.info("finish to create single pulsar subscription for groupId={}, streamId={}", groupId, streamId);
    return ListenerResult.success();
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) 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) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException)

Aggregations

PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)9 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)7 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)6 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)6 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)4 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)3 PulsarTopicBean (org.apache.inlong.manager.common.pojo.pulsar.PulsarTopicBean)3 InlongStreamEntity (org.apache.inlong.manager.dao.entity.InlongStreamEntity)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)1 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)1 HiveSinkResponse (org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkResponse)1 SourceResponse (org.apache.inlong.manager.common.pojo.source.SourceResponse)1 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)1 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)1 InlongGroupExtEntity (org.apache.inlong.manager.dao.entity.InlongGroupExtEntity)1 InlongGroupPulsarEntity (org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity)1 ThirdPartyClusterEntity (org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)1 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)1