Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Add rollout options to job config
Browse files Browse the repository at this point in the history
This allows users to specify `helios rolling-update` options in their
job configuration in addition to being able to specify them with
switches for `rolling-update`.

If not specified, the master will use the following defaults.
The order of precedence for each rollout option is `rolling-update`
switch value, job configuration value, then default.

timeout = 5 seconds
parallelism = 1
migrate = false
overlap = false
token = ""
ignoreFailures = false

Notes:
* set `rolling-update` defaults to null for args that use `storeTrue()`
  This method calls implicitly sets the default to false.
* fix NPE in ZKMM
* Fix tests broken by the assumption that rollout options are never null
  * Change the tests to use the default options. I didn't make the server code
    check for nulls since it should never encounter nulls. ZKMM will fall back to
    defaults.
* Update `inspect` cmd to output rollout options
  * `inspect` command states null RolloutOptions will default to defaults
  * Add `RolloutOptions.getDefault()` as a small optimization.
* Restrict visibility of some attributes and methods.
  • Loading branch information
caipre authored and davidxia committed Oct 19, 2017
1 parent 990e734 commit 4f10aa5
Show file tree
Hide file tree
Showing 25 changed files with 475 additions and 115 deletions.
Expand Up @@ -344,6 +344,10 @@ public static ObjectWriter writer() {
return OBJECT_MAPPER.writer(); return OBJECT_MAPPER.writer();
} }


public static <T> T convert(Object from, Class<T> to) {
return OBJECT_MAPPER.convertValue(from, to);
}

