Skip to content

Commit

Permalink
[backend] Simulations never ends if no inject / disabled injects / de…
Browse files Browse the repository at this point in the history
…leted injects (#1586)
  • Loading branch information
isselparra authored Oct 23, 2024
1 parent 778a7ee commit 7273c2c
Showing 1 changed file with 61 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,61 +177,83 @@ private void executeInject(ExecutableInject executableInject) {
finalStatus.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(finalStatus);
} else {
inject.getInjectorContract().ifPresent(injectorContract -> {
setInjectStatusAndExecuteInject(executableInject, inject);
}
}

if (!inject.isReady()) {
private void setInjectStatusAndExecuteInject(ExecutableInject executableInject, Inject inject) {
inject.getInjectorContract().ifPresentOrElse(injectorContract -> {
if (!inject.isReady()) {
// Status
if (inject.getStatus().isEmpty()) {
InjectStatus status = new InjectStatus();
status.getTraces().add(InjectStatusExecution.traceError("The inject is not ready to be executed (missing mandatory fields)"));
status.setName(ExecutionStatus.ERROR);
status.setTrackingSentDate(Instant.now());
status.setInject(inject);
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
} else {
InjectStatus status = inject.getStatus().get();
status.getTraces().add(InjectStatusExecution.traceError("The inject is not ready to be executed (missing mandatory fields)"));
status.setName(ExecutionStatus.ERROR);
status.setTrackingSentDate(Instant.now());
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
}
return;
}

Injector externalInjector = injectorRepository.findByType(injectorContract.getInjector().getType()).orElseThrow();
LOGGER.log(Level.INFO, "Executing inject " + inject.getInject().getTitle());
// Executor logics
ExecutableInject newExecutableInject = executableInject;
if (Boolean.TRUE.equals(injectorContract.getNeedsExecutor())) {
try {
// Status
if (inject.getStatus().isEmpty()) {
InjectStatus status = new InjectStatus();
status.getTraces().add(InjectStatusExecution.traceError("The inject is not ready to be executed (missing mandatory fields)"));
status.setName(ExecutionStatus.ERROR);
status.setName(ExecutionStatus.EXECUTING);
status.setTrackingSentDate(Instant.now());
status.setInject(inject);
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
} else {
InjectStatus status = inject.getStatus().get();
status.getTraces().add(InjectStatusExecution.traceError("The inject is not ready to be executed (missing mandatory fields)"));
status.setName(ExecutionStatus.ERROR);
status.setName(ExecutionStatus.EXECUTING);
status.setTrackingSentDate(Instant.now());
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
}
return;
newExecutableInject = this.executionExecutorService.launchExecutorContext(executableInject, inject);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (externalInjector.isExternal()) {
executeExternal(newExecutableInject);
} else {
executeInternal(newExecutableInject);
}
}, () -> setInjectStatusWhenNoInjectorContractExists(inject));
}

Injector externalInjector = injectorRepository.findByType(injectorContract.getInjector().getType()).orElseThrow();
LOGGER.log(Level.INFO, "Executing inject " + inject.getInject().getTitle());
// Executor logics
ExecutableInject newExecutableInject = executableInject;
if (Boolean.TRUE.equals(injectorContract.getNeedsExecutor())) {
try {
// Status
if (inject.getStatus().isEmpty()) {
InjectStatus status = new InjectStatus();
status.setName(ExecutionStatus.EXECUTING);
status.setTrackingSentDate(Instant.now());
status.setInject(inject);
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
} else {
InjectStatus status = inject.getStatus().get();
status.setName(ExecutionStatus.EXECUTING);
status.setTrackingSentDate(Instant.now());
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
}
newExecutableInject = this.executionExecutorService.launchExecutorContext(executableInject, inject);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (externalInjector.isExternal()) {
executeExternal(newExecutableInject);
} else {
executeInternal(newExecutableInject);
}
});
private void setInjectStatusWhenNoInjectorContractExists(Inject inject) {
if (inject.getStatus().isEmpty()) {
InjectStatus status = new InjectStatus();
status.getTraces().add(InjectStatusExecution.traceError("Inject does not have a contract"));
status.setName(ExecutionStatus.ERROR);
status.setTrackingSentDate(Instant.now());
status.setInject(inject);
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
} else {
InjectStatus status = inject.getStatus().get();
status.getTraces().add(InjectStatusExecution.traceError("Inject does not have a contract"));
status.setName(ExecutionStatus.ERROR);
status.setTrackingSentDate(Instant.now());
status.setCommandsLines(atomicTestingService.getCommandsLinesFromInject(inject));
injectStatusRepository.save(status);
}
}

Expand Down

0 comments on commit 7273c2c

Please sign in to comment.