diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d83a2f6..d07fa1860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 🐞 解决BUG、优化功能 1. 升级 SpringBoot、Hutool +2. 【server】docker 加入集群无法正常使用问题 ------ diff --git a/modules/sub-plugin/docker-cli/src/test/java/TestLocal.java b/modules/sub-plugin/docker-cli/src/test/java/TestLocal.java index d7b21b902..1d6e36c78 100644 --- a/modules/sub-plugin/docker-cli/src/test/java/TestLocal.java +++ b/modules/sub-plugin/docker-cli/src/test/java/TestLocal.java @@ -20,17 +20,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; +import cn.hutool.json.JSONUtil; import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.StatsCmd; import com.github.dockerjava.api.command.VersionCmd; +import com.github.dockerjava.api.model.Statistics; import com.github.dockerjava.api.model.Version; import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DockerClientConfig; import com.github.dockerjava.core.DockerClientImpl; +import com.github.dockerjava.core.InvocationBuilder; import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; import com.github.dockerjava.transport.DockerHttpClient; +import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; @@ -39,31 +45,43 @@ import org.slf4j.LoggerFactory; * @since 2022/1/25 */ public class TestLocal { - private DockerClient dockerClient; + private DockerClient dockerClient; - @Test - public void test() { - LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); - Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); - logger.setLevel(Level.INFO); + @Before + public void init() { + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + logger.setLevel(Level.INFO); - DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() - // .withDockerHost("tcp://192.168.163.11:2376").build(); + DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() + // .withDockerHost("tcp://192.168.163.11:2376").build(); // .withApiVersion() - .withDockerHost("tcp://127.0.0.1:2375").build(); + .withDockerHost("tcp://127.0.0.1:2375").build(); - DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(config.getDockerHost()) - .sslConfig(config.getSSLConfig()) - .maxConnections(100) + DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder() + .dockerHost(config.getDockerHost()) + .sslConfig(config.getSSLConfig()) + .maxConnections(100) // .connectionTimeout(Duration.ofSeconds(30)) // .responseTimeout(Duration.ofSeconds(45)) - .build(); - this.dockerClient = DockerClientImpl.getInstance(config, httpClient); - dockerClient.pingCmd().exec(); - VersionCmd versionCmd = dockerClient.versionCmd(); - Version exec = versionCmd.exec(); - System.out.println(exec); + .build(); + this.dockerClient = DockerClientImpl.getInstance(config, httpClient); + } - } + @Test + public void test() { + + dockerClient.pingCmd().exec(); + VersionCmd versionCmd = dockerClient.versionCmd(); + Version exec = versionCmd.exec(); + System.out.println(exec); + } + + @Test + public void tset2() throws InterruptedException { + StatsCmd statsCmd = dockerClient.statsCmd("5848fd613ea41f9b370a26949f590be107c165872bfc007f666b26d8a2247ac2"); + Statistics statistics = statsCmd.exec(new InvocationBuilder.AsyncResultCallback<>()).awaitResult(); + System.out.println(statistics); + System.out.println(JSONUtil.toJsonStr(statistics)); + } } diff --git a/web-vue/src/pages/docker/list.vue b/web-vue/src/pages/docker/list.vue index ec213e89f..3b7a43c47 100644 --- a/web-vue/src/pages/docker/list.vue +++ b/web-vue/src/pages/docker/list.vue @@ -183,12 +183,11 @@ option-filter-prop="children" @change=" (v) => { - if ( - swarmList.filter((item) => { - return item.id === v; - }).length - ) { - temp = { ...temp, remoteAddr: temp[0].nodeAddr }; + tempList = swarmList.filter((item) => { + return item.id === v; + }); + if (tempList.length) { + temp = { ...temp, remoteAddr: tempList[0].nodeAddr }; } else { temp = { ...temp, remoteAddr: '' }; }