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

SO1S-461 Nodes GET API 작성 #50

Merged
merged 4 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예전에 YAML 전달 태스크를 처리할 때 고민했던게 있는데요 "yaml만 전달해주는 거면 DTO를 감싸줘야하는가?"라는 고민이 들었습니다. 제가 내렸던 최종적인 결론은 "혹시 모를 확장성을 위해 DTO를 만들고 전달을 하자"라는 결론이었는데 이 부분에 대해서는 어떻게 생각하시나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 저도 동의합니다! DTO 기반으로 수정할게요~


return ResponseEntity.ok(yaml);
}

}
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);
}

}
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;

}
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)));
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.so1s.backend.domain.model.exception;

import io.so1s.backend.global.error.exception.DuplicatedException;
import io.so1s.backend.global.error.exception.NotFoundException;

public class DataTypeNotFoundException extends DuplicatedException {
public class DataTypeNotFoundException extends NotFoundException {

public DataTypeNotFoundException(String message) {
super(message);
Expand Down