use of com.mercedesbenz.sechub.sharedkernel.MustBeDocumented in project sechub by mercedes-benz.
the class DocGenUtilTest method spring_scheduled__is_collected_by_build_method_and_set_to_data.
@Test
public void spring_scheduled__is_collected_by_build_method_and_set_to_data() throws Exception {
/* prepare */
AnnotatedElement element = mock(AnnotatedElement.class);
MustBeDocumented info = mock(MustBeDocumented.class);
Scheduled scheduled = mock(Scheduled.class);
when(scheduled.cron()).thenReturn("crondata");
when(element.getDeclaredAnnotation(Scheduled.class)).thenReturn(scheduled);
/* execute */
DocAnnotationData data = DocGeneratorUtil.buildDataForMustBeDocumented(info, element);
/* test */
assertEquals(scheduled, data.springScheduled);
}
use of com.mercedesbenz.sechub.sharedkernel.MustBeDocumented in project sechub by mercedes-benz.
the class MustBeDocumentedDataCollector method collect.
public List<DocAnnotationData> collect() {
Class<? extends Annotation> annotation = MustBeDocumented.class;
Set<Class<?>> types = reflections.getTypesAnnotatedWith(annotation);
Set<Method> methods = reflections.getMethodsAnnotatedWith(annotation);
Set<Field> fields = reflections.getFieldsAnnotatedWith(annotation);
List<DocAnnotationData> list = new ArrayList<>();
/* handle class annotations */
for (Class<?> type : types) {
MustBeDocumented info = type.getDeclaredAnnotation(MustBeDocumented.class);
if (info == null) {
continue;
}
DocAnnotationData data = DocGeneratorUtil.buildDataForMustBeDocumented(info, type);
data.linkedClass = type;
list.add(data);
}
/* handle method annotations */
for (Method method : methods) {
MustBeDocumented info = method.getDeclaredAnnotation(MustBeDocumented.class);
if (info == null) {
continue;
}
DocAnnotationData data = DocGeneratorUtil.buildDataForMustBeDocumented(info, method);
data.linkedMethod = method;
list.add(data);
}
/* handle field annotations */
for (Field field : fields) {
MustBeDocumented info = field.getDeclaredAnnotation(MustBeDocumented.class);
if (info == null) {
continue;
}
DocAnnotationData data = DocGeneratorUtil.buildDataForMustBeDocumented(info, field);
data.linkedField = field;
list.add(data);
}
return list;
}
use of com.mercedesbenz.sechub.sharedkernel.MustBeDocumented 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());
}
}
Aggregations