Skip to content

Commit

Permalink
Merge pull request #308 from iExecBlockchainComputing/feature/iexec-out
Browse files Browse the repository at this point in the history
Use $IEXEC_IN and $IEXEC_OUT env variables
  • Loading branch information
zguesmi authored May 21, 2020
2 parents 152dd4d + 36a4912 commit 61c8d21
Show file tree
Hide file tree
Showing 15 changed files with 571 additions and 645 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@ public String getTaskBaseDir(String chainTaskId) {
}

public String getTaskInputDir(String chainTaskId) {
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_INPUT;
return getTaskBaseDir(chainTaskId) + FileHelper.SLASH_INPUT;
}

public String getTaskOutputDir(String chainTaskId) {
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_OUTPUT;
return getTaskBaseDir(chainTaskId) + FileHelper.SLASH_OUTPUT;
}

public String getTaskIexecOutDir(String chainTaskId) {
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_OUTPUT
+ FileHelper.SLASH_IEXEC_OUT;
}

public String getTaskSconeDir(String chainTaskId) {
return getWorkerBaseDir() + File.separator + chainTaskId + FileHelper.SLASH_SCONE;
return getTaskOutputDir(chainTaskId) + FileHelper.SLASH_IEXEC_OUT;
}

public String getDatasetSecretFilePath(String chainTaskId) {
Expand Down
348 changes: 220 additions & 128 deletions src/main/java/com/iexec/worker/docker/ComputationService.java

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions src/main/java/com/iexec/worker/docker/ComputeMeta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.iexec.worker.docker;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/* /!\ this probably should be split */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ComputeMeta {

private String chainTaskId;
private boolean isComputed;
private boolean isPreComputed;
private boolean isPostComputed;
@Builder.Default private String secureSessionId = "";
@Builder.Default private String stdout = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
Expand Down
41 changes: 17 additions & 24 deletions src/main/java/com/iexec/worker/executor/TaskManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.iexec.worker.config.WorkerConfigurationService;
import com.iexec.worker.dataset.DataService;
import com.iexec.worker.docker.ComputationService;
import com.iexec.worker.docker.ComputeMeta;
import com.iexec.worker.result.ResultService;
import com.iexec.worker.tee.scone.SconeTeeService;
import com.iexec.worker.utils.LoggingUtils;
Expand Down Expand Up @@ -191,21 +192,26 @@ ReplicateActionResponse compute(String chainTaskId) {
return ReplicateActionResponse.failure(APP_NOT_FOUND_LOCALLY);
}

boolean isComputed;
WorkerpoolAuthorization workerpoolAuthorization =
contributionService.getWorkerpoolAuthorization(chainTaskId);

if (taskDescription.isTeeTask()) {
isComputed = computationService.runTeeComputation(taskDescription, workerpoolAuthorization);
} else {
isComputed = computationService.runNonTeeComputation(taskDescription, workerpoolAuthorization);
ComputeMeta computeMeta = ComputeMeta.builder().chainTaskId(chainTaskId).build();
computationService.runPreCompute(computeMeta, taskDescription, workerpoolAuthorization);
if (!computeMeta.isPreComputed()) {
log.error("Failed to pre-compute [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure(PRE_COMPUTE_FAILED);
}

if (!isComputed) {
computationService.runComputation(computeMeta, taskDescription);
if (!computeMeta.isComputed()) {
log.error("Failed to compute [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure();
}

computationService.runPostCompute(computeMeta, taskDescription);
if (!computeMeta.isPostComputed()) {
log.error("Failed to post-compute [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure(POST_COMPUTE_FAILED);
}
resultService.saveResultInfo(chainTaskId, taskDescription);
return ReplicateActionResponse.success();
}

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

ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
if (computedFile == null) {
log.error("Cannot contribute, getComputedFile [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure(DETERMINISM_HASH_NOT_FOUND);
Expand All @@ -255,7 +261,7 @@ ReplicateActionResponse contribute(String chainTaskId) {
ReplicateActionResponse reveal(String chainTaskId, TaskNotificationExtra extra) {
unsetTaskUsingCpu(chainTaskId);

ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
String resultDigest = computedFile != null ? computedFile.getResultDigest() : "";

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

ReplicateActionResponse uploadResult(String chainTaskId) {
unsetTaskUsingCpu(chainTaskId);

boolean isResultEncryptionNeeded = resultService.isResultEncryptionNeeded(chainTaskId);
boolean isResultEncrypted = false;

if (isResultEncryptionNeeded) {
isResultEncrypted = resultService.encryptResult(chainTaskId);
}

if (isResultEncryptionNeeded && !isResultEncrypted) {
log.error("Cannot upload, failed to encrypt result [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure(RESULT_ENCRYPTION_FAILED);
}

String resultLink = resultService.uploadResultAndGetLink(chainTaskId);
if (resultLink.isEmpty()) {
log.error("Cannot upload, resultLink missing [chainTaskId:{}]", chainTaskId);
return ReplicateActionResponse.failure(RESULT_LINK_MISSING);
}

ComputedFile computedFile = resultService.getComputedFile(chainTaskId);
ComputedFile computedFile = computationService.getComputedFile(chainTaskId);
String callbackData = computedFile != null ? computedFile.getCallbackData() : "";

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

0 comments on commit 61c8d21

Please sign in to comment.