Wenjun Ruan
2 years ago
committed by
GitHub
46 changed files with 1541 additions and 237 deletions
@ -0,0 +1,62 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* This is the main class for executing workflow/workflowInstance/tasks. |
||||
* <pre> |
||||
* ExecuteContext executeContext = ExecuteContext.builder() |
||||
* .processInstance(processInstance) |
||||
* .executeType(...) |
||||
* .build(); |
||||
* executeClient.execute(executeContext); |
||||
* </pre> |
||||
*/ |
||||
@Component |
||||
@SuppressWarnings("unchecked") |
||||
public class ExecuteClient { |
||||
|
||||
private final Map<ExecuteType, ExecuteFunctionBuilder> executorFunctionBuilderMap; |
||||
|
||||
public ExecuteClient(List<ExecuteFunctionBuilder> executeFunctionBuilders) { |
||||
executorFunctionBuilderMap = executeFunctionBuilders.stream() |
||||
.collect(Collectors.toMap(ExecuteFunctionBuilder::getExecuteType, Function.identity())); |
||||
} |
||||
|
||||
public ExecuteResult executeWorkflowInstance(ExecuteContext executeContext) throws ExecuteRuntimeException { |
||||
ExecuteFunctionBuilder<ExecuteRequest, ExecuteResult> executeFunctionBuilder = checkNotNull( |
||||
executorFunctionBuilderMap.get(executeContext.getExecuteType()), |
||||
String.format("The executeType: %s is not supported", executeContext.getExecuteType())); |
||||
|
||||
return executeFunctionBuilder.createWorkflowInstanceExecuteFunction(executeContext) |
||||
.thenCombine(executeFunctionBuilder.createWorkflowInstanceExecuteRequest(executeContext), |
||||
ExecuteFunction::execute) |
||||
.join(); |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import lombok.Data; |
||||
|
||||
// todo: to be interface
|
||||
@Data |
||||
public class ExecuteContext { |
||||
|
||||
private final ProcessInstance workflowInstance; |
||||
|
||||
private final ProcessDefinition workflowDefinition; |
||||
|
||||
private final User executeUser; |
||||
|
||||
private final ExecuteType executeType; |
||||
|
||||
public ExecuteContext(ProcessInstance workflowInstance, |
||||
ProcessDefinition workflowDefinition, |
||||
User executeUser, |
||||
ExecuteType executeType) { |
||||
this.workflowInstance = checkNotNull(workflowInstance, "workflowInstance cannot be null"); |
||||
this.workflowDefinition = checkNotNull(workflowDefinition, "workflowDefinition cannot be null"); |
||||
this.executeUser = checkNotNull(executeUser, "executeUser cannot be null"); |
||||
this.executeType = checkNotNull(executeType, "executeType cannot be null"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
|
||||
public interface ExecuteFunction<Request extends ExecuteRequest, Result extends ExecuteResult> { |
||||
|
||||
/** |
||||
* Execute the workflow by the given request. |
||||
* |
||||
* @param request execute request |
||||
* @return execute result |
||||
* @throws ExecuteRuntimeException If there is an exception during execution, it will be thrown. |
||||
*/ |
||||
Result execute(Request request) throws ExecuteRuntimeException; |
||||
|
||||
/** |
||||
* @return the type of the executor |
||||
*/ |
||||
ExecuteType getExecuteType(); |
||||
} |
@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
public interface ExecuteFunctionBuilder<Request extends ExecuteRequest, Result extends ExecuteResult> { |
||||
|
||||
CompletableFuture<ExecuteFunction<Request, Result>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext); |
||||
|
||||
CompletableFuture<Request> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext); |
||||
|
||||
ExecuteType getExecuteType(); |
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
public interface ExecuteRequest { |
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
/* |
||||
* 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.api.executor; |
||||
|
||||
public interface ExecuteResult { |
||||
|
||||
} |
@ -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.dolphinscheduler.api.executor; |
||||
|
||||
// todo: implement from DolphinSchedulerRuntimeException
|
||||
public class ExecuteRuntimeException extends RuntimeException { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private static final String EXECUTE_WORKFLOW_INSTANCE_ERROR = |
||||
"Execute workflow instance %s failed, execute type is %s"; |
||||
|
||||
public ExecuteRuntimeException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
public ExecuteRuntimeException(String message, Throwable cause) { |
||||
super(message, cause); |
||||
} |
||||
|
||||
public static ExecuteRuntimeException executeWorkflowInstanceError(ExecuteContext executeContext) { |
||||
return executeWorkflowInstanceError(executeContext, null); |
||||
} |
||||
|
||||
public static ExecuteRuntimeException executeWorkflowInstanceError(ExecuteContext executeContext, Throwable cause) { |
||||
return new ExecuteRuntimeException( |
||||
String.format(EXECUTE_WORKFLOW_INSTANCE_ERROR, executeContext.getWorkflowInstance().getName(), |
||||
executeContext.getExecuteType()), |
||||
cause); |
||||
} |
||||
} |
@ -0,0 +1,64 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.failure.recovery; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRuntimeException; |
||||
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||
import org.apache.dolphinscheduler.dao.entity.Command; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
public class FailureRecoveryExecuteFunction implements ExecuteFunction<FailureRecoveryRequest, FailureRecoveryResult> { |
||||
|
||||
private final CommandService commandService; |
||||
|
||||
public FailureRecoveryExecuteFunction(CommandService commandService) { |
||||
this.commandService = commandService; |
||||
} |
||||
|
||||
@Override |
||||
public FailureRecoveryResult execute(FailureRecoveryRequest request) throws ExecuteRuntimeException { |
||||
ProcessInstance workflowInstance = request.getWorkflowInstance(); |
||||
if (!workflowInstance.getState().isFailure()) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("The workflow instance: %s status is %s, can not be recovered", |
||||
workflowInstance.getName(), workflowInstance.getState())); |
||||
} |
||||
|
||||
Command command = Command.builder() |
||||
.commandType(CommandType.START_FAILURE_TASK_PROCESS) |
||||
.processDefinitionCode(workflowInstance.getProcessDefinitionCode()) |
||||
.processDefinitionVersion(workflowInstance.getProcessDefinitionVersion()) |
||||
.processInstanceId(workflowInstance.getId()) |
||||
.executorId(request.getExecuteUser().getId()) |
||||
.testFlag(workflowInstance.getTestFlag()) |
||||
.build(); |
||||
if (commandService.createCommand(command) <= 0) { |
||||
throw new ExecuteRuntimeException( |
||||
"Failure recovery workflow instance failed, due to insert command to db failed"); |
||||
} |
||||
return new FailureRecoveryResult(command.getId()); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return FailureRecoveryExecuteFunctionBuilder.EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.failure.recovery; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteContext; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunctionBuilder; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class FailureRecoveryExecuteFunctionBuilder |
||||
implements |
||||
ExecuteFunctionBuilder<FailureRecoveryRequest, FailureRecoveryResult> { |
||||
|
||||
public static final ExecuteType EXECUTE_TYPE = ExecuteType.START_FAILURE_TASK_PROCESS; |
||||
|
||||
@Autowired |
||||
private CommandService commandService; |
||||
|
||||
@Override |
||||
public CompletableFuture<ExecuteFunction<FailureRecoveryRequest, FailureRecoveryResult>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture(new FailureRecoveryExecuteFunction(commandService)); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<FailureRecoveryRequest> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture( |
||||
new FailureRecoveryRequest( |
||||
executeContext.getWorkflowInstance(), |
||||
executeContext.getWorkflowDefinition(), |
||||
executeContext.getExecuteUser())); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.failure.recovery; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRequest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class FailureRecoveryRequest implements ExecuteRequest { |
||||
|
||||
private final ProcessInstance workflowInstance; |
||||
private final ProcessDefinition workflowDefinition; |
||||
private final User executeUser; |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.failure.recovery; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteResult; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class FailureRecoveryResult implements ExecuteResult { |
||||
|
||||
private final Integer commandId; |
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.pause; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRuntimeException; |
||||
import org.apache.dolphinscheduler.api.rpc.ApiRpcClient; |
||||
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; |
||||
import org.apache.dolphinscheduler.remote.command.WorkflowStateEventChangeCommand; |
||||
import org.apache.dolphinscheduler.remote.exceptions.RemotingException; |
||||
import org.apache.dolphinscheduler.remote.utils.Host; |
||||
|
||||
public class PauseExecuteFunction implements ExecuteFunction<PauseExecuteRequest, PauseExecuteResult> { |
||||
|
||||
private final ProcessInstanceDao processInstanceDao; |
||||
|
||||
private final ApiRpcClient apiRpcClient; |
||||
|
||||
public PauseExecuteFunction(ProcessInstanceDao processInstanceDao, ApiRpcClient apiRpcClient) { |
||||
this.processInstanceDao = processInstanceDao; |
||||
this.apiRpcClient = apiRpcClient; |
||||
} |
||||
|
||||
@Override |
||||
public PauseExecuteResult execute(PauseExecuteRequest request) throws ExecuteRuntimeException { |
||||
ProcessInstance workflowInstance = request.getWorkflowInstance(); |
||||
if (!workflowInstance.getState().isRunning()) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("The workflow instance: %s status is %s, can not pause", workflowInstance.getName(), |
||||
workflowInstance.getState())); |
||||
} |
||||
workflowInstance.setCommandType(CommandType.PAUSE); |
||||
workflowInstance.addHistoryCmd(CommandType.PAUSE); |
||||
workflowInstance.setStateWithDesc(WorkflowExecutionStatus.READY_PAUSE, |
||||
CommandType.PAUSE.getDescp() + " by " + request.getExecuteUser().getUserName()); |
||||
|
||||
if (processInstanceDao.updateProcessInstance(workflowInstance) <= 0) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format( |
||||
"The workflow instance: %s pause failed, due to update the workflow instance status in DB failed", |
||||
workflowInstance.getName())); |
||||
} |
||||
WorkflowStateEventChangeCommand workflowStateEventChangeCommand = new WorkflowStateEventChangeCommand( |
||||
workflowInstance.getId(), 0, workflowInstance.getState(), workflowInstance.getId(), 0); |
||||
try { |
||||
apiRpcClient.send(Host.of(workflowInstance.getHost()), workflowStateEventChangeCommand.convert2Command()); |
||||
} catch (RemotingException e) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format( |
||||
"The workflow instance: %s pause failed, due to send rpc request to master: %s failed", |
||||
workflowInstance.getName(), workflowInstance.getHost()), |
||||
e); |
||||
} |
||||
return new PauseExecuteResult(workflowInstance); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return PauseExecuteFunctionBuilder.EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.pause; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteContext; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunctionBuilder; |
||||
import org.apache.dolphinscheduler.api.rpc.ApiRpcClient; |
||||
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class PauseExecuteFunctionBuilder implements ExecuteFunctionBuilder<PauseExecuteRequest, PauseExecuteResult> { |
||||
|
||||
public static final ExecuteType EXECUTE_TYPE = ExecuteType.PAUSE; |
||||
|
||||
@Autowired |
||||
private ProcessInstanceDao processInstanceDao; |
||||
@Autowired |
||||
private ApiRpcClient apiRpcClient; |
||||
|
||||
@Override |
||||
public CompletableFuture<ExecuteFunction<PauseExecuteRequest, PauseExecuteResult>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture(new PauseExecuteFunction(processInstanceDao, apiRpcClient)); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<PauseExecuteRequest> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture( |
||||
new PauseExecuteRequest( |
||||
executeContext.getWorkflowDefinition(), |
||||
executeContext.getWorkflowInstance(), |
||||
executeContext.getExecuteUser())); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.pause; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRequest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class PauseExecuteRequest implements ExecuteRequest { |
||||
|
||||
private final ProcessDefinition processDefinition; |
||||
private final ProcessInstance workflowInstance; |
||||
private final User executeUser; |
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.pause; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteResult; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
|
||||
@AllArgsConstructor |
||||
public class PauseExecuteResult implements ExecuteResult { |
||||
|
||||
private final ProcessInstance processInstance; |
||||
} |
@ -0,0 +1,78 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.recover; |
||||
|
||||
import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_RECOVER_PROCESS_ID_STRING; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRuntimeException; |
||||
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.apache.dolphinscheduler.dao.entity.Command; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
import java.util.Map; |
||||
|
||||
import com.google.common.collect.ImmutableMap; |
||||
|
||||
public class RecoverExecuteFunction implements ExecuteFunction<RecoverExecuteRequest, RecoverExecuteResult> { |
||||
|
||||
private final CommandService commandService; |
||||
|
||||
public RecoverExecuteFunction(CommandService commandService) { |
||||
this.commandService = commandService; |
||||
} |
||||
|
||||
@Override |
||||
public RecoverExecuteResult execute(RecoverExecuteRequest request) throws ExecuteRuntimeException { |
||||
ProcessInstance workflowInstance = request.getWorkflowInstance(); |
||||
if (!workflowInstance.getState().isPause()) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("The workflow instance: %s state is %s, cannot recovery", workflowInstance.getName(), |
||||
workflowInstance.getState())); |
||||
} |
||||
Command command = Command.builder() |
||||
.commandType(CommandType.RECOVER_SUSPENDED_PROCESS) |
||||
.processDefinitionCode(workflowInstance.getProcessDefinitionCode()) |
||||
.processDefinitionVersion(workflowInstance.getProcessDefinitionVersion()) |
||||
.processInstanceId(workflowInstance.getId()) |
||||
.commandParam(JSONUtils.toJsonString(createCommandParam(workflowInstance))) |
||||
.executorId(request.getExecuteUser().getId()) |
||||
.testFlag(workflowInstance.getTestFlag()) |
||||
.build(); |
||||
if (commandService.createCommand(command) <= 0) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("Recovery workflow instance: %s failed, due to insert command to db failed", |
||||
workflowInstance.getName())); |
||||
} |
||||
return new RecoverExecuteResult(command); |
||||
} |
||||
|
||||
private Map<String, Object> createCommandParam(ProcessInstance workflowInstance) { |
||||
return new ImmutableMap.Builder<String, Object>() |
||||
.put(CMD_PARAM_RECOVER_PROCESS_ID_STRING, workflowInstance.getId()) |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return RecoverExecuteFunctionBuilder.EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.recover; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteContext; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunctionBuilder; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class RecoverExecuteFunctionBuilder |
||||
implements |
||||
ExecuteFunctionBuilder<RecoverExecuteRequest, RecoverExecuteResult> { |
||||
|
||||
public static final ExecuteType EXECUTE_TYPE = ExecuteType.RECOVER_SUSPENDED_PROCESS; |
||||
|
||||
@Autowired |
||||
private CommandService commandService; |
||||
|
||||
@Override |
||||
public CompletableFuture<ExecuteFunction<RecoverExecuteRequest, RecoverExecuteResult>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture( |
||||
new RecoverExecuteFunction(commandService)); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<RecoverExecuteRequest> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture( |
||||
new RecoverExecuteRequest( |
||||
executeContext.getWorkflowInstance(), |
||||
executeContext.getWorkflowDefinition(), |
||||
executeContext.getExecuteUser())); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.recover; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRequest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class RecoverExecuteRequest implements ExecuteRequest { |
||||
|
||||
private final ProcessInstance workflowInstance; |
||||
private final ProcessDefinition processDefinition; |
||||
private final User executeUser; |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.pause.recover; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteResult; |
||||
import org.apache.dolphinscheduler.dao.entity.Command; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
|
||||
@AllArgsConstructor |
||||
public class RecoverExecuteResult implements ExecuteResult { |
||||
|
||||
private final Command command; |
||||
} |
@ -0,0 +1,93 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.rerun; |
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull; |
||||
import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_RECOVER_PROCESS_ID_STRING; |
||||
import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_START_PARAMS; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRuntimeException; |
||||
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.apache.dolphinscheduler.dao.entity.Command; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
import org.apache.commons.collections4.MapUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference; |
||||
|
||||
public class RepeatRunningExecuteFunction implements ExecuteFunction<RepeatRunningRequest, RepeatRunningResult> { |
||||
|
||||
private final CommandService commandService; |
||||
|
||||
public RepeatRunningExecuteFunction(CommandService commandService) { |
||||
this.commandService = commandService; |
||||
} |
||||
|
||||
@Override |
||||
public RepeatRunningResult execute(RepeatRunningRequest request) throws ExecuteRuntimeException { |
||||
checkNotNull(request, "request cannot be null"); |
||||
// todo: check workflow definition valid? or we don't need to do this check, since we will check in master
|
||||
// again.
|
||||
// todo: check tenant valid? or we don't need to do this check, since we need to check in master again.
|
||||
ProcessInstance workflowInstance = request.getWorkflowInstance(); |
||||
if (workflowInstance.getState() == null || !workflowInstance.getState().isFinished()) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("The workflow instance: %s status is %s, cannot repeat running", |
||||
workflowInstance.getName(), workflowInstance.getState())); |
||||
} |
||||
Command command = Command.builder() |
||||
.commandType(CommandType.REPEAT_RUNNING) |
||||
.commandParam(JSONUtils.toJsonString(createCommandParams(workflowInstance))) |
||||
.processDefinitionCode(workflowInstance.getProcessDefinitionCode()) |
||||
.processDefinitionVersion(workflowInstance.getProcessDefinitionVersion()) |
||||
.processInstanceId(workflowInstance.getId()) |
||||
.processInstancePriority(workflowInstance.getProcessInstancePriority()) |
||||
.testFlag(workflowInstance.getTestFlag()) |
||||
.build(); |
||||
if (commandService.createCommand(command) <= 0) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("Repeat running workflow instance: %s failed, due to insert command to db failed", |
||||
workflowInstance.getName())); |
||||
} |
||||
return new RepeatRunningResult(command.getId()); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return RepeatRunningExecuteFunctionBuilder.EXECUTE_TYPE; |
||||
} |
||||
|
||||
private Map<String, Object> createCommandParams(ProcessInstance workflowInstance) { |
||||
Map<String, Object> commandMap = |
||||
JSONUtils.parseObject(workflowInstance.getCommandParam(), new TypeReference<Map<String, Object>>() { |
||||
}); |
||||
Map<String, Object> repeatRunningCommandParams = new HashMap<>(); |
||||
Optional.ofNullable(MapUtils.getObject(commandMap, CMD_PARAM_START_PARAMS)) |
||||
.ifPresent(startParams -> repeatRunningCommandParams.put(CMD_PARAM_START_PARAMS, startParams)); |
||||
repeatRunningCommandParams.put(CMD_PARAM_RECOVER_PROCESS_ID_STRING, workflowInstance.getId()); |
||||
return repeatRunningCommandParams; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.rerun; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteContext; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunctionBuilder; |
||||
import org.apache.dolphinscheduler.service.command.CommandService; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class RepeatRunningExecuteFunctionBuilder |
||||
implements |
||||
ExecuteFunctionBuilder<RepeatRunningRequest, RepeatRunningResult> { |
||||
|
||||
public static final ExecuteType EXECUTE_TYPE = ExecuteType.REPEAT_RUNNING; |
||||
|
||||
@Autowired |
||||
private CommandService commandService; |
||||
|
||||
@Override |
||||
public CompletableFuture<ExecuteFunction<RepeatRunningRequest, RepeatRunningResult>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture(new RepeatRunningExecuteFunction(commandService)); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<RepeatRunningRequest> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture( |
||||
new RepeatRunningRequest( |
||||
executeContext.getWorkflowInstance(), |
||||
executeContext.getWorkflowDefinition(), |
||||
executeContext.getExecuteUser())); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.rerun; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRequest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class RepeatRunningRequest implements ExecuteRequest { |
||||
|
||||
private final ProcessInstance workflowInstance; |
||||
|
||||
private final ProcessDefinition processDefinition; |
||||
|
||||
private final User executeUser; |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.rerun; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteResult; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class RepeatRunningResult implements ExecuteResult { |
||||
|
||||
private final Integer commandId; |
||||
} |
@ -0,0 +1,87 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.stop; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRuntimeException; |
||||
import org.apache.dolphinscheduler.api.rpc.ApiRpcClient; |
||||
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; |
||||
import org.apache.dolphinscheduler.remote.command.WorkflowStateEventChangeCommand; |
||||
import org.apache.dolphinscheduler.remote.exceptions.RemotingException; |
||||
import org.apache.dolphinscheduler.remote.utils.Host; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public class StopExecuteFunction implements ExecuteFunction<StopRequest, StopResult> { |
||||
|
||||
private final ProcessInstanceDao processInstanceDao; |
||||
// todo: Use ApiRpcClient instead of NettyRemotingClient
|
||||
private final ApiRpcClient apiRpcClient; |
||||
|
||||
public StopExecuteFunction(ProcessInstanceDao processInstanceDao, ApiRpcClient apiRpcClient) { |
||||
this.processInstanceDao = processInstanceDao; |
||||
this.apiRpcClient = apiRpcClient; |
||||
} |
||||
|
||||
@Override |
||||
public StopResult execute(StopRequest request) throws ExecuteRuntimeException { |
||||
ProcessInstance workflowInstance = request.getWorkflowInstance(); |
||||
|
||||
if (!workflowInstance.getState().canStop() |
||||
|| workflowInstance.getState() == WorkflowExecutionStatus.READY_STOP) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("The workflow instance: %s status is %s, can not be stopped", |
||||
workflowInstance.getName(), workflowInstance.getState())); |
||||
} |
||||
// update the workflow instance's status to stop
|
||||
workflowInstance.setCommandType(CommandType.STOP); |
||||
workflowInstance.addHistoryCmd(CommandType.STOP); |
||||
workflowInstance.setStateWithDesc(WorkflowExecutionStatus.READY_STOP, CommandType.STOP.getDescp() + " by user"); |
||||
if (processInstanceDao.updateProcessInstance(workflowInstance) > 0) { |
||||
log.info("Workflow instance {} ready to stop success, will call master to stop the workflow instance", |
||||
workflowInstance.getName()); |
||||
// todo: Use specific stop command instead of WorkflowStateEventChangeCommand
|
||||
WorkflowStateEventChangeCommand workflowStateEventChangeCommand = new WorkflowStateEventChangeCommand( |
||||
workflowInstance.getId(), 0, workflowInstance.getState(), workflowInstance.getId(), 0); |
||||
try { |
||||
apiRpcClient.send(Host.of(workflowInstance.getHost()), |
||||
workflowStateEventChangeCommand.convert2Command()); |
||||
} catch (RemotingException e) { |
||||
throw new ExecuteRuntimeException( |
||||
String.format("Workflow instance: %s stop failed, due to send request to master: %s failed", |
||||
workflowInstance.getName(), workflowInstance.getHost()), |
||||
e); |
||||
} |
||||
// todo: use async and inject the completeFuture in the result.
|
||||
return new StopResult(workflowInstance); |
||||
} |
||||
throw new ExecuteRuntimeException( |
||||
"Workflow instance stop failed, due to update the workflow instance status failed"); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return StopExecuteFunctionBuilder.EXECUTE_TYPE; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,56 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.stop; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteContext; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunction; |
||||
import org.apache.dolphinscheduler.api.executor.ExecuteFunctionBuilder; |
||||
import org.apache.dolphinscheduler.api.rpc.ApiRpcClient; |
||||
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class StopExecuteFunctionBuilder implements ExecuteFunctionBuilder<StopRequest, StopResult> { |
||||
|
||||
public static final ExecuteType EXECUTE_TYPE = ExecuteType.STOP; |
||||
|
||||
@Autowired |
||||
private ProcessInstanceDao processInstanceDao; |
||||
@Autowired |
||||
private ApiRpcClient apiRpcClient; |
||||
|
||||
@Override |
||||
public CompletableFuture<ExecuteFunction<StopRequest, StopResult>> createWorkflowInstanceExecuteFunction(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture(new StopExecuteFunction(processInstanceDao, apiRpcClient)); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<StopRequest> createWorkflowInstanceExecuteRequest(ExecuteContext executeContext) { |
||||
return CompletableFuture.completedFuture(new StopRequest(executeContext.getWorkflowInstance())); |
||||
} |
||||
|
||||
@Override |
||||
public ExecuteType getExecuteType() { |
||||
return EXECUTE_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.stop; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteRequest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NonNull; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class StopRequest implements ExecuteRequest { |
||||
|
||||
@NonNull |
||||
private final ProcessInstance workflowInstance; |
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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.api.executor.workflow.instance.stop; |
||||
|
||||
import org.apache.dolphinscheduler.api.executor.ExecuteResult; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NonNull; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class StopResult implements ExecuteResult { |
||||
|
||||
@NonNull |
||||
private final ProcessInstance workflowInstance; |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* 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.api.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.NettyRemotingClient; |
||||
import org.apache.dolphinscheduler.remote.command.Command; |
||||
import org.apache.dolphinscheduler.remote.config.NettyClientConfig; |
||||
import org.apache.dolphinscheduler.remote.exceptions.RemotingException; |
||||
import org.apache.dolphinscheduler.remote.utils.Host; |
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class ApiRpcClient { |
||||
|
||||
private final NettyRemotingClient nettyRemotingClient; |
||||
|
||||
public ApiRpcClient() { |
||||
this.nettyRemotingClient = new NettyRemotingClient(new NettyClientConfig()); |
||||
} |
||||
|
||||
public void send(Host host, Command command) throws RemotingException { |
||||
nettyRemotingClient.send(host, command); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue