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
Changes from 1 commit
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 @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.utils.ZKPaths;
Expand Down Expand Up @@ -31,6 +32,7 @@
import com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType;
import com.hubspot.singularity.SingularityRequestLbCleanup;
import com.hubspot.singularity.SingularityRequestWithState;
import com.hubspot.singularity.api.SingularityBounceRequest;
import com.hubspot.singularity.api.SingularityExpiringRequestParent;
import com.hubspot.singularity.config.SingularityConfiguration;
import com.hubspot.singularity.data.transcoders.Transcoder;
Expand All @@ -53,6 +55,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 +83,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 Expand Up @@ -385,7 +390,31 @@ public <T extends SingularityExpiringParent<? extends SingularityExpiringRequest
}

public Optional<SingularityExpiringBounce> getExpiringBounce(String requestId) {
return getExpiringObject(SingularityExpiringBounce.class, requestId);
final Optional<SingularityExpiringBounce> optionalBounce = getExpiringObject(SingularityExpiringBounce.class, requestId);
Copy link
Member

Choose a reason for hiding this comment

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

more of a convention thing, we tend to name vars for optionals as maybe..., so in this case maybeExpiringBounce or something similar

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

if (!optionalBounce.isPresent()) {
return optionalBounce;
}
final SingularityExpiringBounce bounce = optionalBounce.get();
if (bounce.getExpiringAPIRequestObject().getDurationMillis().isPresent()) {
return optionalBounce;
}
final Long durationMillis = TimeUnit.MINUTES.toMillis(singularityConfiguration.getDefaultBounceExpirationMinutes());
return Optional.of(
new SingularityExpiringBounce(
bounce.getRequestId(),
bounce.getDeployId(),
bounce.getUser(),
bounce.getStartMillis(),
new SingularityBounceRequest(
bounce.getExpiringAPIRequestObject().getIncremental(),
bounce.getExpiringAPIRequestObject().getSkipHealthchecks(),
Optional.of(durationMillis),
bounce.getExpiringAPIRequestObject().getActionId(),
bounce.getExpiringAPIRequestObject().getMessage()
),
bounce.getActionId()
)
);
}

public Optional<SingularityExpiringPause> getExpiringPause(String requestId) {
Expand Down