TaskExecution should use long id
* Replace String executionId with a long executionId * Add externalExecutionID that is a String resolves spring-cloud/spring-cloud-task#47
This commit is contained in:
committed by
Michael Minella
parent
1c3bb94bbd
commit
584cfb90f5
@@ -17,8 +17,8 @@ package org.springframework.cloud.task.listener;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -142,13 +142,10 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
private void doTaskStart() {
|
||||
|
||||
if(!started) {
|
||||
this.taskExecution = new TaskExecution(this.taskRepository.getNextExecutionId(),
|
||||
0, this.taskNameResolver.getTaskName(), new Date(), null, null, null,
|
||||
new ArrayList<String>(0), null);
|
||||
|
||||
String executionId = UUID.randomUUID().toString();
|
||||
this.taskExecution = new TaskExecution();
|
||||
|
||||
this.taskExecution.setTaskName(taskNameResolver.getTaskName());
|
||||
this.taskExecution.setStartTime(new Date());
|
||||
this.taskExecution.setExecutionId(executionId);
|
||||
this.taskRepository.createTaskExecution(this.taskExecution);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -32,7 +32,12 @@ public class TaskExecution {
|
||||
/**
|
||||
* The unique id associated with the task execution.
|
||||
*/
|
||||
private String executionId;
|
||||
private long executionId;
|
||||
|
||||
/**
|
||||
* Id provided by an external system for the given task execution.
|
||||
*/
|
||||
private String externalExecutionID;
|
||||
|
||||
/**
|
||||
* The recorded exit code for the task.
|
||||
@@ -73,14 +78,15 @@ public class TaskExecution {
|
||||
parameters = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TaskExecution(String executionId, int exitCode, String taskName,
|
||||
public TaskExecution(long executionId, int exitCode, String taskName,
|
||||
Date startTime, Date endTime, String statusCode,
|
||||
String exitMessage, List<String> parameters) {
|
||||
String exitMessage, List<String> parameters,
|
||||
String externalExecutionID) {
|
||||
|
||||
Assert.hasText(executionId, "executionId must not be null nor empty");
|
||||
Assert.notNull(parameters, "parameters must not be null");
|
||||
Assert.notNull(startTime, "startTime must not be null");
|
||||
this.executionId = executionId;
|
||||
this.externalExecutionID = externalExecutionID;
|
||||
this.exitCode = exitCode;
|
||||
this.taskName = taskName;
|
||||
this.statusCode = statusCode;
|
||||
@@ -90,14 +96,10 @@ public class TaskExecution {
|
||||
setEndTime(endTime);
|
||||
}
|
||||
|
||||
public String getExecutionId() {
|
||||
public long getExecutionId() {
|
||||
return executionId;
|
||||
}
|
||||
|
||||
public void setExecutionId(String executionId) {
|
||||
this.executionId = executionId;
|
||||
}
|
||||
|
||||
public int getExitCode() {
|
||||
return exitCode;
|
||||
}
|
||||
@@ -154,10 +156,19 @@ public class TaskExecution {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getExternalExecutionID() {
|
||||
return externalExecutionID;
|
||||
}
|
||||
|
||||
public void setExternalExecutionID(String externalExecutionID) {
|
||||
this.externalExecutionID = externalExecutionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskExecution{" +
|
||||
"executionId='" + executionId + '\'' +
|
||||
"executionId=" + executionId +
|
||||
", externalExecutionID='" + externalExecutionID + '\'' +
|
||||
", exitCode=" + exitCode +
|
||||
", taskName='" + taskName + '\'' +
|
||||
", startTime=" + startTime +
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface TaskExplorer {
|
||||
* @param executionId the task execution id
|
||||
* @return the {@link TaskExecution} with this id, or null if not found
|
||||
*/
|
||||
public TaskExecution getTaskExecution(String executionId);
|
||||
public TaskExecution getTaskExecution(long executionId);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,4 +40,10 @@ public interface TaskRepository {
|
||||
*/
|
||||
@Transactional
|
||||
public void createTaskExecution(TaskExecution taskExecution);
|
||||
|
||||
/**
|
||||
* Retrieves the next available execution id for a task execution.
|
||||
* @return long containing the executionId.
|
||||
*/
|
||||
public long getNextExecutionId();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -52,15 +53,16 @@ import org.springframework.util.StringUtils;
|
||||
public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
|
||||
public static String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
|
||||
public static String SELECT_CLAUSE = "TASK_EXECUTION_ID, TASK_EXTERNAL_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE ";
|
||||
|
||||
public static String FROM_CLAUSE = "%PREFIX%EXECUTION";
|
||||
|
||||
private static final String SAVE_TASK_EXECUTION = "INSERT into %PREFIX%EXECUTION"
|
||||
+ "(TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE) values (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
+ "(TASK_EXECUTION_ID, TASK_EXTERNAL_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE)"
|
||||
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String CREATE_TASK_PARAMETER = "INSERT into "
|
||||
+ "%PREFIX%EXECUTION_PARAMS(TASK_EXECUTION_ID, TASK_PARAM ) values (?, ?)";
|
||||
@@ -70,12 +72,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private static final String UPDATE_TASK_EXECUTION = "UPDATE %PREFIX%EXECUTION set "
|
||||
+ "START_TIME = ?, END_TIME = ?, TASK_NAME = ?, EXIT_CODE = ?, "
|
||||
+ "EXIT_MESSAGE = ?, LAST_UPDATED = ?, STATUS_CODE = ? "
|
||||
+ "where TASK_EXECUTION_ID = ?";
|
||||
+ "EXIT_MESSAGE = ?, LAST_UPDATED = ?, STATUS_CODE = ?, "
|
||||
+ "TASK_EXTERNAL_EXECUTION_ID = ? 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, STATUS_CODE "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE, TASK_EXTERNAL_EXECUTION_ID "
|
||||
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String FIND_PARAMS_FROM_ID = "SELECT TASK_EXECUTION_ID, "
|
||||
@@ -89,13 +91,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private static final String FIND_RUNNING_TASK_EXECUTIONS = "SELECT TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE, TASK_EXTERNAL_EXECUTION_ID "
|
||||
+ "from %PREFIX%EXECUTION where TASK_NAME = ? AND END_TIME IS NULL "
|
||||
+ "order by TASK_EXECUTION_ID";
|
||||
|
||||
private static final String FIND_TASK_EXECUTIONS_BY_NAME = "SELECT TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE "
|
||||
+ "EXIT_MESSAGE, LAST_UPDATED, STATUS_CODE, TASK_EXTERNAL_EXECUTION_ID "
|
||||
+ "from %PREFIX%EXECUTION where TASK_NAME = ? "
|
||||
+ "order by TASK_EXECUTION_ID "
|
||||
+ "LIMIT ? OFFSET ?";
|
||||
@@ -110,7 +112,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
Map<String, Order> orderMap;
|
||||
private Map<String, Order> orderMap;
|
||||
|
||||
private DataFieldMaxValueIncrementer taskIncrementer;
|
||||
|
||||
public JdbcTaskExecutionDao(DataSource dataSource) {
|
||||
Assert.notNull(dataSource);
|
||||
@@ -119,12 +123,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
orderMap = new TreeMap<>();
|
||||
orderMap.put("START_TIME", Order.DESCENDING);
|
||||
orderMap.put("TASK_EXECUTION_ID", Order.DESCENDING);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTaskExecution(TaskExecution taskExecution) {
|
||||
Object[] parameters = new Object[]{ taskExecution.getExecutionId(),
|
||||
taskExecution.getExternalExecutionID(),
|
||||
taskExecution.getStartTime(), taskExecution.getEndTime(),
|
||||
taskExecution.getTaskName(), taskExecution.getExitCode(),
|
||||
taskExecution.getExitMessage(), new Date(),
|
||||
@@ -132,8 +136,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
jdbcTemplate.update(
|
||||
getQuery(SAVE_TASK_EXECUTION),
|
||||
parameters,
|
||||
new int[]{ Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR,
|
||||
Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR });
|
||||
new int[]{ Types.BIGINT, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP,
|
||||
Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP,
|
||||
Types.VARCHAR });
|
||||
insertTaskParameters(taskExecution.getExecutionId(), taskExecution.getParameters());
|
||||
}
|
||||
|
||||
@@ -149,12 +154,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
Object[] parameters = new Object[]{ taskExecution.getStartTime(), taskExecution.getEndTime(),
|
||||
taskExecution.getTaskName(), taskExecution.getExitCode(),
|
||||
taskExecution.getExitMessage(), new Date(), taskExecution.getStatusCode(),
|
||||
taskExecution.getExecutionId() };
|
||||
taskExecution.getExternalExecutionID(), taskExecution.getExecutionId()};
|
||||
jdbcTemplate.update(
|
||||
getQuery(UPDATE_TASK_EXECUTION),
|
||||
parameters,
|
||||
new int[]{ Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER,
|
||||
Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR });
|
||||
Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.BIGINT});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +175,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution getTaskExecution(String executionId) {
|
||||
public TaskExecution getTaskExecution(long executionId) {
|
||||
try {
|
||||
TaskExecution taskExecution = jdbcTemplate.queryForObject(getQuery(GET_EXECUTION_BY_ID),
|
||||
new TaskExecutionRowMapper(), executionId);
|
||||
@@ -248,6 +254,14 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
return new PageImpl<TaskExecution>(resultList, pageable, getTaskExecutionCount());
|
||||
}
|
||||
|
||||
public void setTaskIncrementer(DataFieldMaxValueIncrementer taskIncrementer) {
|
||||
this.taskIncrementer = taskIncrementer;
|
||||
}
|
||||
|
||||
public long getNextExecutionId(){
|
||||
return taskIncrementer.nextLongValue();
|
||||
}
|
||||
|
||||
private String getQuery(String base) {
|
||||
return StringUtils.replace(base, "%PREFIX%", tablePrefix);
|
||||
}
|
||||
@@ -259,7 +273,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
* @param executionId The executionId to which the params are associated.
|
||||
* @param taskParameters The parameters to be stored.
|
||||
*/
|
||||
private void insertTaskParameters(String executionId, List<String> taskParameters) {
|
||||
private void insertTaskParameters(long executionId, List<String> taskParameters) {
|
||||
for (String param : taskParameters) {
|
||||
insertParameter(executionId, param);
|
||||
}
|
||||
@@ -269,13 +283,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
* Convenience method that inserts an individual records into the
|
||||
* TASK_EXECUTION_PARAMS table.
|
||||
*/
|
||||
private void insertParameter(String executionId, String param) {
|
||||
private void insertParameter(long executionId, String param) {
|
||||
int[] argTypes = new int[]{ Types.VARCHAR, Types.VARCHAR };
|
||||
Object[] args = new Object[]{ executionId, param };
|
||||
jdbcTemplate.update(getQuery(CREATE_TASK_PARAMETER), args, argTypes);
|
||||
}
|
||||
|
||||
private List<String> getTaskParameters(String executionId){
|
||||
private List<String> getTaskParameters(long executionId){
|
||||
final List<String> params= new ArrayList<>();
|
||||
RowCallbackHandler handler = new RowCallbackHandler() {
|
||||
@Override
|
||||
@@ -287,7 +301,6 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
jdbcTemplate.query(getQuery(FIND_PARAMS_FROM_ID), new Object[] { executionId },
|
||||
handler);
|
||||
return params;
|
||||
|
||||
}
|
||||
/**
|
||||
* Re-usable mapper for {@link TaskExecution} instances.
|
||||
@@ -300,16 +313,16 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
@Override
|
||||
public TaskExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
String id = rs.getString("TASK_EXECUTION_ID");
|
||||
TaskExecution taskExecution=new TaskExecution();
|
||||
taskExecution.setExecutionId(id);
|
||||
taskExecution.setStartTime(rs.getTimestamp("START_TIME"));
|
||||
taskExecution.setEndTime(rs.getTimestamp("END_TIME"));
|
||||
taskExecution.setExitCode(rs.getInt("EXIT_CODE"));
|
||||
taskExecution.setExitMessage(rs.getString("EXIT_MESSAGE"));
|
||||
taskExecution.setStatusCode(rs.getString("STATUS_CODE"));
|
||||
taskExecution.setTaskName(rs.getString("TASK_NAME"));
|
||||
taskExecution.setParameters(getTaskParameters(id));
|
||||
long id = rs.getLong("TASK_EXECUTION_ID");
|
||||
TaskExecution taskExecution=new TaskExecution(id,
|
||||
rs.getInt("EXIT_CODE"),
|
||||
rs.getString("TASK_NAME"),
|
||||
rs.getTimestamp("START_TIME"),
|
||||
rs.getTimestamp("END_TIME"),
|
||||
rs.getString("STATUS_CODE"),
|
||||
rs.getString("EXIT_MESSAGE"),
|
||||
getTaskParameters(id),
|
||||
rs.getString("TASK_EXTERNAL_EXECUTION_ID"));
|
||||
return taskExecution;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -38,7 +39,9 @@ import org.springframework.data.domain.Pageable;
|
||||
*/
|
||||
public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private ConcurrentMap<String, TaskExecution> taskExecutions;
|
||||
private ConcurrentMap<Long, TaskExecution> taskExecutions;
|
||||
|
||||
private final AtomicLong currentId = new AtomicLong(0L);
|
||||
|
||||
public MapTaskExecutionDao() {
|
||||
taskExecutions = new ConcurrentHashMap<>();
|
||||
@@ -55,14 +58,14 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution getTaskExecution(String executionId) {
|
||||
public TaskExecution getTaskExecution(long executionId) {
|
||||
return taskExecutions.get(executionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTaskExecutionCountByTaskName(String taskName) {
|
||||
int count = 0;
|
||||
for (Map.Entry<String, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
for (Map.Entry<Long, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName)) {
|
||||
count++;
|
||||
}
|
||||
@@ -78,7 +81,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public Set<TaskExecution> findRunningTaskExecutions(String taskName) {
|
||||
Set<TaskExecution> result = getTaskExecutionTreeSet();
|
||||
for (Map.Entry<String, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
for (Map.Entry<Long, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName) &&
|
||||
entry.getValue().getEndTime() == null) {
|
||||
result.add(entry.getValue());
|
||||
@@ -91,7 +94,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
public List<TaskExecution> getTaskExecutionsByName(String taskName, int start, int count) {
|
||||
List<TaskExecution> result = new ArrayList<>();
|
||||
Set<TaskExecution> filteredSet = getTaskExecutionTreeSet();
|
||||
for (Map.Entry<String, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
for (Map.Entry<Long, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName)) {
|
||||
filteredSet.add(entry.getValue());
|
||||
}
|
||||
@@ -103,7 +106,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public List<String> getTaskNames() {
|
||||
Set<String> result = new TreeSet<>();
|
||||
for (Map.Entry<String, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
for (Map.Entry<Long, TaskExecution> entry : taskExecutions.entrySet()) {
|
||||
result.add(entry.getValue().getTaskName());
|
||||
}
|
||||
return new ArrayList<String>(result);
|
||||
@@ -122,21 +125,24 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
getTaskExecutionCount());
|
||||
}
|
||||
|
||||
public Map<String, TaskExecution> getTaskExecutions() {
|
||||
public Map<Long, TaskExecution> getTaskExecutions() {
|
||||
return Collections.unmodifiableMap(taskExecutions);
|
||||
}
|
||||
|
||||
public long getNextExecutionId(){
|
||||
return currentId.getAndIncrement();
|
||||
}
|
||||
|
||||
private TreeSet<TaskExecution> getTaskExecutionTreeSet() {
|
||||
return new TreeSet<TaskExecution>(new Comparator<TaskExecution>() {
|
||||
@Override
|
||||
public int compare(TaskExecution e1, TaskExecution e2) {
|
||||
int result = e1.getStartTime().compareTo(e2.getStartTime());
|
||||
if (result == 0){
|
||||
result = e1.getExecutionId().compareTo(e2.getExecutionId());
|
||||
result = Long.valueOf(e1.getExecutionId()).compareTo(e2.getExecutionId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ public interface TaskExecutionDao {
|
||||
/**
|
||||
* Retrieves a task execution from the task repository.
|
||||
*
|
||||
* @param executionId the uuid associated with the task execution.
|
||||
* @param executionId the id associated with the task execution.
|
||||
* @return a fully qualified TaskExecution instance.
|
||||
*/
|
||||
TaskExecution getTaskExecution(String executionId);
|
||||
TaskExecution getTaskExecution(long executionId);
|
||||
|
||||
/**
|
||||
* Retrieves current number of task executions for a taskName.
|
||||
@@ -100,4 +100,10 @@ public interface TaskExecutionDao {
|
||||
*/
|
||||
|
||||
public Page<TaskExecution> findAll(Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves the next available execution id for a task execution.
|
||||
* @return long containing the executionId.
|
||||
*/
|
||||
public long getNextExecutionId();
|
||||
}
|
||||
|
||||
@@ -20,10 +20,13 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
|
||||
import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao;
|
||||
import org.springframework.cloud.task.repository.dao.TaskExecutionDao;
|
||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
|
||||
/**
|
||||
* Automates the creation of a {@link SimpleTaskRepository} which will persist task
|
||||
@@ -42,6 +45,8 @@ public class JdbcTaskRepositoryFactoryBean implements FactoryBean<TaskRepository
|
||||
|
||||
private String tablePrefix = DEFAULT_TABLE_PREFIX;
|
||||
|
||||
private DataFieldMaxValueIncrementerFactory incrementerFactory;
|
||||
|
||||
public JdbcTaskRepositoryFactoryBean(){
|
||||
|
||||
}
|
||||
@@ -50,6 +55,7 @@ public class JdbcTaskRepositoryFactoryBean implements FactoryBean<TaskRepository
|
||||
if(dataSource != null) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +88,18 @@ public class JdbcTaskRepositoryFactoryBean implements FactoryBean<TaskRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
private TaskExecutionDao createJdbcTaskExecutionDao() {
|
||||
private TaskExecutionDao createJdbcTaskExecutionDao() {
|
||||
JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(dataSource);
|
||||
String databaseType = null;
|
||||
try {
|
||||
databaseType = org.springframework.batch.support.DatabaseType.fromMetaData(dataSource).name();
|
||||
}
|
||||
catch (MetaDataAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
dao.setTaskIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "SEQ"));
|
||||
dao.setTablePrefix(tablePrefix);
|
||||
return dao;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SimpleTaskExplorer implements TaskExplorer{
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution getTaskExecution(String executionId) {
|
||||
public TaskExecution getTaskExecution(long executionId) {
|
||||
return taskExecutionDao.getTaskExecution(executionId);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
public static final int MAX_EXIT_MESSAGE_SIZE = 2500;
|
||||
public static final int MAX_TASK_NAME_SIZE = 100;
|
||||
public static final int MAX_STATUS_CODE_SIZE = 10;
|
||||
public static final int MAX_EXECUTION_ID_SIZE = 100;
|
||||
public static final int MAX_EXTERNAL_EXECUTION_ID_SIZE = 100;
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SimpleTaskRepository.class);
|
||||
|
||||
@@ -56,6 +56,10 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
logger.info("Creating: " + taskExecution.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNextExecutionId() {
|
||||
return taskExecutionDao.getNextExecutionId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the taskExecutionDao associated with this repository.
|
||||
@@ -72,7 +76,6 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
*/
|
||||
private void validateTaskExecution(TaskExecution taskExecution) {
|
||||
Assert.notNull(taskExecution, "taskExecution should not be null");
|
||||
Assert.hasText(taskExecution.getExecutionId(), "taskExecutionId should not be null");
|
||||
Assert.notNull(taskExecution.getStartTime(), "TaskExecution start time cannot be null.");
|
||||
|
||||
if (taskExecution.getTaskName() != null &&
|
||||
@@ -85,9 +88,10 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
throw new IllegalArgumentException("StatusCode length exceeds "
|
||||
+ MAX_STATUS_CODE_SIZE + " characters");
|
||||
}
|
||||
if (taskExecution.getExecutionId().length() > MAX_EXECUTION_ID_SIZE) {
|
||||
throw new IllegalArgumentException("ExecutionID length exceeds "
|
||||
+ MAX_EXECUTION_ID_SIZE + " characters");
|
||||
if (taskExecution.getExternalExecutionID() != null &&
|
||||
taskExecution.getExternalExecutionID().length() > MAX_EXTERNAL_EXECUTION_ID_SIZE) {
|
||||
throw new IllegalArgumentException("externalExecutionID length exceeds "
|
||||
+ MAX_EXTERNAL_EXECUTION_ID_SIZE + " characters");
|
||||
}
|
||||
//Trim the exit message
|
||||
if(taskExecution.getExitMessage() != null &&
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
CREATE TABLE TASK_EXECUTION (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL PRIMARY KEY ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
|
||||
TASK_EXTERNAL_EXECUTION_ID VARCHAR(100) ,
|
||||
START_TIME TIMESTAMP DEFAULT NULL ,
|
||||
END_TIME TIMESTAMP DEFAULT NULL ,
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
@@ -11,8 +12,12 @@ CREATE TABLE TASK_EXECUTION (
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||
TASK_PARAM VARCHAR(250) ,
|
||||
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
CREATE TABLE TASK_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
CREATE TABLE TASK_EXECUTION (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL PRIMARY KEY ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
|
||||
TASK_EXTERNAL_EXECUTION_ID VARCHAR(100),
|
||||
START_TIME DATETIME DEFAULT NULL ,
|
||||
END_TIME DATETIME DEFAULT NULL ,
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
@@ -11,8 +12,17 @@ CREATE TABLE TASK_EXECUTION (
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||
TASK_PARAM VARCHAR(250) ,
|
||||
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
|
||||
CREATE TABLE TASK_SEQ (
|
||||
ID BIGINT NOT NULL,
|
||||
UNIQUE_KEY CHAR(1) NOT NULL,
|
||||
constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
INSERT INTO TASK_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
CREATE TABLE TASK_EXECUTION (
|
||||
TASK_EXECUTION_ID VARCHAR2(100) NOT NULL PRIMARY KEY ,
|
||||
TASK_EXECUTION_ID NUMBER NOT NULL PRIMARY KEY ,
|
||||
TASK_EXTERNAL_EXECUTION_ID VARCHAR2(100),
|
||||
START_TIME TIMESTAMP DEFAULT NULL ,
|
||||
END_TIME TIMESTAMP DEFAULT NULL ,
|
||||
TASK_NAME VARCHAR2(100) ,
|
||||
@@ -11,8 +12,10 @@ CREATE TABLE TASK_EXECUTION (
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
TASK_EXECUTION_ID VARCHAR2(100) NOT NULL ,
|
||||
TASK_EXECUTION_ID NUMBER NOT NULL ,
|
||||
TASK_PARAM VARCHAR2(250) ,
|
||||
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
CREATE SEQUENCE TASK_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NOCYCLE;
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
CREATE TABLE TASK_EXECUTION (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL PRIMARY KEY ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
|
||||
TASK_EXTERNAL_EXECUTION_ID VARCHAR(100) ,
|
||||
START_TIME TIMESTAMP DEFAULT NULL ,
|
||||
END_TIME TIMESTAMP DEFAULT NULL ,
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
@@ -11,8 +12,10 @@ CREATE TABLE TASK_EXECUTION (
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
TASK_EXECUTION_ID VARCHAR(100) NOT NULL ,
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||
TASK_PARAM VARCHAR(250) ,
|
||||
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
CREATE SEQUENCE TASK_SEQ MAXVALUE 9223372036854775807 NO CYCLE;
|
||||
Reference in New Issue
Block a user