Skip to content

Commit

Permalink
Merge pull request #136 from iExecBlockchainComputing/release/8.4.0
Browse files Browse the repository at this point in the history
Release/8.4.0
  • Loading branch information
mcornaton authored Feb 29, 2024
2 parents ff6ce5c + 0e4c21b commit 5a1b3e7
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 263 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

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

## [[8.4.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.4.0) 2024-02-29

### New Features

- Label REST API with `v1` version. (#132)

### Bug Fixes

- Add retry mechanism and set command status to `FAILURE` after all attempts failed. (#134)

### Quality

- Remove `/tasks/{chainTaskId}` endpoint, the adapter must only call `initialize` and `finalize` **PoCo** methods. (#130)
- Remove `/broker/orders/match` endpoint, `matchOrders` must be done through the **Market API**. (#131)
- Remove dead code in `IexecHubService` and `CommandStorage`. (#133)

### Dependency Upgrades

- Upgrade to `iexec-common` 8.4.0. (#135)

## [[8.3.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.3.0) 2024-01-10

### New Features
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version=8.3.0
iexecCommonVersion=8.3.1
version=8.4.0
iexecCommonVersion=8.4.0
iexecCommonsPocoVersion=3.2.0

nexusUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
import com.iexec.common.config.PublicChainConfig;
import com.iexec.common.sdk.broker.BrokerOrder;
import com.iexec.commons.poco.chain.ChainTask;
import feign.Param;
import feign.RequestLine;

Expand All @@ -34,27 +32,20 @@
*/
public interface BlockchainAdapterApiClient {

// region authenticated APIs
@RequestLine("POST /broker/orders/match")
String matchOrders(BrokerOrder brokerOrder);

@RequestLine("GET /metrics")
String getMetrics();

@RequestLine("GET /tasks/{chainTaskId}")
ChainTask getTask(@Param("chainTaskId") String chainTaskId);

@RequestLine("POST /tasks/initialize?chainDealId={chainDealId}&taskIndex={taskIndex}")
@RequestLine("POST /v1/tasks/initialize?chainDealId={chainDealId}&taskIndex={taskIndex}")
String requestInitializeTask(@Param("chainDealId") String chainDealId,
@Param("taskIndex") int taskIndex);

@RequestLine("GET /tasks/initialize/{chainTaskId}/status")
@RequestLine("GET /v1/tasks/initialize/{chainTaskId}/status")
CommandStatus getStatusForInitializeTaskRequest(@Param("chainTaskId") String chainTaskId);

@RequestLine("POST /tasks/finalize/{chainTaskId}")
@RequestLine("POST /v1/tasks/finalize/{chainTaskId}")
String requestFinalizeTask(@Param("chainTaskId") String chainTaskId, TaskFinalizeArgs taskFinalizeArgs);

@RequestLine("GET /tasks/finalize/{chainTaskId}/status")
@RequestLine("GET /v1/tasks/finalize/{chainTaskId}/status")
CommandStatus getStatusForFinalizeTaskRequest(@Param("chainTaskId") String chainTaskId);

// endregion
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/com/iexec/blockchain/broker/BrokerController.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,8 @@
@Slf4j
public abstract class CommandEngine<C extends Command<A>, A extends CommandArgs> {

private static final int MAX_ATTEMPTS = 5;

private final CommandBlockchain<A> blockchainService;
private final CommandStorage<C, A> updaterService;
private final QueueService queueService;
Expand Down Expand Up @@ -88,24 +90,24 @@ public void triggerBlockchainCommand(A args) {
chainObjectId, args);
return;
}
int attempt = 0;
log.info("Processing command [chainObjectId:{}, commandArgs:{}]",
chainObjectId, args);
TransactionReceipt receipt;
try {
receipt = blockchainService.sendBlockchainCommand(args);
} catch (Exception e) {
log.error("Something wrong happened while triggering blockchain " +
"command [chainObjectId:{}, commandArgs:{}]",
chainObjectId, args, e);
//TODO Update to proper status: PROCESSING_FAILED or FAILURE
return;
TransactionReceipt receipt = null;
while (attempt < MAX_ATTEMPTS && receipt == null) {
attempt++;
try {
receipt = blockchainService.sendBlockchainCommand(args);
} catch (Exception e) {
log.error("Something wrong happened while triggering command [chainObjectId:{}, commandArgs:{}, attempt:{}]",
chainObjectId, args, attempt, e);
}
}
if (receipt == null) {
log.error("Triggering blockchain command failed " +
"(received null receipt after blockchain send) " +
"[chainObjectId:{}, commandArgs:{}]",
chainObjectId, args);
return;
"[chainObjectId:{}, commandArgs:{}, attempt:{}]",
chainObjectId, args, attempt);
}
updaterService.updateToFinal(chainObjectId, receipt);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,7 @@
package com.iexec.blockchain.command.generic;

import com.iexec.blockchain.api.CommandStatus;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.web3j.protocol.core.methods.response.TransactionReceipt;

import java.time.Instant;
Expand Down Expand Up @@ -69,7 +67,6 @@ public boolean updateToReceived(A args) {
public boolean updateToProcessing(String chainObjectId) {
Optional<C> localCommand = commandRepository
.findByChainObjectId(chainObjectId)
.filter(command -> command.getStatus() != null)
.filter(command -> command.getStatus() == CommandStatus.RECEIVED);
if (localCommand.isEmpty()) {
return false;
Expand All @@ -90,32 +87,25 @@ public boolean updateToProcessing(String chainObjectId) {
* @param receipt blockchain receipt
*/
public void updateToFinal(String chainObjectId,
@NonNull TransactionReceipt receipt) {
Optional<C> localCommand = commandRepository
TransactionReceipt receipt) {
final C command = commandRepository
.findByChainObjectId(chainObjectId)
.filter(command -> command.getStatus() != null)
.filter(command -> command.getStatus() == CommandStatus.PROCESSING);
if (localCommand.isEmpty()) {
.filter(cmd -> cmd.getStatus() == CommandStatus.PROCESSING)
.orElse(null);
if (command == null) {
log.error("No entry was found in database, could not update to final state");
return;
}
C command = localCommand.get();

CommandStatus status;
if (StringUtils.isNotEmpty(receipt.getStatus())
&& receipt.getStatus().equals("0x1")) {
status = CommandStatus.SUCCESS;
log.info("Success command with transaction receipt " +
"[chainObjectId:{}, command:{}, receipt:{}]",
chainObjectId,
command.getClass().getSimpleName(),
receipt);
if (receipt != null && receipt.isStatusOK()) {
command.setStatus(CommandStatus.SUCCESS);
log.info("Success command with transaction receipt [chainObjectId:{}, command:{}, receipt:{}]",
chainObjectId, command.getClass().getSimpleName(), receipt);
} else {
status = CommandStatus.FAILURE;
log.info("Failure after transaction sent [chainObjectId:{}, " +
"command:{}, receipt:{}]", chainObjectId,
command.getClass().getSimpleName(), receipt);
command.setStatus(CommandStatus.FAILURE);
log.info("Failure after transaction sent [chainObjectId:{}, command:{}, receipt:{}]",
chainObjectId, command.getClass().getSimpleName(), receipt);
}
command.setStatus(status);
command.setTransactionReceipt(receipt);
command.setFinalDate(Instant.now());
commandRepository.save(command);
Expand Down
61 changes: 16 additions & 45 deletions src/main/java/com/iexec/blockchain/command/task/TaskController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2021-2024 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,45 +19,24 @@
import com.iexec.blockchain.api.CommandStatus;
import com.iexec.blockchain.command.task.finalize.TaskFinalizeService;
import com.iexec.blockchain.command.task.initialize.TaskInitializeService;
import com.iexec.blockchain.tool.IexecHubService;
import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
import com.iexec.commons.poco.chain.ChainTask;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

/**
* @deprecated Call /v1/tasks endpoints in {@code TaskControllerV1}
*/
@Deprecated(forRemoval = true)
@RestController
@RequestMapping("/tasks")
public class TaskController {

private final IexecHubService iexecHubService;
private final TaskInitializeService taskInitializeService;
private final TaskFinalizeService taskFinalizeService;
public class TaskController extends TaskControllerV1 {

public TaskController(IexecHubService iexecHubService,
TaskInitializeService taskInitializeService,
TaskFinalizeService taskFinalizeService) {
this.iexecHubService = iexecHubService;
this.taskInitializeService = taskInitializeService;
this.taskFinalizeService = taskFinalizeService;
}

/**
* Read task metadata on the blockchain.
*
* @param chainTaskId blockchain ID of the task
* @return task metadata
*/
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
@GetMapping("/{chainTaskId}")
public ResponseEntity<ChainTask> getTask(
@PathVariable String chainTaskId) {
return iexecHubService.getChainTask(chainTaskId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
public TaskController(TaskInitializeService taskInitializeService, TaskFinalizeService taskFinalizeService) {
super(taskInitializeService, taskFinalizeService);
}

/**
Expand All @@ -67,17 +46,13 @@ public ResponseEntity<ChainTask> getTask(
* @param taskIndex index of the task int the bag
* @return blockchain task ID if successful
*/
@Override
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
@PostMapping("/initialize")
public ResponseEntity<String> requestInitializeTask(
@RequestParam String chainDealId,
@RequestParam int taskIndex) {
String chainTaskId =
taskInitializeService.start(chainDealId, taskIndex);
if (!chainTaskId.isEmpty()) {
return ResponseEntity.ok(chainTaskId);
}
return ResponseEntity.badRequest().build();
return super.requestInitializeTask(chainDealId, taskIndex);
}

/**
Expand All @@ -86,13 +61,12 @@ public ResponseEntity<String> requestInitializeTask(
* @param chainTaskId blockchain ID of the task
* @return status
*/
@Override
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
@GetMapping("/initialize/{chainTaskId}/status")
public ResponseEntity<CommandStatus> getStatusForInitializeTaskRequest(
@PathVariable String chainTaskId) {
return taskInitializeService.getStatusForCommand(chainTaskId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
return super.getStatusForInitializeTaskRequest(chainTaskId);
}

/**
Expand All @@ -102,15 +76,13 @@ public ResponseEntity<CommandStatus> getStatusForInitializeTaskRequest(
* @param args input arguments for `finalize task`
* @return blockchain task ID if successful
*/
@Override
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
@PostMapping("/finalize/{chainTaskId}")
public ResponseEntity<String> requestFinalizeTask(
@PathVariable String chainTaskId,
@RequestBody TaskFinalizeArgs args) {
if (!taskFinalizeService.start(chainTaskId, args).isEmpty()) {
return ResponseEntity.ok(chainTaskId);
}
return ResponseEntity.badRequest().build();
return super.requestFinalizeTask(chainTaskId, args);
}

/**
Expand All @@ -119,13 +91,12 @@ public ResponseEntity<String> requestFinalizeTask(
* @param chainTaskId blockchain ID of the task
* @return status
*/
@Override
@Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH))
@GetMapping("/finalize/{chainTaskId}/status")
public ResponseEntity<CommandStatus> getStatusForFinalizeTaskRequest(
@PathVariable String chainTaskId) {
return taskFinalizeService.getStatusForCommand(chainTaskId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
return super.getStatusForFinalizeTaskRequest(chainTaskId);
}

}
Loading

0 comments on commit 5a1b3e7

Please sign in to comment.