Skip to content

Commit 4c84306

Browse files
Merge pull request #149 from iExecBlockchainComputing/proxy-conf
Proxy conf
2 parents 1f0be73 + 2dfc074 commit 4c84306

File tree

7 files changed

+69
-22
lines changed

7 files changed

+69
-22
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM openjdk:8u171-jre-alpine
22

33
ADD build/libs/iexec-worker-@[email protected] iexec-worker.jar
4+
COPY build/resources/main/entrypoint.sh entrypoint.sh
5+
RUN chmod +x entrypoint.sh
46

5-
ENTRYPOINT ["java","-jar","/iexec-worker.jar"]
7+
ENTRYPOINT ["./entrypoint.sh"]

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,16 @@ task pushImage(type: Exec) {
164164

165165
pushImage.dependsOn buildImage
166166
pushImage.enabled = isMasterBranch && project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")
167+
168+
//gradle bootRun -PproxyHost=192.168.XX.XXX -PproxyPort=3128
169+
project.ext.getJvmArgs = {
170+
if (project.hasProperty("proxyHost") && project.hasProperty("proxyPort")) {
171+
return ["-Dhttp.proxyHost="+project.proxyHost, "-Dhttp.proxyPort="+project.proxyPort]
172+
} else {
173+
return []
174+
}
175+
}
176+
177+
bootRun {
178+
jvmArgs = project.ext.getJvmArgs()
179+
}

src/main/java/com/iexec/worker/Application.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.iexec.worker;
22

33

4-
import java.util.List;
5-
64
import com.iexec.common.config.WorkerConfigurationModel;
75
import com.iexec.worker.amnesia.AmnesiaRecoveryService;
86
import com.iexec.worker.chain.CredentialsService;
@@ -21,6 +19,8 @@
2119
import org.springframework.scheduling.annotation.EnableAsync;
2220
import org.springframework.scheduling.annotation.EnableScheduling;
2321

22+
import java.util.List;
23+
2424

2525
@SpringBootApplication
2626
@EnableFeignClients
@@ -71,11 +71,13 @@ public void run(String... args) {
7171
.teeEnabled(workerConfig.isTeeEnabled())
7272
.build();
7373

74-
7574
log.info("Number of tasks that can run in parallel on this machine [tasks:{}]", workerConfig.getNbCPU() / 2);
7675
log.info("Address of the core [address:{}]", "http://" + coreHost + ":" + corePort);
7776
log.info("Version of the core [version:{}]", customFeignClient.getCoreVersion());
7877
log.info("Get configuration of the core [config:{}]", customFeignClient.getPublicConfiguration());
78+
if (workerConfig.getHttpProxyHost() != null && workerConfig.getHttpProxyPort() != null) {
79+
log.info("Running with proxy [proxyHost:{}, proxyPort:{}]", workerConfig.getHttpProxyHost(), workerConfig.getHttpProxyPort());
80+
}
7981

8082
if (!iexecHubService.hasEnoughGas()) {
8183
log.error("No enough gas, please refill your wallet!");

src/main/java/com/iexec/worker/config/WorkerConfigurationService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.iexec.worker.config;
22

33
import com.iexec.worker.chain.CredentialsService;
4+
import org.apache.http.HttpHost;
5+
import org.apache.http.impl.client.HttpClientBuilder;
46
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
59
import org.springframework.stereotype.Service;
10+
import org.springframework.web.client.RestTemplate;
611

712
import java.io.File;
813

@@ -79,4 +84,25 @@ public boolean isTeeEnabled() {
7984
public String getOverrideBlockchainNodeAddress() {
8085
return overrideBlockchainNodeAddress;
8186
}
87+
88+
public String getHttpProxyHost() {
89+
return System.getProperty("http.proxyHost");
90+
}
91+
92+
public Integer getHttpProxyPort() {
93+
String proxyPort = System.getProperty("http.proxyPort");
94+
return proxyPort != null && !proxyPort.isEmpty() ? Integer.valueOf(proxyPort) : null;
95+
}
96+
97+
@Bean
98+
private RestTemplate restTemplate() {
99+
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
100+
if (getHttpProxyHost() != null && getHttpProxyPort() != null) {
101+
HttpHost myProxy = new HttpHost(getHttpProxyHost(), getHttpProxyPort());
102+
clientBuilder.setProxy(myProxy);
103+
}
104+
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
105+
factory.setHttpClient(clientBuilder.build());
106+
return new RestTemplate(factory);
107+
}
82108
}

src/main/java/com/iexec/worker/pubsub/SubscriptionService.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22

33
import com.iexec.common.notification.TaskNotification;
44
import com.iexec.common.notification.TaskNotificationType;
5-
import com.iexec.worker.chain.CredentialsService;
6-
import com.iexec.worker.chain.RevealService;
75
import com.iexec.worker.config.CoreConfigurationService;
8-
import com.iexec.worker.config.PublicConfigurationService;
96
import com.iexec.worker.config.WorkerConfigurationService;
107
import com.iexec.worker.executor.TaskExecutorService;
11-
import com.iexec.worker.feign.CustomFeignClient;
12-
import com.iexec.worker.feign.ResultRepoClient;
13-
import com.iexec.worker.result.ResultService;
148
import lombok.extern.slf4j.Slf4j;
15-
169
import org.springframework.lang.Nullable;
1710
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
1811
import org.springframework.messaging.simp.SimpMessageType;
1912
import org.springframework.messaging.simp.stomp.*;
2013
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
2114
import org.springframework.stereotype.Service;
15+
import org.springframework.web.client.RestTemplate;
2216
import org.springframework.web.socket.client.WebSocketClient;
2317
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
2418
import org.springframework.web.socket.messaging.WebSocketStompClient;
19+
import org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport;
20+
import org.springframework.web.socket.sockjs.client.SockJsClient;
21+
import org.springframework.web.socket.sockjs.client.Transport;
22+
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
2523

2624
import javax.annotation.PostConstruct;
2725
import java.lang.reflect.Type;
2826
import java.util.ArrayList;
27+
import java.util.Arrays;
2928
import java.util.List;
3029
import java.util.Map;
3130
import java.util.concurrent.ConcurrentHashMap;
@@ -38,7 +37,7 @@ public class SubscriptionService extends StompSessionHandlerAdapter {
3837
private final String coreHost;
3938
private final int corePort;
4039
private final String workerWalletAddress;
41-
40+
private RestTemplate restTemplate;
4241
// external services
4342
private TaskExecutorService taskExecutorService;
4443

@@ -50,21 +49,17 @@ public class SubscriptionService extends StompSessionHandlerAdapter {
5049

5150
public SubscriptionService(CoreConfigurationService coreConfigurationService,
5251
WorkerConfigurationService workerConfigurationService,
53-
ResultRepoClient resultRepoClient,
54-
ResultService resultService,
55-
RevealService revealService,
56-
CustomFeignClient feignClient,
57-
PublicConfigurationService publicConfigurationService,
58-
CredentialsService credentialsService,
59-
TaskExecutorService taskExecutorService) {
52+
TaskExecutorService taskExecutorService,
53+
RestTemplate restTemplate) {
6054
this.taskExecutorService = taskExecutorService;
6155

6256
this.coreHost = coreConfigurationService.getHost();
6357
this.corePort = coreConfigurationService.getPort();
6458
this.workerWalletAddress = workerConfigurationService.getWorkerWalletAddress();
59+
this.restTemplate = restTemplate;
6560

6661
chainTaskIdToSubscription = new ConcurrentHashMap<>();
67-
url = "ws://" + coreHost + ":" + corePort + "/connect";
62+
url = "http://" + coreHost + ":" + corePort + "/connect";
6863
}
6964

7065
@PostConstruct
@@ -75,7 +70,11 @@ private void run() {
7570
private void restartStomp() {
7671
log.info("Starting STOMP");
7772
WebSocketClient webSocketClient = new StandardWebSocketClient();
78-
this.stompClient = new WebSocketStompClient(webSocketClient);
73+
List<Transport> webSocketTransports = Arrays.asList(new WebSocketTransport(webSocketClient),
74+
new RestTemplateXhrTransport(restTemplate));
75+
SockJsClient sockJsClient = new SockJsClient(webSocketTransports);
76+
this.stompClient = new WebSocketStompClient(sockJsClient);//without SockJS: new WebSocketStompClient(webSocketClient);
77+
this.stompClient.setAutoStartup(true);
7978
this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
8079
this.stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
8180
this.stompClient.connect(url, this);

src/main/resources/application.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ worker:
1212
gasPriceCap: ${IEXEC_GAS_PRICE_CAP:22000000000} #in Wei, will be used for txs if networkGasPrice*gasPriceMultiplier > gasPriceCap
1313
teeEnabled: ${IEXEC_TEE_ENABLED:false}
1414
overrideBlockchainNodeAddress: ${IEXEC_WORKER_OVERRIDE_BLOCKCHAIN_NODE_ADDRESS:} #will use it if set, else will use the one given by the core
15-
1615
wallet:
1716
encryptedFilePath: ${IEXEC_WORKER_WALLET_PATH:./src/main/resources/wallet/encrypted-wallet_worker1.json}
1817
password: ${IEXEC_WORKER_WALLET_PASSWORD:whatever}

src/main/resources/entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
if [ ! -z $IEXEC_HTTP_PROXY_HOST ] && [ ! -z $IEXEC_HTTP_PROXY_PORT ]; then
3+
java -Dhttp.proxyHost=$IEXEC_HTTP_PROXY_HOST -Dhttp.proxyPort=$IEXEC_HTTP_PROXY_PORT -jar /iexec-worker.jar
4+
fi
5+
6+
java -jar /iexec-worker.jar

0 commit comments

Comments
 (0)