Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create iexec-task-api to access task feedback API #695

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2024

### New Features

- Create `iexec-task-api` to access task feedback API. (#695)

### Bug Fixes

- Always use `WorkerpoolAuthorization` to retrieve JWT and check result upload on Result Proxy. (#690)
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
implementation "com.iexec.result-proxy:iexec-result-proxy-library:$iexecResultVersion"
implementation "com.iexec.sms:iexec-sms-library:$iexecSmsVersion"
implementation project(':iexec-core-library')
implementation project(':iexec-task-api')

// spring
implementation "org.springframework.boot:spring-boot-starter"
Expand Down
2 changes: 2 additions & 0 deletions iexec-core-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ plugins {
dependencies {
implementation "com.iexec.commons:iexec-commons-poco:$iexecCommonsPocoVersion"
implementation "com.iexec.common:iexec-common:$iexecCommonVersion"
// TODO remove this later when migration has been done
implementation project(':iexec-task-api')
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2023-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 @@ -35,6 +35,10 @@
import java.util.List;

public interface SchedulerClient {
/**
* @deprecated Use iexec-task-feedback-api
*/
@Deprecated(forRemoval = true)
@RequestLine("GET /metrics")
PlatformMetric getMetrics();

Expand Down Expand Up @@ -85,18 +89,35 @@ TaskNotificationType updateReplicateStatus(
// endregion

// region /tasks

/**
* @deprecated Use iexec-task-feedback-api
*/
@Deprecated(forRemoval = true)
@RequestLine("GET /tasks/{chainTaskId}")
TaskModel getTask(@Param("chainTaskId") String chainTaskId);

/**
* @deprecated Use iexec-task-feedback-api
*/
@Deprecated(forRemoval = true)
@RequestLine("GET /tasks/logs/challenge?address={address}")
EIP712Challenge getTaskLogsChallenge(@Param("address") String address);

/**
* @deprecated Use iexec-task-feedback-api
*/
@Deprecated(forRemoval = true)
@Headers("Authorization: {authorization}")
@RequestLine("GET /tasks/{chainTaskId}/logs")
TaskLogsModel getTaskLogs(
@Param("chainTaskId") String chainTaskId,
@Param("authorization") String authorization);

/**
* @deprecated Use iexec-task-feedback-api
*/
@Deprecated(forRemoval = true)
@Headers("Authorization: {authorization}")
@RequestLine("GET /tasks/{chainTaskId}/replicates/{walletAddress}/logs")
ComputeLogs getComputeLogs(
Expand Down
57 changes: 57 additions & 0 deletions iexec-task-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
plugins {
id 'java-library'
id 'io.freefair.lombok'
id 'jacoco'
id 'maven-publish'
}

dependencies {
implementation "com.iexec.commons:iexec-commons-poco:$iexecCommonsPocoVersion"
implementation "com.iexec.common:iexec-common:$iexecCommonVersion"
}

java {
sourceCompatibility = "11"
targetCompatibility = "11"
withJavadocJar()
withSourcesJar()
}

testing {
suites {
test {
useJUnitJupiter()
dependencies {
implementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}
}
}
}

tasks.withType(Test).configureEach {
finalizedBy tasks.jacocoTestReport
}

// sonarqube code coverage requires jacoco XML report
jacocoTestReport {
reports {
xml.required = true
}
}

publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
credentials {
username nexusUser
password nexusPassword
}
url = project.hasProperty("nexusUrl") ? project.nexusUrl : ''
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iexec.core.api;

import com.iexec.common.replicate.ComputeLogs;
import com.iexec.commons.poco.eip712.entity.EIP712Challenge;
import com.iexec.core.logs.TaskLogsModel;
import com.iexec.core.metric.PlatformMetric;
import com.iexec.core.task.TaskModel;
import feign.Headers;
import feign.Param;
import feign.RequestLine;

public interface IexecTaskApiClient {
@RequestLine("GET /metrics")
PlatformMetric getMetrics();

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

@RequestLine("GET /tasks/logs/challenge?address={address}")
EIP712Challenge getTaskLogsChallenge(@Param("address") String address);

@Headers("Authorization: {authorization}")
@RequestLine("GET /tasks/{chainTaskId}/logs")
TaskLogsModel getTaskLogs(
@Param("chainTaskId") String chainTaskId,
@Param("authorization") String authorization);

@Headers("Authorization: {authorization}")
@RequestLine("GET /tasks/{chainTaskId}/replicates/{walletAddress}/logs")
ComputeLogs getComputeLogs(
@Param("chainTaskId") String chainTaskId,
@Param("walletAddress") String walletAddress,
@Param("authorization") String authorization);
// endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iexec.core.api;

import com.iexec.common.utils.FeignBuilder;
import feign.Logger;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class IexecTaskApiClientBuilder {
public static IexecTaskApiClient getInstance(Logger.Level logLevel, String url) {
return FeignBuilder.createBuilder(logLevel)
.target(IexecTaskApiClient.class, url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.iexec.core.task;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public enum TaskStatus {
RECEIVED,
Expand Down Expand Up @@ -52,10 +55,10 @@ public static List<TaskStatus> getWaitingContributionStatuses() {

public static List<TaskStatus> getWaitingRevealStatuses() {
return Arrays.asList(
CONSENSUS_REACHED,
AT_LEAST_ONE_REVEALED,
RESULT_UPLOADING,
RESULT_UPLOADED
CONSENSUS_REACHED,
AT_LEAST_ONE_REVEALED,
RESULT_UPLOADING,
RESULT_UPLOADED
);
}

Expand Down Expand Up @@ -83,9 +86,9 @@ public static boolean isInResultUploadPhase(TaskStatus status) {

public static boolean isInCompletionPhase(TaskStatus status) {
return Arrays.asList(
FINALIZING,
FINALIZED,
COMPLETED
FINALIZING,
FINALIZED,
COMPLETED
).contains(status);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iexec.core.api;

import feign.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class IexecTaskApiClientTests {
@Test
void instantiationTest() {
Assertions.assertNotNull(IexecTaskApiClientBuilder.getInstance(Logger.Level.FULL, "localhost"));
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'iexec-core'
include 'iexec-core-library'
include 'iexec-core-library', 'iexec-task-api'