Do not update the externalExecutionId if null when starting TaskExecution

resolves #271
This commit is contained in:
Glenn Renfro
2017-01-16 10:26:58 -05:00
committed by Michael Minella
parent 2b8e5799f7
commit a7fe76c7d6
4 changed files with 96 additions and 17 deletions

View File

@@ -78,10 +78,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
private static final String CREATE_TASK_ARGUMENT = "INSERT into "
+ "%PREFIX%EXECUTION_PARAMS(TASK_EXECUTION_ID, TASK_PARAM ) values (?, ?)";
private static final String START_TASK_EXECUTION = "UPDATE %PREFIX%EXECUTION set "
+ "START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?, "
+ "EXTERNAL_EXECUTION_ID = ?, PARENT_EXECUTION_ID = ? "
+ "where TASK_EXECUTION_ID = ?";
private static final String START_TASK_EXECUTION_PREFIX = "UPDATE %PREFIX%EXECUTION set "
+ "START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?";
private static final String START_TASK_EXECUTION_EXTERNAL_ID_SUFFIX = ", "
+ "EXTERNAL_EXECUTION_ID = ?, PARENT_EXECUTION_ID = ? where TASK_EXECUTION_ID = ?";
private static final String START_TASK_EXECUTION_SUFFIX = ", PARENT_EXECUTION_ID = ? where TASK_EXECUTION_ID = ?";
private static final String CHECK_TASK_EXECUTION_EXISTS = "SELECT COUNT(*) FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = ?";
@@ -180,7 +183,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
}
@Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
public TaskExecution startTaskExecution(long executionId, String taskName,
Date startTime, List<String> arguments,
String externalExecutionId) {
return startTaskExecution(executionId, taskName, startTime, arguments,
externalExecutionId, null);
@@ -192,15 +196,25 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
String externalExecutionId, Long parentExecutionId) {
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
startTime, null, null, arguments,null, externalExecutionId, parentExecutionId);
Object[] queryParameters;
int[] argTypes;
String updateString = START_TASK_EXECUTION_PREFIX;
if(externalExecutionId == null) {
queryParameters = new Object[]{startTime, taskName,
new Date(), parentExecutionId, executionId};
updateString += START_TASK_EXECUTION_SUFFIX;
argTypes = new int[]{Types.TIMESTAMP, Types.VARCHAR,
Types.TIMESTAMP, Types.BIGINT, Types.BIGINT};
}
else {
queryParameters = new Object[]{ startTime, taskName,
new Date(), externalExecutionId, parentExecutionId, executionId};
argTypes = new int[]{ Types.TIMESTAMP, Types.VARCHAR,
Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT, Types.BIGINT };
updateString += START_TASK_EXECUTION_EXTERNAL_ID_SUFFIX;
}
Object[] queryParameters = new Object[]{ startTime, taskName,
new Date(), externalExecutionId,
parentExecutionId, executionId};
jdbcTemplate.update(
getQuery(START_TASK_EXECUTION),
queryParameters,
new int[]{ Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP,
Types.VARCHAR, Types.BIGINT, Types.BIGINT });
jdbcTemplate.update(getQuery(updateString), queryParameters, argTypes);
insertTaskArguments(executionId, arguments);
return taskExecution;
}

View File

@@ -83,9 +83,10 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
taskExecution.setTaskName(taskName);
taskExecution.setStartTime(startTime);
taskExecution.setArguments(arguments);
taskExecution.setExternalExecutionId(externalExecutionid);
taskExecution.setParentExecutionId(parentExecutionId);
if(externalExecutionid != null) {
taskExecution.setExternalExecutionId(externalExecutionid);
}
return taskExecution;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 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.
@@ -166,6 +166,40 @@ public class JdbcTaskExecutionDaoTests {
assertEquals("FOO3", taskExecution.getTaskName());
}
@Test
@DirtiesContext
public void testStartExecutionWithNullExternalExecutionIdExisting() {
TaskExecution expectedTaskExecution =
initializeTaskExecutionWithExternalExecutionId();
dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
null);
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
}
@Test
@DirtiesContext
public void testStartExecutionWithNullExternalExecutionIdNonExisting() {
TaskExecution expectedTaskExecution =
initializeTaskExecutionWithExternalExecutionId();
dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
"BAR");
expectedTaskExecution.setExternalExecutionId("BAR");
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
}
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
"FOO1");
}
private Iterator<TaskExecution> getPageIterator(int pageNum, int pageSize, Sort sort) {
Pageable pageable = (sort == null) ?
new PageRequest(pageNum, pageSize) :

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 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.
@@ -137,4 +137,34 @@ public class MapTaskExecutionDaoTests {
assertNull(this.dao.getTaskExecutionIdByJobExecutionId(789L));
}
@Test
public void testStartExecutionWithNullExternalExecutionIdExisting(){
TaskExecution expectedTaskExecution =
initializeTaskExecutionWithExternalExecutionId();
Map<Long, TaskExecution> taskExecutionMap = this.dao.getTaskExecutions();
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
null);
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
}
@Test
public void testStartExecutionWithNullExternalExecutionIdNonExisting(){
TaskExecution expectedTaskExecution =
initializeTaskExecutionWithExternalExecutionId();
Map<Long, TaskExecution> taskExecutionMap = this.dao.getTaskExecutions();
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
"BAR");
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
}
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
"FOO1");
}
}