Skip to content

Commit 61c8d21

Browse files
authored
Merge pull request #308 from iExecBlockchainComputing/feature/iexec-out
Use $IEXEC_IN and $IEXEC_OUT env variables
2 parents 152dd4d + 36a4912 commit 61c8d21

File tree

15 files changed

+571
-645
lines changed

15 files changed

+571
-645
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,15 @@ public String getTaskBaseDir(String chainTaskId) {
6060
}
6161

6262
public String getTaskInputDir(String chainTaskId) {
63-
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_INPUT;
63+
return getTaskBaseDir(chainTaskId) + FileHelper.SLASH_INPUT;
6464
}
6565

6666
public String getTaskOutputDir(String chainTaskId) {
67-
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_OUTPUT;
67+
return getTaskBaseDir(chainTaskId) + FileHelper.SLASH_OUTPUT;
6868
}
6969

7070
public String getTaskIexecOutDir(String chainTaskId) {
71-
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_OUTPUT
72-
+ FileHelper.SLASH_IEXEC_OUT;
73-
}
74-
75-
public String getTaskSconeDir(String chainTaskId) {
76-
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_SCONE;
71+
return getTaskOutputDir(chainTaskId) + FileHelper.SLASH_IEXEC_OUT;
7772
}
7873

7974
public String getDatasetSecretFilePath(String chainTaskId) {

src/main/java/com/iexec/worker/docker/ComputationService.java

Lines changed: 220 additions & 128 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.iexec.worker.docker;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/* /!\ this probably should be split */
9+
10+
@Data
11+
@Builder
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
public class ComputeMeta {
15+
16+
private String chainTaskId;
17+
private boolean isComputed;
18+
private boolean isPreComputed;
19+
private boolean isPostComputed;
20+
@Builder.Default private String secureSessionId = "";
21+
@Builder.Default private String stdout = "";
22+
}

src/main/java/com/iexec/worker/docker/DockerExecutionConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import lombok.Builder;
66
import lombok.Data;
77
import lombok.NoArgsConstructor;
8-
import lombok.extern.slf4j.Slf4j;
98

109
import java.util.List;
1110
import java.util.Map;

src/main/java/com/iexec/worker/executor/TaskManagerService.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.iexec.worker.config.WorkerConfigurationService;
1515
import com.iexec.worker.dataset.DataService;
1616
import com.iexec.worker.docker.ComputationService;
17+
import com.iexec.worker.docker.ComputeMeta;
1718
import com.iexec.worker.result.ResultService;
1819
import com.iexec.worker.tee.scone.SconeTeeService;
1920
import com.iexec.worker.utils.LoggingUtils;
@@ -191,21 +192,26 @@ ReplicateActionResponse compute(String chainTaskId) {
191192
return ReplicateActionResponse.failure(APP_NOT_FOUND_LOCALLY);
192193
}
193194

194-
boolean isComputed;
195195
WorkerpoolAuthorization workerpoolAuthorization =
196196
contributionService.getWorkerpoolAuthorization(chainTaskId);
197197

198-
if (taskDescription.isTeeTask()) {
199-
isComputed = computationService.runTeeComputation(taskDescription, workerpoolAuthorization);
200-
} else {
201-
isComputed = computationService.runNonTeeComputation(taskDescription, workerpoolAuthorization);
198+
ComputeMeta computeMeta = ComputeMeta.builder().chainTaskId(chainTaskId).build();
199+
computationService.runPreCompute(computeMeta, taskDescription, workerpoolAuthorization);
200+
if (!computeMeta.isPreComputed()) {
201+
log.error("Failed to pre-compute [chainTaskId:{}]", chainTaskId);
202+
return ReplicateActionResponse.failure(PRE_COMPUTE_FAILED);
202203
}
203-
204-
if (!isComputed) {
204+
computationService.runComputation(computeMeta, taskDescription);
205+
if (!computeMeta.isComputed()) {
205206
log.error("Failed to compute [chainTaskId:{}]", chainTaskId);
206207
return ReplicateActionResponse.failure();
207208
}
208-
209+
computationService.runPostCompute(computeMeta, taskDescription);
210+
if (!computeMeta.isPostComputed()) {
211+
log.error("Failed to post-compute [chainTaskId:{}]", chainTaskId);
212+
return ReplicateActionResponse.failure(POST_COMPUTE_FAILED);
213+
}
214+
resultService.saveResultInfo(chainTaskId, taskDescription);
209215
return ReplicateActionResponse.success();
210216
}
211217

@@ -231,7 +237,7 @@ ReplicateActionResponse contribute(String chainTaskId) {
231237
// System.exit(0);
232238
}
233239

234-
ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
240+
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
235241
if (computedFile == null) {
236242
log.error("Cannot contribute, getComputedFile [chainTaskId:{}]", chainTaskId);
237243
return ReplicateActionResponse.failure(DETERMINISM_HASH_NOT_FOUND);
@@ -255,7 +261,7 @@ ReplicateActionResponse contribute(String chainTaskId) {
255261
ReplicateActionResponse reveal(String chainTaskId, TaskNotificationExtra extra) {
256262
unsetTaskUsingCpu(chainTaskId);
257263

258-
ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
264+
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
259265
String resultDigest = computedFile != null ? computedFile.getResultDigest() : "";
260266

261267
if (resultDigest.isEmpty()) {
@@ -298,26 +304,13 @@ ReplicateActionResponse reveal(String chainTaskId, TaskNotificationExtra extra)
298304

299305
ReplicateActionResponse uploadResult(String chainTaskId) {
300306
unsetTaskUsingCpu(chainTaskId);
301-
302-
boolean isResultEncryptionNeeded = resultService.isResultEncryptionNeeded(chainTaskId);
303-
boolean isResultEncrypted = false;
304-
305-
if (isResultEncryptionNeeded) {
306-
isResultEncrypted = resultService.encryptResult(chainTaskId);
307-
}
308-
309-
if (isResultEncryptionNeeded && !isResultEncrypted) {
310-
log.error("Cannot upload, failed to encrypt result [chainTaskId:{}]", chainTaskId);
311-
return ReplicateActionResponse.failure(RESULT_ENCRYPTION_FAILED);
312-
}
313-
314307
String resultLink = resultService.uploadResultAndGetLink(chainTaskId);
315308
if (resultLink.isEmpty()) {
316309
log.error("Cannot upload, resultLink missing [chainTaskId:{}]", chainTaskId);
317310
return ReplicateActionResponse.failure(RESULT_LINK_MISSING);
318311
}
319312

320-
ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
313+
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
321314
String callbackData = computedFile != null ? computedFile.getCallbackData() : "";
322315

323316
log.info("Result uploaded [chainTaskId:{}, resultLink:{}, callbackData:{}]",

0 commit comments

Comments
 (0)