use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerJobBatchTriggerService method triggerExecutionOfNextJob.
// default 10 seconds delay and 5 seconds initial
@MustBeDocumented(value = "Job scheduling is triggered by a cron job operation - default is 10 seconds to delay after last execution. " + "For initial delay " + DEFAULT_INITIAL_DELAY_MILLIS + " milliseconds are defined. It can be configured differently. This is useful when you need to startup a cluster. Simply change the initial delay values in to allow the cluster to startup.", scope = "schedule")
@Scheduled(initialDelayString = "${sechub.config.trigger.nextjob.initialdelay:" + DEFAULT_INITIAL_DELAY_MILLIS + "}", fixedDelayString = "${sechub.config.trigger.nextjob.delay:" + DEFAULT_FIXED_DELAY_MILLIS + "}")
@UseCaseSchedulerStartsJob(@Step(number = 1, name = "Scheduling", description = "Fetches next schedule job from queue and trigger execution."))
public void triggerExecutionOfNextJob() {
if (LOG.isTraceEnabled()) {
/* NOSONAR */
LOG.trace("Trigger execution of next job started. Environment: {}", environmentService.getEnvironment());
}
if (!configService.isJobProcessingEnabled()) {
LOG.warn("Job processing is disabled, so cancel scheduling. Environment: {}", environmentService.getEnvironment());
return;
}
if (healthCheckEnabled) {
if (monitorService.isCPULoadAverageMaxReached()) {
alertLogService.log(SCHEDULER_PROBLEM, CPU_OVERLOAD, "Job processing is skipped. {}, {}", monitorService.createCPUDescription(), environmentService.getEnvironment());
return;
}
if (monitorService.isMemoryUsageMaxReached()) {
alertLogService.log(SCHEDULER_PROBLEM, MEMORY_OVERLOAD, "Job processing is skipped. {}, {}", monitorService.createMemoryDescription(), environmentService.getEnvironment());
return;
}
}
RetryContext retryContext = new RetryContext(markNextJobRetries);
do {
try {
ScheduleSecHubJob next = markerService.markNextJobToExecuteByThisInstance();
retryContext.executionDone();
if (next == null) {
return;
}
try {
launcherService.executeJob(next);
} catch (Exception e) {
/* fatal failure happened, job launch was not executable */
LOG.trace("was not able to execute next job, because fatal error occurred. Environment: {}", environmentService.getEnvironment());
markerService.markJobExecutionFailed(next);
retryContext.markAsFatalFailure();
}
} catch (OptimisticLockingFailureException e) {
LOG.trace("was not able to trigger next, because already done. Environment: {}", environmentService.getEnvironment());
retryContext.setRetryTimeToWait(createRandomTimeMillisToWait()).executionFailed();
} catch (Exception e) {
LOG.trace("was not able to trigger next job, because fatal error occurred. Environment: {}", environmentService.getEnvironment());
retryContext.markAsFatalFailure();
}
} while (retryContext.isRetryPossible());
if (!retryContext.isExecutionDone()) {
LOG.warn("Was not able to handle trigger execution of next job, failed {} times. Environment:{}", retryContext.getExecutionFailedCount(), environmentService.getEnvironment());
}
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerRestartJobService method restartJob.
private void restartJob(UUID jobUUID, String ownerEmailAddress, boolean hard) {
assertion.assertIsValidJobUUID(jobUUID);
auditLogService.log("triggered restart of job:{}, variant:[hard={}]", jobUUID, hard);
Optional<ScheduleSecHubJob> optJob = jobRepository.findById(jobUUID);
if (!optJob.isPresent()) {
LOG.warn("SecHub job {} not found, so not able to restart!", jobUUID);
JobDataContext context = new JobDataContext();
context.sechubJobUUID = jobUUID;
context.ownerEmailAddress = ownerEmailAddress;
context.info = "Restart canceled, because job not found!";
sendJobRestartCanceled(context);
throw new NotFoundException("Job not found or you have no access");
}
/* job exists, so can be restarted - hard or soft */
ScheduleSecHubJob job = optJob.get();
if (job.getExecutionResult().hasFinished()) {
/* already done so just ignore */
LOG.warn("SecHub job {} has already finished, so not able to restart!", jobUUID);
sendJobRestartCanceled(job, ownerEmailAddress, "Restart canceled, because job already finished");
throw new AlreadyExistsException("Job has already finished - restart not necessary");
}
/*
* when we have still running batch jobs we must terminate them as well +
* abandon
*/
schedulerCancelJobService.stopAndAbandonAllRunningBatchJobsForSechubJobUUID(jobUUID);
if (hard) {
sendPurgeJobResultsSynchronousRequest(job);
}
ScheduleSecHubJob secHubJob = optJob.get();
markJobAsNewExecutedNow(secHubJob);
sendJobRestartTriggered(secHubJob, ownerEmailAddress);
launcherService.executeJob(secHubJob);
String type = (hard ? "hard" : "normal");
LOG.info("job {} has been {} restarted", jobUUID, type);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerStartHandler method buildZombieInformation.
String buildZombieInformation(List<ScheduleSecHubJob> jobsRunningButStartedBefore) {
if (jobsRunningButStartedBefore == null || jobsRunningButStartedBefore.isEmpty()) {
return "OK: No zombie jobs found";
}
StringBuilder sb = new StringBuilder();
sb.append("---------------------------------------\n");
sb.append("ATTENTION: Potential zombie jobs found:\n");
sb.append("---------------------------------------\n");
for (ScheduleSecHubJob potentialZombieJob : jobsRunningButStartedBefore) {
sb.append("- job:").append(potentialZombieJob.getUUID());
sb.append(", started:").append(potentialZombieJob.getStarted());
sb.append(", execution-state:").append(potentialZombieJob.getExecutionState());
sb.append("\n");
}
sb.append("\nPlease check if they have been already started by another before started (and still running) scheduler instance. If identified as zombie job you have to restart the job!");
return sb.toString();
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class ScheduleJobMarkerService method markNextJobToExecuteByThisInstance.
/**
* @return either schedule job to execute, or <code>null</code> if no one has to
* be executed
*/
@Transactional
public ScheduleSecHubJob markNextJobToExecuteByThisInstance() {
schedulerStrategy = schedulerStrategyFactory.build();
if (LOG.isTraceEnabled()) {
/* NOSONAR */
LOG.trace("Trigger execution of next job started");
}
UUID nextJobId = schedulerStrategy.nextJobId();
if (nextJobId == null) {
return null;
}
Optional<ScheduleSecHubJob> secHubJobOptional = jobRepository.getJob(nextJobId);
if (!secHubJobOptional.isPresent()) {
if (LOG.isTraceEnabled()) {
/* NOSONAR */
LOG.trace("No job found.");
}
return null;
}
ScheduleSecHubJob secHubJob = secHubJobOptional.get();
secHubJob.setExecutionState(ExecutionState.STARTED);
secHubJob.setStarted(LocalDateTime.now());
return jobRepository.save(secHubJob);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class IntegrationTestSchedulerService method revertJobAsStillNotApproved.
public void revertJobAsStillNotApproved(UUID sechubJobUUID) {
Optional<ScheduleSecHubJob> found = repository.findById(sechubJobUUID);
if (!found.isPresent()) {
throw new NotFoundException("Job not found!");
}
ScheduleSecHubJob job = found.get();
job.setExecutionResult(ExecutionResult.NONE);
job.setExecutionState(ExecutionState.INITIALIZING);
job.setEnded(null);
job.setTrafficLight(null);
repository.save(job);
}
Aggregations