diff --git a/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DefaultDockerSwarmPluginImpl.java b/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DefaultDockerSwarmPluginImpl.java index da90c0313..81635b882 100644 --- a/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DefaultDockerSwarmPluginImpl.java +++ b/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DefaultDockerSwarmPluginImpl.java @@ -25,6 +25,7 @@ package io.jpom; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.EnumUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; @@ -164,70 +165,9 @@ public class DefaultDockerSwarmPluginImpl implements IDefaultPlugin { } serviceSpec.withMode(serviceModeConfig); } -// { -// UpdateConfig updateConfig = new UpdateConfig(); -// -// serviceSpec.withUpdateConfig(updateConfig); -// } { - String image = (String) parameter.get("image"); TaskSpec taskSpec = new TaskSpec(); - ContainerSpec containerSpec = new ContainerSpec(); - containerSpec.withImage(image); - // - Collection> args = (Collection) parameter.get("args"); - if (CollUtil.isNotEmpty(args)) { - List value = args.stream() - .map(stringStringMap -> stringStringMap.get("value")) - .filter(StrUtil::isNotEmpty) - .collect(Collectors.toList()); - containerSpec.withArgs(value); - } - Collection> envs = (Collection) parameter.get("envs"); - if (CollUtil.isNotEmpty(envs)) { - List value = envs.stream() - .map(stringStringMap -> { - String name1 = stringStringMap.get("name"); - String value1 = stringStringMap.get("value"); - if (StrUtil.isEmpty(name1)) { - return null; - } - return StrUtil.format("{}={}", name1, value1); - }) - .filter(StrUtil::isNotEmpty) - .collect(Collectors.toList()); - containerSpec.withEnv(value); - } - Collection> commands = (Collection) parameter.get("commands"); - if (CollUtil.isNotEmpty(commands)) { - List value = commands.stream() - .map(stringStringMap -> stringStringMap.get("value")) - .filter(StrUtil::isNotEmpty) - .collect(Collectors.toList()); - containerSpec.withCommand(value); - } - // - Collection> volumes = (Collection>) parameter.get("volumes"); - if (CollUtil.isNotEmpty(volumes)) { - List value = volumes.stream() - .map(stringStringMap -> { - String source = stringStringMap.get("source"); - String target = stringStringMap.get("target"); - if (StrUtil.hasBlank(source, target)) { - return null; - } - String type = stringStringMap.get("type"); - MountType mountType = EnumUtil.fromString(MountType.class, type); - Mount mount = new Mount(); - mount.withSource(source); - mount.withTarget(target); - mount.withType(mountType); - return mount; - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - containerSpec.withMounts(value); - } + ContainerSpec containerSpec = this.buildContainerSpec(parameter); taskSpec.withContainerSpec(containerSpec); // serviceSpec.withTaskTemplate(taskSpec); @@ -263,6 +203,14 @@ public class DefaultDockerSwarmPluginImpl implements IDefaultPlugin { } serviceSpec.withEndpointSpec(endpointSpec); } + { + Map update = (Map) parameter.get("update"); + UpdateConfig updateConfig = this.buildUpdateConfig(update); + serviceSpec.withUpdateConfig(updateConfig); + Map rollback = (Map) parameter.get("rollback"); + UpdateConfig rollbackConfig = this.buildUpdateConfig(rollback); + serviceSpec.withRollbackConfig(rollbackConfig); + } String serviceId = (String) parameter.get("serviceId"); String version = (String) parameter.get("version"); if (StrUtil.isNotEmpty(serviceId)) { @@ -278,6 +226,102 @@ public class DefaultDockerSwarmPluginImpl implements IDefaultPlugin { } } + private ContainerSpec buildContainerSpec(Map parameter) { + String image = (String) parameter.get("image"); + ContainerSpec containerSpec = new ContainerSpec(); + containerSpec.withImage(image); + // + Collection> args = (Collection) parameter.get("args"); + if (CollUtil.isNotEmpty(args)) { + List value = args.stream() + .map(stringStringMap -> stringStringMap.get("value")) + .filter(StrUtil::isNotEmpty) + .collect(Collectors.toList()); + containerSpec.withArgs(value); + } + Collection> envs = (Collection) parameter.get("envs"); + if (CollUtil.isNotEmpty(envs)) { + List value = envs.stream() + .map(stringStringMap -> { + String name1 = stringStringMap.get("name"); + String value1 = stringStringMap.get("value"); + if (StrUtil.isEmpty(name1)) { + return null; + } + return StrUtil.format("{}={}", name1, value1); + }) + .filter(StrUtil::isNotEmpty) + .collect(Collectors.toList()); + containerSpec.withEnv(value); + } + Collection> commands = (Collection) parameter.get("commands"); + if (CollUtil.isNotEmpty(commands)) { + List value = commands.stream() + .map(stringStringMap -> stringStringMap.get("value")) + .filter(StrUtil::isNotEmpty) + .collect(Collectors.toList()); + containerSpec.withCommand(value); + } + // + Collection> volumes = (Collection>) parameter.get("volumes"); + if (CollUtil.isNotEmpty(volumes)) { + List value = volumes.stream() + .map(stringStringMap -> { + String source = stringStringMap.get("source"); + String target = stringStringMap.get("target"); + if (StrUtil.hasBlank(source, target)) { + return null; + } + String type = stringStringMap.get("type"); + MountType mountType = EnumUtil.fromString(MountType.class, type); + Mount mount = new Mount(); + mount.withSource(source); + mount.withTarget(target); + mount.withType(mountType); + return mount; + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + containerSpec.withMounts(value); + } + return containerSpec; + } + + private UpdateConfig buildUpdateConfig(Map update) { + if (MapUtil.isNotEmpty(update)) { + UpdateConfig updateConfig = new UpdateConfig(); + String failureAction = (String) update.get("failureAction"); + if (StrUtil.isNotEmpty(failureAction)) { + UpdateFailureAction updateFailureAction = EnumUtil.fromString(UpdateFailureAction.class, failureAction); + updateConfig.withFailureAction(updateFailureAction); + } + String order = (String) update.get("order"); + if (StrUtil.isNotEmpty(order)) { + UpdateOrder updateOrder = EnumUtil.fromString(UpdateOrder.class, order); + updateConfig.withOrder(updateOrder); + } + Object parallelism = update.get("parallelism"); + if (parallelism != null) { + updateConfig.withParallelism(Convert.toLong(parallelism)); + } + Object delay = update.get("delay"); + if (delay != null) { + updateConfig.withDelay(Convert.toLong(delay)); + } + Object maxFailureRatio = update.get("maxFailureRatio"); + if (maxFailureRatio != null) { + updateConfig.withMaxFailureRatio(Convert.toFloat(maxFailureRatio)); + } + Object monitor = update.get("monitor"); + if (monitor != null) { + updateConfig.withMonitor(Convert.toLong(monitor)); + } + return updateConfig; + } + return null; + } + + public void removeServiceCmd(Map parameter) { DockerClient dockerClient = DockerUtil.build(parameter); try { diff --git a/modules/sub-plugin/docker-cli/src/test/java/TestSwarm.java b/modules/sub-plugin/docker-cli/src/test/java/TestSwarm.java index 32dc838be..a6e37364a 100644 --- a/modules/sub-plugin/docker-cli/src/test/java/TestSwarm.java +++ b/modules/sub-plugin/docker-cli/src/test/java/TestSwarm.java @@ -329,6 +329,7 @@ public class TestSwarm { taskSpec.withContainerSpec(containerSpec); serviceSpec.withTaskTemplate(taskSpec); } +// serviceSpec.withRollbackConfig() serviceSpec.withEndpointSpec(new EndpointSpec()); String serviceId = "tf2r29awevz2fcprybv6cvlm9"; InspectServiceCmd inspectServiceCmd = client.inspectServiceCmd(serviceId); diff --git a/web-vue/src/pages/docker/swarm/service.vue b/web-vue/src/pages/docker/swarm/service.vue index bec5bec8c..9b20d4f07 100644 --- a/web-vue/src/pages/docker/swarm/service.vue +++ b/web-vue/src/pages/docker/swarm/service.vue @@ -50,7 +50,7 @@ - + {{ text }} @@ -303,6 +303,60 @@ + + + + + + + + + + + + + 暂停 + 继续 + 回滚 + + + + + 先停止 + 先启动 + + + + + + + + + + + + + + + + + + + 暂停 + 继续 + 回滚 + + + + + 先停止 + 先启动 + + + + + + @@ -338,7 +392,10 @@ export default { loading: false, listQuery: {}, list: [], - temp: {}, + temp: { + update: {}, + rollback: {}, + }, editVisible: false, initSwarmVisible: false, taskVisible: false, @@ -427,6 +484,8 @@ export default { args: [{}], commands: [{}], envs: [{}], + update: {}, + rollback: {}, }; }, // 编辑 @@ -462,6 +521,8 @@ export default { args: [{}], commands: [{}], envs: [{}], + update: {}, + rollback: {}, }; const args = spec.taskTemplate?.containerSpec?.args; @@ -469,7 +530,8 @@ export default { const command = spec.taskTemplate?.containerSpec?.command; const env = spec.taskTemplate?.containerSpec?.env; const ports = spec.endpointSpec?.ports; - + const updateConfig = spec.updateConfig; + const rollbackConfig = spec.rollbackConfig; if (args) { this.temp = { ...this.temp, @@ -507,6 +569,12 @@ export default { if (mounts) { this.temp = { ...this.temp, volumes: mounts }; } + if (updateConfig) { + this.temp = { ...this.temp, update: updateConfig }; + } + if (rollbackConfig) { + this.temp = { ...this.temp, rollback: rollbackConfig }; + } }, handleEditOk() { this.$refs["editForm"].validate((valid) => { diff --git a/web-vue/src/pages/docker/swarm/task.vue b/web-vue/src/pages/docker/swarm/task.vue index b4a4b000d..230335412 100644 --- a/web-vue/src/pages/docker/swarm/task.vue +++ b/web-vue/src/pages/docker/swarm/task.vue @@ -8,9 +8,11 @@ - - {{ item }}- {{ key }} - + + + {{ item }}- {{ key }} + + 搜索