Skip to content

Commit 08cdeee

Browse files
Merge split URL configuration properties to a single URL field (#748)
1 parent 2c40fb4 commit 08cdeee

14 files changed

+66
-79
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ All notable changes to this project will be documented in this file.
2020
- Compute alive workers metrics in `WorkerService#updateMetrics` scheduled job. (#739 #745)
2121
- Fix Spring Security deprecations after Spring Boot 3.3.8 upgrade. (#740)
2222
- Remove code related to reopen PoCo feature in `IexecHubService` and `TaskUpdateManager`. (#743)
23-
- Harmonize YML internal variables to proper case. (#744)
2423

2524
### Breaking API changes
2625

@@ -31,6 +30,8 @@ All notable changes to this project will be documented in this file.
3130
- Remove deprecated methods in `iexec-core-library`. (#737)
3231
- Remove unused `ContributionUtils` class. (#738)
3332
- Rework metrics to expose count of computing CPUs or GPUs instead of available ones. (#739)
33+
- Harmonize YML internal variables to proper case. (#744)
34+
- Merge split URL configuration properties (protocol, host, port) to a single URL field to offer URL validation at startup. (#748)
3435

3536
### Dependency Upgrades
3637

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,11 @@ You can configure the _iExec Core Scheduler_ with the following properties:
3939
| `IEXEC_START_BLOCK_NUMBER` | Subscribe to new deal events from a specific block number. | Positive integer | `0` |
4040
| `IEXEC_GAS_PRICE_MULTIPLIER` | Transactions will be sent with `networkGasPrice * gasPriceMultiplier`. | Float | `1.0` |
4141
| `IEXEC_GAS_PRICE_CAP` | In Wei, will be used for transactions if `networkGasPrice * gasPriceMultiplier > gasPriceCap` | Integer | `22000000000` |
42-
| `IEXEC_CORE_CHAIN_ADAPTER_PROTOCOL` | _iExec Blockchain Adapter_ communication protocol. | String | `http` |
43-
| `IEXEC_CORE_CHAIN_ADAPTER_HOST` | _iExec Blockchain Adapter_ server host. | String | `localhost` |
44-
| `IEXEC_CORE_CHAIN_ADAPTER_PORT` | _iExec Blockchain Adapter_ server port. | Positive integer | `13010` |
42+
| `IEXEC_CORE_CHAIN_ADAPTER_URL` | _iExec Blockchain Adapter_ communication url. | String | `http://localhost:13010`|
4543
| `IEXEC_CORE_CHAIN_ADAPTER_USERNAME` | Username to connect to the _iExec Blockchain Adapter_ server. | String | `admin` |
4644
| `IEXEC_CORE_CHAIN_ADAPTER_PASSWORD` | Password to connect to the _iExec Blockchain Adapter_ server. | String | `whatever` |
47-
| `IEXEC_CONFIG_SERVER_PROTOCOL` | _iExec Config Server_ communication protocol. | String | `http` |
48-
| `IEXEC_CONFIG_SERVER_HOST` | _iExec Config Server_ host. | String | `localhost` |
49-
| `IEXEC_CONFIG_SERVER_PORT` | _iExec Config Server_ port. | Positive integer | `8888` |
50-
| `IEXEC_RESULT_REPOSITORY_PROTOCOL` | _iExec Result Proxy_ server communication protocol. | String | `http` |
51-
| `IEXEC_RESULT_REPOSITORY_HOST` | _iExec Result Proxy_ server host. | String | `localhost` |
52-
| `IEXEC_RESULT_REPOSITORY_PORT` | _iExec Result Proxy_ server port. | Positive integer | `13200` |
45+
| `IEXEC_CONFIG_SERVER_URL` | _iExec Config Server_ communication url. | String | `http://localhost:8888`|
46+
| `IEXEC_RESULT_REPOSITORY_URL` | _iExec Result Proxy_ server communication url. | String | `http://localhost:13200`|
5347
| `IEXEC_CORE_MANAGEMENT_ACTUATORS` | Endpoint IDs that should be included or `*` for all. | String | `health, info` |
5448
| `IEXEC_LOGS_PURGE_RATE_IN_DAYS` | Interval in days between 2 executions of the purge mechanism. | Positive integer | `1` |
5549
| `IEXEC_LOGS_AVAILABILITY_PERIOD_IN_DAYS` | Number of days to keep logs of past tasks. | Positive integer | `3` |

src/main/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfig.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,42 @@
2020
import com.iexec.blockchain.api.BlockchainAdapterApiClientBuilder;
2121
import com.iexec.blockchain.api.BlockchainAdapterService;
2222
import feign.Logger;
23-
import lombok.Data;
24-
import org.springframework.beans.factory.annotation.Value;
23+
import jakarta.validation.constraints.NotEmpty;
24+
import lombok.Value;
25+
import org.hibernate.validator.constraints.URL;
2526
import org.springframework.boot.context.properties.ConfigurationProperties;
2627
import org.springframework.context.annotation.Bean;
28+
import org.springframework.validation.annotation.Validated;
2729

2830
import java.time.Duration;
2931

30-
@Data
32+
@Value
33+
@Validated
3134
@ConfigurationProperties(prefix = "blockchain-adapter")
3235
public class BlockchainAdapterClientConfig {
3336

3437
// TODO add configuration parameters for next major version
3538
public static final int WATCH_PERIOD_SECONDS = 2;
3639
public static final int MAX_ATTEMPTS = 25;
3740

38-
private final String protocol;
39-
private final String host;
40-
private final int port;
41-
// TODO improve property names before next major version
42-
@Value("${blockchain-adapter.user.name}")
43-
private final String username;
44-
@Value("${blockchain-adapter.user.password}")
45-
private final String password;
46-
47-
private String buildHostUrl(String protocol, String host, int port) {
48-
return protocol + "://" + host + ":" + port;
49-
}
41+
@URL(message = "URL must be a valid URL")
42+
@NotEmpty(message = "URL must not be empty")
43+
String url;
44+
45+
BlockchainAdapterAuth auth;
5046

5147
@Bean
5248
public BlockchainAdapterApiClient blockchainAdapterClient() {
5349
return BlockchainAdapterApiClientBuilder.getInstanceWithBasicAuth(
54-
Logger.Level.NONE, buildHostUrl(protocol, host, port), username, password);
50+
Logger.Level.NONE, url, auth.username(), auth.password());
5551
}
5652

5753
@Bean
5854
public BlockchainAdapterService blockchainAdapterService(BlockchainAdapterApiClient blockchainAdapterClient) {
5955
return new BlockchainAdapterService(blockchainAdapterClient, Duration.ofSeconds(WATCH_PERIOD_SECONDS), MAX_ATTEMPTS);
6056
}
57+
58+
record BlockchainAdapterAuth(String username, String password
59+
) {
60+
}
6161
}

src/main/java/com/iexec/core/configuration/ConfigServerClientConfig.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020
import com.iexec.common.config.ConfigServerClientBuilder;
2121
import com.iexec.common.config.PublicChainConfig;
2222
import feign.Logger;
23-
import lombok.Data;
23+
import jakarta.validation.constraints.NotEmpty;
24+
import lombok.Value;
25+
import org.hibernate.validator.constraints.URL;
2426
import org.springframework.boot.context.properties.ConfigurationProperties;
2527
import org.springframework.context.annotation.Bean;
28+
import org.springframework.validation.annotation.Validated;
2629

27-
@Data
30+
@Value
31+
@Validated
2832
@ConfigurationProperties(prefix = "config-server")
2933
public class ConfigServerClientConfig {
3034

31-
private final String protocol;
32-
private final String host;
33-
private final int port;
34-
35-
public String getUrl() {
36-
return protocol + "://" + host + ":" + port;
37-
}
35+
@URL(message = "URL must be a valid URL")
36+
@NotEmpty(message = "URL must not be empty")
37+
String url;
3838

3939
@Bean
4040
public ConfigServerClient configServerClient() {
4141
return ConfigServerClientBuilder.getInstance(
42-
Logger.Level.NONE, getUrl());
42+
Logger.Level.NONE, url);
4343
}
4444

4545
@Bean

src/main/java/com/iexec/core/configuration/PublicConfigurationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void buildPublicConfiguration() {
6363
.workerPoolAddress(chainConfig.getPoolAddress())
6464
.configServerUrl(configServerClientConfig.getUrl())
6565
.schedulerPublicAddress(signerService.getAddress())
66-
.resultRepositoryURL(resultRepoConfig.getResultRepositoryURL())
66+
.resultRepositoryURL(resultRepoConfig.getUrl())
6767
.askForReplicatePeriod(workerConfiguration.getAskForReplicatePeriod())
6868
.requiredWorkerVersion(workerConfiguration.getRequiredWorkerVersion())
6969
.build();

src/main/java/com/iexec/core/configuration/ResultRepositoryConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
import com.iexec.resultproxy.api.ResultProxyClient;
2020
import com.iexec.resultproxy.api.ResultProxyClientBuilder;
2121
import feign.Logger;
22+
import jakarta.validation.constraints.NotEmpty;
2223
import lombok.Value;
2324
import lombok.extern.slf4j.Slf4j;
2425
import org.apache.commons.lang3.StringUtils;
26+
import org.hibernate.validator.constraints.URL;
2527
import org.springframework.boot.context.properties.ConfigurationProperties;
28+
import org.springframework.validation.annotation.Validated;
2629

2730
@Value
31+
@Validated
2832
@ConfigurationProperties(prefix = "result-repository")
2933
@Slf4j
3034
public class ResultRepositoryConfiguration {
31-
String protocol;
32-
String host;
33-
String port;
34-
35-
public String getResultRepositoryURL() {
36-
return protocol + "://" + host + ":" + port;
37-
}
35+
@URL(message = "URL must be a valid URL")
36+
@NotEmpty(message = "URL must not be empty")
37+
String url;
3838

3939
public ResultProxyClient createResultProxyClientFromURL(final String url) {
4040
final boolean useDefaultUrl = StringUtils.isBlank(url);
41-
final String resultProxyClientURL = useDefaultUrl ? getResultRepositoryURL() : url;
41+
final String resultProxyClientURL = useDefaultUrl ? getUrl() : url;
4242
log.debug("result-proxy URL [url:{}, default-url:{}]", resultProxyClientURL, useDefaultUrl);
4343
return ResultProxyClientBuilder.getInstance(Logger.Level.NONE, resultProxyClientURL);
4444
}

src/main/java/com/iexec/core/sms/SmsService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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.
@@ -199,7 +199,7 @@ private boolean isWorkerpoolResultProxyUrlPresent(final String smsURL) {
199199
public void pushWorkerpoolResultProxyUrl(final TaskInitializedEvent event) {
200200
log.debug("pushWorkerpoolResultProxyUrl [event:{}]", event);
201201
try {
202-
final String resultProxyURL = resultRepositoryConfiguration.getResultRepositoryURL();
202+
final String resultProxyURL = resultRepositoryConfiguration.getUrl();
203203
final String smsURL = getVerifiedSmsUrl(event.getChainTaskId()).orElseThrow();
204204
log.debug("Pushing result-proxy default URL to SMS [sms:{}, result-proxy:{}]", smsURL, resultProxyURL);
205205
final SmsClient smsClient = smsClientProvider.getSmsClient(smsURL);

src/main/resources/application.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,16 @@ chain:
5858
gas-price-cap: ${IEXEC_GAS_PRICE_CAP:22000000000} #in Wei, will be used for txs if networkGasPrice*gasPriceMultiplier > gasPriceCap
5959

6060
blockchain-adapter:
61-
protocol: ${IEXEC_CORE_CHAIN_ADAPTER_PROTOCOL:http}
62-
host: ${IEXEC_CORE_CHAIN_ADAPTER_HOST:localhost}
63-
port: ${IEXEC_CORE_CHAIN_ADAPTER_PORT:13010}
64-
user:
65-
name: ${IEXEC_CORE_CHAIN_ADAPTER_USERNAME:admin}
61+
url: ${IEXEC_CORE_CHAIN_ADAPTER_URL:http://localhost:13010}
62+
auth:
63+
username: ${IEXEC_CORE_CHAIN_ADAPTER_USERNAME:admin}
6664
password: ${IEXEC_CORE_CHAIN_ADAPTER_PASSWORD:whatever}
6765

6866
config-server:
69-
protocol: ${IEXEC_CONFIG_SERVER_PROTOCOL:http}
70-
host: ${IEXEC_CONFIG_SERVER_HOST:localhost}
71-
port: ${IEXEC_CONFIG_SERVER_PORT:8888}
67+
url: ${IEXEC_CONFIG_SERVER_URL:http://localhost:8888}
7268

7369
result-repository:
74-
protocol: ${IEXEC_RESULT_REPOSITORY_PROTOCOL:http}
75-
host: ${IEXEC_RESULT_REPOSITORY_HOST:localhost}
76-
port: ${IEXEC_RESULT_REPOSITORY_PORT:13200}
70+
url: ${IEXEC_RESULT_REPOSITORY_URL:http://localhost:13200}
7771

7872
management:
7973
endpoints:

src/test/java/com/iexec/core/chain/WebSocketBlockchainListenerTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ static void registerProperties(DynamicPropertyRegistry registry) {
6262
environment.getServiceHost(CHAIN_SVC_NAME, CHAIN_SVC_PORT),
6363
environment.getServicePort(CHAIN_SVC_NAME, CHAIN_SVC_PORT))
6464
);
65-
registry.add("config-server.host", () -> environment.getServiceHost(CONFIG_SVC_NAME, CONFIG_SVC_PORT));
66-
registry.add("config-server.port", () -> environment.getServicePort(CONFIG_SVC_NAME, CONFIG_SVC_PORT));
65+
registry.add("config-server.url", () -> getServiceUrl(
66+
environment.getServiceHost(CONFIG_SVC_NAME, CONFIG_SVC_PORT),
67+
environment.getServicePort(CONFIG_SVC_NAME, CONFIG_SVC_PORT))
68+
);
6769
registry.add("sprint.data.mongodb.host", () -> environment.getServiceHost(MONGO_SVC_NAME, MONGO_SVC_PORT));
6870
registry.add("spring.data.mongodb.port", () -> environment.getServicePort(MONGO_SVC_NAME, MONGO_SVC_PORT));
6971
}

src/test/java/com/iexec/core/chain/adapter/BlockchainAdapterClientConfigTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2021-2025 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.
@@ -39,9 +39,9 @@ class BlockchainAdapterClientConfigTests {
3939

4040
@DynamicPropertySource
4141
static void registerProperties(DynamicPropertyRegistry registry) {
42-
registry.add("blockchain-adapter.protocol", () -> "http");
43-
registry.add("blockchain-adapter.host", () -> "localhost");
44-
registry.add("blockchain-adapter.port", () -> "13010");
42+
registry.add("blockchain-adapter.url", () -> "http://localhost:13010");
43+
registry.add("blockchain-adapter.auth.username", () -> "admin");
44+
registry.add("blockchain-adapter.auth.password", () -> "whatever");
4545
}
4646

4747
@Test

0 commit comments

Comments
 (0)