-
Notifications
You must be signed in to change notification settings - Fork 2
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
SO1S-461 Nodes GET API 작성 #50
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/io/so1s/backend/domain/kubernetes/controller/NodeController.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.so1s.backend.domain.kubernetes.controller; | ||
|
||
import io.fabric8.kubernetes.api.model.Node; | ||
import io.so1s.backend.domain.kubernetes.service.KubernetesService; | ||
import io.so1s.backend.domain.kubernetes.service.NodesService; | ||
import java.util.List; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/nodes") | ||
@RequiredArgsConstructor | ||
public class NodeController { | ||
|
||
private final NodesService nodesService; | ||
private final KubernetesService kubernetesService; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<Node>> getNodes() { | ||
return ResponseEntity.ok(nodesService.findNodes()); | ||
} | ||
|
||
@GetMapping("/{node_name}/yaml") | ||
public ResponseEntity<String> findDeploymentYaml( | ||
@Valid @PathVariable("node_name") String nodeName) { | ||
Node node = nodesService.findNodeByName(nodeName); | ||
String yaml = kubernetesService.getWorkloadToYaml(node); | ||
|
||
return ResponseEntity.ok(yaml); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/so1s/backend/domain/kubernetes/exception/NodeNotFoundException.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.so1s.backend.domain.kubernetes.exception; | ||
|
||
import io.so1s.backend.global.error.exception.NotFoundException; | ||
|
||
public class NodeNotFoundException extends NotFoundException { | ||
|
||
public NodeNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/io/so1s/backend/domain/kubernetes/service/NodesService.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.so1s.backend.domain.kubernetes.service; | ||
|
||
import io.fabric8.kubernetes.api.model.Node; | ||
import io.so1s.backend.domain.kubernetes.exception.NodeNotFoundException; | ||
import java.util.List; | ||
|
||
public interface NodesService { | ||
|
||
List<Node> findNodes(); | ||
|
||
Node findNodeByName(String name) throws NodeNotFoundException; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/so1s/backend/domain/kubernetes/service/NodesServiceImpl.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.so1s.backend.domain.kubernetes.service; | ||
|
||
import io.fabric8.kubernetes.api.model.Node; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.so1s.backend.domain.kubernetes.exception.NodeNotFoundException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NodesServiceImpl implements NodesService { | ||
|
||
private final KubernetesClient client; | ||
|
||
@Override | ||
public List<Node> findNodes() { | ||
return client.nodes().list().getItems(); | ||
} | ||
|
||
@Override | ||
public Node findNodeByName(String name) throws NodeNotFoundException { | ||
return Optional.ofNullable(client.nodes().withName(name).get()) | ||
.orElseThrow(() -> new NodeNotFoundException( | ||
String.format("Node %s not found.", name))); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
src/main/java/io/so1s/backend/domain/model/exception/DataTypeNotFoundException.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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예전에 YAML 전달 태스크를 처리할 때 고민했던게 있는데요 "yaml만 전달해주는 거면 DTO를 감싸줘야하는가?"라는 고민이 들었습니다. 제가 내렸던 최종적인 결론은 "혹시 모를 확장성을 위해 DTO를 만들고 전달을 하자"라는 결론이었는데 이 부분에 대해서는 어떻게 생각하시나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 저도 동의합니다! DTO 기반으로 수정할게요~