-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: UnexpectedTaskExecutionException for CTR
- Loading branch information
Showing
3 changed files
with
216 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
...framework/cloud/dataflow/composedtaskrunner/support/UnexpectedTaskExecutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* | ||
* Copyright 2017-2023 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.springframework.cloud.dataflow.composedtaskrunner.support; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.springframework.batch.core.UnexpectedJobExecutionException; | ||
import org.springframework.boot.ExitCodeGenerator; | ||
import org.springframework.cloud.task.repository.TaskExecution; | ||
|
||
/** | ||
* Creates a {@link UnexpectedTaskExecutionException} which extends {@link UnsupportedOperationException}, but | ||
* also contains the exitCode as information. | ||
* | ||
* @author Tobias Soloschenko | ||
*/ | ||
public class UnexpectedTaskExecutionException extends UnexpectedJobExecutionException implements ExitCodeGenerator { | ||
|
||
private static final long serialVersionUID = 3494615323781500165L; | ||
|
||
/** | ||
* The unique id associated with the task execution. | ||
*/ | ||
private long executionId; | ||
|
||
/** | ||
* The parent task execution id. | ||
*/ | ||
private Long parentExecutionId; | ||
|
||
/** | ||
* The recorded exit code for the task. | ||
*/ | ||
private Integer exitCode = -1; | ||
|
||
/** | ||
* User defined name for the task. | ||
*/ | ||
private String taskName; | ||
|
||
/** | ||
* Time of when the task was started. | ||
*/ | ||
private Date startTime; | ||
|
||
/** | ||
* Timestamp of when the task was completed/terminated. | ||
*/ | ||
private Date endTime; | ||
|
||
/** | ||
* Message returned from the task or stacktrace. | ||
*/ | ||
private String exitMessage; | ||
|
||
/** | ||
* Id assigned to the task by the platform. | ||
*/ | ||
private String externalExecutionId; | ||
|
||
/** | ||
* Error information available upon the failure of a task. | ||
*/ | ||
private String errorMessage; | ||
|
||
/** | ||
* The arguments that were used for this task execution. | ||
*/ | ||
private ArrayList<String> arguments; | ||
|
||
/** | ||
* Constructs an UnexpectedTaskExecutionException with the specified | ||
* detail message. | ||
* | ||
* @param message the detail message | ||
*/ | ||
public UnexpectedTaskExecutionException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs an UnexpectedTaskExecutionException with the specified | ||
* detail message, cause and exitCode. | ||
* | ||
* @param message the detail message | ||
* @param cause the cause which leads to this exception | ||
*/ | ||
public UnexpectedTaskExecutionException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
/** | ||
* Constructs an UnexpectedTaskExecutionException with the specified | ||
* detail message and taskExecution. | ||
* | ||
* @param message the detail message | ||
* @param taskExecution the taskExecution of the task | ||
*/ | ||
public UnexpectedTaskExecutionException(String message, TaskExecution taskExecution) { | ||
this(message); | ||
assignTaskExecutionFields(taskExecution); | ||
} | ||
|
||
/** | ||
* Constructs an UnexpectedTaskExecutionException with the specified | ||
* detail message, cause and taskExecution. | ||
* | ||
* @param message the detail message | ||
* @param cause the cause which leads to this exception | ||
* @param taskExecution the taskExecution of the task | ||
*/ | ||
public UnexpectedTaskExecutionException(String message, Throwable cause, TaskExecution taskExecution) { | ||
this(message, cause); | ||
assignTaskExecutionFields(taskExecution); | ||
} | ||
|
||
/** | ||
* Assigns the task execution fields to this exception. | ||
* | ||
* @param taskExecution the task execution of which the fields should be assigned to this exception | ||
*/ | ||
private void assignTaskExecutionFields(TaskExecution taskExecution) { | ||
if(taskExecution != null) { | ||
executionId = taskExecution.getExecutionId(); | ||
parentExecutionId = taskExecution.getParentExecutionId(); | ||
exitCode = taskExecution.getExitCode(); | ||
taskName = taskExecution.getTaskName(); | ||
startTime = taskExecution.getStartTime(); | ||
endTime = taskExecution.getEndTime(); | ||
externalExecutionId = taskExecution.getExternalExecutionId(); | ||
errorMessage = taskExecution.getErrorMessage(); | ||
exitMessage = taskExecution.getExitMessage(); | ||
arguments = new ArrayList<>(taskExecution.getArguments()); | ||
} | ||
} | ||
|
||
public long getExecutionId() { | ||
return this.executionId; | ||
} | ||
|
||
/** | ||
* Returns the exit code of the task. | ||
* | ||
* @return the exit code or -1 if the exit code couldn't be determined | ||
*/ | ||
@Override | ||
public int getExitCode() { | ||
return this.exitCode; | ||
} | ||
|
||
public String getTaskName() { | ||
return this.taskName; | ||
} | ||
|
||
public Date getStartTime() { | ||
return (this.startTime != null) ? (Date) this.startTime.clone() : null; | ||
} | ||
|
||
public Date getEndTime() { | ||
return (this.endTime != null) ? (Date) this.endTime.clone() : null; | ||
} | ||
|
||
public String getExitMessage() { | ||
return this.exitMessage; | ||
} | ||
|
||
public List<String> getArguments() { | ||
return this.arguments; | ||
} | ||
|
||
public String getErrorMessage() { | ||
return this.errorMessage; | ||
} | ||
|
||
public String getExternalExecutionId() { | ||
return this.externalExecutionId; | ||
} | ||
|
||
public Long getParentExecutionId() { | ||
return this.parentExecutionId; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters