Search in sources :

Example 21 with DomainMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.

the class ScheduleMessageHandlerTest method handler_receiving_auto_cleanup_calls_config_serice_with_message_data.

@Test
void handler_receiving_auto_cleanup_calls_config_serice_with_message_data() {
    /* prepare */
    long days = System.nanoTime();
    AdministrationConfigMessage configMessage = new AdministrationConfigMessage();
    configMessage.setAutoCleanupInDays(days);
    DomainMessage message = new DomainMessage(MessageID.AUTO_CLEANUP_CONFIGURATION_CHANGED);
    message.set(MessageDataKeys.AUTO_CLEANUP_CONFIG_CHANGE_DATA, configMessage);
    /* execute */
    scheduleHandlerToTest.receiveAsyncMessage(message);
    /* test */
    verify(scheduleHandlerToTest.configService).updateAutoCleanupInDays(days);
}
Also used : AdministrationConfigMessage(com.mercedesbenz.sechub.sharedkernel.messaging.AdministrationConfigMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test)

Example 22 with DomainMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.

the class ScheduleMessageHandlerTest method when_sending_message_id_USER_DELETED_the_revokeUserService_is_called.

@Test
void when_sending_message_id_USER_DELETED_the_revokeUserService_is_called() {
    /* prepare */
    DomainMessage request = new DomainMessage(MessageID.USER_DELETED);
    UserMessage content = new UserMessage();
    content.setUserId("userId1");
    request.set(MessageDataKeys.USER_DELETE_DATA, content);
    /* execute */
    simulateEventSend(request, scheduleHandlerToTest);
    /* test */
    verify(scheduleHandlerToTest.revokeUserService).revokeUserAccess("userId1");
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test)

Example 23 with DomainMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.

the class ScheduleMessageHandlerTest method when_sending_message_id_USER_REMOVED_FROM_PROJECT_the_revokeUserFromProjectService_is_called.

@Test
void when_sending_message_id_USER_REMOVED_FROM_PROJECT_the_revokeUserFromProjectService_is_called() {
    /* prepare */
    DomainMessage request = new DomainMessage(MessageID.USER_REMOVED_FROM_PROJECT);
    UserMessage content = new UserMessage();
    content.setProjectId("projectId1");
    content.setUserId("userId1");
    request.set(MessageDataKeys.PROJECT_TO_USER_DATA, content);
    /* execute */
    simulateEventSend(request, scheduleHandlerToTest);
    /* test */
    verify(scheduleHandlerToTest.revokeUserFromProjectService).revokeUserAccessFromProject("userId1", "projectId1");
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test)

Example 24 with DomainMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.

the class SynchronSecHubJobExecutor method execute.

@IsSendingSyncMessage(MessageID.START_SCAN)
public void execute(final ScheduleSecHubJob secHubJob, final Long batchJobId) {
    Thread scanThread = new Thread(new Runnable() {

        @Override
        public void run() {
            UUID secHubJobUUID = secHubJob.getUUID();
            String secHubJobUUIDAsString = secHubJobUUID.toString();
            try {
                String secHubConfiguration = secHubJob.getJsonConfiguration();
                /* own thread so MDC.put necessary */
                MDC.clear();
                MDC.put(LogConstants.MDC_SECHUB_JOB_UUID, secHubJobUUIDAsString);
                MDC.put(LogConstants.MDC_SECHUB_PROJECT_ID, secHubJob.getProjectId());
                LOG.info("Executing sechub job: {}", secHubJobUUIDAsString);
                /* we send no a synchronous SCAN event */
                DomainMessage request = new DomainMessage(MessageID.START_SCAN);
                request.set(MessageDataKeys.EXECUTED_BY, secHubJob.getOwner());
                request.set(MessageDataKeys.SECHUB_UUID, secHubJobUUID);
                request.set(MessageDataKeys.SECHUB_CONFIG, MessageDataKeys.SECHUB_CONFIG.getProvider().get(secHubConfiguration));
                BatchJobMessage batchJobIdMessage = new BatchJobMessage();
                batchJobIdMessage.setBatchJobId(batchJobId);
                batchJobIdMessage.setSecHubJobUUID(secHubJobUUID);
                request.set(MessageDataKeys.BATCH_JOB_ID, batchJobIdMessage);
                /* wait for scan event result - synchron */
                DomainMessageSynchronousResult response = messageService.sendSynchron(request);
                updateSecHubJob(secHubJobUUID, response);
                sendJobDoneMessageWhenNotAbandonded(secHubJobUUID, response);
            } catch (Exception e) {
                LOG.error("Error happend at spring batch task execution:" + e.getMessage(), e);
                markSechHubJobFailed(secHubJobUUID);
                sendJobFailed(secHubJobUUID);
            } finally {
                /* cleanup MDC */
                MDC.clear();
            }
        }
    }, "scan_" + secHubJob.getUUID());
    scanThread.start();
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) UUID(java.util.UUID) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingSyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)

Example 25 with DomainMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.

the class SynchronSecHubJobExecutor method sendJobInfo.

private void sendJobInfo(MessageDataKey<JobMessage> key, UUID jobUUID, MessageID id) {
    DomainMessage request = new DomainMessage(id);
    JobMessage message = createMessage(jobUUID);
    request.set(key, message);
    messageService.sendAsynchron(request);
}
Also used : BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)

Aggregations

DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)69 IsSendingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)31 UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)21 Test (org.junit.Test)18 Test (org.junit.jupiter.api.Test)13 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)10 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)8 JobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)6 AdministrationConfigMessage (com.mercedesbenz.sechub.sharedkernel.messaging.AdministrationConfigMessage)5 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)4 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)3 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)3 UUID (java.util.UUID)3 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)2 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)1 User (com.mercedesbenz.sechub.domain.administration.user.User)1 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)1 ScanProjectConfig (com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig)1