forked from kornelrabczak/dockhand
-
Notifications
You must be signed in to change notification settings - Fork 0
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 kornelrabczak#25 from nikom1337/docker_hosts_manag…
…ement Docker hosts management
- Loading branch information
Showing
14 changed files
with
176 additions
and
228 deletions.
There are no files selected for viewing
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
8 changes: 6 additions & 2 deletions
8
src/main/java/com/thecookiezen/bussiness/containers/boundary/ContainerFetcher.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,14 +1,18 @@ | ||
package com.thecookiezen.bussiness.containers.boundary; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.command.StatsCmd; | ||
import com.github.dockerjava.api.model.Container; | ||
import com.github.dockerjava.api.model.Info; | ||
|
||
import java.util.Collection; | ||
|
||
public interface ContainerFetcher { | ||
Collection<Container> list(); | ||
Info getInfo(); | ||
Collection<Container> list(DockerClient dockerClient); | ||
|
||
Info getInfo(DockerClient dockerClient); | ||
|
||
DockerClient getDockerClient(final String dockerHost, final String apiVersion); | ||
|
||
StatsCmd statsCmd(String containerId); | ||
} |
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
30 changes: 1 addition & 29 deletions
30
src/main/java/com/thecookiezen/presentation/IndexController.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,43 +1,15 @@ | ||
package com.thecookiezen.presentation; | ||
|
||
import com.github.dockerjava.api.model.Container; | ||
import com.github.dockerjava.api.model.Info; | ||
import com.thecookiezen.bussiness.cluster.boundary.ClusterRepository; | ||
import com.thecookiezen.bussiness.containers.boundary.ContainerFetcher; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.log4j.Log4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.Collection; | ||
|
||
@Controller | ||
@Log4j | ||
@AllArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class IndexController { | ||
|
||
ClusterRepository clusterRepository; | ||
|
||
ContainerFetcher containerFetcher; | ||
|
||
@RequestMapping("/index") | ||
public String index(Model model) { | ||
Collection<Container> list = containerFetcher.list(); | ||
Info info = containerFetcher.getInfo(); | ||
model.addAttribute("nodeInfo", info); | ||
model.addAttribute("containers", list); | ||
public String index() { | ||
return "index"; | ||
} | ||
|
||
@RequestMapping("/container") | ||
public String container(Model model) { | ||
return "container"; | ||
} | ||
|
||
@RequestMapping("/test") | ||
public String test() { | ||
return "test"; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/thecookiezen/presentation/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,53 @@ | ||
package com.thecookiezen.presentation; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.model.Container; | ||
import com.github.dockerjava.api.model.Info; | ||
import com.thecookiezen.bussiness.cluster.boundary.ClusterRepository; | ||
import com.thecookiezen.bussiness.cluster.entity.Cluster; | ||
import com.thecookiezen.bussiness.cluster.entity.DockerHost; | ||
import com.thecookiezen.bussiness.containers.boundary.ContainerFetcher; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.log4j.Log4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import javax.ws.rs.NotFoundException; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
@Controller | ||
@Log4j | ||
@AllArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class NodeController { | ||
|
||
ContainerFetcher containerFetcher; | ||
|
||
ClusterRepository clusterRepository; | ||
|
||
@RequestMapping("/clusters/node") | ||
public String node(@RequestParam long clusterId, @RequestParam long nodeId, Model model) { | ||
Optional<Cluster> byId = clusterRepository.getById(clusterId); | ||
if (!byId.isPresent()) | ||
throw new NotFoundException("CHANGE ME !"); | ||
|
||
Cluster cluster = byId.get(); | ||
Optional<DockerHost> nodeOptional = cluster.getHosts().stream().filter(n -> n.getId() == nodeId).findFirst(); | ||
if (!nodeOptional.isPresent()) | ||
throw new NotFoundException("CHANGE ME !"); | ||
|
||
DockerClient dockerClient = containerFetcher.getDockerClient(nodeOptional.get().getDockerDaemonUrl(), cluster.getDockerApiVersion()); | ||
Collection<Container> list = containerFetcher.list(dockerClient); | ||
Info info = containerFetcher.getInfo(dockerClient); | ||
|
||
model.addAttribute("cluster", cluster); | ||
model.addAttribute("node", nodeOptional.get()); | ||
model.addAttribute("nodeInfo", info); | ||
model.addAttribute("containers", list); | ||
return "clusters/node"; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" layout:decorator="layout"> | ||
<head> | ||
</head> | ||
<body> | ||
|
||
<div layout:fragment="content"> | ||
|
||
<div th:replace="fragments/node/info :: info"></div> | ||
|
||
</div> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.