Skip to content

Conversation

@ch200203
Copy link

Summary

  • Resolve TODOs in CommandLineJobOperator by adding explicit state checks and clearer error logs.
  • Prevent invalid operations at the CLI layer without using deprecated exceptions.

Changes

  • restart(long jobExecutionId): Only allow when status is FAILED or STOPPED; otherwise log current status and return JVM_EXITCODE_GENERIC_ERROR.
  • abandon(long jobExecutionId): Only allow when status is STOPPED; otherwise log current status and return JVM_EXITCODE_GENERIC_ERROR.
  • Added concise error messages including the current BatchStatus.
public int restart(long jobExecutionId) {
    logger.info(() -> "Restarting job execution with ID: " + jobExecutionId);
    try {
        JobExecution jobExecution = this.jobRepository.getJobExecution(jobExecutionId);
        if (jobExecution == null) {
            logger.error(() -> "No job execution found with ID: " + jobExecutionId);
            return JVM_EXITCODE_GENERIC_ERROR;
        }
        BatchStatus status = jobExecution.getStatus();
        if (status != BatchStatus.FAILED && status != BatchStatus.STOPPED) {
            logger.error(() -> "Cannot restart job execution " + jobExecutionId
                    + ": current status is " + status + " (must be FAILED or STOPPED).");
            return JVM_EXITCODE_GENERIC_ERROR;
        }
        JobExecution restartedExecution = this.jobOperator.restart(jobExecution);
        return this.exitCodeMapper.intValue(restartedExecution.getExitStatus().getExitCode());
    }
    catch (Exception e) {
        return JVM_EXITCODE_GENERIC_ERROR;
    }
}

public int abandon(long jobExecutionId) {
    logger.info(() -> "Abandoning job execution with ID: " + jobExecutionId);
    try {
        JobExecution jobExecution = this.jobRepository.getJobExecution(jobExecutionId);
        if (jobExecution == null) {
            logger.error(() -> "No job execution found with ID: " + jobExecutionId);
            return JVM_EXITCODE_GENERIC_ERROR;
        }
        BatchStatus status = jobExecution.getStatus();
        if (status != BatchStatus.STOPPED) {
            logger.error(() -> "Cannot abandon job execution " + jobExecutionId
                    + ": current status is " + status + " (must be STOPPED).");
            return JVM_EXITCODE_GENERIC_ERROR;
        }
        JobExecution abandonedExecution = this.jobOperator.abandon(jobExecution);
        return this.exitCodeMapper.intValue(abandonedExecution.getExitStatus().getExitCode());
    }
    catch (Exception e) {
        return JVM_EXITCODE_GENERIC_ERROR;
    }
}

Tests

  • Reject restart when not FAILED/STOPPED (e.g., COMPLETED) and do not delegate.
  • Allow restart when STOPPED and delegate to jobOperator.restart.
  • Reject abandon when not STOPPED and do not delegate.
  • Happy paths updated to set proper statuses.

Resolve #5057

Signed-off-by: Cheolhwan Ihn <ch200203@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandLineJobOperator improve state validation for restart/abandon and enhance logging

1 participant