Skip to content

Commit

Permalink
Drop no longer used "abandon" parts #1652
Browse files Browse the repository at this point in the history
- removed interface Abandonable
- removed exception SechubExecutionAbandonException
- removed message id
- changed doc
- changed context (removed isCancelRequestedOrAbandonded)
  usages of old method do now use isCancelRequested
- dropped abandon data from BatchJobMessage
  • Loading branch information
de-jcup committed Sep 16, 2022
1 parent 4ae1c20 commit e585d9b
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The restart will
- be canceled, when job does not exist in scheduler
- be canceled, when execution already finished
- check for running batch jobs with {sechub} job UUID. +
If there are existing batch operations, those will be stopped and abandoned
If there are existing batch operations, those will be stopped
- new scan will be restarted immediately without scheduling, will try to reuse existing
results +
_E.g. when a static code scan job is triggered to a product and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The restart will
- be canceled, when execution already finished
- delete all former product results and also adapter meta data
- check for running batch jobs with {sechub} job UUID. +
If there are existing batch operations, those will be stopped and abandoned
If there are existing batch operations, those will be stopped
- new scan will be restarted immediately without scheduling, will not try to reuse existing
results because such information was formerly deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public void sechub_starts_job_and_triggers_cancel_must_be_handled_by_PDS_script(
messageTypesFound.add(sechubMessage.getType());
messageTextsFound.add(sechubMessage.getText());
}

// We have two special info messages here. Each has info type
assertTrue(messageTypesFound.contains(SecHubMessageType.INFO));
assertEquals(1, messageTypesFound.size());

// Now check for the final cancel successful message:
assertTrue(messageTextsFound.contains("Event type:cancel_requested was received and handled by script"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void waitForProcessEndAndGetResultByFiles(PDSExecutionResult result, UUID jobUUI
result.failed = false;
result.exitCode = process.exitValue();

LOG.debug("Process of job with uuid:{} ended after with exit code: {} after {} ms - for product with id: {}", jobUUID, result.exitCode, timeElapsedInMilliseconds, config.getProductId());
LOG.debug("Process of job with uuid:{} ended after with exit code: {} after {} ms - for product with id: {}", jobUUID, result.exitCode,
timeElapsedInMilliseconds, config.getProductId());

storeResultFileOrCreateShrinkedProblemDataInstead(result, jobUUID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void requestJobCancellation(UUID jobUUID) {
}

transactionService.markJobAsCancelRequestedInOwnTransaction(jobUUID);

}, jobUUID.toString());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mercedesbenz.sechub.sharedkernel.Abandonable;
import com.mercedesbenz.sechub.sharedkernel.NullProgressMonitor;
import com.mercedesbenz.sechub.sharedkernel.ProgressMonitor;

Expand Down Expand Up @@ -104,37 +103,12 @@ private void handleErrors(SecHubExecutionException exception) throws SecHubExecu
/* no failure - so just return */
return;
}
/*
* abdoned exception are treated special: executor will NOT persist result in
* this case!
*/
if (exception instanceof SecHubExecutionAbandonedException) {
LOG.debug("Rethrow SecHubExecutionAbandonedException");
throw exception; // just rethrow abandoned
}
LOG.debug("No SecHubExecutionAbandonedException");
if (progress instanceof Abandonable) {
LOG.debug("Start abandoble check");
Abandonable abandonable = (Abandonable) progress;
if (abandonable.isAbandoned()) {
LOG.debug("Done abandoble check- IS abandonded");
throw new SecHubExecutionAbandonedException(context, "A failure happend, but already abandoned job", exception);
}
LOG.debug("Done abandoble check- not abandonded");

}
LOG.debug("Rethrow normal sechub execution exception");
throw exception;
}

