castorqin commented on code in PR #8892: URL: https://github.com/apache/inlong/pull/8892#discussion_r1327897125
########## inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/node/cls/ClsDataNodeRequest.java: ########## @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.manager.pojo.node.cls; + +import org.apache.inlong.manager.common.consts.DataNodeType; +import org.apache.inlong.manager.common.util.JsonTypeDefine; +import org.apache.inlong.manager.pojo.node.DataNodeRequest; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +/** + * cloud log service data node request Review Comment: done ########## inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/cls/ClsResourceOperator.java: ########## @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.manager.service.resource.sink.cls; + +import org.apache.inlong.manager.common.consts.DataNodeType; +import org.apache.inlong.manager.common.consts.InlongConstants; +import org.apache.inlong.manager.common.consts.SinkType; +import org.apache.inlong.manager.common.enums.SinkStatus; +import org.apache.inlong.manager.common.exceptions.BusinessException; +import org.apache.inlong.manager.common.util.CommonBeanUtils; +import org.apache.inlong.manager.common.util.JsonUtils; +import org.apache.inlong.manager.dao.entity.DataNodeEntity; +import org.apache.inlong.manager.dao.entity.StreamSinkEntity; +import org.apache.inlong.manager.dao.mapper.DataNodeEntityMapper; +import org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper; +import org.apache.inlong.manager.pojo.node.cls.ClsDataNodeDTO; +import org.apache.inlong.manager.pojo.sink.SinkInfo; +import org.apache.inlong.manager.pojo.sink.cls.ClsSinkDTO; +import org.apache.inlong.manager.service.resource.sink.SinkResourceOperator; +import org.apache.inlong.manager.service.sink.StreamSinkService; + +import com.tencentcloudapi.cls.v20201016.ClsClient; +import com.tencentcloudapi.cls.v20201016.models.CreateIndexRequest; +import com.tencentcloudapi.cls.v20201016.models.CreateTopicRequest; +import com.tencentcloudapi.cls.v20201016.models.CreateTopicResponse; +import com.tencentcloudapi.cls.v20201016.models.FullTextInfo; +import com.tencentcloudapi.cls.v20201016.models.RuleInfo; +import com.tencentcloudapi.cls.v20201016.models.Tag; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import org.apache.directory.api.util.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ClsResourceOperator implements SinkResourceOperator { + + private static final Logger LOG = LoggerFactory.getLogger(ClsResourceOperator.class); + + @Autowired + private DataNodeEntityMapper dataNodeEntityMapper; + @Autowired + private StreamSinkService sinkService; + @Autowired + private StreamSinkEntityMapper streamSinkEntityMapper; + + @Override + public Boolean accept(String sinkType) { + return SinkType.CLS.equals(sinkType); + } + + @Override + public void createSinkResource(SinkInfo sinkInfo) { + LOG.info("begin to create sink resources sinkId={}", sinkInfo.getId()); + if (SinkStatus.CONFIG_SUCCESSFUL.getCode().equals(sinkInfo.getStatus())) { + LOG.warn("sink resource [" + sinkInfo.getId() + "] already success, skip to create"); + return; + } else if (InlongConstants.DISABLE_CREATE_RESOURCE.equals(sinkInfo.getEnableCreateResource())) { + LOG.warn("create resource was disabled, skip to create for [" + sinkInfo.getId() + "]"); + return; + } + this.createTopicID(sinkInfo); + } + + private void createTopicID(SinkInfo sinkInfo) { + ClsDataNodeDTO clsDataNode = getClsDataNode(sinkInfo); + ClsSinkDTO clsSinkDTO = JsonUtils.parseObject(sinkInfo.getExtParams(), ClsSinkDTO.class); + try { + ClsClient client = getClsClient(clsDataNode); + CreateTopicRequest req = new CreateTopicRequest(); + String[] allTags = clsSinkDTO.getTag().split(InlongConstants.CENTER_LINE); + Tag[] tags = convertTags(allTags); + req.setTags(tags); + req.setLogsetId(clsDataNode.getLogSetId()); Review Comment: done ########## inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/cls/ClsResourceOperator.java: ########## @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.manager.service.resource.sink.cls; + +import org.apache.inlong.manager.common.consts.DataNodeType; +import org.apache.inlong.manager.common.consts.InlongConstants; +import org.apache.inlong.manager.common.consts.SinkType; +import org.apache.inlong.manager.common.enums.SinkStatus; +import org.apache.inlong.manager.common.exceptions.BusinessException; +import org.apache.inlong.manager.common.util.CommonBeanUtils; +import org.apache.inlong.manager.common.util.JsonUtils; +import org.apache.inlong.manager.dao.entity.DataNodeEntity; +import org.apache.inlong.manager.dao.entity.StreamSinkEntity; +import org.apache.inlong.manager.dao.mapper.DataNodeEntityMapper; +import org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper; +import org.apache.inlong.manager.pojo.node.cls.ClsDataNodeDTO; +import org.apache.inlong.manager.pojo.sink.SinkInfo; +import org.apache.inlong.manager.pojo.sink.cls.ClsSinkDTO; +import org.apache.inlong.manager.service.resource.sink.SinkResourceOperator; +import org.apache.inlong.manager.service.sink.StreamSinkService; + +import com.tencentcloudapi.cls.v20201016.ClsClient; +import com.tencentcloudapi.cls.v20201016.models.CreateIndexRequest; +import com.tencentcloudapi.cls.v20201016.models.CreateTopicRequest; +import com.tencentcloudapi.cls.v20201016.models.CreateTopicResponse; +import com.tencentcloudapi.cls.v20201016.models.FullTextInfo; +import com.tencentcloudapi.cls.v20201016.models.RuleInfo; +import com.tencentcloudapi.cls.v20201016.models.Tag; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import org.apache.directory.api.util.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ClsResourceOperator implements SinkResourceOperator { + + private static final Logger LOG = LoggerFactory.getLogger(ClsResourceOperator.class); + + @Autowired + private DataNodeEntityMapper dataNodeEntityMapper; + @Autowired + private StreamSinkService sinkService; + @Autowired + private StreamSinkEntityMapper streamSinkEntityMapper; + + @Override + public Boolean accept(String sinkType) { + return SinkType.CLS.equals(sinkType); + } + + @Override + public void createSinkResource(SinkInfo sinkInfo) { + LOG.info("begin to create sink resources sinkId={}", sinkInfo.getId()); + if (SinkStatus.CONFIG_SUCCESSFUL.getCode().equals(sinkInfo.getStatus())) { + LOG.warn("sink resource [" + sinkInfo.getId() + "] already success, skip to create"); + return; + } else if (InlongConstants.DISABLE_CREATE_RESOURCE.equals(sinkInfo.getEnableCreateResource())) { + LOG.warn("create resource was disabled, skip to create for [" + sinkInfo.getId() + "]"); + return; + } + this.createTopicID(sinkInfo); + } + + private void createTopicID(SinkInfo sinkInfo) { + ClsDataNodeDTO clsDataNode = getClsDataNode(sinkInfo); + ClsSinkDTO clsSinkDTO = JsonUtils.parseObject(sinkInfo.getExtParams(), ClsSinkDTO.class); + try { + ClsClient client = getClsClient(clsDataNode); + CreateTopicRequest req = new CreateTopicRequest(); + String[] allTags = clsSinkDTO.getTag().split(InlongConstants.CENTER_LINE); + Tag[] tags = convertTags(allTags); + req.setTags(tags); + req.setLogsetId(clsDataNode.getLogSetId()); + req.setTopicName(clsSinkDTO.getTopicName()); + CreateTopicResponse resp = client.CreateTopic(req); + LOG.info("create cls topic {} success ,topicId {}", clsSinkDTO.getTopicName(), resp.getTopicId()); + clsSinkDTO.setTopicId(resp.getTopicId()); + sinkInfo.setExtParams(JsonUtils.toJsonString(clsSinkDTO)); + StreamSinkEntity streamSinkEntity = new StreamSinkEntity(); + CommonBeanUtils.copyProperties(sinkInfo, streamSinkEntity, true); + streamSinkEntityMapper.updateByIdSelective(streamSinkEntity); + this.createTopicIndex(sinkInfo); + String info = "success to create cls resource"; + sinkService.updateStatus(sinkInfo.getId(), SinkStatus.CONFIG_SUCCESSFUL.getCode(), info); + LOG.info("update cls sink = {}info status success ,topicName {}", streamSinkEntity.getSinkName(), + clsSinkDTO.getTopicName()); + } catch (TencentCloudSDKException e) { + String errMsg = "Create cls topic failed: " + e.getMessage(); + LOG.error(errMsg, e); + sinkService.updateStatus(sinkInfo.getId(), SinkStatus.CONFIG_FAILED.getCode(), errMsg); + throw new BusinessException(errMsg); + } + } + + private ClsClient getClsClient(ClsDataNodeDTO clsDataNode) { + Credential cred = new Credential(clsDataNode.getManageSecretId(), + clsDataNode.getManageSecretId()); + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint(clsDataNode.getEndpoint()); + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + return new ClsClient(cred, clsDataNode.getRegion(), clientProfile); + } + + private void createTopicIndex(SinkInfo sinkInfo) throws BusinessException { + ClsSinkDTO clsSinkDTO = JsonUtils.parseObject(sinkInfo.getExtParams(), ClsSinkDTO.class); + if (Strings.isEmpty(clsSinkDTO.getTokenizer())) { Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
