use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage in project sechub by mercedes-benz.
the class SchedulerBatchJobStatusRequestHandler method returnStatus.
@IsSendingSyncMessageAnswer(value = MessageID.BATCH_JOB_STATUS, answeringTo = MessageID.REQUEST_BATCH_JOB_STATUS, branchName = "success")
private DomainMessageSynchronousResult returnStatus(DomainMessage request) {
DomainMessageSynchronousResult result = new DomainMessageSynchronousResult(MessageID.BATCH_JOB_STATUS);
BatchJobMessage batchJobMessage = request.get(MessageDataKeys.BATCH_JOB_STATUS);
UUID sechubBatchJobUUID = batchJobMessage.getSechubJobUUID();
long batchJobId = batchJobMessage.getBatchJobId();
BatchJobMessage status = new BatchJobMessage();
status.setBatchJobId(batchJobId);
status.setSecHubJobUUID(sechubBatchJobUUID);
/* find */
JobExecution jobExecution = explorer.getJobExecution(batchJobId);
if (jobExecution == null) {
status.setExisting(false);
} else {
BatchStatus batchStatus = jobExecution.getStatus();
status.setCanceled(checkRepresentsCancel(batchStatus));
status.setAbandoned(checkRepresentsAbandoned(batchStatus));
status.setExisting(true);
}
result.set(MessageDataKeys.BATCH_JOB_STATUS, status);
return result;
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage 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();
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage in project sechub by mercedes-benz.
the class ScanServiceTest method prepareRequest.
private DomainMessage prepareRequest(SecHubConfiguration configMin) {
DomainMessage request = new DomainMessage(MessageID.START_SCAN);
request.set(MessageDataKeys.SECHUB_UUID, UUID);
request.set(MessageDataKeys.SECHUB_CONFIG, configMin);
BatchJobMessage batchJobMessage = new BatchJobMessage();
batchJobMessage.setSecHubJobUUID(UUID);
batchJobMessage.setBatchJobId(42);
request.set(MessageDataKeys.BATCH_JOB_ID, batchJobMessage);
return request;
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage in project sechub by mercedes-benz.
the class ScanProgressMonitor method sendRequestBatchJobStatusRequestSynchron.
@IsSendingSyncMessage(MessageID.REQUEST_BATCH_JOB_STATUS)
protected BatchJobMessage sendRequestBatchJobStatusRequestSynchron() {
DomainMessage request = new DomainMessage(MessageID.REQUEST_BATCH_JOB_STATUS);
BatchJobMessage statusRequestMessage = new BatchJobMessage();
statusRequestMessage.setBatchJobId(batchJobId);
request.set(MessageDataKeys.BATCH_JOB_STATUS, statusRequestMessage);
/* ask for status */
DomainMessageSynchronousResult response = eventBus.sendSynchron(request);
BatchJobMessage jobStatusRepsonse = response.get(MessageDataKeys.BATCH_JOB_STATUS);
return jobStatusRepsonse;
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage in project sechub by mercedes-benz.
the class ScanService method executeScan.
protected void executeScan(SecHubExecutionContext context, DomainMessage request) throws SecHubExecutionException {
DomainDataTraceLogID sechubJobUUID = traceLogID(request);
LOG.info("start scan for {}", sechubJobUUID);
UUID logUUID = scanLogService.logScanStarted(context);
try {
BatchJobMessage jobIdMessage = request.get(MessageDataKeys.BATCH_JOB_ID);
if (jobIdMessage == null) {
throw new IllegalStateException("no batch job id set for sechub job:" + sechubJobUUID);
}
long batchJobId = jobIdMessage.getBatchJobId();
ProgressMonitor progressMonitor = monitorFactory.createProgressMonitor(batchJobId);
/* delegate execution : */
ScanJobExecutor executor = new ScanJobExecutor(this, context, progressMonitor, millisecondsToWaitBeforeCancelCheck);
executor.execute();
scanLogService.logScanEnded(logUUID);
} catch (Exception e) {
if (context.isAbandonded()) {
scanLogService.logScanAbandoned(logUUID);
} else {
scanLogService.logScanFailed(logUUID);
}
/* rethrow when already an execution exception */
if (e instanceof SecHubExecutionException) {
SecHubExecutionException exceptionToRethrow = (SecHubExecutionException) e;
throw exceptionToRethrow;
}
/* wrap it */
throw new SecHubExecutionException("Execute scan failed", e);
}
}
Aggregations