Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: funman taskrunner api plumbing #3411

Merged
merged 15 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions containers/scripts/docker-compose-taskrunner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ services:
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"

funman-taskrunner:
container_name: funman-taskrunner
image: ghcr.io/darpa-askem/funman-taskrunner:latest
networks:
- terarium
environment:
TERARIUM_MQ-ADDRESSES: "amqp://rabbitmq:5672"
TERARIUM_MQ-PASSWORD: "terarium123"
TERARIUM_MQ-USERNAME: "terarium"
TERARIUM_TASKRUNNER_REQUEST-TYPE: "funman"
depends_on:
rabbitmq:
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"
Original file line number Diff line number Diff line change
@@ -1,25 +1,97 @@
package software.uncharted.terarium.hmiserver.controller.funman;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.FeignException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.annotation.PostConstruct;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.server.ResponseStatusException;
import software.uncharted.terarium.hmiserver.models.funman.FunmanPostQueriesRequest;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType;
import software.uncharted.terarium.hmiserver.models.task.TaskResponse;
import software.uncharted.terarium.hmiserver.proxies.funman.FunmanProxy;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.CurrentUserService;
import software.uncharted.terarium.hmiserver.service.tasks.TaskService;
import software.uncharted.terarium.hmiserver.service.tasks.TaskService.TaskMode;
import software.uncharted.terarium.hmiserver.service.tasks.ValidateModelConfigHandler;

@RestController
@RequestMapping("/funman/queries")
@RequiredArgsConstructor
@Slf4j
public class FunmanController {

private final ObjectMapper objectMapper;
private final TaskService taskService;
private final CurrentUserService currentUserService;

private final ValidateModelConfigHandler validateModelConfigHandler;

@PostConstruct
void init() {
taskService.addResponseHandler(validateModelConfigHandler);
}

@PostMapping("/test")
@Secured(Roles.USER)
@Operation(summary = "Dispatch a model configuration validation task")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Dispatched successfully",
content =
@Content(
mediaType = "application/json",
schema =
@io.swagger.v3.oas.annotations.media.Schema(
implementation = TaskResponse.class))),
@ApiResponse(
responseCode = "400",
description = "The provided document text is too long",
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
content = @Content),
@ApiResponse(
responseCode = "500",
description = "There was an issue dispatching the request",
content = @Content)
})
public ResponseEntity<TaskResponse> createValidationRequest(@RequestBody final JsonNode input) {

try {
final TaskRequest taskRequest = new TaskRequest();
taskRequest.setType(TaskType.FUNMAN);
taskRequest.setScript(ValidateModelConfigHandler.NAME);
taskRequest.setUserId(currentUserService.get().getId());
taskRequest.setInput(objectMapper.writeValueAsBytes(input));

// TODO: create Simulation for tracking
final UUID uuid = UUID.randomUUID();
final ValidateModelConfigHandler.Properties props = new ValidateModelConfigHandler.Properties();
props.setSimulationId(uuid);
taskRequest.setAdditionalProperties(props);

return ResponseEntity.ok().body(taskService.runTask(TaskMode.ASYNC, taskRequest));
} catch (final ResponseStatusException e) {
throw e;
} catch (final Exception e) {
final String error = "Unable to dispatch task request";
throw new ResponseStatusException(org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR, error);
}
}

// Depreacated
private final FunmanProxy funmanProxy;

@GetMapping("/{queryId}/halt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static enum TaskType {
@JsonAlias("gollm")
GOLLM("gollm"),
@JsonAlias("mira")
MIRA("mira");
MIRA("mira"),
@JsonAlias("funman")
FUNMAN("funman");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package software.uncharted.terarium.hmiserver.service.tasks;

import java.util.UUID;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import software.uncharted.terarium.hmiserver.models.task.TaskResponse;

@Component
@RequiredArgsConstructor
@Slf4j
public class ValidateModelConfigHandler extends TaskResponseHandler {
public static final String NAME = "funman_task:validate_modelconfig";

@Override
public String getName() {
return NAME;
}

@Data
public static class Properties {
UUID simulationId;
}

@Override
public TaskResponse onSuccess(final TaskResponse resp) {
try {
final Properties props = resp.getAdditionalProperties(Properties.class);
final UUID simulationId = props.getSimulationId();

System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + simulationId.toString());
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
} catch (final Exception e) {
throw new RuntimeException(e);
}
return resp;
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading