Adds support for Task Execution Parent Ids

resolves #261
This commit is contained in:
Glenn Renfro
2017-01-06 09:42:10 -05:00
committed by Michael Minella
parent 91aaf0022c
commit acaaad89f3
37 changed files with 336 additions and 64 deletions

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.
@@ -184,15 +184,34 @@ public class TaskLifecycleListenerTests {
this.taskExplorer = context.getBean(TaskExplorer.class);
verifyTaskExecution(0, false, 0, null, "myid");
}
@Test
public void testParentExecutionId() {
ConfigurableEnvironment environment = new StandardEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
Map myMap = new HashMap();
myMap.put("spring.cloud.task.parentExecutionId", 789);
propertySources.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
context.setEnvironment(environment);
context.refresh();
this.taskExplorer = context.getBean(TaskExplorer.class);
verifyTaskExecution(0, false, 0, null, null, 789L);
}
private void verifyTaskExecution(int numberOfParams, boolean update) {
verifyTaskExecution(numberOfParams, update, 0, null, null);
}
private void verifyTaskExecution(int numberOfParams, boolean update,
Integer exitCode, Throwable exception, String externalExecutionId) {
verifyTaskExecution(numberOfParams, update, exitCode, exception,
externalExecutionId, null);
}
private void verifyTaskExecution(int numberOfParams, boolean update,
Integer exitCode, Throwable exception, String externalExecutionId,
Long parentExecutionId) {
Sort sort = new Sort("id");
@@ -206,6 +225,7 @@ public class TaskLifecycleListenerTests {
assertEquals(numberOfParams, taskExecution.getArguments().size());
assertEquals(exitCode, taskExecution.getExitCode());
assertEquals(externalExecutionId, taskExecution.getExternalExecutionId());
assertEquals(parentExecutionId, taskExecution.getParentExecutionId());
if(exception != null) {
assertTrue(taskExecution.getErrorMessage().length() > exception.getStackTrace().length);

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.
@@ -43,30 +43,30 @@ public class FindAllPagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "%PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION) TASK_EXECUTION_PAGE "
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, "

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.
@@ -44,34 +44,34 @@ public class WhereClausePagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, "
+ "LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = "
+ "'0000') TASK_EXECUTION_PAGE WHERE TMP_ROW_NUM >= 1 "

View File

@@ -162,6 +162,25 @@ public class SimpleTaskRepositoryJdbcTests {
expectedTaskExecution.getExternalExecutionId());
}
@Test
@DirtiesContext
public void startTaskExecutionWithParent() {
TaskExecution expectedTaskExecution =
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
expectedTaskExecution.setStartTime(new Date());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
expectedTaskExecution.setParentExecutionId(12345L);
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId(),
expectedTaskExecution.getParentExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@Test
@DirtiesContext
public void testCompleteTaskExecution() {

View File

@@ -115,7 +115,9 @@ public class SimpleTaskRepositoryMapTests {
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId(),
expectedTaskExecution.getParentExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@@ -135,6 +137,23 @@ public class SimpleTaskRepositoryMapTests {
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@Test
public void startTaskExecutionWithParent() {
TaskExecution expectedTaskExecution =
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
expectedTaskExecution.setStartTime(new Date());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
expectedTaskExecution.setParentExecutionId(12345L);
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@Test
public void testCompleteTaskExecution() {
TaskExecution expectedTaskExecution =

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.
@@ -47,8 +47,7 @@ public class TaskExecutionCreator {
* @return the taskExecution created.
*/
public static TaskExecution createAndStoreTaskExecutionNoParams(TaskRepository taskRepository) {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution = taskRepository.createTaskExecution();
TaskExecution expectedTaskExecution = taskRepository.createTaskExecution();
return expectedTaskExecution;
}

View File

@@ -159,6 +159,9 @@ public class TestVerifierUtils {
assertEquals("externalExecutionId must be equal",
expectedTaskExecution.getExternalExecutionId(),
actualTaskExecution.getExternalExecutionId());
assertEquals("parentExecutionId must be equal",
expectedTaskExecution.getParentExecutionId(),
actualTaskExecution.getParentExecutionId());
if (expectedTaskExecution.getArguments() != null) {
assertNotNull("arguments should not be null",