Introduced Error Message to Task Execution
To provide the ability to control task orchestration via the exit message, we moved the stack trace storage to a new field. This means that exit message is now a field we can use similar to how exit code is in batch, and still have the stack trace of an unsuccessful task execution stored. Resolves spring-cloud/spring-cloud-task#186 Disabled integration tests by default Just some cleanup on merge
This commit is contained in:
committed by
Glenn Renfro
parent
551a4bc53a
commit
db0565b7cf
@@ -156,7 +156,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
}
|
||||
|
||||
if(this.applicationFailedEvent != null) {
|
||||
this.taskExecution.setExitMessage(stackTraceToString(this.applicationFailedEvent.getException()));
|
||||
this.taskExecution.setErrorMessage(stackTraceToString(this.applicationFailedEvent.getException()));
|
||||
}
|
||||
|
||||
if(this.taskExecution.getExitCode() != 0){
|
||||
@@ -165,7 +165,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
}
|
||||
taskExecution.setExitMessage(invokeOnTaskEnd(taskExecution).getExitMessage());
|
||||
taskRepository.completeTaskExecution(taskExecution.getExecutionId(), taskExecution.getExitCode(),
|
||||
taskExecution.getEndTime(), taskExecution.getExitMessage());
|
||||
taskExecution.getEndTime(), taskExecution.getExitMessage(), taskExecution.getErrorMessage());
|
||||
|
||||
this.finished = true;
|
||||
|
||||
@@ -237,7 +237,8 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
return new TaskExecution(taskExecution.getExecutionId(),
|
||||
taskExecution.getExitCode(), taskExecution.getTaskName(), startTime,
|
||||
endTime,taskExecution.getExitMessage(),
|
||||
Collections.unmodifiableList(taskExecution.getArguments()));
|
||||
Collections.unmodifiableList(taskExecution.getArguments()),
|
||||
taskExecution.getErrorMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
|
||||
* Represents the state of the Task for each execution.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author Michael Minella
|
||||
*/
|
||||
|
||||
public class TaskExecution {
|
||||
@@ -59,6 +60,13 @@ public class TaskExecution {
|
||||
*/
|
||||
private String exitMessage;
|
||||
|
||||
/**
|
||||
* Error information available upon the failure of a task
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* The arguments that were used for this task execution.
|
||||
*/
|
||||
@@ -70,7 +78,8 @@ public class TaskExecution {
|
||||
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName,
|
||||
Date startTime, Date endTime,
|
||||
String exitMessage, List<String> arguments) {
|
||||
String exitMessage, List<String> arguments,
|
||||
String errorMessage) {
|
||||
|
||||
Assert.notNull(arguments, "arguments must not be null");
|
||||
Assert.notNull(startTime, "startTime must not be null");
|
||||
@@ -81,6 +90,7 @@ public class TaskExecution {
|
||||
this.arguments = new ArrayList<>(arguments);
|
||||
this.startTime = (Date)startTime.clone();
|
||||
this.endTime = (endTime != null) ? (Date)endTime.clone() : null;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public long getExecutionId() {
|
||||
@@ -135,6 +145,14 @@ public class TaskExecution {
|
||||
this.arguments = new ArrayList<> (arguments);
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskExecution{" +
|
||||
@@ -144,6 +162,7 @@ public class TaskExecution {
|
||||
", startTime=" + startTime +
|
||||
", endTime=" + endTime +
|
||||
", exitMessage='" + exitMessage + '\'' +
|
||||
", errorMessage='" + errorMessage + "\'" +
|
||||
", arguments=" + arguments +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -42,6 +42,20 @@ public interface TaskRepository {
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage);
|
||||
|
||||
/**
|
||||
* Notifies the repository that a taskExecution has completed.
|
||||
*
|
||||
* @param executionId to the task execution to be updated.
|
||||
* @param exitCode to be stored for this task.
|
||||
* @param endTime designated when the task completed.
|
||||
* @param exitMessage to be stored for the task.
|
||||
* @return the updated {@link TaskExecution}
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Transactional
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage, String errorMessage);
|
||||
|
||||
/**
|
||||
* Notifies the repository that a taskExecution needs to be created.
|
||||
*
|
||||
|
||||
@@ -58,7 +58,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED ";
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED ";
|
||||
|
||||
public static final String FROM_CLAUSE = "%PREFIX%EXECUTION";
|
||||
|
||||
@@ -78,12 +78,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String UPDATE_TASK_EXECUTION = "UPDATE %PREFIX%EXECUTION set "
|
||||
+ "END_TIME = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, LAST_UPDATED = ? "
|
||||
+ "where TASK_EXECUTION_ID = ?";
|
||||
+ "END_TIME = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, ERROR_MESSAGE = ?, "
|
||||
+ "LAST_UPDATED = ? where TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, " +
|
||||
"START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
|
||||
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String FIND_ARGUMENT_FROM_ID = "SELECT TASK_EXECUTION_ID, "
|
||||
@@ -129,7 +129,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
Date startTime, List<String> arguments) {
|
||||
long taskExecutionId = getNextExecutionId();
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
|
||||
startTime, null, null, arguments);
|
||||
startTime, null, null, arguments, null);
|
||||
|
||||
Object[] queryParameters = new Object[]{ taskExecutionId, startTime, taskName, new Date()};
|
||||
jdbcTemplate.update(
|
||||
@@ -142,7 +142,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime,
|
||||
String exitMessage) {
|
||||
String exitMessage, String errorMessage) {
|
||||
// Check if given TaskExecution's Id already exists, if none is found
|
||||
// it is invalid and an exception should be thrown.
|
||||
if (jdbcTemplate.queryForObject(getQuery(CHECK_TASK_EXECUTION_EXISTS), Integer.class,
|
||||
@@ -150,15 +150,21 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
throw new IllegalStateException("Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
}
|
||||
|
||||
Object[] parameters = new Object[]{ endTime, exitCode, exitMessage, new Date(),
|
||||
Object[] parameters = new Object[]{ endTime, exitCode, exitMessage, errorMessage, new Date(),
|
||||
taskExecutionId};
|
||||
jdbcTemplate.update(
|
||||
getQuery(UPDATE_TASK_EXECUTION),
|
||||
parameters,
|
||||
new int[]{ Types.TIMESTAMP, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP,
|
||||
new int[]{ Types.TIMESTAMP, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP,
|
||||
Types.BIGINT});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime,
|
||||
String exitMessage) {
|
||||
completeTaskExecution(taskExecutionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the table prefix property. This will be prefixed to all
|
||||
* the table names before queries are executed. Defaults to
|
||||
@@ -374,7 +380,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
rs.getTimestamp("START_TIME"),
|
||||
rs.getTimestamp("END_TIME"),
|
||||
rs.getString("EXIT_MESSAGE"),
|
||||
getTaskArguments(id));
|
||||
getTaskArguments(id),
|
||||
rs.getString("ERROR_MESSAGE"));
|
||||
}
|
||||
|
||||
private Integer getNullableExitCode(ResultSet rs) throws SQLException {
|
||||
|
||||
@@ -56,17 +56,23 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
Date startTime, List<String> arguments) {
|
||||
long taskExecutionId = getNextExecutionId();
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
|
||||
startTime, null, null, arguments);
|
||||
startTime, null, null, arguments, null);
|
||||
taskExecutions.put(taskExecutionId, taskExecution);
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, String errorMessage) {
|
||||
TaskExecution taskExecution= taskExecutions.get(executionId);
|
||||
taskExecution.setEndTime(endTime);
|
||||
taskExecution.setExitCode(exitCode);
|
||||
taskExecution.setExitMessage(exitMessage);
|
||||
taskExecution.setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,6 +42,18 @@ public interface TaskExecutionDao {
|
||||
TaskExecution createTaskExecution( String taskName,
|
||||
Date startTime, List<String> arguments);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution}.
|
||||
*
|
||||
* @param executionId the id of the taskExecution to be updated.
|
||||
* @param exitCode the status of the task upon completion.
|
||||
* @param endTime the time the task completed.
|
||||
* @param exitMessage the message assigned to the task upon completion.
|
||||
* @param errorMessage error information available upon failure of a task.
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, String errorMessage);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution}.
|
||||
*
|
||||
|
||||
@@ -51,19 +51,25 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
this.taskExecutionDaoFactoryBean = taskExecutionDaoFactoryBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
return completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage) {
|
||||
String exitMessage, String errorMessage) {
|
||||
initialize();
|
||||
|
||||
validateExitInformation(executionId, exitCode, endTime);
|
||||
exitMessage = trimExitMessage(exitMessage);
|
||||
taskExecutionDao.completeTaskExecution(executionId, exitCode, endTime, exitMessage);
|
||||
taskExecutionDao.completeTaskExecution(executionId, exitCode, endTime, exitMessage, errorMessage);
|
||||
logger.debug("Updating: TaskExecution with executionId="+executionId
|
||||
+ " with the following {"
|
||||
+ "exitCode=" + exitCode
|
||||
+ ", endTime=" + endTime
|
||||
+ ", exitMessage='" + exitMessage + '\''
|
||||
+ ", errorMessage='" + errorMessage + '\''
|
||||
+ '}');
|
||||
|
||||
return taskExecutionDao.getTaskExecution(executionId);
|
||||
|
||||
@@ -6,6 +6,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR2(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR2(2500) ,
|
||||
ERROR_MESSAGE VARCHAR2(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ CREATE TABLE TASK_EXECUTION (
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED DATETIME
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user