From 297cfa34e311dec3f55b7531a94e784cbb717774 Mon Sep 17 00:00:00 2001 From: Arne M Date: Fri, 1 May 2020 14:49:39 +0200 Subject: [PATCH 1/3] Added support for "--replicas-max-per-node" --- .../api/model/ServicePlacement.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java index 9c2f0223a..0e3b28bb7 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java @@ -1,6 +1,7 @@ package com.github.dockerjava.api.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.api.exception.DockerClientException; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -28,6 +29,12 @@ public class ServicePlacement implements Serializable { @JsonProperty("Platforms") private List platforms; + /** + * @since 1.40 + */ + @JsonProperty("MaxReplicas") + private int maxReplicas = 0; + /** * @see #constraints */ @@ -54,4 +61,32 @@ public List getPlatforms() { public void setPlatforms(List platforms) { this.platforms = platforms; } + + /** + * Specifies the maximum amount of replicas / tasks that can run on one node. + * 0 means unlimited replicas per node. + * + * @param maxReplicas Max number of replicas + * @return This instance of ServicePlacement + */ + public ServicePlacement withMaxReplicas(int maxReplicas) throws DockerClientException { + if (maxReplicas >= 0) { + this.maxReplicas = maxReplicas; + + } else { + throw new DockerClientException("The Value for MaxReplicas must be greater or equal to 0"); + } + + return this; + } + + /** + * Getter for maxReplicas + * + * @return The maximum amount of replicas / tasks that can run on one node. + */ + public int getMaxReplicas() { + return this.maxReplicas; + } + } From 05e943b9844d700b341d5471c2e4be9f28a237ab Mon Sep 17 00:00:00 2001 From: derteufelqwe <44213358+derteufelqwe@users.noreply.github.com> Date: Tue, 2 Jun 2020 09:56:47 +0200 Subject: [PATCH 2/3] Update ServicePlacement.java Replaced DockerClientException with IllegalArgumentException --- .../java/com/github/dockerjava/api/model/ServicePlacement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java index 0e3b28bb7..fa5518199 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java @@ -74,7 +74,7 @@ public ServicePlacement withMaxReplicas(int maxReplicas) throws DockerClientExce this.maxReplicas = maxReplicas; } else { - throw new DockerClientException("The Value for MaxReplicas must be greater or equal to 0"); + throw new IllegalArgumentException("The Value for MaxReplicas must be greater or equal to 0"); } return this; From 1bc9b3b8fc8f7d5d5a3b49dba6ed91178c9fea4d Mon Sep 17 00:00:00 2001 From: Sergei Egorov Date: Thu, 4 Jun 2020 11:39:49 +0200 Subject: [PATCH 3/3] Update ServicePlacement.java --- .../dockerjava/api/model/ServicePlacement.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java index fa5518199..777be8668 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ServicePlacement.java @@ -1,7 +1,6 @@ package com.github.dockerjava.api.model; import com.fasterxml.jackson.annotation.JsonProperty; -import com.github.dockerjava.api.exception.DockerClientException; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -33,7 +32,7 @@ public class ServicePlacement implements Serializable { * @since 1.40 */ @JsonProperty("MaxReplicas") - private int maxReplicas = 0; + private Integer maxReplicas; /** * @see #constraints @@ -68,15 +67,14 @@ public void setPlatforms(List platforms) { * * @param maxReplicas Max number of replicas * @return This instance of ServicePlacement + * @throws IllegalArgumentException if maxReplicas is less than 0 */ - public ServicePlacement withMaxReplicas(int maxReplicas) throws DockerClientException { - if (maxReplicas >= 0) { - this.maxReplicas = maxReplicas; - - } else { + public ServicePlacement withMaxReplicas(int maxReplicas) { + if (maxReplicas < 0) { throw new IllegalArgumentException("The Value for MaxReplicas must be greater or equal to 0"); } + this.maxReplicas = maxReplicas; return this; } @@ -85,7 +83,7 @@ public ServicePlacement withMaxReplicas(int maxReplicas) throws DockerClientExce * * @return The maximum amount of replicas / tasks that can run on one node. */ - public int getMaxReplicas() { + public Integer getMaxReplicas() { return this.maxReplicas; }