public static byte[] sha1digest(final Object obj) throws IOException { public static byte[] sha1digest(final Object obj) throws IOException {
final String json = NORMALIZING_OBJECT_WRITER.writeValueAsString(obj); final String json = NORMALIZING_OBJECT_WRITER.writeValueAsString(obj);
final Map<String, Object> map = OBJECT_MAPPER.readValue(json, MAP_TYPE); final Map<String, Object> map = OBJECT_MAPPER.readValue(json, MAP_TYPE);
Expand Down
Expand Up @@ -64,6 +64,14 @@
* }, * },
* "expires" : null, * "expires" : null,
* "gracePeriod": 60, * "gracePeriod": 60,
* "rolloutOptions": {
* "migrate": false,
* "parallelism": 2,
* "timeout": 1000,
* "overlap": true,
* "token": "insecure-access-token",
* "ignoreFailures": false
* },
* "healthCheck" : { * "healthCheck" : {
* "type" : "http", * "type" : "http",
* "path" : "/healthcheck", * "path" : "/healthcheck",
Expand Down Expand Up @@ -109,6 +117,9 @@
* "token": "insecure-access-token", * "token": "insecure-access-token",
* "volumes" : { * "volumes" : {
* "/destination/path/in/container.yaml:ro" : "/source/path/in/host.yaml" * "/destination/path/in/container.yaml:ro" : "/source/path/in/host.yaml"
* },
* "ramdisks": {
* "/mount/point/in/container": "mount-options"
* } * }
* } * }
* </pre> * </pre>
Expand Down Expand Up @@ -138,6 +149,7 @@ public class Job extends Descriptor implements Comparable<Job> {
public static final Map<String, String> EMPTY_LABELS = emptyMap(); public static final Map<String, String> EMPTY_LABELS = emptyMap();
public static final Integer EMPTY_SECONDS_TO_WAIT = null; public static final Integer EMPTY_SECONDS_TO_WAIT = null;
public static final Map<String, String> EMPTY_RAMDISKS = emptyMap(); public static final Map<String, String> EMPTY_RAMDISKS = emptyMap();
public static final RolloutOptions EMPTY_ROLLOUT_OPTIONS = null;


private final JobId id; private final JobId id;
private final String image; private final String image;
Expand All @@ -163,6 +175,7 @@ public class Job extends Descriptor implements Comparable<Job> {
private final Map<String, String> labels; private final Map<String, String> labels;
private final Integer secondsToWaitBeforeKill; private final Integer secondsToWaitBeforeKill;
private final Map<String, String> ramdisks; private final Map<String, String> ramdisks;
private final RolloutOptions rolloutOptions;


/** /**
* Create a Job. * Create a Job.
Expand Down Expand Up @@ -200,6 +213,9 @@ public class Job extends Descriptor implements Comparable<Job> {
* @param labels Labels to set on the container. Optional. * @param labels Labels to set on the container. Optional.
* @param secondsToWaitBeforeKill The time to ask Docker to wait after sending a SIGTERM to the * @param secondsToWaitBeforeKill The time to ask Docker to wait after sending a SIGTERM to the
* container's main process before sending it a SIGKILL. Optional. * container's main process before sending it a SIGKILL. Optional.
* @param ramdisks Ramdisks (tmpfs) partitions created and mounted when the
* container is run.
* @param rolloutOptions The options to use for a rolling-update.
* *
* @see <a href="https://docs.docker.com/engine/reference/run">Docker run reference</a> * @see <a href="https://docs.docker.com/engine/reference/run">Docker run reference</a>
*/ */
Expand Down Expand Up @@ -227,7 +243,8 @@ public Job(
@JsonProperty("dropCapabilities") @Nullable final Set<String> dropCapabilities, @JsonProperty("dropCapabilities") @Nullable final Set<String> dropCapabilities,
@JsonProperty("labels") @Nullable final Map<String, String> labels, @JsonProperty("labels") @Nullable final Map<String, String> labels,
@JsonProperty("secondsToWaitBeforeKill") @Nullable final Integer secondsToWaitBeforeKill, @JsonProperty("secondsToWaitBeforeKill") @Nullable final Integer secondsToWaitBeforeKill,
@JsonProperty("ramdisks") @Nullable final Map<String, String> ramdisks) { @JsonProperty("ramdisks") @Nullable final Map<String, String> ramdisks,
@JsonProperty("rolloutOptions") @Nullable final RolloutOptions rolloutOptions) {
this.id = id; this.id = id;
this.image = image; this.image = image;


Expand Down Expand Up @@ -255,6 +272,7 @@ public Job(
this.labels = Optional.fromNullable(labels).or(EMPTY_LABELS); this.labels = Optional.fromNullable(labels).or(EMPTY_LABELS);
this.secondsToWaitBeforeKill = secondsToWaitBeforeKill; this.secondsToWaitBeforeKill = secondsToWaitBeforeKill;
this.ramdisks = firstNonNull(ramdisks, EMPTY_RAMDISKS); this.ramdisks = firstNonNull(ramdisks, EMPTY_RAMDISKS);
this.rolloutOptions = rolloutOptions;
} }


private Job(final JobId id, final Builder.Parameters pm) { private Job(final JobId id, final Builder.Parameters pm) {
Expand Down Expand Up @@ -284,6 +302,7 @@ private Job(final JobId id, final Builder.Parameters pm) {
this.secondsToWaitBeforeKill = pm.secondsToWaitBeforeKill; this.secondsToWaitBeforeKill = pm.secondsToWaitBeforeKill;
this.labels = ImmutableMap.copyOf(pm.labels); this.labels = ImmutableMap.copyOf(pm.labels);
this.ramdisks = ImmutableMap.copyOf(pm.ramdisks); this.ramdisks = ImmutableMap.copyOf(pm.ramdisks);
this.rolloutOptions = pm.rolloutOptions;
} }


public JobId getId() { public JobId getId() {
Expand Down Expand Up @@ -382,6 +401,10 @@ public Map<String, String> getRamdisks() {
return ramdisks; return ramdisks;
} }


public RolloutOptions getRolloutOptions() {
return rolloutOptions;
}

public static Builder newBuilder() { public static Builder newBuilder() {
return new Builder(); return new Builder();
} }
Expand Down Expand Up @@ -425,7 +448,8 @@ public boolean equals(final Object obj) {
&& Objects.equals(this.dropCapabilities, that.dropCapabilities) && Objects.equals(this.dropCapabilities, that.dropCapabilities)
&& Objects.equals(this.labels, that.labels) && Objects.equals(this.labels, that.labels)
&& Objects.equals(this.secondsToWaitBeforeKill, that.secondsToWaitBeforeKill) && Objects.equals(this.secondsToWaitBeforeKill, that.secondsToWaitBeforeKill)
&& Objects.equals(this.ramdisks, that.ramdisks); && Objects.equals(this.ramdisks, that.ramdisks)
&& Objects.equals(this.rolloutOptions, that.rolloutOptions);
} }


@Override @Override
Expand All @@ -434,7 +458,7 @@ public int hashCode() {
id, image, hostname, expires, created, command, env, resources, id, image, hostname, expires, created, command, env, resources,
ports, registration, registrationDomain, gracePeriod, volumes, creatingUser, ports, registration, registrationDomain, gracePeriod, volumes, creatingUser,
token, healthCheck, securityOpt, networkMode, metadata, addCapabilities, token, healthCheck, securityOpt, networkMode, metadata, addCapabilities,
dropCapabilities, labels, secondsToWaitBeforeKill, ramdisks); dropCapabilities, labels, secondsToWaitBeforeKill, ramdisks, rolloutOptions);
} }


