Added ability to update externalExecutionId

resolves #259
This commit is contained in:
Glenn Renfro
2017-01-03 17:13:15 -05:00
committed by Eric Bottard
parent 1185421803
commit 2eb1c49e12
8 changed files with 138 additions and 14 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.
@@ -83,15 +83,25 @@ public interface TaskRepository {
/**
* 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 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.
* @return
* @return TaskExecution created based on the parameters.
*/
@Transactional
TaskExecution startTaskExecution(long executionid, String taskName,
Date startTime,List<String> arguments, String externalExecutionId);
/**
* Notifies the repository to update the taskExecution's externalExecutionId.
*
* @param executionid to the task execution to be updated.
* @param externalExecutionId id assigned to the task by the platform.
*/
@Transactional
void updateExternalExecutionId(long executionid,
String externalExecutionId);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -86,6 +86,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
+ "END_TIME = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, ERROR_MESSAGE = ?, "
+ "LAST_UPDATED = ? where TASK_EXECUTION_ID = ?";
private static final String UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID = "UPDATE %PREFIX%EXECUTION set "
+ "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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
@@ -313,6 +316,19 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
}
}
@Override
public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
Object[] parameters = new Object[]{externalExecutionId,
taskExecutionId};
if (jdbcTemplate.update(
getQuery(UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID),
parameters,
new int[]{Types.VARCHAR, Types.BIGINT}) != 1) {
throw new IllegalStateException("Invalid TaskExecution, ID "
+ taskExecutionId + " not found.");
}
}
private Page<TaskExecution> queryForPageableResults(Pageable pageable,
String selectClause,
String fromClause,

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.
@@ -32,6 +32,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
/**
* Stores Task Execution Information to a in-memory map.
@@ -203,6 +204,14 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
}
}
@Override
public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
TaskExecution taskExecution = taskExecutions.get(taskExecutionId);
Assert.notNull(taskExecution, "Invalid TaskExecution, ID "
+ taskExecutionId + " not found.");
taskExecution.setExternalExecutionId(externalExecutionId);
}
public ConcurrentMap<Long, Set<Long>> getBatchJobAssociations() {
return batchJobAssociations;
}

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.
@@ -163,4 +163,12 @@ public interface TaskExecutionDao {
* @return a <code>Set</code> of the ids of the job executions executed within the task.
*/
Set<Long> getJobExecutionIdsByTaskExecutionId(long taskExecutionId);
/**
* Updates the externalExecutionId for the execution id specified.
* @param taskExecutionId the execution id for the task to be updated.
* @param externalExecutionId the new externalExecutionId.
*/
void updateExternalExecutionId(long taskExecutionId,
String externalExecutionId);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -134,6 +134,12 @@ public class SimpleTaskRepository implements TaskRepository {
return taskExecution;
}
@Override
public void updateExternalExecutionId(long executionid, String externalExecutionId) {
initialize();
taskExecutionDao.updateExternalExecutionId(executionid, externalExecutionId);
}
/**
* Retrieves the taskExecutionDao associated with this repository.
* @return the taskExecutionDao