From 0bf0516b3b233a982f94ce0f37417c68cd9fdd40 Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Tue, 23 Apr 2024 14:52:33 +0200 Subject: [PATCH 1/4] Create a `ConfigServerClient` instance and use it --- CHANGELOG.md | 1 + gradle.properties | 3 +- .../BlockchainAdapterClientConfig.java | 14 +--- .../ConfigServerClientConfig.java | 60 +++++++++++++++ .../PublicConfigurationService.java | 8 +- src/main/resources/application.yml | 5 ++ .../BlockchainAdapterClientConfigTests.java | 44 +---------- .../ConfigServerClientConfigTests.java | 77 +++++++++++++++++++ .../PublicConfigurationServiceTests.java | 2 + 9 files changed, 157 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java create mode 100644 src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d4c35bffa..6b68ffe9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Create `iexec-task-api` to access task feedback API. (#695) - Move `notification` package from `iexec-commons-poco` to `iexec-core-library`. (#697 #698) - Move `PublicConfiguration` class from `iexec-common` to `iexec-core-library`. (#699) +- Create a `ConfigServerClient` instance and use it. (#700) ### Bug Fixes diff --git a/gradle.properties b/gradle.properties index 1e608502d..1a9e1a902 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,8 @@ version=8.4.1 -iexecCommonVersion=8.4.0 +iexecCommonVersion=8.4.0-NEXT-SNAPSHOT iexecCommonsPocoVersion=3.2.0 iexecBlockchainAdapterVersion=8.4.0 iexecResultVersion=8.4.0 iexecSmsVersion=8.5.1 - nexusUser nexusPassword diff --git a/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java b/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java index 93213152c..55b486c9a 100644 --- a/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java +++ b/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java @@ -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. @@ -19,7 +19,6 @@ import com.iexec.blockchain.api.BlockchainAdapterApiClient; import com.iexec.blockchain.api.BlockchainAdapterApiClientBuilder; import com.iexec.blockchain.api.BlockchainAdapterService; -import com.iexec.common.config.PublicChainConfig; import feign.Logger; import lombok.Data; import org.springframework.beans.factory.annotation.Value; @@ -64,15 +63,4 @@ public BlockchainAdapterApiClient blockchainAdapterClient() { public BlockchainAdapterService blockchainAdapterService(BlockchainAdapterApiClient blockchainAdapterClient) { return new BlockchainAdapterService(blockchainAdapterClient, Duration.ofSeconds(WATCH_PERIOD_SECONDS), MAX_ATTEMPTS); } - - @Bean - public PublicChainConfig publicChainConfig(BlockchainAdapterApiClient apiClient) { - return apiClient.getPublicChainConfig(); - } - - @Bean - public int getChainId(PublicChainConfig publicChainConfig) { - return publicChainConfig.getChainId(); - } - } diff --git a/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java b/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java new file mode 100644 index 000000000..97062e6b5 --- /dev/null +++ b/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java @@ -0,0 +1,60 @@ +/* + * 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.configuration; + +import com.iexec.common.config.ConfigServerClient; +import com.iexec.common.config.ConfigServerClientBuilder; +import com.iexec.common.config.PublicChainConfig; +import feign.Logger; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.context.annotation.Bean; + +@Data +@ConstructorBinding +@ConfigurationProperties(prefix = "config-server") +public class ConfigServerClientConfig { + + private final String protocol; + private final String host; + private final int port; + + public String getUrl() { + return buildHostUrl(protocol, host, port); + } + + private String buildHostUrl(String protocol, String host, int port) { + return protocol + "://" + host + ":" + port; + } + + @Bean + public ConfigServerClient configServerClient() { + return ConfigServerClientBuilder.getInstance( + Logger.Level.NONE, getUrl()); + } + + @Bean + public PublicChainConfig publicChainConfig(ConfigServerClient apiClient) { + return apiClient.getPublicChainConfig(); + } + + @Bean + public int getChainId(PublicChainConfig publicChainConfig) { + return publicChainConfig.getChainId(); + } +} diff --git a/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java b/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java index 08d9fb2e2..eb272dccd 100644 --- a/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java +++ b/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 IEXEC BLOCKCHAIN TECH + * Copyright 2022-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. @@ -38,6 +38,7 @@ public class PublicConfigurationService { private final WorkerConfiguration workerConfiguration; private final ResultRepositoryConfiguration resultRepoConfig; private final BlockchainAdapterClientConfig blockchainAdapterClientConfig; + private final ConfigServerClientConfig configServerClientConfig; private PublicConfiguration publicConfiguration = null; /** @@ -51,12 +52,14 @@ public PublicConfigurationService(ChainConfig chainConfig, CredentialsService credentialsService, WorkerConfiguration workerConfiguration, ResultRepositoryConfiguration resultRepoConfig, - BlockchainAdapterClientConfig blockchainAdapterClientConfig) { + BlockchainAdapterClientConfig blockchainAdapterClientConfig, + ConfigServerClientConfig configServerClientConfig) { this.chainConfig = chainConfig; this.credentialsService = credentialsService; this.workerConfiguration = workerConfiguration; this.resultRepoConfig = resultRepoConfig; this.blockchainAdapterClientConfig = blockchainAdapterClientConfig; + this.configServerClientConfig = configServerClientConfig; } @PostConstruct @@ -64,6 +67,7 @@ void buildPublicConfiguration() { this.publicConfiguration = PublicConfiguration.builder() .workerPoolAddress(chainConfig.getPoolAddress()) .blockchainAdapterUrl(blockchainAdapterClientConfig.getUrl()) + .configServerUrl(configServerClientConfig.getUrl()) .schedulerPublicAddress(credentialsService.getCredentials().getAddress()) .resultRepositoryURL(resultRepoConfig.getResultRepositoryURL()) .askForReplicatePeriod(workerConfiguration.getAskForReplicatePeriod()) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index de381467e..76ae21b36 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -68,6 +68,11 @@ blockchain-adapter: name: ${IEXEC_CORE_CHAIN_ADAPTER_USERNAME:admin} password: ${IEXEC_CORE_CHAIN_ADAPTER_PASSWORD:whatever} +config-server: + protocol: ${IEXEC_CONFIG_SERVER_PROTOCOL:http} + host: ${IEXEC_CONFIG_SERVER_HOST:localhost} + port: ${IEXEC_CONFIG_SERVER_PORT:13020} + resultRepository: protocol: ${IEXEC_RESULT_REPOSITORY_PROTOCOL:http} host: ${IEXEC_RESULT_REPOSITORY_HOST:localhost} diff --git a/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java b/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java index 0093c010e..55033718a 100644 --- a/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java +++ b/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java @@ -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. @@ -16,55 +16,19 @@ package com.iexec.core.chain.adapter; -import com.iexec.common.config.PublicChainConfig; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.testcontainers.containers.BindMode; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; - -import java.time.Duration; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @Slf4j -@ExtendWith(SpringExtension.class) @EnableConfigurationProperties(value = BlockchainAdapterClientConfig.class) -@Testcontainers class BlockchainAdapterClientConfigTests { - private static final int WIREMOCK_PORT = 8080; - - @Autowired - private PublicChainConfig chainConfig; - - @Container - static final GenericContainer wmServer = new GenericContainer<>("wiremock/wiremock:3.3.1") - .withClasspathResourceMapping("wiremock", "/home/wiremock", BindMode.READ_ONLY) - .withExposedPorts(WIREMOCK_PORT); - - @DynamicPropertySource - static void registerProperties(DynamicPropertyRegistry registry) { - registry.add("blockchain-adapter.protocol", () -> "http"); - registry.add("blockchain-adapter.host", () -> "localhost"); - registry.add("blockchain-adapter.port", () -> wmServer.getMappedPort(WIREMOCK_PORT)); - } @Test - void checkChainConfigInitialization() { - PublicChainConfig expectedConfig = PublicChainConfig.builder() - .chainId(255) - .chainNodeUrl("http://localhost:8545") - .blockTime(Duration.ofSeconds(5L)) - .sidechain(true) - .build(); - assertThat(chainConfig).isEqualTo(expectedConfig); + void checkURL() { + final BlockchainAdapterClientConfig blockchainAdapterClientConfig = new BlockchainAdapterClientConfig("http", "localhost", 8080, "", ""); + assertThat(blockchainAdapterClientConfig.getUrl()).isEqualTo("http://localhost:8080"); } - } diff --git a/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java b/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java new file mode 100644 index 000000000..ac24d5e75 --- /dev/null +++ b/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java @@ -0,0 +1,77 @@ +/* + * 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.configuration; + +import com.iexec.common.config.PublicChainConfig; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.time.Duration; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@Slf4j +@ExtendWith(SpringExtension.class) +@EnableConfigurationProperties(value = ConfigServerClientConfig.class) +@Testcontainers +class ConfigServerClientConfigTests { + private static final int WIREMOCK_PORT = 8080; + + @Autowired + private PublicChainConfig chainConfig; + + @Autowired + private int getChainId; + + @Container + static final GenericContainer wmServer = new GenericContainer<>("wiremock/wiremock:3.3.1") + .withClasspathResourceMapping("wiremock", "/home/wiremock", BindMode.READ_ONLY) + .withExposedPorts(WIREMOCK_PORT); + + @DynamicPropertySource + static void registerProperties(DynamicPropertyRegistry registry) { + registry.add("config-server.protocol", () -> "http"); + registry.add("config-server.host", () -> "localhost"); + registry.add("config-server.port", () -> wmServer.getMappedPort(WIREMOCK_PORT)); + } + + @Test + void checkChainConfigInitialization() { + PublicChainConfig expectedConfig = PublicChainConfig.builder() + .chainId(255) + .chainNodeUrl("http://localhost:8545") + .blockTime(Duration.ofSeconds(5L)) + .sidechain(true) + .build(); + assertThat(chainConfig).isEqualTo(expectedConfig); + } + + @Test + void checkChainIdInitialization() { + assertThat(getChainId).isEqualTo(255); + } +} \ No newline at end of file diff --git a/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java b/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java index 349da0706..30ec0f55d 100644 --- a/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java +++ b/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java @@ -42,6 +42,8 @@ class PublicConfigurationServiceTests { private ResultRepositoryConfiguration resultRepoConfig; @Mock private BlockchainAdapterClientConfig blockchainAdapterClientConfig; + @Mock + private ConfigServerClientConfig configServerClientConfig; @InjectMocks private PublicConfigurationService publicConfigurationService; From e700d97bfb25b1660f681ffc80d7ba9e79178dec Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Tue, 23 Apr 2024 14:55:32 +0200 Subject: [PATCH 2/4] Fix missing endline and changelog --- CHANGELOG.md | 2 +- .../iexec/core/configuration/ConfigServerClientConfigTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b68ffe9f..eb5c61b9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. - Create `iexec-task-api` to access task feedback API. (#695) - Move `notification` package from `iexec-commons-poco` to `iexec-core-library`. (#697 #698) - Move `PublicConfiguration` class from `iexec-common` to `iexec-core-library`. (#699) -- Create a `ConfigServerClient` instance and use it. (#700) +- Create `ConfigServerClient` instance and use it. (#700) ### Bug Fixes diff --git a/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java b/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java index ac24d5e75..ebfa7d9f9 100644 --- a/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java +++ b/src/test/java/com/iexec/core/configuration/ConfigServerClientConfigTests.java @@ -74,4 +74,4 @@ void checkChainConfigInitialization() { void checkChainIdInitialization() { assertThat(getChainId).isEqualTo(255); } -} \ No newline at end of file +} From b77fbdc83faafa7b217877555f7f702075ddfce0 Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Wed, 24 Apr 2024 10:52:37 +0200 Subject: [PATCH 3/4] Update readme and make some code improvements --- README.md | 4 +++ .../BlockchainAdapterClientConfig.java | 6 +--- .../ConfigServerClientConfig.java | 4 --- .../PublicConfigurationService.java | 6 +--- src/main/resources/application.yml | 2 +- .../BlockchainAdapterClientConfigTests.java | 28 ++++++++++++++++--- .../PublicConfigurationServiceTests.java | 3 -- 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 7553108e1..d6bb923ff 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ To run properly, the _iExec Core Scheduler_ requires: * An _iExec Blockchain Adapter_ for several blockchain network interactions. * An _iExec Result Proxy_ to check if tasks results have been published. * An _iExec Platform Registry_ to retrieve locations of _iExec SMS_ services. +* An _iExec Config Server_ to retrieve configuration about blockchain. * One or many _iExec Secret Management Service_ instances (referenced by the _iExec Platform Registry_) to handle secrets and enclave sessions of TEE tasks. You can configure the _iExec Core Scheduler_ with the following properties: @@ -43,6 +44,9 @@ You can configure the _iExec Core Scheduler_ with the following properties: | `IEXEC_CORE_CHAIN_ADAPTER_PORT` | _iExec Blockchain Adapter_ server port. | Positive integer | `13010` | | `IEXEC_CORE_CHAIN_ADAPTER_USERNAME` | Username to connect to the _iExec Blockchain Adapter_ server. | String | `admin` | | `IEXEC_CORE_CHAIN_ADAPTER_PASSWORD` | Password to connect to the _iExec Blockchain Adapter_ server. | String | `whatever` | +| `IEXEC_CONFIG_SERVER_PROTOCOL` | _iExec Config Server_ communication protocol. | String | `http` | +| `IEXEC_CONFIG_SERVER_HOST` | _iExec Config Server_ server host. | String | `localhost` | +| `IEXEC_CONFIG_SERVER_PORT` | _iExec Config Server_ server port. | Positive integer | `8888` | | `IEXEC_CHAIN_HEALTH_POLLING_INTERVAL_IN_BLOCKS` | Polling interval (in blocks) on the blockchain to check this _Scheduler_ can communicate with it. | Positive integer | 3 | | `IEXEC_CHAIN_HEALTH_OUT_OF_SERVICE_THRESHOLD` | Max number of consecutive failures of blockchain connection attempts before this _Scheduler_ is declared as OUT-OF-SERVICE. | Positive integer | 4 | | `IEXEC_RESULT_REPOSITORY_PROTOCOL` | _iExec Result Proxy_ server communication protocol. | String | `http` | diff --git a/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java b/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java index 55b486c9a..f24a8c397 100644 --- a/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java +++ b/src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java @@ -45,10 +45,6 @@ public class BlockchainAdapterClientConfig { @Value("${blockchain-adapter.user.password}") private final String password; - public String getUrl() { - return buildHostUrl(protocol, host, port); - } - private String buildHostUrl(String protocol, String host, int port) { return protocol + "://" + host + ":" + port; } @@ -56,7 +52,7 @@ private String buildHostUrl(String protocol, String host, int port) { @Bean public BlockchainAdapterApiClient blockchainAdapterClient() { return BlockchainAdapterApiClientBuilder.getInstanceWithBasicAuth( - Logger.Level.NONE, getUrl(), username, password); + Logger.Level.NONE, buildHostUrl(protocol, host, port), username, password); } @Bean diff --git a/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java b/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java index 97062e6b5..f19978c96 100644 --- a/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java +++ b/src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java @@ -35,10 +35,6 @@ public class ConfigServerClientConfig { private final int port; public String getUrl() { - return buildHostUrl(protocol, host, port); - } - - private String buildHostUrl(String protocol, String host, int port) { return protocol + "://" + host + ":" + port; } diff --git a/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java b/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java index eb272dccd..d47357dfe 100644 --- a/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java +++ b/src/main/java/com/iexec/core/configuration/PublicConfigurationService.java @@ -18,7 +18,6 @@ import com.iexec.core.chain.ChainConfig; import com.iexec.core.chain.CredentialsService; -import com.iexec.core.chain.adapter.BlockchainAdapterClientConfig; import com.iexec.core.config.PublicConfiguration; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -37,7 +36,6 @@ public class PublicConfigurationService { private final CredentialsService credentialsService; private final WorkerConfiguration workerConfiguration; private final ResultRepositoryConfiguration resultRepoConfig; - private final BlockchainAdapterClientConfig blockchainAdapterClientConfig; private final ConfigServerClientConfig configServerClientConfig; private PublicConfiguration publicConfiguration = null; @@ -52,13 +50,11 @@ public PublicConfigurationService(ChainConfig chainConfig, CredentialsService credentialsService, WorkerConfiguration workerConfiguration, ResultRepositoryConfiguration resultRepoConfig, - BlockchainAdapterClientConfig blockchainAdapterClientConfig, ConfigServerClientConfig configServerClientConfig) { this.chainConfig = chainConfig; this.credentialsService = credentialsService; this.workerConfiguration = workerConfiguration; this.resultRepoConfig = resultRepoConfig; - this.blockchainAdapterClientConfig = blockchainAdapterClientConfig; this.configServerClientConfig = configServerClientConfig; } @@ -66,7 +62,7 @@ public PublicConfigurationService(ChainConfig chainConfig, void buildPublicConfiguration() { this.publicConfiguration = PublicConfiguration.builder() .workerPoolAddress(chainConfig.getPoolAddress()) - .blockchainAdapterUrl(blockchainAdapterClientConfig.getUrl()) + .blockchainAdapterUrl(configServerClientConfig.getUrl()) .configServerUrl(configServerClientConfig.getUrl()) .schedulerPublicAddress(credentialsService.getCredentials().getAddress()) .resultRepositoryURL(resultRepoConfig.getResultRepositoryURL()) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 76ae21b36..875a477d6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -71,7 +71,7 @@ blockchain-adapter: config-server: protocol: ${IEXEC_CONFIG_SERVER_PROTOCOL:http} host: ${IEXEC_CONFIG_SERVER_HOST:localhost} - port: ${IEXEC_CONFIG_SERVER_PORT:13020} + port: ${IEXEC_CONFIG_SERVER_PORT:8888} resultRepository: protocol: ${IEXEC_RESULT_REPOSITORY_PROTOCOL:http} diff --git a/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java b/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java index 55033718a..5187b2101 100644 --- a/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java +++ b/src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java @@ -18,17 +18,37 @@ import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; @Slf4j +@ExtendWith(SpringExtension.class) @EnableConfigurationProperties(value = BlockchainAdapterClientConfig.class) class BlockchainAdapterClientConfigTests { + @Autowired + private ApplicationContext context; + + @DynamicPropertySource + static void registerProperties(DynamicPropertyRegistry registry) { + registry.add("blockchain-adapter.protocol", () -> "http"); + registry.add("blockchain-adapter.host", () -> "localhost"); + registry.add("blockchain-adapter.port", () -> "13010"); + } + @Test - void checkURL() { - final BlockchainAdapterClientConfig blockchainAdapterClientConfig = new BlockchainAdapterClientConfig("http", "localhost", 8080, "", ""); - assertThat(blockchainAdapterClientConfig.getUrl()).isEqualTo("http://localhost:8080"); + void shouldCreateBeanInstance() { + assertAll( + () -> assertThat(context.containsBean("blockchainAdapterClient")).isTrue(), + () -> assertThat(context.containsBean("blockchainAdapterService")).isTrue() + ); } } diff --git a/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java b/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java index 30ec0f55d..34a61fbcd 100644 --- a/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java +++ b/src/test/java/com/iexec/core/configuration/PublicConfigurationServiceTests.java @@ -18,7 +18,6 @@ import com.iexec.core.chain.ChainConfig; import com.iexec.core.chain.CredentialsService; -import com.iexec.core.chain.adapter.BlockchainAdapterClientConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -41,8 +40,6 @@ class PublicConfigurationServiceTests { @Mock private ResultRepositoryConfiguration resultRepoConfig; @Mock - private BlockchainAdapterClientConfig blockchainAdapterClientConfig; - @Mock private ConfigServerClientConfig configServerClientConfig; @InjectMocks From d66bb91e4dc130a7b4330b9f6f6b706efbe58e50 Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Wed, 24 Apr 2024 15:01:35 +0200 Subject: [PATCH 4/4] Remove redundant info in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d6bb923ff..362993316 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ You can configure the _iExec Core Scheduler_ with the following properties: | `IEXEC_CORE_CHAIN_ADAPTER_USERNAME` | Username to connect to the _iExec Blockchain Adapter_ server. | String | `admin` | | `IEXEC_CORE_CHAIN_ADAPTER_PASSWORD` | Password to connect to the _iExec Blockchain Adapter_ server. | String | `whatever` | | `IEXEC_CONFIG_SERVER_PROTOCOL` | _iExec Config Server_ communication protocol. | String | `http` | -| `IEXEC_CONFIG_SERVER_HOST` | _iExec Config Server_ server host. | String | `localhost` | -| `IEXEC_CONFIG_SERVER_PORT` | _iExec Config Server_ server port. | Positive integer | `8888` | +| `IEXEC_CONFIG_SERVER_HOST` | _iExec Config Server_ host. | String | `localhost` | +| `IEXEC_CONFIG_SERVER_PORT` | _iExec Config Server_ port. | Positive integer | `8888` | | `IEXEC_CHAIN_HEALTH_POLLING_INTERVAL_IN_BLOCKS` | Polling interval (in blocks) on the blockchain to check this _Scheduler_ can communicate with it. | Positive integer | 3 | | `IEXEC_CHAIN_HEALTH_OUT_OF_SERVICE_THRESHOLD` | Max number of consecutive failures of blockchain connection attempts before this _Scheduler_ is declared as OUT-OF-SERVICE. | Positive integer | 4 | | `IEXEC_RESULT_REPOSITORY_PROTOCOL` | _iExec Result Proxy_ server communication protocol. | String | `http` |