@Override @Override
Expand Down Expand Up @@ -464,6 +488,7 @@ public String toString() {
+ ", labels=" + labels + ", labels=" + labels
+ ", secondsToWaitBeforeKill=" + secondsToWaitBeforeKill + ", secondsToWaitBeforeKill=" + secondsToWaitBeforeKill
+ ", ramdisks=" + ramdisks + ", ramdisks=" + ramdisks
+ ", rolloutOptions=" + rolloutOptions
+ '}'; + '}';
} }


Expand Down Expand Up @@ -497,7 +522,8 @@ public Builder toBuilder() {
.setDropCapabilities(dropCapabilities) .setDropCapabilities(dropCapabilities)
.setLabels(labels) .setLabels(labels)
.setSecondsToWaitBeforeKill(secondsToWaitBeforeKill) .setSecondsToWaitBeforeKill(secondsToWaitBeforeKill)
.setRamdisks(ramdisks); .setRamdisks(ramdisks)
.setRolloutOptions(rolloutOptions);
} }


public static class Builder implements Cloneable { public static class Builder implements Cloneable {
Expand Down Expand Up @@ -541,6 +567,7 @@ private static class Parameters implements Cloneable {
public Map<String, String> labels; public Map<String, String> labels;
public Integer secondsToWaitBeforeKill; public Integer secondsToWaitBeforeKill;
public Map<String, String> ramdisks; public Map<String, String> ramdisks;
public RolloutOptions rolloutOptions;


private Parameters() { private Parameters() {
this.created = EMPTY_CREATED; this.created = EMPTY_CREATED;
Expand All @@ -561,6 +588,7 @@ private Parameters() {
this.dropCapabilities = EMPTY_CAPS; this.dropCapabilities = EMPTY_CAPS;
this.labels = EMPTY_LABELS; this.labels = EMPTY_LABELS;
this.ramdisks = Maps.newHashMap(EMPTY_RAMDISKS); this.ramdisks = Maps.newHashMap(EMPTY_RAMDISKS);
this.rolloutOptions = EMPTY_ROLLOUT_OPTIONS;
} }


private Parameters(final Parameters pm) { private Parameters(final Parameters pm) {
Expand Down Expand Up @@ -589,6 +617,7 @@ private Parameters(final Parameters pm) {
this.labels = pm.labels; this.labels = pm.labels;
this.secondsToWaitBeforeKill = pm.secondsToWaitBeforeKill; this.secondsToWaitBeforeKill = pm.secondsToWaitBeforeKill;
this.ramdisks = Maps.newHashMap(pm.ramdisks); this.ramdisks = Maps.newHashMap(pm.ramdisks);
this.rolloutOptions = pm.rolloutOptions;
} }


private Parameters withoutMetaParameters() { private Parameters withoutMetaParameters() {
Expand Down Expand Up @@ -770,6 +799,11 @@ public Builder addRamdisk(final String mountPoint, final String mountOptions) {
return this; return this;
} }


public Builder setRolloutOptions(final RolloutOptions options) {
pm.rolloutOptions = options;
return this;
}

public String getName() { public String getName() {
return pm.name; return pm.name;
} }
Expand Down Expand Up @@ -862,6 +896,10 @@ public Map<String, String> getRamdisks() {
return ImmutableMap.copyOf(pm.ramdisks); return ImmutableMap.copyOf(pm.ramdisks);
} }


public RolloutOptions getRolloutOptions() {
return pm.rolloutOptions;
}

@SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException", @SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException",
"CloneDoesntCallSuperClone" }) "CloneDoesntCallSuperClone" })
@Override @Override
Expand Down

0 comments on commit 4f10aa5

Please sign in to comment.