Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee durationMillis is present in getExpiringBounce response #1197

Merged
merged 13 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public static SingularityBounceRequest defaultRequest() {
return new SingularityBounceRequest(Optional.<Boolean>absent(), Optional.<Boolean>absent(), Optional.<Long>absent(), Optional.of(UUID.randomUUID().toString()), Optional.<String>absent());
}

public SingularityBounceRequestBuilder toBuilder() {
return new SingularityBounceRequestBuilder()
.setIncremental(incremental)
.setSkipHealthchecks(skipHealthchecks)
.setDurationMillis(getDurationMillis())
.setActionId(getActionId())
.setMessage(getMessage());
}

@ApiModelProperty(required=false, value="If present and set to true, old tasks will be killed as soon as replacement tasks are available, instead of waiting for all replacement tasks to be healthy")
public Optional<Boolean> getIncremental() {
return incremental;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.hubspot.singularity.api;

import com.google.common.base.Optional;

public class SingularityBounceRequestBuilder {

private Optional<Boolean> incremental;
private Optional<Boolean> skipHealthchecks;

private Optional<Long> durationMillis;
private Optional<String> actionId;
private Optional<String> message;

public SingularityBounceRequestBuilder() {
this.incremental = Optional.absent();
this.skipHealthchecks = Optional.absent();

this.durationMillis = Optional.absent();
this.actionId = Optional.absent();
this.message = Optional.absent();
}

public SingularityBounceRequest build() {
return new SingularityBounceRequest(incremental, skipHealthchecks, durationMillis, actionId, message);
}

public Optional<Long> getDurationMillis() {
return durationMillis;
}

public SingularityBounceRequestBuilder setDurationMillis(Optional<Long> durationMillis) {
this.durationMillis = durationMillis;
return this;
}

public Optional<String> getActionId() {
return actionId;
}

public SingularityBounceRequestBuilder setActionId(Optional<String> actionId) {
this.actionId = actionId;
return this;
}

public Optional<String> getMessage() {
return message;
}

public SingularityBounceRequestBuilder setMessage(Optional<String> message) {
this.message = message;
return this;
}

public Optional<Boolean> getIncremental() {
return incremental;
}

public SingularityBounceRequestBuilder setIncremental(Optional<Boolean> incremental) {
this.incremental = incremental;
return this;
}

public Optional<Boolean> getSkipHealthchecks() {
return skipHealthchecks;
}

public SingularityBounceRequestBuilder setSkipHealthchecks(Optional<Boolean> skipHealthchecks) {
this.skipHealthchecks = skipHealthchecks;
return this;
}

@Override
public String toString() {
return "SingularityBounceRequestBuilder{" +
"durationMillis='" + durationMillis + '\'' +
", actionId='" + actionId + '\'' +
", message=" + message + '\'' +
", incremental=" + incremental + '\'' +
", skipHealthchecks=" + skipHealthchecks + '\'' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you might have changed this already, but the last three parts are missing the first apostrophe ", incremental=" => ", incremental='"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class RequestManager extends CuratorAsyncManager {
private final Transcoder<SingularityRequestLbCleanup> requestLbCleanupTranscoder;

private final SingularityEventListener singularityEventListener;
private final SingularityConfiguration singularityConfiguration;

private static final String REQUEST_ROOT = "/requests";

Expand Down Expand Up @@ -80,14 +81,16 @@ public class RequestManager extends CuratorAsyncManager {
public RequestManager(CuratorFramework curator, SingularityConfiguration configuration, MetricRegistry metricRegistry, SingularityEventListener singularityEventListener,
Transcoder<SingularityRequestCleanup> requestCleanupTranscoder, Transcoder<SingularityRequestWithState> requestTranscoder, Transcoder<SingularityRequestLbCleanup> requestLbCleanupTranscoder,
Transcoder<SingularityPendingRequest> pendingRequestTranscoder, Transcoder<SingularityRequestHistory> requestHistoryTranscoder, Transcoder<SingularityExpiringBounce> expiringBounceTranscoder,
Transcoder<SingularityExpiringScale> expiringScaleTranscoder, Transcoder<SingularityExpiringPause> expiringPauseTranscoder, Transcoder<SingularityExpiringSkipHealthchecks> expiringSkipHealthchecksTranscoder) {
Transcoder<SingularityExpiringScale> expiringScaleTranscoder, Transcoder<SingularityExpiringPause> expiringPauseTranscoder, Transcoder<SingularityExpiringSkipHealthchecks> expiringSkipHealthchecksTranscoder,
SingularityConfiguration singularityConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singularityConfiguration is not in use

super(curator, configuration, metricRegistry);
this.requestTranscoder = requestTranscoder;
this.requestCleanupTranscoder = requestCleanupTranscoder;
this.pendingRequestTranscoder = pendingRequestTranscoder;
this.requestHistoryTranscoder = requestHistoryTranscoder;
this.singularityEventListener = singularityEventListener;
this.requestLbCleanupTranscoder = requestLbCleanupTranscoder;
this.singularityConfiguration = singularityConfiguration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't look like singularityConfiguration is in use in this class anymore, can you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sure thing. The perils of moving methods around.


this.expiringTranscoderMap = ImmutableMap.of(
SingularityExpiringBounce.class, expiringBounceTranscoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
Expand Down Expand Up @@ -201,8 +202,17 @@ public SingularityRequestParent bounce(@ApiParam("The request ID to bounce") @Pa

requestManager.bounce(requestWithState.getRequest(), System.currentTimeMillis(), JavaUtils.getUserEmail(user), message);

SingularityBounceRequest defaultBounceRequest = bounceRequest.or(SingularityBounceRequest.defaultRequest());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last nitpick on this, since this can be the user-provided data or the default, default doesn't make sense as a variable name. Maybe something like effectiveBounceRequest (or something similar??)

if (!defaultBounceRequest.getDurationMillis().isPresent()) {
final Long durationMillis = TimeUnit.MINUTES.toMillis(configuration.getDefaultBounceExpirationMinutes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nitpick, but you should utilize primitive types wherever possible (i.e. long instead of Long)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I was following the convention established in the constructor of the SingularityBounceRequest class (@JsonProperty("durationMillis") Optional<Long> durationMillis). If I change it here, should I change it in the constructor as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using it as a type in the Optional<> you have to use the generic object (Long) in that case. A primitive does not extend any Object so it cannot be the type argument there. But, when it isn't required to have the generic object (like in your case, just setting a variable and using the value) it is preferred to use the primitive. You can pass that primitive (long) as an arg for something that takes Long just fine. (i.e. Optional.of(yourVar))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ 👍. The JVM's ability to hop between primitives (long) and "boxed" types (Long) is called auto-boxing. This is just one of those style things everyone learns the hard way 😃

defaultBounceRequest = defaultBounceRequest
.toBuilder()
.setDurationMillis(Optional.of(durationMillis))
.build();
}

requestManager.saveExpiringObject(new SingularityExpiringBounce(requestId, deployId, JavaUtils.getUserEmail(user),
System.currentTimeMillis(), bounceRequest.or(SingularityBounceRequest.defaultRequest()), actionId.get()));
System.currentTimeMillis(), defaultBounceRequest, actionId.get()));

return fillEntireRequest(requestWithState);
}
Expand Down