Java Code Examples for org.springframework.cloud.task.repository.TaskExecution#getExecutionId()

The following examples show how to use org.springframework.cloud.task.repository.TaskExecution#getExecutionId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobCommandTests.java    From spring-cloud-dataflow with Apache License 2.0 9 votes vote down vote up
private static long createSampleJob(String jobName, int jobExecutionCount) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	jobInstances.add(instance);
	TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	Map<String, JobParameter> jobParameterMap = new HashMap<>();
	jobParameterMap.put("foo", new JobParameter("FOO", true));
	jobParameterMap.put("bar", new JobParameter("BAR", false));
	JobParameters jobParameters = new JobParameters(jobParameterMap);
	JobExecution jobExecution;
	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance, jobParameters, null);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		StepExecution stepExecution = new StepExecution("foobar", jobExecution);
		jobRepository.add(stepExecution);
	}
	return taskExecution.getExecutionId();
}
 
Example 2
Source File: TaskExecutionResource.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to initialize the TaskExecutionResource using a
 * {@link TaskExecution} and {@link TaskManifest}.
 *
 * @param taskExecution contains the {@link TaskExecution}
 * @param taskManifest contains the (@link TaskManifest}
 */
public TaskExecutionResource(TaskExecution taskExecution, TaskManifest taskManifest) {
	Assert.notNull(taskExecution, "taskExecution must not be null");
	Assert.notNull(taskManifest, "taskManifest must not be null");
	this.executionId = taskExecution.getExecutionId();
	this.exitCode = taskExecution.getExitCode();
	this.taskName = taskExecution.getTaskName();
	this.exitMessage = taskExecution.getExitMessage();
	this.arguments = Collections.unmodifiableList(taskExecution.getArguments());
	this.startTime = taskExecution.getStartTime();
	this.endTime = taskExecution.getEndTime();
	this.errorMessage = taskExecution.getErrorMessage();
	this.externalExecutionId = taskExecution.getExternalExecutionId();
	this.resourceUrl = taskManifest.getTaskDeploymentRequest().getResource().toString();
	this.appProperties = taskManifest.getTaskDeploymentRequest().getDefinition().getProperties();
	this.deploymentProperties = taskManifest.getTaskDeploymentRequest().getDeploymentProperties();
}
 
Example 3
Source File: TaskExecutionResource.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor to initialize the TaskExecutionResource using a
 * {@link TaskExecution}.
 *
 * @param taskExecution contains the {@link TaskExecution}
 */
public TaskExecutionResource(TaskExecution taskExecution) {
	Assert.notNull(taskExecution, "taskExecution must not be null");
	this.executionId = taskExecution.getExecutionId();
	this.exitCode = taskExecution.getExitCode();
	this.taskName = taskExecution.getTaskName();
	this.exitMessage = taskExecution.getExitMessage();
	this.arguments = Collections.unmodifiableList(taskExecution.getArguments());
	this.startTime = taskExecution.getStartTime();
	this.endTime = taskExecution.getEndTime();
	this.errorMessage = taskExecution.getErrorMessage();
	this.externalExecutionId = taskExecution.getExternalExecutionId();
}
 
Example 4
Source File: DefaultTaskExecutionService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * A task should not be allowed to be launched when one is running (allowing the upgrade
 * to proceed may kill running task instances of that definition on certain platforms).
 *
 * @param taskName task name to check
 * @param taskExecution the candidate TaskExecution
 * @param taskLauncher the TaskLauncher used to verify the status of a recorded task execution.
 */
