-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add extra parameters to deployment endpoint (#15)
- Loading branch information
1 parent
e2f4095
commit 9eaedec
Showing
10 changed files
with
314 additions
and
200 deletions.
There are no files selected for viewing
124 changes: 63 additions & 61 deletions
124
src/main/java/com/epam/aidial/controller/DeploymentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,63 @@ | ||
package com.epam.aidial.controller; | ||
|
||
import com.epam.aidial.dto.CreateDeploymentRequestDto; | ||
import com.epam.aidial.dto.CreateDeploymentResponseDto; | ||
import com.epam.aidial.dto.DeleteImageResponseDto; | ||
import com.epam.aidial.dto.GetApplicationLogsResponseDto; | ||
import com.epam.aidial.service.DeployService; | ||
import com.epam.aidial.service.HeartbeatService; | ||
import com.epam.aidial.util.SseUtils; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.codec.ServerSentEvent; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/v1/deployment") | ||
@RequiredArgsConstructor | ||
public class DeploymentController { | ||
private final DeployService deployService; | ||
private final HeartbeatService heartbeatService; | ||
|
||
@PostMapping(value = "{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
public Flux<ServerSentEvent<Object>> create( | ||
@PathVariable("name") String name, | ||
@RequestBody CreateDeploymentRequestDto request) { | ||
Mono<CreateDeploymentResponseDto> result = deployService.deploy(name, Objects.requireNonNullElse(request.env(), Map.of())) | ||
.doOnError(e -> log.error("Failed to deploy service {}", name, e)) | ||
.map(CreateDeploymentResponseDto::new); | ||
|
||
return heartbeatService.setupHeartbeats(SseUtils.mapToSseEvent(result)); | ||
} | ||
|
||
@DeleteMapping(value = "{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
public Flux<ServerSentEvent<Object>> delete(@PathVariable("name") String name) { | ||
Mono<DeleteImageResponseDto> result = deployService.undeploy(name) | ||
.doOnError(e -> log.error("Failed to delete service {}", name, e)) | ||
.map(DeleteImageResponseDto::new); | ||
|
||
return heartbeatService.setupHeartbeats(SseUtils.mapToSseEvent(result)); | ||
} | ||
|
||
@GetMapping(value = "{name}/logs") | ||
public Mono<GetApplicationLogsResponseDto> logs(@PathVariable("name") String name) { | ||
return deployService.logs(name) | ||
.map(GetApplicationLogsResponseDto::new) | ||
.doOnError(e -> log.error("Failed to retrieve logs for {}", name, e)); | ||
} | ||
} | ||
package com.epam.aidial.controller; | ||
|
||
import com.epam.aidial.dto.CreateDeploymentRequestDto; | ||
import com.epam.aidial.dto.CreateDeploymentResponseDto; | ||
import com.epam.aidial.dto.DeleteImageResponseDto; | ||
import com.epam.aidial.dto.GetApplicationLogsResponseDto; | ||
import com.epam.aidial.service.DeployService; | ||
import com.epam.aidial.service.HeartbeatService; | ||
import com.epam.aidial.util.SseUtils; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.codec.ServerSentEvent; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/v1/deployment") | ||
@RequiredArgsConstructor | ||
public class DeploymentController { | ||
private final DeployService deployService; | ||
private final HeartbeatService heartbeatService; | ||
|
||
@PostMapping(value = "{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
public Flux<ServerSentEvent<Object>> create( | ||
@PathVariable("name") String name, | ||
@RequestBody CreateDeploymentRequestDto request) { | ||
Map<String, String> env = Objects.requireNonNullElse(request.env(), Map.of()); | ||
Mono<CreateDeploymentResponseDto> result = deployService.deploy( | ||
name, env, request.image(), request.initialScale(), request.minScale(), request.maxScale()) | ||
.doOnError(e -> log.error("Failed to deploy service {}", name, e)) | ||
.map(CreateDeploymentResponseDto::new); | ||
|
||
return heartbeatService.setupHeartbeats(SseUtils.mapToSseEvent(result)); | ||
} | ||
|
||
@DeleteMapping(value = "{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
public Flux<ServerSentEvent<Object>> delete(@PathVariable("name") String name) { | ||
Mono<DeleteImageResponseDto> result = deployService.undeploy(name) | ||
.doOnError(e -> log.error("Failed to delete service {}", name, e)) | ||
.map(DeleteImageResponseDto::new); | ||
|
||
return heartbeatService.setupHeartbeats(SseUtils.mapToSseEvent(result)); | ||
} | ||
|
||
@GetMapping(value = "{name}/logs") | ||
public Mono<GetApplicationLogsResponseDto> logs(@PathVariable("name") String name) { | ||
return deployService.logs(name) | ||
.map(GetApplicationLogsResponseDto::new) | ||
.doOnError(e -> log.error("Failed to retrieve logs for {}", name, e)); | ||
} | ||
} |
19 changes: 13 additions & 6 deletions
19
src/main/java/com/epam/aidial/dto/CreateDeploymentRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
package com.epam.aidial.dto; | ||
|
||
import java.util.Map; | ||
|
||
public record CreateDeploymentRequestDto(Map<String, String> env) { | ||
} | ||
package com.epam.aidial.dto; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
public record CreateDeploymentRequestDto( | ||
@Nullable Map<String, String> env, | ||
@Nullable String image, | ||
@Nullable Integer initialScale, | ||
@Nullable Integer minScale, | ||
@Nullable Integer maxScale) { | ||
} |
12 changes: 8 additions & 4 deletions
12
src/main/java/com/epam/aidial/dto/CreateImageRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package com.epam.aidial.dto; | ||
|
||
public record CreateImageRequestDto(String sources, String runtime) { | ||
} | ||
package com.epam.aidial.dto; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record CreateImageRequestDto( | ||
String sources, | ||
@Nullable String runtime) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.