Skip to content

Commit

Permalink
Add /status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrys committed Jul 25, 2024
1 parent cc96ca9 commit deca8a6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.odysseusinc.arachne.execution_engine_common.api.v1.dto;

import java.time.Instant;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class EngineStatus {
/**
* The moment when EE has started.
*/
private Instant started;
/**
* The list of
*/
private Map<Long, ExecutionOutcome> submissions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisRequestStatusDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisResultDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisSyncRequestDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.EngineStatus;
import com.odysseusinc.arachne.executionengine.execution.AnalysisService;
import com.odysseusinc.arachne.executionengine.execution.CallbackService;
import com.odysseusinc.arachne.executionengine.execution.Overseer;
import com.odysseusinc.arachne.executionengine.util.AnalisysUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -60,11 +60,13 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -102,6 +104,12 @@ public AnalysisController(AnalysisService analysisService, CallbackService callb
this.threadPoolExecutor = threadPoolExecutor;
}

@ApiOperation(value = "Status for analysis")
@GetMapping(value = "/status", produces = MediaType.APPLICATION_JSON_VALUE)
public EngineStatus status(@RequestParam(value = "id", required = false) List<Long> ids) {
return analysisService.getStatus(ids);
}

@ApiOperation(value = "Files for analysis")
@RequestMapping(value = REST_API_ANALYZE,
method = RequestMethod.POST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisResultStatusDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisSyncRequestDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.DataSourceUnsecuredDTO;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.EngineStatus;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.ExecutionOutcome;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.Stage;
import com.odysseusinc.arachne.executionengine.aspect.FileDescriptorCount;
import com.odysseusinc.arachne.executionengine.service.CdmMetadataService;
import com.odysseusinc.arachne.executionengine.util.AutoCloseWrapper;
import java.io.File;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -57,6 +60,7 @@
import net.lingala.zip4j.exception.ZipException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -152,6 +156,22 @@ private void attachMetadata(AnalysisSyncRequestDTO analysis, File analysisDir) {
}
}

public EngineStatus getStatus(List<Long> idsMaybe) {
Map<Long, ExecutionOutcome> statuses = Optional.ofNullable(idsMaybe).map(ids ->
ids.stream().flatMap(id ->
Optional.ofNullable(overseers.get(id)).map(overseer ->
Stream.of(Pair.of(id, getStatus(overseer)))
).orElseGet(Stream::of)
).collect(Collectors.toMap(Pair::getKey, Pair::getValue))
).orElseGet(Collections::emptyMap);
return new EngineStatus(Instant.now(), statuses);
}

private static ExecutionOutcome getStatus(Overseer overseer) {
return Optional.ofNullable(overseer.getResult().getNow(null)).orElseGet(() ->
new ExecutionOutcome(Stage.EXECUTE, null, overseer.getStdout())
);
}

@FileDescriptorCount
public AnalysisRequestStatusDTO analyze(
Expand Down

0 comments on commit deca8a6

Please sign in to comment.