Skip to content

Commit

Permalink
Remove additionalProperties from the TaskService sha256 (#4561)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbirk authored Aug 26, 2024
1 parent 5a87727 commit d415c37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ public String getSHA256() {
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);

final String encodedInput = Base64.getEncoder().encodeToString(input);
final String encodedAdditionalProperties = Base64.getEncoder()
.encodeToString(objectMapper.writeValueAsBytes(additionalProperties));

final String strHash = String.format("%s-%s-%s-%s", type, script, encodedInput, encodedAdditionalProperties);
final String strHash = String.format("%s-%s-%s", type, script, encodedInput);
final MessageDigest md = MessageDigest.getInstance("SHA-256");
return Base64.getEncoder().encodeToString(md.digest(strHash.getBytes(StandardCharsets.UTF_8)));
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ private static class TaskRequestWithId extends TaskRequest {
additionalProperties = req.getAdditionalProperties();
}

public TaskResponse createResponse(final TaskStatus status) {
public TaskResponse createResponse(final TaskStatus status, final String stdout, final String stderr) {
return new TaskResponse()
.setId(id)
.setStatus(status)
.setScript(getScript())
.setUserId(userId)
.setProjectId(projectId)
.setScript(getScript())
.setAdditionalProperties(getAdditionalProperties())
.setStdout(stdout)
.setStderr(stderr)
.setRequestSHA256(getSHA256());
}
}
Expand All @@ -109,11 +111,18 @@ public CompletableTaskFuture(final UUID id) {
this.future = new CompletableFuture<>();
}

public CompletableTaskFuture(final UUID id, final TaskResponse resp) {
this.id = id;
public CompletableTaskFuture(final TaskRequestWithId req, final TaskResponse resp) {
this.id = req.getId();

// We are re-using a cached response, so lets create a TaskResponse from the
// actual TaskRequest
// and then copy over the response payload.
final TaskResponse actualResp = req.createResponse(resp.getStatus(), resp.getStdout(), resp.getStderr());
actualResp.setOutput(resp.getOutput());

this.future = new CompletableFuture<>();
this.future.complete(resp);
this.latestResponse = resp;
this.future.complete(actualResp);
this.latestResponse = actualResp;
}

public synchronized void complete(final TaskResponse resp) {
Expand Down Expand Up @@ -464,7 +473,7 @@ public TaskFuture runTaskAsync(final TaskRequest r) throws JsonProcessingExcepti
log.info("Task response found in cache for SHA: {}", hash);

// create and return a completed task future
return new CompletableTaskFuture(req.getId(), resp);
return new CompletableTaskFuture(req, resp);
}

// no cache entry for task, send a new one
Expand Down Expand Up @@ -506,7 +515,7 @@ public TaskFuture runTaskAsync(final TaskRequest r) throws JsonProcessingExcepti
rabbitTemplate.convertAndSend(requestQueue, jsonStr);

// publish the queued task response
final TaskResponse queuedResponse = req.createResponse(TaskStatus.QUEUED);
final TaskResponse queuedResponse = req.createResponse(TaskStatus.QUEUED, "", "");
final String respJsonStr = objectMapper.writeValueAsString(queuedResponse);
rabbitTemplate.convertAndSend(TASK_RUNNER_RESPONSE_EXCHANGE, "", respJsonStr);

Expand Down

0 comments on commit d415c37

Please sign in to comment.