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/05/18 14:38:06 UTC

[GitHub] [incubator-inlong] healchow commented on a diff in pull request #4253: [INLONG-4247][Manager] Add stream create/suspend/restart/delete api

healchow commented on code in PR #4253:
URL: https://github.com/apache/incubator-inlong/pull/4253#discussion_r875981076


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operation/InlongStreamProcessOperation.java:
##########
@@ -0,0 +1,291 @@
+/*
+ * 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.core.operation;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.enums.GroupOperateType;
+import org.apache.inlong.manager.common.enums.GroupStatus;
+import org.apache.inlong.manager.common.enums.ProcessStatus;
+import org.apache.inlong.manager.common.enums.StreamStatus;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
+import org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo;
+import org.apache.inlong.manager.common.pojo.workflow.WorkflowResult;
+import org.apache.inlong.manager.common.pojo.workflow.form.StreamResourceProcessForm;
+import org.apache.inlong.manager.service.core.InlongGroupService;
+import org.apache.inlong.manager.service.core.InlongStreamService;
+import org.apache.inlong.manager.service.workflow.ProcessName;
+import org.apache.inlong.manager.service.workflow.WorkflowService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Operation related to inlong stream process
+ */
+@Service
+@Slf4j
+public class InlongStreamProcessOperation {
+
+    private final ExecutorService executorService = new ThreadPoolExecutor(
+            20,
+            40,
+            0L,
+            TimeUnit.MILLISECONDS,
+            new LinkedBlockingQueue<>(),
+            new ThreadFactoryBuilder().setNameFormat("inlong-stream-process-%s").build(),
+            new CallerRunsPolicy());
+
+    @Autowired
+    private InlongGroupService groupService;
+
+    @Autowired
+    private InlongStreamService streamService;
+
+    @Autowired
+    private WorkflowService workflowService;
+
+    /**
+     * Create stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean startProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("StartProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL && groupStatus != GroupStatus.RESTARTED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, status=%s not correct for stream start", groupId, groupStatus));
+        }
+        InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
+        if (streamInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.STREAM_NOT_FOUND);
+        }
+        StreamStatus status = StreamStatus.forCode(streamInfo.getStatus());
+        if (status == StreamStatus.CONFIG_ING || status == StreamStatus.CONFIG_SUCCESSFUL) {
+            log.warn("GroupId={}, StreamId={} is already in {}", groupId, streamId, status);
+            return true;
+        }
+        if (status != StreamStatus.NEW || status != StreamStatus.CONFIG_FAILED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, StreamId=%s, status=%s not correct for stream start", groupId, streamId,
+                            status));
+        }
+        StreamResourceProcessForm processForm = genStreamProcessForm(groupInfo, streamInfo, GroupOperateType.INIT);
+        ProcessName processName = ProcessName.CREATE_STREAM_RESOURCE;
+        if (sync) {
+            WorkflowResult workflowResult = workflowService.start(processName, operator,
+                    processForm);
+            ProcessStatus processStatus = workflowResult.getProcessInfo().getStatus();
+            return processStatus == ProcessStatus.COMPLETED;
+        } else {
+            executorService.execute(
+                    () -> workflowService.start(processName, operator, processForm));
+            return true;
+        }
+    }
+
+    /**
+     * Suspend stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean suspendProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("SuspendProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL
+                && groupStatus != GroupStatus.RESTARTED
+                && groupStatus != GroupStatus.SUSPENDED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, status=%s not correct for stream suspend", groupId, groupStatus));
+        }
+        InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
+        if (streamInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.STREAM_NOT_FOUND);
+        }
+        StreamStatus status = StreamStatus.forCode(streamInfo.getStatus());
+        if (status == StreamStatus.SUSPENDED || status == StreamStatus.SUSPENDING) {
+            log.warn("GroupId={}, StreamId={} is already in {}", groupId, streamId, status);
+            return true;
+        }
+        if (status != StreamStatus.CONFIG_SUCCESSFUL && status != StreamStatus.RESTARTED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, StreamId=%s, status=%s not correct for stream suspend", groupId,
+                            streamId,
+                            status));
+        }
+        StreamResourceProcessForm processForm = genStreamProcessForm(groupInfo, streamInfo, GroupOperateType.SUSPEND);
+        ProcessName processName = ProcessName.SUSPEND_STREAM_RESOURCE;
+        if (sync) {
+            WorkflowResult workflowResult = workflowService.start(processName, operator,
+                    processForm);
+            ProcessStatus processStatus = workflowResult.getProcessInfo().getStatus();
+            return processStatus == ProcessStatus.COMPLETED;
+        } else {
+            executorService.execute(
+                    () -> workflowService.start(processName, operator, processForm));
+            return true;
+        }
+    }
+
+    /**
+     * Restart stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean restartProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("RestartProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL
+                && groupStatus != GroupStatus.RESTARTED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, status=%s not correct for stream restart", groupId, groupStatus));
+        }
+        InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
+        if (streamInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.STREAM_NOT_FOUND);
+        }
+        StreamStatus status = StreamStatus.forCode(streamInfo.getStatus());
+        if (status == StreamStatus.RESTARTED || status == StreamStatus.RESTARTING) {
+            log.warn("GroupId={}, StreamId={} is already in {}", groupId, streamId, status);
+            return true;
+        }
+        if (status != StreamStatus.SUSPENDED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, StreamId=%s, status=%s not correct for stream restart", groupId,
+                            streamId,
+                            status));
+        }
+        StreamResourceProcessForm processForm = genStreamProcessForm(groupInfo, streamInfo, GroupOperateType.RESTART);
+        ProcessName processName = ProcessName.RESTART_STREAM_RESOURCE;
+        if (sync) {
+            WorkflowResult workflowResult = workflowService.start(processName, operator,
+                    processForm);
+            ProcessStatus processStatus = workflowResult.getProcessInfo().getStatus();
+            return processStatus == ProcessStatus.COMPLETED;
+        } else {
+            executorService.execute(
+                    () -> workflowService.start(processName, operator, processForm));
+            return true;
+        }
+    }
+
+    /**
+     * Restart stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean deleteProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("DeleteProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL

Review Comment:
   Do we need to set those statuses as a constant set, and move them into the `GroupStatus`?



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operation/InlongStreamProcessOperation.java:
##########
@@ -0,0 +1,291 @@
+/*
+ * 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.core.operation;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.enums.GroupOperateType;
+import org.apache.inlong.manager.common.enums.GroupStatus;
+import org.apache.inlong.manager.common.enums.ProcessStatus;
+import org.apache.inlong.manager.common.enums.StreamStatus;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
+import org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo;
+import org.apache.inlong.manager.common.pojo.workflow.WorkflowResult;
+import org.apache.inlong.manager.common.pojo.workflow.form.StreamResourceProcessForm;
+import org.apache.inlong.manager.service.core.InlongGroupService;
+import org.apache.inlong.manager.service.core.InlongStreamService;
+import org.apache.inlong.manager.service.workflow.ProcessName;
+import org.apache.inlong.manager.service.workflow.WorkflowService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Operation related to inlong stream process
+ */
+@Service
+@Slf4j
+public class InlongStreamProcessOperation {
+
+    private final ExecutorService executorService = new ThreadPoolExecutor(
+            20,
+            40,
+            0L,
+            TimeUnit.MILLISECONDS,
+            new LinkedBlockingQueue<>(),
+            new ThreadFactoryBuilder().setNameFormat("inlong-stream-process-%s").build(),
+            new CallerRunsPolicy());
+
+    @Autowired
+    private InlongGroupService groupService;
+
+    @Autowired
+    private InlongStreamService streamService;
+
+    @Autowired
+    private WorkflowService workflowService;
+
+    /**
+     * Create stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean startProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("StartProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL && groupStatus != GroupStatus.RESTARTED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, status=%s not correct for stream start", groupId, groupStatus));
+        }
+        InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
+        if (streamInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.STREAM_NOT_FOUND);
+        }
+        StreamStatus status = StreamStatus.forCode(streamInfo.getStatus());
+        if (status == StreamStatus.CONFIG_ING || status == StreamStatus.CONFIG_SUCCESSFUL) {
+            log.warn("GroupId={}, StreamId={} is already in {}", groupId, streamId, status);
+            return true;
+        }
+        if (status != StreamStatus.NEW || status != StreamStatus.CONFIG_FAILED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, StreamId=%s, status=%s not correct for stream start", groupId, streamId,
+                            status));
+        }
+        StreamResourceProcessForm processForm = genStreamProcessForm(groupInfo, streamInfo, GroupOperateType.INIT);
+        ProcessName processName = ProcessName.CREATE_STREAM_RESOURCE;
+        if (sync) {
+            WorkflowResult workflowResult = workflowService.start(processName, operator,
+                    processForm);
+            ProcessStatus processStatus = workflowResult.getProcessInfo().getStatus();
+            return processStatus == ProcessStatus.COMPLETED;
+        } else {
+            executorService.execute(
+                    () -> workflowService.start(processName, operator, processForm));
+            return true;
+        }
+    }
+
+    /**
+     * Suspend stream in synchronous/asynchronous way.
+     *
+     * @param groupId
+     * @param streamId
+     * @param operator
+     * @param sync
+     * @return
+     */
+    public boolean suspendProcess(String groupId, String streamId, String operator, boolean sync) {
+        log.info("SuspendProcess for groupId={}, streamId={}", groupId, streamId);
+        InlongGroupInfo groupInfo = groupService.get(groupId);
+        if (groupInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
+        }
+        GroupStatus groupStatus = GroupStatus.forCode(groupInfo.getStatus());
+        if (groupStatus != GroupStatus.CONFIG_SUCCESSFUL
+                && groupStatus != GroupStatus.RESTARTED
+                && groupStatus != GroupStatus.SUSPENDED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, status=%s not correct for stream suspend", groupId, groupStatus));
+        }
+        InlongStreamInfo streamInfo = streamService.get(groupId, streamId);
+        if (streamInfo == null) {
+            throw new BusinessException(ErrorCodeEnum.STREAM_NOT_FOUND);
+        }
+        StreamStatus status = StreamStatus.forCode(streamInfo.getStatus());
+        if (status == StreamStatus.SUSPENDED || status == StreamStatus.SUSPENDING) {
+            log.warn("GroupId={}, StreamId={} is already in {}", groupId, streamId, status);
+            return true;
+        }
+        if (status != StreamStatus.CONFIG_SUCCESSFUL && status != StreamStatus.RESTARTED) {
+            throw new BusinessException(
+                    String.format("GroupId=%s, StreamId=%s, status=%s not correct for stream suspend", groupId,
+                            streamId,
+                            status));
+        }
+        StreamResourceProcessForm processForm = genStreamProcessForm(groupInfo, streamInfo, GroupOperateType.SUSPEND);
+        ProcessName processName = ProcessName.SUSPEND_STREAM_RESOURCE;
+        if (sync) {
+            WorkflowResult workflowResult = workflowService.start(processName, operator,
+                    processForm);
+            ProcessStatus processStatus = workflowResult.getProcessInfo().getStatus();
+            return processStatus == ProcessStatus.COMPLETED;
+        } else {
+            executorService.execute(
+                    () -> workflowService.start(processName, operator, processForm));
+            return true;
+        }
+    }
+
+    /**
+     * Restart stream in synchronous/asynchronous way.
+     *
+     * @param groupId

Review Comment:
   If the params and return tag were empty, just remove them.



##########
inlong-manager/manager-test/src/main/resources/application-test.properties:
##########
@@ -100,4 +100,4 @@ common.http-client.validateAfterInactivity=5000
 common.http-client.connectionTimeout=3000
 common.http-client.readTimeout=10000
 common.http-client.connectionRequestTimeout=3000
-spring.main.allow-circular-references=true
\ No newline at end of file
+spring.main.allow-circular-references=false

Review Comment:
   Please change this config in other properties in `manager-web` module, thanks.



-- 
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