Search in sources :

Example 41 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_ADDED_TO_PROJECT_the_addUserToProjectService_is_called.

@Test
void when_sending_message_id_USER_ADDED_TO_PROJECT_the_addUserToProjectService_is_called() {
    /* prepare */
    DomainMessage request = new DomainMessage(MessageID.USER_ADDED_TO_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.grantService).grantUserAccessToProject("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 42 with DomainMessage

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

the class SchedulerStartHandlerTest method schedulerHasBeenStarted.

@Test
public void schedulerHasBeenStarted() throws Exception {
    /* prepare */
    List<ScheduleSecHubJob> jobsRunningButStartedBefore = new ArrayList<>();
    ScheduleSecHubJob job1 = mock(ScheduleSecHubJob.class);
    UUID uuid1 = UUID.randomUUID();
    when(job1.getUUID()).thenReturn(uuid1);
    jobsRunningButStartedBefore.add(job1);
    when(repository.findAllRunningJobsStartedBefore(any())).thenReturn(jobsRunningButStartedBefore);
    /* execute */
    handlerToTest.schedulerHasBeenStarted().run();
    /* test */
    ArgumentCaptor<DomainMessage> argument = ArgumentCaptor.forClass(DomainMessage.class);
    verify(eventBus).sendAsynchron(argument.capture());
    DomainMessage domainMessage = argument.getValue();
    assertEquals(BASE_URL1, domainMessage.get(MessageDataKeys.ENVIRONMENT_BASE_URL));
    ClusterMemberMessage status = domainMessage.get(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS);
    assertNotNull(status);
    assertEquals(HOSTNAME_1, status.getHostName());
}
Also used : ArrayList(java.util.ArrayList) ClusterMemberMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ClusterMemberMessage) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UUID(java.util.UUID) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 43 with DomainMessage

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

the class ScanExecutionTasklet 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);
    scope.getEventBusService().sendAsynchron(request);
}
Also used : JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)

Example 44 with DomainMessage

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

the class SchedulerConfigService method setJobProcessingEnabled.

/**
 * Enables or disables job processing
 *
 * @param enableJobProcessing
 * @return <code>true</code> when processing has been changed and a event was
 *         sent. <code>false</code> when already in wanted state
 */
boolean setJobProcessingEnabled(boolean enableJobProcessing) {
    SchedulerConfig config = getOrCreateConfig();
    if (enableJobProcessing == config.isJobProcessingEnabled()) {
        return false;
    }
    config.setJobProcessingEnabled(enableJobProcessing);
    repository.save(config);
    DomainMessage domainMessage = null;
    if (enableJobProcessing) {
        domainMessage = DomainMessageFactory.createEmptyRequest(MessageID.SCHEDULER_JOB_PROCESSING_ENABLED);
    } else {
        domainMessage = DomainMessageFactory.createEmptyRequest(MessageID.SCHEDULER_JOB_PROCESSING_DISABLED);
    }
    domainMessage.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environmentData.getServerBaseUrl());
    domainMessageService.sendAsynchron(domainMessage);
    return true;
}
Also used : DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)

Example 45 with DomainMessage

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

the class SchedulerStatusService method buildStatus.

@IsSendingAsyncMessage(MessageID.SCHEDULER_STATUS_UPDATE)
public void buildStatus() {
    DomainMessage message = DomainMessageFactory.createEmptyRequest(MessageID.SCHEDULER_STATUS_UPDATE);
    SchedulerMessage sm = new SchedulerMessage();
    long amountOfJobsAll = jobRepository.count();
    long amountOfRunningJobs = jobRepository.countRunningJobs();
    long amountOfWaitingJobs = jobRepository.countWaitingJobs();
    boolean processingEnabled = configService.isJobProcessingEnabled();
    sm.setAmountOfJobsAll(amountOfJobsAll);
    sm.setAmountOfRunningJobs(amountOfRunningJobs);
    sm.setAmountOfWaitingJobs(amountOfWaitingJobs);
    sm.setJobProcessingEnabled(processingEnabled);
    message.set(MessageDataKeys.SCHEDULER_STATUS_DATA, sm);
    eventBus.sendAsynchron(message);
}
Also used : SchedulerMessage(com.mercedesbenz.sechub.sharedkernel.messaging.SchedulerMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)

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