Search in sources :

Example 1 with MustBeDocumented

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);
}
Also used : Scheduled(org.springframework.scheduling.annotation.Scheduled) AnnotatedElement(java.lang.reflect.AnnotatedElement) DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) MustBeDocumented(com.mercedesbenz.sechub.sharedkernel.MustBeDocumented) Test(org.junit.Test)

Example 2 with MustBeDocumented

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;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) MustBeDocumented(com.mercedesbenz.sechub.sharedkernel.MustBeDocumented) Method(java.lang.reflect.Method)

Example 3 with MustBeDocumented

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());
    }
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) Scheduled(org.springframework.scheduling.annotation.Scheduled) UseCaseSchedulerStartsJob(com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseSchedulerStartsJob) MustBeDocumented(com.mercedesbenz.sechub.sharedkernel.MustBeDocumented)

Aggregations

MustBeDocumented (com.mercedesbenz.sechub.sharedkernel.MustBeDocumented)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 DocAnnotationData (com.mercedesbenz.sechub.docgen.DocAnnotationData)1 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)1 UseCaseSchedulerStartsJob (com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseSchedulerStartsJob)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)1