committed by
Michael Minella
parent
91aaf0022c
commit
acaaad89f3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -76,6 +76,9 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
|
||||
public static final String SPRING_CLOUD_TASK_STEP_NAME =
|
||||
"spring.cloud.task.step-name";
|
||||
|
||||
public static final String SPRING_CLOUD_TASK_PARENT_EXECUTION_ID =
|
||||
"spring.cloud.task.parentExecutionId";
|
||||
|
||||
public static final String SPRING_CLOUD_TASK_NAME = "spring.cloud.task.name";
|
||||
|
||||
private int maxWorkers = -1;
|
||||
@@ -268,6 +271,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
|
||||
taskExecution.getTaskName(),
|
||||
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
|
||||
workerStepExecution.getStepName())));
|
||||
arguments.add(formatArgument(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
|
||||
String.valueOf(taskExecution.getExecutionId())));
|
||||
|
||||
copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cloud.task.batch.partition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -160,6 +161,41 @@ public class DeployerPartitionHandlerTests {
|
||||
assertEquals("step1:partition1", resultStepExecution.getStepName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentExecutionId() throws Exception {
|
||||
|
||||
StepExecution masterStepExecution = createMasterStepExecution();
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step1");
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null,
|
||||
null, null, new ArrayList<String>(), null, null);
|
||||
|
||||
taskExecution.setTaskName("partitionedJobTask");
|
||||
|
||||
Set<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThreePartitions() throws Exception {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -37,7 +37,13 @@ public class TaskProperties {
|
||||
/**
|
||||
* An id that will be used by the task when updating the task execution.
|
||||
*/
|
||||
private Integer executionid;
|
||||
private Long executionid;
|
||||
|
||||
/**
|
||||
* The id of the parent task execution id that launched this task execution.
|
||||
* Defaults to null if task execution had no parent.
|
||||
*/
|
||||
private Long parentExecutionId;
|
||||
|
||||
/**
|
||||
* The prefix to append to the table names created by Spring Cloud Task.
|
||||
@@ -58,11 +64,11 @@ public class TaskProperties {
|
||||
this.externalExecutionId = externalExecutionId;
|
||||
}
|
||||
|
||||
public Integer getExecutionid() {
|
||||
public Long getExecutionid() {
|
||||
return executionid;
|
||||
}
|
||||
|
||||
public void setExecutionid(Integer executionid) {
|
||||
public void setExecutionid(Long executionid) {
|
||||
this.executionid = executionid;
|
||||
}
|
||||
|
||||
@@ -81,4 +87,12 @@ public class TaskProperties {
|
||||
public void setTablePrefix(String tablePrefix) {
|
||||
this.tablePrefix = tablePrefix;
|
||||
}
|
||||
|
||||
public Long getParentExecutionId() {
|
||||
return parentExecutionId;
|
||||
}
|
||||
|
||||
public void setParentExecutionId(Long parentExecutionId) {
|
||||
this.parentExecutionId = parentExecutionId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -201,7 +201,9 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
Assert.isNull(taskExecution.getEndTime(), String.format(
|
||||
"Invalid TaskExecution, ID %s task is already complete", taskProperties.getExecutionid()));
|
||||
this.taskExecution = this.taskRepository.startTaskExecution(taskProperties.getExecutionid(),
|
||||
this.taskNameResolver.getTaskName(), new Date(), args, taskProperties.getExternalExecutionId());
|
||||
this.taskNameResolver.getTaskName(), new Date(), args,
|
||||
taskProperties.getExternalExecutionId(),
|
||||
taskProperties.getParentExecutionId());
|
||||
}
|
||||
else {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
@@ -209,6 +211,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setArguments(args);
|
||||
taskExecution.setExternalExecutionId(taskProperties.getExternalExecutionId());
|
||||
taskExecution.setParentExecutionId(taskProperties.getParentExecutionId());
|
||||
this.taskExecution = this.taskRepository.createTaskExecution(
|
||||
taskExecution);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Represents the state of the Task for each execution.
|
||||
@@ -31,11 +30,17 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
|
||||
public class TaskExecution {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -87,7 +92,8 @@ public class TaskExecution {
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName,
|
||||
Date startTime, Date endTime,
|
||||
String exitMessage, List<String> arguments,
|
||||
String errorMessage, String externalExecutionId) {
|
||||
String errorMessage, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
|
||||
Assert.notNull(arguments, "arguments must not be null");
|
||||
this.executionId = executionId;
|
||||
@@ -99,6 +105,16 @@ public class TaskExecution {
|
||||
this.endTime = (endTime != null) ? (Date)endTime.clone() : null;
|
||||
this.errorMessage = errorMessage;
|
||||
this.externalExecutionId = externalExecutionId;
|
||||
this.parentExecutionId = parentExecutionId;
|
||||
}
|
||||
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName,
|
||||
Date startTime, Date endTime,
|
||||
String exitMessage, List<String> arguments,
|
||||
String errorMessage, String externalExecutionId) {
|
||||
|
||||
this(executionId, exitCode, taskName, startTime, endTime, exitMessage,
|
||||
arguments, errorMessage,externalExecutionId, null);
|
||||
}
|
||||
|
||||
public long getExecutionId() {
|
||||
@@ -169,16 +185,26 @@ public class TaskExecution {
|
||||
this.externalExecutionId = externalExecutionId;
|
||||
}
|
||||
|
||||
public Long getParentExecutionId() {
|
||||
return parentExecutionId;
|
||||
}
|
||||
|
||||
public void setParentExecutionId(Long parentExecutionId) {
|
||||
this.parentExecutionId = parentExecutionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskExecution{" +
|
||||
"executionId=" + executionId +
|
||||
", parentExecutionId=" + parentExecutionId +
|
||||
", exitCode=" + exitCode +
|
||||
", taskName='" + taskName + '\'' +
|
||||
", startTime=" + startTime +
|
||||
", endTime=" + endTime +
|
||||
", exitMessage='" + exitMessage + '\'' +
|
||||
", errorMessage='" + errorMessage + "\'" +
|
||||
", externalExecutionId='" + externalExecutionId + '\'' +
|
||||
", errorMessage='" + errorMessage + '\'' +
|
||||
", arguments=" + arguments +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -104,4 +104,21 @@ public interface TaskRepository {
|
||||
@Transactional
|
||||
void updateExternalExecutionId(long executionid,
|
||||
String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Notifies the repository that a taskExecution has has started.
|
||||
* @param executionid to the task execution to be updated.
|
||||
* @param taskName the name that associated with the task execution.
|
||||
* @param startTime the time task began.
|
||||
* @param arguments list of key/value pairs that configure the task.
|
||||
* @param externalExecutionId id assigned to the task by the platform.
|
||||
* @param parentExecutionId the parent task execution id.
|
||||
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
TaskExecution startTaskExecution(long executionid, String taskName,
|
||||
Date startTime,List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId);
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID ";
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, "
|
||||
+ "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID ";
|
||||
|
||||
public static final String FROM_CLAUSE = "%PREFIX%EXECUTION";
|
||||
|
||||
@@ -71,14 +72,16 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
public static final String TASK_NAME_WHERE_CLAUSE = "where TASK_NAME = ? ";
|
||||
|
||||
private static final String SAVE_TASK_EXECUTION = "INSERT into %PREFIX%EXECUTION"
|
||||
+ "(TASK_EXECUTION_ID, START_TIME, TASK_NAME, LAST_UPDATED, EXTERNAL_EXECUTION_ID)"
|
||||
+ "values (?, ?, ?, ?, ?)";
|
||||
+ "(TASK_EXECUTION_ID, START_TIME, TASK_NAME, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID)"
|
||||
+ "values (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
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 = ? where TASK_EXECUTION_ID = ?";
|
||||
+ "START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?, "
|
||||
+ "EXTERNAL_EXECUTION_ID = ?, PARENT_EXECUTION_ID = ? "
|
||||
+ "where TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String CHECK_TASK_EXECUTION_EXISTS = "SELECT COUNT(*) FROM "
|
||||
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = ?";
|
||||
@@ -92,7 +95,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, " +
|
||||
"START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, "
|
||||
+ "PARENT_EXECUTION_ID "
|
||||
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = ?";
|
||||
|
||||
private static final String FIND_ARGUMENT_FROM_ID = "SELECT TASK_EXECUTION_ID, "
|
||||
@@ -150,16 +154,27 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
long nextExecutionId = getNextExecutionId();
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(nextExecutionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId);
|
||||
|
||||
Object[] queryParameters = new Object[]{ nextExecutionId, startTime, taskName, new Date(), externalExecutionId};
|
||||
Object[] queryParameters = new Object[]{ nextExecutionId, startTime,
|
||||
taskName, new Date(), externalExecutionId,
|
||||
parentExecutionId};
|
||||
jdbcTemplate.update(
|
||||
getQuery(SAVE_TASK_EXECUTION),
|
||||
queryParameters,
|
||||
new int[]{ Types.BIGINT, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR });
|
||||
new int[]{ Types.BIGINT, Types.TIMESTAMP, Types.VARCHAR,
|
||||
Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT});
|
||||
insertTaskArguments(nextExecutionId, arguments);
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -167,14 +182,25 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId);
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
}
|
||||
|
||||
Object[] queryParameters = new Object[]{ startTime, taskName, new Date(), externalExecutionId, executionId};
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
|
||||
startTime, null, null, arguments,null, externalExecutionId, parentExecutionId);
|
||||
|
||||
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 });
|
||||
new int[]{ Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP,
|
||||
Types.VARCHAR, Types.BIGINT, Types.BIGINT });
|
||||
insertTaskArguments(executionId, arguments);
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -442,6 +468,10 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
long id = rs.getLong("TASK_EXECUTION_ID");
|
||||
Long parentExecutionId = rs.getLong("PARENT_EXECUTION_ID");
|
||||
if(rs.wasNull()) {
|
||||
parentExecutionId = null;
|
||||
}
|
||||
return new TaskExecution(id,
|
||||
getNullableExitCode(rs),
|
||||
rs.getString("TASK_NAME"),
|
||||
@@ -450,7 +480,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
rs.getString("EXIT_MESSAGE"),
|
||||
getTaskArguments(id),
|
||||
rs.getString("ERROR_MESSAGE"),
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"));
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"),
|
||||
parentExecutionId);
|
||||
}
|
||||
|
||||
private Integer getNullableExitCode(ResultSet rs) throws SQLException {
|
||||
|
||||
@@ -55,9 +55,15 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, String externalExecutionId, Long parentExecutionId) {
|
||||
long taskExecutionId = getNextExecutionId();
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId);
|
||||
startTime, null, null, arguments, null, externalExecutionId, parentExecutionId);
|
||||
taskExecutions.put(taskExecutionId, taskExecution);
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -65,12 +71,20 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionid) {
|
||||
TaskExecution taskExecution= taskExecutions.get(executionId);
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments,
|
||||
externalExecutionid, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionid,
|
||||
Long parentExecutionId) {
|
||||
TaskExecution taskExecution= taskExecutions.get(executionId);
|
||||
taskExecution.setTaskName(taskName);
|
||||
taskExecution.setStartTime(startTime);
|
||||
taskExecution.setArguments(arguments);
|
||||
taskExecution.setExternalExecutionId(externalExecutionid);
|
||||
taskExecution.setParentExecutionId(parentExecutionId);
|
||||
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,21 @@ public interface TaskExecutionDao {
|
||||
TaskExecution createTaskExecution( String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Save a new {@link TaskExecution}.
|
||||
*
|
||||
* @param taskName the name that associated with the task execution.
|
||||
* @param startTime the time task began.
|
||||
* @param arguments list of key/value pairs that configure the task.
|
||||
* @param externalExecutionId id assigned to the task by the platform
|
||||
* @param parentExecutionId the parent task execution id.
|
||||
* @return A fully qualified {@link TaskExecution} instance.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
TaskExecution createTaskExecution( String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as started.
|
||||
*
|
||||
@@ -56,6 +71,21 @@ public interface TaskExecutionDao {
|
||||
TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as started.
|
||||
*
|
||||
* @param executionId the id of the taskExecution to be updated.
|
||||
* @param taskName the name that associated with the task execution.
|
||||
* @param startTime the time task began.
|
||||
* @param arguments list of key/value pairs that configure the task.
|
||||
* @param externalExecutionId id assigned to the task by the platform
|
||||
* @param parentExecutionId the parent task execution id.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as completed.
|
||||
*
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -109,7 +108,8 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
taskExecution.getTaskName(),
|
||||
taskExecution.getStartTime(),
|
||||
taskExecution.getArguments(),
|
||||
taskExecution.getExternalExecutionId());
|
||||
taskExecution.getExternalExecutionId(),
|
||||
taskExecution.getParentExecutionId());
|
||||
logger.debug("Creating: " + taskExecution.toString());
|
||||
return daoTaskExecution;
|
||||
}
|
||||
@@ -127,11 +127,8 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
initialize();
|
||||
TaskExecution taskExecution =
|
||||
taskExecutionDao.startTaskExecution(executionid, taskName, startTime, arguments, externalExecutionId);
|
||||
logger.debug("Starting: " + taskExecution.toString());
|
||||
return taskExecution;
|
||||
return startTaskExecution(executionid, taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,6 +137,19 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
taskExecutionDao.updateExternalExecutionId(executionid, externalExecutionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
initialize();
|
||||
TaskExecution taskExecution =
|
||||
taskExecutionDao.startTaskExecution(executionid, taskName,
|
||||
startTime, arguments, externalExecutionId,
|
||||
parentExecutionId);
|
||||
logger.debug("Starting: " + taskExecution.toString());
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the taskExecutionDao associated with this repository.
|
||||
* @return the taskExecutionDao
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -0,0 +1 @@
|
||||
alter table task_execution add PARENT_EXECUTION_ID BIGINT;
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR2(2500) ,
|
||||
ERROR_MESSAGE VARCHAR2(2500) ,
|
||||
LAST_UPDATED TIMESTAMP,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR2(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR2(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -8,7 +8,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP ,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
ERROR_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED DATETIME ,
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255)
|
||||
EXTERNAL_EXECUTION_ID VARCHAR(255),
|
||||
PARENT_EXECUTION_ID BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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, "
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -194,6 +194,19 @@ following property:
|
||||
spring.cloud.task.external-execution-id=<externalTaskId>
|
||||
```
|
||||
|
||||
[[features-parent_task_id]]
|
||||
=== Parent Task Id
|
||||
|
||||
Spring Cloud Task allows a user to store an parent task Id for each
|
||||
TaskExecution. An example of this would be a task that executes another task
|
||||
or tasks and the user would like to store what task launched the child tasks.
|
||||
In order to configure your Task to set a parent TaskExecutionId add the
|
||||
following property on the child task:
|
||||
|
||||
```
|
||||
spring.cloud.task.parent-execution-id=<parentExecutionTaskId>
|
||||
```
|
||||
|
||||
[[features-task-configurer]]
|
||||
=== TaskConfigurer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user