Skip to content

Commit

Permalink
Revert upload run return type to string
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
  • Loading branch information
lampajr committed Dec 5, 2024
1 parent 08ac154 commit db1bf13
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
19 changes: 5 additions & 14 deletions docs/site/content/en/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -653,28 +653,19 @@ paths:
\ of created run IDs if available, or an empty list if processing is still\
\ ongoing. Label values and change detection processing is performed asynchronously."
content:
application/json:
text/plain:
schema:
type: array
items:
format: int32
type: integer
example:
- 101
- 102
- 103
example:
- 101
- 102
- 103
type: string
example: "101,102,103"
example: "101,102,103"
"204":
description: Data is valid but no run was created
content:
text/plain: {}
"400":
description: Some fields are missing or invalid
content:
application/json: {}
text/plain: {}
/api/run/list:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ Response add(@QueryParam("test") String testNameOrId,
@APIResponses(value = {
@APIResponse(responseCode = "202", description = "The request has been accepted for processing. Returns a list of created run IDs if available, "
+ "or an empty list if processing is still ongoing. Label values and change detection processing " +
"is performed asynchronously.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.ARRAY, implementation = Integer.class, example = "[101, 102, 103]"), example = "[101, 102, 103]")),
"is performed asynchronously.", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = SchemaType.STRING, example = "101,102,103"), example = "101,102,103")),
@APIResponse(responseCode = "204", description = "Data is valid but no run was created", content = @Content(mediaType = MediaType.TEXT_PLAIN)),
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.TEXT_PLAIN))
})
Response addRunFromData(@QueryParam("start") String start,
@QueryParam("stop") String stop,
Expand All @@ -245,9 +245,9 @@ Response addRunFromData(@QueryParam("start") String start,
@APIResponses(value = {
@APIResponse(responseCode = "202", description = "The request has been accepted for processing. Returns a list of created run IDs if available, "
+ "or an empty list if processing is still ongoing. Label values and change detection processing " +
"is performed asynchronously.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.ARRAY, implementation = Integer.class, example = "[101, 102, 103]"), example = "[101, 102, 103]")),
"is performed asynchronously.", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = SchemaType.STRING, example = "101,102,103"), example = "101,102,103")),
@APIResponse(responseCode = "204", description = "Data is valid but no run was created", content = @Content(mediaType = MediaType.TEXT_PLAIN)),
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.TEXT_PLAIN))
})
Response addRunFromData(@Parameter(required = true) @QueryParam("start") String start,
@Parameter(required = true) @QueryParam("stop") String stop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Response addRunFromData(String start, String stop, String test,
// if the request is accepted return 202 with all generated run ids
// if no run ids, means all run upload have been queued up (datastore scenario)
return Response.status(Response.Status.ACCEPTED)
.entity(runs.stream().map(val -> val.runId).toList())
.entity(runs.stream().map(val -> Integer.toString(val.runId)).collect(Collectors.joining(",")))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public void processSchemaSync(int schemaId) {
public void processRunUpload(RunUpload runUpload) {
log.debugf("Run Upload: %d", runUpload.testId);
runService.persistRun(runUpload);

}

@Transactional(Transactional.TxType.NOT_SUPPORTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,18 @@ protected int uploadRun(long start, long stop, Object runJson, String test) {
}

protected int uploadRun(long start, long stop, Object runJson, String test, String owner, Access access) {
List<?> runIds = given().auth().oauth2(getUploaderToken())
String runIdsAsString = given().auth().oauth2(getUploaderToken())
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.body(runJson)
.post("/api/run/data?start=" + start + "&stop=" + stop + "&test=" + test + "&owner=" + owner + "&access="
+ access)
.then()
.statusCode(202)
.extract().as(List.class);
.extract().asString();

List<Integer> runIds = parseCommaSeparatedIds(runIdsAsString);
assertEquals(1, runIds.size());
return Integer.parseInt(runIds.get(0).toString());
return runIds.get(0);
}

protected List<Integer> uploadRun(String start, String stop, String test, String owner, Access access,
Expand All @@ -307,17 +308,18 @@ protected List<Integer> uploadRun(String start, String stop, String test, String
schemaUri, description, jakarta.ws.rs.core.Response.Status.ACCEPTED.getStatusCode(), runJson);
}

@SuppressWarnings("unchecked")
protected List<Integer> uploadRun(String start, String stop, String test, String owner, Access access,
String schemaUri, String description, Integer statusCode, Object runJson) {
return RestAssured.given().auth().oauth2(getUploaderToken())
String runIdsAsString = RestAssured.given().auth().oauth2(getUploaderToken())
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.body(runJson)
.post("/api/run/data?start=" + start + "&stop=" + stop + "&test=" + test + "&owner=" + owner
+ "&access=" + access + "&schema=" + schemaUri + "&description=" + description)
.then()
.statusCode(statusCode)
.extract().as(List.class);
.extract().asString();

return parseCommaSeparatedIds(runIdsAsString);
}

protected int uploadRun(long timestamp, JsonNode data, JsonNode metadata, String testName) {
Expand All @@ -326,8 +328,7 @@ protected int uploadRun(long timestamp, JsonNode data, JsonNode metadata, String

protected int uploadRun(long start, long stop, JsonNode data, JsonNode metadata, String testName, String owner,
Access access) {
@SuppressWarnings("unchecked")
List<Integer> runIds = given().auth().oauth2(getUploaderToken())
String runIdsAsString = given().auth().oauth2(getUploaderToken())
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA)
// the .toString().getBytes(...) is required because RestAssured otherwise won't send the filename
// and Quarkus in turn will use null FileUpload: https://github.com/quarkusio/quarkus/issues/20938
Expand All @@ -338,15 +339,15 @@ protected int uploadRun(long start, long stop, JsonNode data, JsonNode metadata,
+ access)
.then()
.statusCode(202)
.extract().as(List.class);
.extract().asString();
List<Integer> runIds = parseCommaSeparatedIds(runIdsAsString);
assertEquals(1, runIds.size());
return runIds.get(0);
}

protected int uploadRun(String start, String stop, JsonNode data, JsonNode metadata, String testName, String owner,
Access access) {
@SuppressWarnings("unchecked")
List<Integer> runIds = given().auth().oauth2(getUploaderToken())
String runIdsAsString = given().auth().oauth2(getUploaderToken())
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA)
// the .toString().getBytes(...) is required because RestAssured otherwise won't send the filename
// and Quarkus in turn will use null FileUpload: https://github.com/quarkusio/quarkus/issues/20938
Expand All @@ -357,7 +358,8 @@ protected int uploadRun(String start, String stop, JsonNode data, JsonNode metad
+ access)
.then()
.statusCode(202)
.extract().as(List.class);
.extract().asString();
List<Integer> runIds = parseCommaSeparatedIds(runIdsAsString);
assertEquals(1, runIds.size());
return runIds.get(0);
}
Expand Down Expand Up @@ -1154,4 +1156,9 @@ protected <T> void testSerialization(T event, Class<T> eventClass) {
throw new AssertionError("Cannot deserialize " + event + " from " + changeJson.toPrettyString(), e);
}
}

private List<Integer> parseCommaSeparatedIds(String idsAsString) {
return idsAsString.isBlank() ? List.of()
: Stream.of(idsAsString.trim().split(",")).map(Integer::parseInt).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Response add(@QueryParam("test") String testNameOrId,

@POST
@Path("data")
@Produces(MediaType.TEXT_PLAIN) // run ID as string
@Produces(MediaType.TEXT_PLAIN) // array of generated Run IDs
Response addRunFromData(@QueryParam("start") String start,
@QueryParam("stop") String stop,
@QueryParam("test") String test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public void testAddRunFromData() throws JsonProcessingException {
JsonNode payload = new ObjectMapper().readTree(resourceToString("data/config-quickstart.jvm.json"));

try {
horreumClient.runService.addRunFromData("$.start", "$.stop", dummyTest.name, dummyTest.owner, Access.PUBLIC,
horreumClient.runService.addRunFromData("$.start", "$.stop", dummyTest.name, dummyTest.owner,
Access.PUBLIC,
null, "test", payload);
} catch (BadRequestException badRequestException) {
fail(badRequestException.getMessage()
Expand Down

0 comments on commit db1bf13

Please sign in to comment.