From f1f61a3a389fad56ba074393465a85538ed2a6d3 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Mon, 23 Oct 2023 10:16:43 +0200 Subject: [PATCH] Add `iexec-core-library` subproject --- CHANGELOG.md | 3 + build.gradle | 41 +++++----- iexec-core-library/build.gradle | 48 +++++++++++ .../com/iexec/core/api/SchedulerClient.java | 79 +++++++++++++++++++ .../core/api/SchedulerClientBuilder.java | 30 +++++++ .../iexec/core/api/SchedulerClientTest.java | 30 +++++++ settings.gradle | 1 + 7 files changed, 211 insertions(+), 21 deletions(-) create mode 100644 iexec-core-library/build.gradle create mode 100644 iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClient.java create mode 100644 iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClientBuilder.java create mode 100644 iexec-core-library/src/test/java/com/iexec/core/api/SchedulerClientTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6f313d7..f14818281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2023 +### New Features +- Create `iexec-core-library` sub-project to split shared code/apis from specific scheduler application code. (#623) + ## [[8.2.0]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.2.0) 2023-09-29 ### New Features diff --git a/build.gradle b/build.gradle index 3dd32c36f..798cdfdbc 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,6 @@ plugins { id 'maven-publish' } -group = 'com.iexec.core' - ext { springCloudVersion = '2021.0.8' jjwtVersion = '0.11.5' @@ -21,21 +19,28 @@ if (!project.hasProperty('gitBranch')) { ext.gitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim() } -if (gitBranch != 'main' && gitBranch != 'master' && ! (gitBranch ==~ '(release|hotfix|support)/.*')) { - version += '-NEXT-SNAPSHOT' -} - -repositories { - mavenLocal() - mavenCentral() - maven { - url "https://docker-regis-adm.iex.ec/repository/maven-public/" - credentials { - username nexusUser - password nexusPassword +allprojects { + group = 'com.iexec.core' + if (gitBranch != 'main' && gitBranch != 'master' && !(gitBranch ==~ '(release|hotfix|support)/.*')) { + version += '-NEXT-SNAPSHOT' + } + repositories { + mavenLocal() + mavenCentral() + maven { + url "https://docker-regis-adm.iex.ec/repository/maven-public/" + credentials { + username nexusUser + password nexusPassword + } + } + maven { url "https://jitpack.io" } + } + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) } } - maven { url "https://jitpack.io" } } dependencyManagement { @@ -104,12 +109,6 @@ dependencies { testImplementation "org.testcontainers:mongodb:$testContainersVersion" } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } -} - jar { enabled = true archiveClassifier.set('library') diff --git a/iexec-core-library/build.gradle b/iexec-core-library/build.gradle new file mode 100644 index 000000000..e98fb2bd7 --- /dev/null +++ b/iexec-core-library/build.gradle @@ -0,0 +1,48 @@ +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" + testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +java { + withJavadocJar() + withSourcesJar() +} + + +tasks.withType(Test).configureEach { + finalizedBy tasks.jacocoTestReport + useJUnitPlatform() +} + +// 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: '' + } + } +} diff --git a/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClient.java b/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClient.java new file mode 100644 index 000000000..447cb8e2b --- /dev/null +++ b/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClient.java @@ -0,0 +1,79 @@ +/* + * Copyright 2023-2023 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.config.PublicConfiguration; +import com.iexec.common.config.WorkerModel; +import com.iexec.common.replicate.ReplicateStatusUpdate; +import com.iexec.common.replicate.ReplicateTaskSummary; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationType; +import feign.Headers; +import feign.Param; +import feign.RequestLine; + +import java.security.Signature; +import java.util.List; + +public interface SchedulerClient { + + @RequestLine("GET /version") + String getCoreVersion(); + + // region /workers + @RequestLine("GET /workers/challenge?walletAddress={walletAddress}") + String getChallenge(@Param("walletAddress") String walletAddress); + + @RequestLine("POST /workers/login?walletAddress={walletAddress}") + String login(@Param("walletAddress") String walletAddress, Signature signature); + + @RequestLine("POST /workers/ping") + @Headers("Authorization: {authorization}") + String ping(@Param("authorization") String authorization); + + @RequestLine("POST /workers/register") + @Headers("Authorization: {authorization}") + void registerWorker(@Param("authorization") String authorization, WorkerModel model); + + @RequestLine("GET /workers/config") + PublicConfiguration getPublicConfiguration(); + + @RequestLine("GET /workers/computing") + @Headers("Authorization: {authorization}") + List getComputingTasks(@Param("authorization") String authorization); + // endregion + + // region /replicates + @RequestLine("GET /replicates/available?blockNumber={blockNumber}") + @Headers("Authorization: {authorization}") + ReplicateTaskSummary getAvailableReplicateTaskSummary( + @Param("authorization") String authorization, @Param("blockNumber") long blockNumber); + + @RequestLine("GET /replicates/interrupted?blockNumber={blockNumber}") + @Headers("Authorization: {authorization}") + List getMissedTaskNotifications( + @Param("authorization") String authorization, @Param("blockNumber") long blockNumber); + + @RequestLine("POST /replicates/{chainTaskId}/updateStatus") + @Headers("Authorization: {authorization}") + TaskNotificationType updateReplicateStatus( + @Param("authorization") String authorization, + @Param("chainTaskId") String chainTaskId, + ReplicateStatusUpdate replicateStatusUpdate + ); + // endregion +} diff --git a/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClientBuilder.java b/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClientBuilder.java new file mode 100644 index 000000000..2362df281 --- /dev/null +++ b/iexec-core-library/src/main/java/com/iexec/core/api/SchedulerClientBuilder.java @@ -0,0 +1,30 @@ +/* + * Copyright 2023-2023 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; + +public class SchedulerClientBuilder { + + private SchedulerClientBuilder() {} + + public static SchedulerClient getInstance(Logger.Level logLevel, String url) { + return FeignBuilder.createBuilder(logLevel) + .target(SchedulerClient.class, url); + } +} diff --git a/iexec-core-library/src/test/java/com/iexec/core/api/SchedulerClientTest.java b/iexec-core-library/src/test/java/com/iexec/core/api/SchedulerClientTest.java new file mode 100644 index 000000000..58db33c9c --- /dev/null +++ b/iexec-core-library/src/test/java/com/iexec/core/api/SchedulerClientTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2023-2023 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 SchedulerClientTest { + + @Test + void instantiationTest() { + Assertions.assertNotNull(SchedulerClientBuilder.getInstance(Logger.Level.FULL, "localhost")); + } + +} diff --git a/settings.gradle b/settings.gradle index 249e4089d..0fa137f7b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,2 @@ rootProject.name = 'iexec-core' +include 'iexec-core-library'