-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from So1S/SO1S-461
SO1S-461 Nodes GET API 작성
- Loading branch information
Showing
6 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
package io.so1s.backend.domain.kubernetes.controller; | ||
|
||
import io.fabric8.kubernetes.api.model.Node; | ||
import io.so1s.backend.domain.kubernetes.dto.response.NodeFindResponseDto; | ||
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<NodeFindResponseDto> findDeploymentYaml( | ||
@Valid @PathVariable("node_name") String nodeName) { | ||
Node node = nodesService.findNodeByName(nodeName); | ||
String yaml = kubernetesService.getWorkloadToYaml(node); | ||
|
||
return ResponseEntity.ok(NodeFindResponseDto.builder().yaml(yaml).build()); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/so1s/backend/domain/kubernetes/dto/response/NodeFindResponseDto.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,17 @@ | ||
package io.so1s.backend.domain.kubernetes.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NodeFindResponseDto { | ||
|
||
@Builder.Default | ||
private String 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