Skip to content

Commit

Permalink
[backend] Prevent looping of caldera injector (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed May 17, 2024
1 parent 736ec12 commit 6f9f521
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private Endpoint findAndRegisterAssetForExecution(@NotNull final Inject inject,
newEndpoint.setIps(assetEndpoint.getIps());
newEndpoint.setHostname(assetEndpoint.getHostname());
newEndpoint.setPlatform(assetEndpoint.getPlatform());
newEndpoint.setExternalReference(agents.get(i).getPaw());
newEndpoint.setExternalReference(agents.get(j).getPaw());
newEndpoint.setExecutor(assetEndpoint.getExecutor());
endpointForExecution = this.endpointService.createEndpoint(newEndpoint);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@Log
@Service
public class CalderaResultCollectorService implements Runnable {
private final int EXPIRATION_TIME = 900;

private final InjectRepository injectRepository;
private final InjectStatusRepository injectStatusRepository;
Expand All @@ -54,6 +55,7 @@ public CalderaResultCollectorService(
}

@Override
@Transactional
public void run() {
// Retrieve Caldera inject not done
List<InjectStatus> injectStatuses = this.injectStatusRepository.pendingForInjectType(CalderaContract.TYPE);
Expand All @@ -74,7 +76,13 @@ public void run() {
ResultStatus resultStatus = this.calderaService.results(linkId);
log.log(Level.INFO, "Returning results");
if (resultStatus.getPaw() == null) {
injectStatus.getTraces().add(traceInfo("Results are not yet available (still on-going)"));
if (injectStatus.getTrackingSentDate().isBefore(Instant.now().minus(EXPIRATION_TIME / 60, ChronoUnit.MINUTES))) {
injectStatus.getTraces().add(traceError("Cannot get result for " + linkId + ", injection is expired"));
computeInjectStatus(injectStatus, finalExecutionTime, 0, 0);
computeInject(injectStatus);
} else {
injectStatus.getTraces().add(traceInfo("Results are not yet available (still on-going)"));
}
} else {
Endpoint currentEndpoint = this.endpointService.findByExternalReference(resultStatus.getPaw()).orElseThrow();
String currentAssetId = currentEndpoint.getId();
Expand Down

0 comments on commit 6f9f521

Please sign in to comment.