private void verifyTaskIsNotRunning(String taskName, TaskExecution taskExecution, TaskLauncher taskLauncher) {
	Page<TaskExecution> runningTaskExecutions =
			this.taskExplorer.findRunningTaskExecutions(taskName, PageRequest.of(0, 1));

	//Found only the candidate TaskExecution
	if(runningTaskExecutions.getTotalElements() == 1 && runningTaskExecutions.toList().get(0).getExecutionId() == taskExecution.getExecutionId()) {
		return;
	}

	/*
	 * The task repository recorded a different task execution for the task which is started but not completed.
	 * It is possible that the task failed and terminated before updating the task repository.
	 * Use the TaskLauncher to verify the actual state.
	 */
	if (runningTaskExecutions.getTotalElements() > 0) {

		LaunchState launchState = taskLauncher.status(runningTaskExecutions.toList().get(0).getExternalExecutionId()).getState();
		if (launchState.equals(LaunchState.running) || launchState.equals(LaunchState.launching)) {
			throw new IllegalStateException("Unable to update application due to currently running applications");
		}
		else {
			logger.warn("Task repository shows a running task execution for task {} but the actual state is {}."
					+ launchState.toString(), taskName, launchState);
		}
	}
}
 
Example 5
Source File: TaskLifecycleListener.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private TaskExecution getTaskExecutionCopy(TaskExecution taskExecution) {
	Date startTime = new Date(taskExecution.getStartTime().getTime());
	Date endTime = (taskExecution.getEndTime() == null) ? null
			: new Date(taskExecution.getEndTime().getTime());

	return new TaskExecution(taskExecution.getExecutionId(),
			taskExecution.getExitCode(), taskExecution.getTaskName(), startTime,
			endTime, taskExecution.getExitMessage(),
			Collections.unmodifiableList(taskExecution.getArguments()),
			taskExecution.getErrorMessage(), taskExecution.getExternalExecutionId());
}
 
Example 6
Source File: TestDBUtils.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private static void populateParamsToDB(DataSource dataSource,
		TaskExecution taskExecution) {
	String sql = "SELECT * FROM TASK_EXECUTION_PARAMS WHERE TASK_EXECUTION_ID = '"
			+ taskExecution.getExecutionId() + "'";

	JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
	List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);
	List<String> arguments = new ArrayList<>();
	for (Map row : rows) {
		arguments.add((String) row.get("TASK_PARAM"));
	}
	taskExecution.setArguments(arguments);
}
 
Example 7
Source File: MapTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Override
public List<TaskExecution> getLatestTaskExecutionsByTaskNames(String... taskNames) {

	Assert.notEmpty(taskNames, "At least 1 task name must be provided.");

	final List<String> taskNamesAsList = new ArrayList<>();

	for (String taskName : taskNames) {
		if (StringUtils.hasText(taskName)) {
			taskNamesAsList.add(taskName);
		}
	}

	Assert.isTrue(taskNamesAsList.size() == taskNames.length, String.format(
			"Task names must not contain any empty elements but %s of %s were empty or null.",
			taskNames.length - taskNamesAsList.size(), taskNames.length));

	final Map<String, TaskExecution> tempTaskExecutions = new HashMap<>();

	for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : this.taskExecutions
			.entrySet()) {
		if (!taskNamesAsList
				.contains(taskExecutionMapEntry.getValue().getTaskName())) {
			continue;
		}

		final TaskExecution tempTaskExecution = tempTaskExecutions
				.get(taskExecutionMapEntry.getValue().getTaskName());
		if (tempTaskExecution == null
				|| tempTaskExecution.getStartTime()
						.before(taskExecutionMapEntry.getValue().getStartTime())
				|| (tempTaskExecution.getStartTime()
						.equals(taskExecutionMapEntry.getValue().getStartTime())
						&& tempTaskExecution.getExecutionId() < taskExecutionMapEntry
								.getValue().getExecutionId())) {
			tempTaskExecutions.put(taskExecutionMapEntry.getValue().getTaskName(),
					taskExecutionMapEntry.getValue());
		}
	}
	final List<TaskExecution> latestTaskExecutions = new ArrayList<>(
			tempTaskExecutions.values());
	Collections.sort(latestTaskExecutions, new TaskExecutionComparator());
	return latestTaskExecutions;
}