|
|
|
|
@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
@ -118,35 +119,52 @@ public class ExperimentsController {
|
|
|
|
|
@PostMapping
|
|
|
|
|
public Mono<ResponseEntity<ExperimentsEntity>> createExperiment(@RequestBody ExperimentsEntity experiment) {
|
|
|
|
|
|
|
|
|
|
// 1️⃣ DB 저장
|
|
|
|
|
ExperimentsEntity saved = experimentsService.save(experiment);
|
|
|
|
|
|
|
|
|
|
// 2️⃣ Kubeflow POST 요청 payload
|
|
|
|
|
Map<String, Object> payload = new HashMap<>();
|
|
|
|
|
payload.put("display_name", saved.getDisplayName());
|
|
|
|
|
payload.put("description", saved.getDescription());
|
|
|
|
|
payload.put("namespace", "default"); // 필요에 따라 변경
|
|
|
|
|
|
|
|
|
|
// 날짜를 ISO 8601 UTC 포맷으로
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
|
|
|
|
|
|
|
|
|
|
payload.computeIfPresent("created_at", (k, v) ->
|
|
|
|
|
saved.getKubeflowCreatedAt() != null
|
|
|
|
|
? saved.getKubeflowCreatedAt().atZone(ZoneId.of("Asia/Seoul")).format(formatter)
|
|
|
|
|
: null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3️⃣ WebClient POST
|
|
|
|
|
return webClientBuilder.build()
|
|
|
|
|
.post()
|
|
|
|
|
.uri(kubeflowBaseUrl + "/apis/v2beta1/experiments")
|
|
|
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
|
|
|
.bodyValue(payload)
|
|
|
|
|
.retrieve()
|
|
|
|
|
.bodyToMono(Map.class) // 응답 필요 없으면 Void.class
|
|
|
|
|
.doOnNext(resp -> log.info("Kubeflow experiment 등록 완료: {}", resp))
|
|
|
|
|
.then(Mono.just(ResponseEntity.ok(saved))) // DB 저장된 엔티티 반환
|
|
|
|
|
.bodyToMono(Map.class) // Kubeflow 응답 받기
|
|
|
|
|
.flatMap(resp -> {
|
|
|
|
|
// Kubeflow 응답에서 값 꺼내기
|
|
|
|
|
if (resp.containsKey("experiment_id")) {
|
|
|
|
|
saved.setKubeFlowId((String) resp.get("experiment_id"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resp.containsKey("created_at")) {
|
|
|
|
|
saved.setKubeflowCreatedAt(
|
|
|
|
|
Instant.parse((String) resp.get("created_at"))
|
|
|
|
|
.atZone(ZoneId.of("Asia/Seoul"))
|
|
|
|
|
.toLocalDateTime()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resp.containsKey("last_run_created_at")) {
|
|
|
|
|
saved.setKubeflowLastRunCreatedAt(
|
|
|
|
|
Instant.parse((String) resp.get("last_run_created_at"))
|
|
|
|
|
.atZone(ZoneId.of("Asia/Seoul"))
|
|
|
|
|
.toLocalDateTime()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resp.containsKey("storage_state")) {
|
|
|
|
|
saved.setKubeflowStorageState((String) resp.get("storage_state"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DB 업데이트
|
|
|
|
|
experimentsService.save(saved);
|
|
|
|
|
|
|
|
|
|
log.info("Kubeflow experiment 등록 완료: {}", resp);
|
|
|
|
|
return Mono.just(ResponseEntity.ok(saved));
|
|
|
|
|
})
|
|
|
|
|
.doOnError(e -> log.error("Kubeflow experiment 등록 실패", e));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|