Skip to content

Commit 5a1b3e7

Browse files
authored
Merge pull request #136 from iExecBlockchainComputing/release/8.4.0
Release/8.4.0
2 parents ff6ce5c + 0e4c21b commit 5a1b3e7

File tree

13 files changed

+306
-263
lines changed

13 files changed

+306
-263
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [[8.4.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.4.0) 2024-02-29
6+
7+
### New Features
8+
9+
- Label REST API with `v1` version. (#132)
10+
11+
### Bug Fixes
12+
13+
- Add retry mechanism and set command status to `FAILURE` after all attempts failed. (#134)
14+
15+
### Quality
16+
17+
- Remove `/tasks/{chainTaskId}` endpoint, the adapter must only call `initialize` and `finalize` **PoCo** methods. (#130)
18+
- Remove `/broker/orders/match` endpoint, `matchOrders` must be done through the **Market API**. (#131)
19+
- Remove dead code in `IexecHubService` and `CommandStorage`. (#133)
20+
21+
### Dependency Upgrades
22+
23+
- Upgrade to `iexec-common` 8.4.0. (#135)
24+
525
## [[8.3.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.3.0) 2024-01-10
626

727
### New Features

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
version=8.3.0
2-
iexecCommonVersion=8.3.1
1+
version=8.4.0
2+
iexecCommonVersion=8.4.0
33
iexecCommonsPocoVersion=3.2.0
44

55
nexusUser

iexec-blockchain-adapter-api-library/src/main/java/com/iexec/blockchain/api/BlockchainAdapterApiClient.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
2020
import com.iexec.common.config.PublicChainConfig;
21-
import com.iexec.common.sdk.broker.BrokerOrder;
22-
import com.iexec.commons.poco.chain.ChainTask;
2321
import feign.Param;
2422
import feign.RequestLine;
2523

@@ -34,27 +32,20 @@
3432
*/
3533
public interface BlockchainAdapterApiClient {
3634

37-
// region authenticated APIs
38-
@RequestLine("POST /broker/orders/match")
39-
String matchOrders(BrokerOrder brokerOrder);
40-
4135
@RequestLine("GET /metrics")
4236
String getMetrics();
4337

44-
@RequestLine("GET /tasks/{chainTaskId}")
45-
ChainTask getTask(@Param("chainTaskId") String chainTaskId);
46-
47-
@RequestLine("POST /tasks/initialize?chainDealId={chainDealId}&taskIndex={taskIndex}")
38+
@RequestLine("POST /v1/tasks/initialize?chainDealId={chainDealId}&taskIndex={taskIndex}")
4839
String requestInitializeTask(@Param("chainDealId") String chainDealId,
4940
@Param("taskIndex") int taskIndex);
5041

51-
@RequestLine("GET /tasks/initialize/{chainTaskId}/status")
42+
@RequestLine("GET /v1/tasks/initialize/{chainTaskId}/status")
5243
CommandStatus getStatusForInitializeTaskRequest(@Param("chainTaskId") String chainTaskId);
5344

54-
@RequestLine("POST /tasks/finalize/{chainTaskId}")
45+
@RequestLine("POST /v1/tasks/finalize/{chainTaskId}")
5546
String requestFinalizeTask(@Param("chainTaskId") String chainTaskId, TaskFinalizeArgs taskFinalizeArgs);
5647

57-
@RequestLine("GET /tasks/finalize/{chainTaskId}/status")
48+
@RequestLine("GET /v1/tasks/finalize/{chainTaskId}/status")
5849
CommandStatus getStatusForFinalizeTaskRequest(@Param("chainTaskId") String chainTaskId);
5950

6051
// endregion

src/main/java/com/iexec/blockchain/broker/BrokerController.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/main/java/com/iexec/blockchain/command/generic/CommandEngine.java

Lines changed: 15 additions & 13 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.
@@ -27,6 +27,8 @@
2727
@Slf4j
2828
public abstract class CommandEngine<C extends Command<A>, A extends CommandArgs> {
2929

30+
private static final int MAX_ATTEMPTS = 5;
31+
3032
private final CommandBlockchain<A> blockchainService;
3133
private final CommandStorage<C, A> updaterService;
3234
private final QueueService queueService;
@@ -88,24 +90,24 @@ public void triggerBlockchainCommand(A args) {
8890
chainObjectId, args);
8991
return;
9092
}
93+
int attempt = 0;
9194
log.info("Processing command [chainObjectId:{}, commandArgs:{}]",
9295
chainObjectId, args);
93-
TransactionReceipt receipt;
94-
try {
95-
receipt = blockchainService.sendBlockchainCommand(args);
96-
} catch (Exception e) {
97-
log.error("Something wrong happened while triggering blockchain " +
98-
"command [chainObjectId:{}, commandArgs:{}]",
99-
chainObjectId, args, e);
100-
//TODO Update to proper status: PROCESSING_FAILED or FAILURE
101-
return;
96+
TransactionReceipt receipt = null;
97+
while (attempt < MAX_ATTEMPTS && receipt == null) {
98+
attempt++;
99+
try {
100+
receipt = blockchainService.sendBlockchainCommand(args);
101+
} catch (Exception e) {
102+
log.error("Something wrong happened while triggering command [chainObjectId:{}, commandArgs:{}, attempt:{}]",
103+
chainObjectId, args, attempt, e);
104+
}
102105
}
103106
if (receipt == null) {
104107
log.error("Triggering blockchain command failed " +
105108
"(received null receipt after blockchain send) " +
106-
"[chainObjectId:{}, commandArgs:{}]",
107-
chainObjectId, args);
108-
return;
109+
"[chainObjectId:{}, commandArgs:{}, attempt:{}]",
110+
chainObjectId, args, attempt);
109111
}
110112
updaterService.updateToFinal(chainObjectId, receipt);
111113
}

src/main/java/com/iexec/blockchain/command/generic/CommandStorage.java

Lines changed: 14 additions & 24 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.
@@ -17,9 +17,7 @@
1717
package com.iexec.blockchain.command.generic;
1818

1919
import com.iexec.blockchain.api.CommandStatus;
20-
import lombok.NonNull;
2120
import lombok.extern.slf4j.Slf4j;
22-
import org.apache.commons.lang3.StringUtils;
2321
import org.web3j.protocol.core.methods.response.TransactionReceipt;
2422

2523
import java.time.Instant;
@@ -69,7 +67,6 @@ public boolean updateToReceived(A args) {
6967
public boolean updateToProcessing(String chainObjectId) {
7068
Optional<C> localCommand = commandRepository
7169
.findByChainObjectId(chainObjectId)
72-
.filter(command -> command.getStatus() != null)
7370
.filter(command -> command.getStatus() == CommandStatus.RECEIVED);
7471
if (localCommand.isEmpty()) {
7572
return false;
@@ -90,32 +87,25 @@ public boolean updateToProcessing(String chainObjectId) {
9087
* @param receipt blockchain receipt
9188
*/
9289
public void updateToFinal(String chainObjectId,
93-
@NonNull TransactionReceipt receipt) {
94-
Optional<C> localCommand = commandRepository
90+
TransactionReceipt receipt) {
91+
final C command = commandRepository
9592
.findByChainObjectId(chainObjectId)
96-
.filter(command -> command.getStatus() != null)
97-
.filter(command -> command.getStatus() == CommandStatus.PROCESSING);
98-
if (localCommand.isEmpty()) {
93+
.filter(cmd -> cmd.getStatus() == CommandStatus.PROCESSING)
94+
.orElse(null);
95+
if (command == null) {
96+
log.error("No entry was found in database, could not update to final state");
9997
return;
10098
}
101-
C command = localCommand.get();
10299

103-
CommandStatus status;
104-
if (StringUtils.isNotEmpty(receipt.getStatus())
105-
&& receipt.getStatus().equals("0x1")) {
106-
status = CommandStatus.SUCCESS;
107-
log.info("Success command with transaction receipt " +
108-
"[chainObjectId:{}, command:{}, receipt:{}]",
109-
chainObjectId,
110-
command.getClass().getSimpleName(),
111-
receipt);
100+
if (receipt != null && receipt.isStatusOK()) {
101+
command.setStatus(CommandStatus.SUCCESS);
102+
log.info("Success command with transaction receipt [chainObjectId:{}, command:{}, receipt:{}]",
103+
chainObjectId, command.getClass().getSimpleName(), receipt);
112104
} else {
113-
status = CommandStatus.FAILURE;
114-
log.info("Failure after transaction sent [chainObjectId:{}, " +
115-
"command:{}, receipt:{}]", chainObjectId,
116-
command.getClass().getSimpleName(), receipt);
105+
command.setStatus(CommandStatus.FAILURE);
106+
log.info("Failure after transaction sent [chainObjectId:{}, command:{}, receipt:{}]",
107+
chainObjectId, command.getClass().getSimpleName(), receipt);
117108
}
118-
command.setStatus(status);
119109
command.setTransactionReceipt(receipt);
120110
command.setFinalDate(Instant.now());
121111
commandRepository.save(command);
Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2021-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.
@@ -19,45 +19,24 @@
1919
import com.iexec.blockchain.api.CommandStatus;
2020
import com.iexec.blockchain.command.task.finalize.TaskFinalizeService;
2121
import com.iexec.blockchain.command.task.initialize.TaskInitializeService;
22-
import com.iexec.blockchain.tool.IexecHubService;
2322
import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
24-
import com.iexec.commons.poco.chain.ChainTask;
2523
import io.swagger.v3.oas.annotations.Operation;
2624
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
2725
import org.springframework.http.ResponseEntity;
2826
import org.springframework.web.bind.annotation.*;
2927

3028
import static com.iexec.blockchain.swagger.OpenApiConfig.SWAGGER_BASIC_AUTH;
3129

30+
/**
31+
* @deprecated Call /v1/tasks endpoints in {@code TaskControllerV1}
32+
*/
33+
@Deprecated(forRemoval = true)
3234
@RestController
3335
@RequestMapping("/tasks")
34-
public class TaskController {
35-
36-
private final IexecHubService iexecHubService;
37-
private final TaskInitializeService taskInitializeService;
38-
private final TaskFinalizeService taskFinalizeService;
36+
public class TaskController extends TaskControllerV1 {
3937

40-
public TaskController(IexecHubService iexecHubService,
41-
TaskInitializeService taskInitializeService,
42-
TaskFinalizeService taskFinalizeService) {
43-
this.iexecHubService = iexecHubService;
44-
this.taskInitializeService = taskInitializeService;
45-
this.taskFinalizeService = taskFinalizeService;
46-
}
47-
48-
/**
49-
* Read task metadata on the blockchain.
50-
*
51-
* @param chainTaskId blockchain ID of the task
52-
* @return task metadata
53-
*/
54-
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
55-
@GetMapping("/{chainTaskId}")
56-
public ResponseEntity<ChainTask> getTask(
57-
@PathVariable String chainTaskId) {
58-
return iexecHubService.getChainTask(chainTaskId)
59-
.map(ResponseEntity::ok)
60-
.orElse(ResponseEntity.notFound().build());
38+
public TaskController(TaskInitializeService taskInitializeService, TaskFinalizeService taskFinalizeService) {
39+
super(taskInitializeService, taskFinalizeService);
6140
}
6241

6342
/**
@@ -67,17 +46,13 @@ public ResponseEntity<ChainTask> getTask(
6746
* @param taskIndex index of the task int the bag
6847
* @return blockchain task ID if successful
6948
*/
49+
@Override
7050
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
7151
@PostMapping("/initialize")
7252
public ResponseEntity<String> requestInitializeTask(
7353
@RequestParam String chainDealId,
7454
@RequestParam int taskIndex) {
75-
String chainTaskId =
76-
taskInitializeService.start(chainDealId, taskIndex);
77-
if (!chainTaskId.isEmpty()) {
78-
return ResponseEntity.ok(chainTaskId);
79-
}
80-
return ResponseEntity.badRequest().build();
55+
return super.requestInitializeTask(chainDealId, taskIndex);
8156
}
8257

8358
/**
@@ -86,13 +61,12 @@ public ResponseEntity<String> requestInitializeTask(
8661
* @param chainTaskId blockchain ID of the task
8762
* @return status
8863
*/
64+
@Override
8965
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
9066
@GetMapping("/initialize/{chainTaskId}/status")
9167
public ResponseEntity<CommandStatus> getStatusForInitializeTaskRequest(
9268
@PathVariable String chainTaskId) {
93-
return taskInitializeService.getStatusForCommand(chainTaskId)
94-
.map(ResponseEntity::ok)
95-
.orElse(ResponseEntity.notFound().build());
69+
return super.getStatusForInitializeTaskRequest(chainTaskId);
9670
}
9771

9872
/**
@@ -102,15 +76,13 @@ public ResponseEntity<CommandStatus> getStatusForInitializeTaskRequest(
10276
* @param args input arguments for `finalize task`
10377
* @return blockchain task ID if successful
10478
*/
79+
@Override
10580
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
10681
@PostMapping("/finalize/{chainTaskId}")
10782
public ResponseEntity<String> requestFinalizeTask(
10883
@PathVariable String chainTaskId,
10984
@RequestBody TaskFinalizeArgs args) {
110-
if (!taskFinalizeService.start(chainTaskId, args).isEmpty()) {
111-
return ResponseEntity.ok(chainTaskId);
112-
}
113-
return ResponseEntity.badRequest().build();
85+
return super.requestFinalizeTask(chainTaskId, args);
11486
}
11587

11688
/**
@@ -119,13 +91,12 @@ public ResponseEntity<String> requestFinalizeTask(
11991
* @param chainTaskId blockchain ID of the task
12092
* @return status
12193
*/
94+
@Override
12295
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
12396
@GetMapping("/finalize/{chainTaskId}/status")
12497
public ResponseEntity<CommandStatus> getStatusForFinalizeTaskRequest(
12598
@PathVariable String chainTaskId) {
126-
return taskFinalizeService.getStatusForCommand(chainTaskId)
127-
.map(ResponseEntity::ok)
128-
.orElse(ResponseEntity.notFound().build());
99+
return super.getStatusForFinalizeTaskRequest(chainTaskId);
129100
}
130101

131102
}

0 commit comments

Comments
 (0)