private void handleCancelRequested(ScanJobExecutionRunnable executionRunable, UUID sechubJobUUID) throws SecHubExecutionAbandonedException {
private void handleCancelRequested(ScanJobExecutionRunnable executionRunable, UUID sechubJobUUID) {
LOG.info("Received cancel signal, so start canceling job: {}", sechubJobUUID);
cancelExecutoinRunnableAndFailIfAbandoned(executionRunable, sechubJobUUID);

/*
* not abandoned, so we shall also try to cancel the operations still in
* execution history
*/
ScanJobRunnableData data = executionRunable.getRunnableData();
if (data.getException() != null) {
/*
Expand Down Expand Up @@ -168,19 +142,4 @@ private void startCancelThreadIfNecessary(ScanJobRunnableData data) {
cancelThread.start();
}

private void cancelExecutoinRunnableAndFailIfAbandoned(ScanJobExecutionRunnable executionRunable, UUID sechubJobUUID)
throws SecHubExecutionAbandonedException {
executionRunable.cancelScanJob();

if (!(progress instanceof Abandonable)) {
return;
}
Abandonable abandoble = (Abandonable) progress;
LOG.info("Check if job {} shall be abandoned", sechubJobUUID);
if (abandoble.isAbandoned()) {
LOG.info("Must abandon {}", sechubJobUUID);
throw new SecHubExecutionAbandonedException(context, "Abandonded job " + sechubJobUUID + " because canceled", null);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public class ScanService implements SynchronMessageHandler {

@IsSendingSyncMessageAnswer(value = MessageID.SCAN_DONE, answeringTo = MessageID.START_SCAN, branchName = "success")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_FAILED, answeringTo = MessageID.START_SCAN, branchName = "failure")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_ABANDONDED, answeringTo = MessageID.START_SCAN, branchName = "failure")
DomainMessageSynchronousResult startScan(DomainMessage request) {

SecHubExecutionContext context = null;
Expand All @@ -110,10 +109,6 @@ DomainMessageSynchronousResult startScan(DomainMessage request) {
} catch (ScanReportException e) {
LOG.error("Execution was possible, but report failed." + traceLogID(request), e);
return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);

} catch (SecHubExecutionAbandonedException e) {
LOG.info("Execution abandoned on scan {} - message: {}", traceLogID(request), e.getMessage());
return new DomainMessageSynchronousResult(MessageID.SCAN_ABANDONDED, e);
} catch (SecHubExecutionException e) {
LOG.error("Execution problems on scan." + traceLogID(request), e);
return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
Expand All @@ -124,9 +119,7 @@ DomainMessageSynchronousResult startScan(DomainMessage request) {
if (context == null) {
LOG.warn("No sechub execution context available, so cannot check state or cleanup storage");
} else {
if (!context.isAbandonded()) {
cleanupStorage(context);
}
cleanupStorage(context);
}
}
}
Expand All @@ -148,11 +141,8 @@ protected void executeScan(SecHubExecutionContext context, DomainMessage request
scanLogService.logScanEnded(logUUID);

} catch (Exception e) {
if (context.isAbandonded()) {
scanLogService.logScanAbandoned(logUUID);
} else {
scanLogService.logScanFailed(logUUID);
}
scanLogService.logScanFailed(logUUID);

/* rethrow when already an execution exception */
if (e instanceof SecHubExecutionException) {
SecHubExecutionException exceptionToRethrow = (SecHubExecutionException) e;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class SecHubExecutionContext {
private String executedBy;
private Map<String, Object> dataMap = new HashMap<>();

private boolean abandonded;

private boolean cancelRequested;

private SecHubExecutionOperationType operationType;
Expand All @@ -57,10 +55,6 @@ public SecHubExecutionOperationType getOperationType() {
return operationType;
}

public void markAbandonded() {
abandonded = true;
}

public void markCancelRequested() {
cancelRequested = true;
}
Expand All @@ -69,10 +63,6 @@ public boolean isCancelRequested() {
return cancelRequested;
}

public boolean isCancelRequestedOrAbandonded() {
return cancelRequested || abandonded;
}

public String getExecutedBy() {
return executedBy;
}
Expand Down Expand Up @@ -135,10 +125,6 @@ public boolean isDeleteFormerResultsWanted() {
return false;
}

public boolean isAbandonded() {
return abandonded;
}

SecHubExecutionHistory getExecutionHistory() {
return executionHistory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class ProjectScanLog {
public static final String STATUS_STARTED = "STARTED";
public static final String STATUS_OK = "OK";
public static final String STATUS_FAILED = "FAILED";
public static final String STATUS_ABANDONED = "ABANDONDED";

public static final String QUERY_DELETE_LOGS_OLDER_THAN = "DELETE FROM ProjectScanLog log WHERE log." + PROPERTY_STARTED + " < :cleanTimeStamp";;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public void logScanFailed(UUID logUUID) {
logEndedWithStatus(logUUID, ProjectScanLog.STATUS_FAILED);
}

public void logScanAbandoned(UUID logUUID) {
logEndedWithStatus(logUUID, ProjectScanLog.STATUS_ABANDONED);
}

private void logEndedWithStatus(UUID logScanUUID, String status) {
Optional<ProjectScanLog> optLog = repository.findById(logScanUUID);
if (!optLog.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void executeProductsAndStoreResults(SecHubExecutionContext context) throw
UUIDTraceLogID traceLogID = traceLogID(context.getSechubJobUUID());

SecHubConfiguration configuration = context.getConfiguration();
if (context.isCancelRequestedOrAbandonded()) {
LOG.debug("{} canceled or abandoned, so ignored by {}", traceLogID, getClass().getSimpleName());
if (context.isCancelRequested()) {
LOG.debug("{} canceled, so ignored by {}", traceLogID, getClass().getSimpleName());
return;
}
if (!isExecutionNecessary(context, traceLogID, configuration)) {
Expand Down Expand Up @@ -115,7 +115,7 @@ protected List<ProductResult> execute(ProductExecutor executor, ProductExecutorC
LOG.info("Start executor:{} config:{} and wait for result. {}", executor.getIdentifier(), executorConfigUUID, traceLogID);

List<ProductResult> productResults = executor.execute(context, executorContext);
if (context.isCancelRequestedOrAbandonded()) {
if (context.isCancelRequested()) {
return Collections.emptyList();
}
int amount = 0;
Expand Down Expand Up @@ -152,7 +152,7 @@ protected void runOnAllAvailableExecutors(List<? extends ProductExecutor> execut
ProductExecutor serecoProductExecutor = null;

for (ProductExecutor productExecutor : executors) {
if (context.isCancelRequestedOrAbandonded()) {
if (context.isCancelRequested()) {
return;
}
ProductIdentifier productIdentifier = productExecutor.getIdentifier();
Expand Down Expand Up @@ -211,7 +211,7 @@ private void runOnExecutorWithOneConfiguration(ProductExecutorConfig executorCon
List<ProductResult> productResults = null;
try {
productResults = execute(productExecutor, executorContext, context, traceLogID);
if (context.isCancelRequestedOrAbandonded()) {
if (context.isCancelRequested()) {
return;
}
if (productResults == null) {
Expand All @@ -234,7 +234,7 @@ private void runOnExecutorWithOneConfiguration(ProductExecutorConfig executorCon
}
productResults.add(currentResult);
}
if (context.isCancelRequestedOrAbandonded()) {
if (context.isCancelRequested()) {
return;
}
/* execution was successful - so persist new results */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ private void restartJob(UUID jobUUID, String ownerEmailAddress, boolean hard) {
}

/*
* when we have still running batch jobs we must terminate them as well +
* abandon
* when we have still running batch jobs we must terminate them as well
*/
schedulerCancelJobService.stopAndAbandonAllRunningBatchJobsForSechubJobUUID(jobUUID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ public void run() {
}

private void sendJobDoneMessageWhenNotAbandonded(UUID secHubJobUUID, DomainMessageSynchronousResult response) {
if (MessageID.SCAN_ABANDONDED.equals(response.getMessageId())) {
LOG.info("Will not send job done message, because scan was abandoned");
return;
}
LOG.debug("Will send job done message for: {}", secHubJobUUID);
sendJobDone(secHubJobUUID);
}
Expand All @@ -109,16 +105,7 @@ private void markSechHubJobFailed(UUID secHubJobUUID) {

private void updateSecHubJob(UUID secHubUUID, DomainMessageSynchronousResult response) {
ExecutionResult result;
if (MessageID.SCAN_ABANDONDED.equals(response.getMessageId())) {
/*
* Abandon happens normally only, when doing a restart or a hard internal cancel
* operation. In both situations, the SecHub job execution result inside
* scheduler is already set before, and state will also be changed to CANCELED,
* or on restart to RUNNING
*/
LOG.info("Ignore sechub job update, because scan was abandoned");
return;
}

if (response.hasFailed()) {
result = ExecutionResult.FAILED;
} else {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class BatchJobMessage implements JSONable<BatchJobMessage> {
private long batchJobId;
private boolean canceled;
private boolean existing;
private boolean abandoned;

@Override
public Class<BatchJobMessage> getJSONTargetClass() {
Expand Down Expand Up @@ -61,12 +60,4 @@ public boolean isExisting() {
return existing;
}

public void setAbandoned(boolean abandoned) {
this.abandoned = abandoned;
}

public boolean isAbandoned() {
return abandoned;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public enum MessageID {

SCAN_FAILED,

/**
* Will happen because of scan has been restarted
*/
SCAN_ABANDONDED,

/**
* This message will contain full data of an created user. Secure data will be
* only contained hashed.
Expand Down

0 comments on commit e585d9b

Please sign in to comment.