Skip to content

Commit 58f3e61

Browse files
authored
Deprecate legacy task feedback API endpoints (#701)
1 parent 4cb5e53 commit 58f3e61

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
1515

1616
- Always use `WorkerpoolAuthorization` to retrieve JWT and check result upload on Result Proxy. (#690)
1717
- Use correct `Signature` import in `SchedulerClient`. (#697)
18+
- Deprecate legacy task feedback API endpoints. (#701)
1819

1920
### Quality
2021

src/main/java/com/iexec/core/task/TaskController.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,10 +120,18 @@ ReplicateModel buildReplicateModel(Replicate replicate) {
120120
return replicateModel;
121121
}
122122

123-
@GetMapping(path = {
124-
"/tasks/{chainTaskId}/stdout", // @Deprecated
125-
"/tasks/{chainTaskId}/logs"
126-
})
123+
/**
124+
* @deprecated Use {@code /tasks/{chainTaskId}/logs} instead
125+
*/
126+
@Deprecated(forRemoval = true)
127+
@GetMapping("/tasks/{chainTaskId}/stdout")
128+
public ResponseEntity<TaskLogsModel> getTaskLogsLegacy(
129+
@PathVariable("chainTaskId") String chainTaskId,
130+
@RequestHeader("Authorization") String authorization) {
131+
return getTaskLogs(chainTaskId, authorization);
132+
}
133+
134+
@GetMapping("/tasks/{chainTaskId}/logs")
127135
public ResponseEntity<TaskLogsModel> getTaskLogs(
128136
@PathVariable("chainTaskId") String chainTaskId,
129137
@RequestHeader("Authorization") String authorization) {
@@ -147,10 +155,19 @@ public ResponseEntity<TaskLogsModel> getTaskLogs(
147155
.orElse(ResponseEntity.notFound().build());
148156
}
149157

150-
@GetMapping(path = {
151-
"/tasks/{chainTaskId}/replicates/{walletAddress}/stdout", // @Deprecated
152-
"/tasks/{chainTaskId}/replicates/{walletAddress}/logs"
153-
})
158+
/**
159+
* @deprecated Use {@code /tasks/{chainTaskId}/replicates/{walletAddress}/logs} instead
160+
*/
161+
@Deprecated(forRemoval = true)
162+
@GetMapping("/tasks/{chainTaskId}/replicates/{walletAddress}/stdout")
163+
public ResponseEntity<ComputeLogs> getComputeLogsLegacy(
164+
@PathVariable("chainTaskId") String chainTaskId,
165+
@PathVariable("walletAddress") String walletAddress,
166+
@RequestHeader("Authorization") String authorization) {
167+
return getComputeLogs(chainTaskId, walletAddress, authorization);
168+
}
169+
170+
@GetMapping("/tasks/{chainTaskId}/replicates/{walletAddress}/logs")
154171
public ResponseEntity<ComputeLogs> getComputeLogs(
155172
@PathVariable("chainTaskId") String chainTaskId,
156173
@PathVariable("walletAddress") String walletAddress,

src/test/java/com/iexec/core/task/TaskControllerTests.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2022-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,9 +32,10 @@
3232
import lombok.SneakyThrows;
3333
import org.junit.jupiter.api.BeforeEach;
3434
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.extension.ExtendWith;
3536
import org.mockito.InjectMocks;
3637
import org.mockito.Mock;
37-
import org.mockito.MockitoAnnotations;
38+
import org.mockito.junit.jupiter.MockitoExtension;
3839
import org.springframework.http.HttpStatus;
3940
import org.springframework.http.ResponseEntity;
4041
import org.web3j.crypto.Credentials;
@@ -47,6 +48,7 @@
4748
import static org.junit.jupiter.api.Assertions.*;
4849
import static org.mockito.Mockito.*;
4950

51+
@ExtendWith(MockitoExtension.class)
5052
class TaskControllerTests {
5153

5254
private static final String TASK_ID = "0xtask";
@@ -74,7 +76,6 @@ class TaskControllerTests {
7476
@BeforeEach
7577
@SneakyThrows
7678
void setUp() {
77-
MockitoAnnotations.openMocks(this);
7879
EIP712Domain domain = new EIP712Domain();
7980
challenge = new EIP712Challenge(domain, Challenge.builder().challenge("challenge").build());
8081
badChallenge = new EIP712Challenge(domain, Challenge.builder().challenge("bad-challenge").build());
@@ -86,11 +87,29 @@ void setUp() {
8687
//region utilities
8788
@SneakyThrows
8889
String generateWalletAddress() {
89-
ECKeyPair ecKeyPair = Keys.createEcKeyPair();
90-
return Credentials.create(ecKeyPair).getAddress();
90+
final ECKeyPair otherKeyPair = Keys.createEcKeyPair();
91+
return Credentials.create(otherKeyPair).getAddress();
9192
}
9293
//endregion
9394

95+
// region deprecated methods, to remove in future version
96+
@Test
97+
void shouldCallGetTaskLogs() {
98+
final TaskController controller = spy(taskController);
99+
final String authorization = String.join("_", challenge.getHash(), signature, requesterAddress);
100+
controller.getTaskLogsLegacy(TASK_ID, authorization);
101+
verify(controller).getTaskLogs(TASK_ID, authorization);
102+
}
103+
104+
@Test
105+
void shouldCallGetComputeLogs() {
106+
final TaskController controller = spy(taskController);
107+
final String authorization = String.join("_", challenge.getHash(), signature, requesterAddress);
108+
controller.getComputeLogsLegacy(TASK_ID, WORKER_ADDRESS, authorization);
109+
verify(controller).getComputeLogs(TASK_ID, WORKER_ADDRESS, authorization);
110+
}
111+
// endregion
112+
94113
//region getChallenge
95114
@Test
96115
void shouldGetChallenge() {
@@ -193,7 +212,7 @@ void shouldBuildReplicateModelWithComputeLogs() {
193212
ReplicateModel dto = taskController.buildReplicateModel(entity);
194213
assertEquals(TASK_ID, dto.getChainTaskId());
195214
assertTrue(dto.getSelf().endsWith("/tasks/0xtask/replicates/0xworker"));
196-
assertTrue(dto.getAppLogs().endsWith("/tasks/0xtask/replicates/0xworker/stdout"));
215+
assertTrue(dto.getAppLogs().endsWith("/tasks/0xtask/replicates/0xworker/logs"));
197216
}
198217
//endregion
199218

@@ -235,7 +254,6 @@ void shouldFailToGetTaskLogsWhenBadChallenge() {
235254
.build();
236255
when(iexecHubService.getTaskDescription(TASK_ID)).thenReturn(description);
237256
when(challengeService.getChallenge(requesterAddress)).thenReturn(challenge);
238-
when(taskLogsService.getComputeLogs(TASK_ID, WORKER_ADDRESS)).thenReturn(Optional.empty());
239257
ResponseEntity<TaskLogsModel> response = taskController.getTaskLogs(TASK_ID, authorization);
240258
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
241259
verify(iexecHubService).getTaskDescription(TASK_ID);
@@ -256,7 +274,6 @@ void shouldFailToGetTaskLogsWhenNotTaskRequester() {
256274
.build();
257275
String authorization = String.join("_", challenge.getHash(), signature, requesterAddress);
258276
when(iexecHubService.getTaskDescription(TASK_ID)).thenReturn(description);
259-
when(challengeService.getChallenge(requesterAddress)).thenReturn(challenge);
260277
ResponseEntity<TaskLogsModel> response = taskController.getTaskLogs(TASK_ID, authorization);
261278
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
262279
verify(iexecHubService).getTaskDescription(TASK_ID);
@@ -301,7 +318,6 @@ void shouldFailToGetComputeLogsWhenBadChallenge() {
301318
.build();
302319
when(iexecHubService.getTaskDescription(TASK_ID)).thenReturn(description);
303320
when(challengeService.getChallenge(requesterAddress)).thenReturn(challenge);
304-
when(taskLogsService.getComputeLogs(TASK_ID, WORKER_ADDRESS)).thenReturn(Optional.empty());
305321
ResponseEntity<ComputeLogs> response = taskController.getComputeLogs(TASK_ID, WORKER_ADDRESS, authorization);
306322
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
307323
verify(iexecHubService).getTaskDescription(TASK_ID);
@@ -322,7 +338,6 @@ void shouldFailToGetComputeLogsWhenNotTaskRequester() {
322338
.build();
323339
String authorization = String.join("_", challenge.getHash(), signature, requesterAddress);
324340
when(iexecHubService.getTaskDescription(TASK_ID)).thenReturn(description);
325-
when(challengeService.getChallenge(requesterAddress)).thenReturn(challenge);
326341
ResponseEntity<ComputeLogs> response = taskController.getComputeLogs(TASK_ID, WORKER_ADDRESS, authorization);
327342
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
328343
verify(iexecHubService).getTaskDescription(TASK_ID);

0 commit comments

Comments
 (0)