ruanwenjun commented on code in PR #10875: URL: https://github.com/apache/dolphinscheduler/pull/10875#discussion_r917399655
########## dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/controller/WorkflowExecuteController.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.dolphinscheduler.server.master.controller; + +import org.apache.dolphinscheduler.remote.dto.WorkflowExecuteDto; +import org.apache.dolphinscheduler.server.master.service.ExecutingService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/workflow-execute") Review Comment: `workflow/execute` is more restful? ########## dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/service/ExecutingService.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.dolphinscheduler.server.master.service; + +import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.remote.dto.TaskInstanceExecuteDto; +import org.apache.dolphinscheduler.remote.dto.WorkflowExecuteDto; +import org.apache.dolphinscheduler.server.master.cache.ProcessInstanceExecCacheManager; +import org.apache.dolphinscheduler.server.master.controller.WorkflowExecuteController; +import org.apache.dolphinscheduler.server.master.runner.WorkflowExecuteRunnable; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * executing service, to query executing data from memory, such workflow instance + */ +@Component +public class ExecutingService { + + private static final Logger logger = LoggerFactory.getLogger(WorkflowExecuteController.class); + + @Autowired + private ProcessInstanceExecCacheManager processInstanceExecCacheManager; + + public WorkflowExecuteDto queryWorkflowExecutingData(Integer processInstanceId) { + WorkflowExecuteRunnable workflowExecuteRunnable = processInstanceExecCacheManager.getByProcessInstanceId(processInstanceId); + if (workflowExecuteRunnable == null) { + logger.info("workflow execute data not found, maybe it has finished, workflow id:{}", processInstanceId); + return null; + } + try { + WorkflowExecuteDto workflowExecuteDto = new WorkflowExecuteDto(); + BeanUtils.copyProperties(workflowExecuteDto, workflowExecuteRunnable.getProcessInstance()); Review Comment: I am not sure if the BeanUtils can work well in processInstance, since processInstance is not a simple pojo, I have ever try to use BeanUtils to copy TaskInstance, it failed:). And it's better don't use BeanUtils, this is just sofy copy, and we don't need to chang the field here, so we can directly use the proceInstance. ```suggestion BeanUtils.copyProperties(workflowExecuteDto, workflowExecuteRunnable.getProcessInstance()); ``` ########## dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/dto/TaskInstanceExecuteDto.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.dolphinscheduler.remote.dto; + +import org.apache.dolphinscheduler.common.enums.Flag; +import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus; + +import java.util.Date; +import java.util.Map; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter Review Comment: Use data can help to generate toString() ```suggestion @Data ``` ``` ########## dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/controller/WorkflowExecuteController.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.dolphinscheduler.server.master.controller; + +import org.apache.dolphinscheduler.remote.dto.WorkflowExecuteDto; +import org.apache.dolphinscheduler.server.master.service.ExecutingService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/workflow-execute") +public class WorkflowExecuteController { + + @Autowired + private ExecutingService executingService; + + /** + * query workflow execute data in memory + * @param id + * @return + */ + @GetMapping("") + @ResponseStatus(HttpStatus.OK) + public WorkflowExecuteDto queryExecuteData(@RequestParam("id") int id) { Review Comment: ```suggestion public WorkflowExecuteDto queryExecuteData(@RequestParam("id") int processInstanceId) { ``` ########## dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/service/ExecutingService.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.dolphinscheduler.server.master.service; + +import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.remote.dto.TaskInstanceExecuteDto; +import org.apache.dolphinscheduler.remote.dto.WorkflowExecuteDto; +import org.apache.dolphinscheduler.server.master.cache.ProcessInstanceExecCacheManager; +import org.apache.dolphinscheduler.server.master.controller.WorkflowExecuteController; +import org.apache.dolphinscheduler.server.master.runner.WorkflowExecuteRunnable; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * executing service, to query executing data from memory, such workflow instance + */ +@Component +public class ExecutingService { + + private static final Logger logger = LoggerFactory.getLogger(WorkflowExecuteController.class); + + @Autowired + private ProcessInstanceExecCacheManager processInstanceExecCacheManager; + + public WorkflowExecuteDto queryWorkflowExecutingData(Integer processInstanceId) { Review Comment: ```suggestion public Optional<WorkflowExecuteDto> queryWorkflowExecutingData(Integer processInstanceId) { ``` -- 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]
