Search in sources :

Example 1 with JobPersistence

use of org.glassfish.api.admin.progress.JobPersistence in project Payara by payara.

the class AdminCommandInstanceImpl method complete.

@Override
public void complete(ActionReport report, Payload.Outbound outbound) {
    if (commandProgress != null && report != null && report.getActionExitCode() == ExitCode.SUCCESS) {
        commandProgress.complete();
    }
    super.actionReport = report;
    this.payload = outbound;
    this.completionDate = System.currentTimeMillis();
    if (isManagedJob) {
        if (getState().equals(State.RUNNING_RETRYABLE) && failToRetryable) {
            JobManagerService jobManager = Globals.getDefaultHabitat().getService(JobManagerService.class);
            jobManager.getRetryableJobsInfo().put(id, CheckpointHelper.CheckpointFilename.createBasic(this));
            jobManager.purgeJob(id);
            setState(State.FAILED_RETRYABLE);
        } else {
            JobPersistence jobPersistenceService;
            if (scope != null) {
                jobPersistenceService = Globals.getDefaultHabitat().getService(JobPersistence.class, scope + "job-persistence");
            } else {
                jobPersistenceService = Globals.getDefaultHabitat().getService(JobPersistenceService.class);
            }
            State finalState = State.COMPLETED;
            if (getState().equals(State.REVERTING)) {
                finalState = State.REVERTED;
            }
            String user = null;
            if (subjectUsernames.size() > 0) {
                user = subjectUsernames.get(0);
            }
            jobPersistenceService.persist(new JobInfo(id, commandName, executionDate, report.getActionExitCode().name(), user, report.getMessage(), getJobsFile(), finalState.name(), completionDate));
            if (getState().equals(State.RUNNING_RETRYABLE) || getState().equals(State.REVERTING)) {
                JobManagerService jobManager = Globals.getDefaultHabitat().getService(JobManagerService.class);
                File jobFile = getJobsFile();
                if (jobFile == null) {
                    jobFile = jobManager.getJobsFile();
                }
                jobManager.deleteCheckpoint(jobFile.getParentFile(), getId());
            }
            setState(finalState);
        }
    } else {
        setState(State.COMPLETED);
    }
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo) File(java.io.File) JobPersistence(org.glassfish.api.admin.progress.JobPersistence)

Aggregations

File (java.io.File)1 JobInfo (org.glassfish.api.admin.progress.JobInfo)1 JobPersistence (org.glassfish.api.admin.progress.JobPersistence)1