You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/18 10:42:39 UTC

[GitHub] [inlong] leosanqing commented on a diff in pull request #5542: [INLONG-5302][Manager] Supports the extension of data consumption for different MQs

leosanqing commented on code in PR #5542:
URL: https://github.com/apache/inlong/pull/5542#discussion_r948945103


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/consume/InlongConsumeServiceImpl.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.consume;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.inlong.manager.common.enums.ConsumptionStatus;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.dao.entity.InlongConsumeEntity;
+import org.apache.inlong.manager.dao.mapper.InlongConsumeEntityMapper;
+import org.apache.inlong.manager.pojo.common.CountInfo;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionListVo;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionQuery;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionSummary;
+import org.apache.inlong.manager.pojo.consumption.InlongConsumeInfo;
+import org.apache.inlong.manager.pojo.consumption.InlongConsumeRequest;
+import org.apache.inlong.manager.pojo.user.UserRoleCode;
+import org.apache.inlong.manager.service.user.LoginUserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+
+/**
+ * Inlong consume service layer implementation
+ */
+@Slf4j
+@Service
+public class InlongConsumeServiceImpl implements InlongConsumeService {
+
+    @Autowired
+    private InlongConsumeEntityMapper consumeEntityMapper;
+
+    @Autowired
+    private InlongConsumeOperatorFactory consumeOperatorFactory;
+
+    @Override
+    public Integer save(InlongConsumeRequest consumeRequest, String operator) {
+        log.debug("begin to save consumption info={}", consumeRequest);
+        Preconditions.checkNotNull(consumeRequest, "consumption info cannot be null");
+        Preconditions.checkNotNull(consumeRequest.getTopic(), "consumption topic cannot be empty");
+        if (isConsumerGroupExists(consumeRequest.getConsumerGroup(), consumeRequest.getId())) {
+            throw new BusinessException(String.format("consumer group %s already exist",
+                    consumeRequest.getConsumerGroup()));
+        }
+
+        if (consumeRequest.getId() != null) {
+            InlongConsumeEntity consumeEntity = consumeEntityMapper.selectByPrimaryKey(consumeRequest.getId());
+            Preconditions.checkNotNull(consumeEntity, "consumption not exist with id: " + consumeRequest.getId());
+            ConsumptionStatus consumptionStatus = ConsumptionStatus.fromStatus(consumeEntity.getStatus());
+            Preconditions.checkTrue(ConsumptionStatus.ALLOW_SAVE_UPDATE_STATUS.contains(consumptionStatus),
+                    "consumption not allow update when status is " + consumptionStatus.name());
+        }
+
+        InlongConsumeOperator instance = consumeOperatorFactory.getInstance(consumeRequest.getMqType());
+        instance.setTopicInfo(consumeRequest);
+        instance.saveOpt(consumeRequest, operator);
+        return consumeRequest.getId();
+    }
+
+    @Override
+    public boolean isConsumerGroupExists(String consumerGroup, Integer excludeSelfId) {
+        ConsumptionQuery consumptionQuery = new ConsumptionQuery();
+        consumptionQuery.setConsumerGroup(consumerGroup);
+        consumptionQuery.setIsAdminRole(true);
+        List<InlongConsumeEntity> result = consumeEntityMapper.listByQuery(consumptionQuery);
+        if (excludeSelfId != null) {
+            result = result.stream().filter(consumer -> !excludeSelfId.equals(consumer.getId()))
+                    .collect(Collectors.toList());
+        }
+        return !CollectionUtils.isEmpty(result);

Review Comment:
   Could use apache.commons.collectionUtils.CollectionUtils.isNotEmpty()
   Easier to understand



##########
inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/consumption/pulsar/ConsumePulsarDTO.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.consumption.pulsar;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Inlong group info for Pulsar
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@ApiModel("Inlong group info for Pulsar")
+public class ConsumePulsarDTO {
+
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); // thread safe
+
+    @ApiModelProperty(value = "Consumption ID")
+    private Integer consumptionId;
+
+//    @ApiModelProperty(value = "Consumer group")

Review Comment:
   Personal suggestion, new classes, it is best not to keep comments, delete them directly,
   
   Same as below



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/consume/InlongConsumeOperatorFactory.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.consume;
+
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Optional;
+
+@Service
+public class InlongConsumeOperatorFactory {
+
+    @Autowired
+    private List<InlongConsumeOperator> consumeOperatorList;
+
+    /**
+     * Get a consumption operator instance via the given mqType
+     */
+    public InlongConsumeOperator getInstance(String mqType) {

Review Comment:
   ```suggestion
       public InlongConsumeOperator getInstance(String mqType) {
           return consumeOperatorList.stream()
                   .filter(inst -> inst.accept(mqType))
                   .findFirst()
                   .orElseThrow(() -> new BusinessException(String.format(ErrorCodeEnum.MQ_TYPE_NOT_SUPPORTED.getMessage(), mqType)));
       }
   ```



##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongConsumeController.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.web.controller;
+
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import org.apache.inlong.manager.common.enums.OperationType;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionListVo;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionQuery;
+import org.apache.inlong.manager.pojo.consumption.ConsumptionSummary;
+import org.apache.inlong.manager.pojo.consumption.InlongConsumeInfo;
+import org.apache.inlong.manager.pojo.consumption.InlongConsumeRequest;
+import org.apache.inlong.manager.service.consume.InlongConsumeService;
+import org.apache.inlong.manager.service.group.InlongGroupProcessService;
+import org.apache.inlong.manager.service.group.InlongGroupService;
+import org.apache.inlong.manager.service.operationlog.OperationLog;
+import org.apache.inlong.manager.service.user.LoginUserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Inlong consume control layer
+ */
+@RestController
+@RequestMapping("/api")
+@Api(tags = "Inlong-Consume-API")
+public class InlongConsumeController {
+
+    @Autowired
+    private InlongGroupService groupService;
+    @Autowired
+    private InlongGroupProcessService groupProcessOperation;
+    @Autowired
+    private InlongConsumeService consumeService;
+
+    @RequestMapping(value = "/consume/save", method = RequestMethod.POST)
+    @OperationLog(operation = OperationType.CREATE)
+    @ApiOperation(value = "Save inlong consume")
+    public Response<Integer> save(@Validated @RequestBody InlongConsumeRequest consumeRequest) {

Review Comment:
   Create and update different field checks, such as Id, you can refer to this class
   
   org.apache.inlong.manager.web.controller.StreamTransformController#update
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org