-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[Transform] finalize feature reset integration #71133
Merged
benwtrent
merged 11 commits into
elastic:master
from
benwtrent:feature/transform-feature-reset-integration
Apr 7, 2021
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
75ad1c5
[Transform] finalize feature reset integration
benwtrent e9240b4
Merge remote-tracking branch 'upstream/master' into feature/transform…
benwtrent 910944e
removing unused header
benwtrent 490e57c
fixing issue with trained model stats persistence and reset/upgrade m…
benwtrent c9e7af7
reverting change to model stats service
benwtrent 92f668f
Merge remote-tracking branch 'upstream/master' into feature/transform…
benwtrent 3466c89
fixing compilation after merge
benwtrent a8c12e7
addressing PR comments
benwtrent 165d66e
Merge remote-tracking branch 'upstream/master' into feature/transform…
benwtrent 07e240b
fixing style
benwtrent cd0ab85
Merge remote-tracking branch 'upstream/master' into feature/transform…
benwtrent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...rc/main/java/org/elasticsearch/xpack/core/action/AbstractTransportSetResetModeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.action; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.elasticsearch.ElasticsearchTimeoutException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.AcknowledgedTransportMasterNodeAction; | ||
import org.elasticsearch.cluster.AckedClusterStateUpdateTask; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public abstract class AbstractTransportSetResetModeAction extends AcknowledgedTransportMasterNodeAction<SetResetModeActionRequest> { | ||
|
||
private static final Logger logger = LogManager.getLogger(AbstractTransportSetResetModeAction.class); | ||
private final ClusterService clusterService; | ||
|
||
@Inject | ||
public AbstractTransportSetResetModeAction( | ||
String actionName, | ||
TransportService transportService, | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super( | ||
actionName, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
SetResetModeActionRequest::new, | ||
indexNameExpressionResolver, | ||
ThreadPool.Names.SAME | ||
); | ||
this.clusterService = clusterService; | ||
} | ||
|
||
protected abstract boolean isResetMode(ClusterState clusterState); | ||
|
||
protected abstract String featureName(); | ||
|
||
protected abstract ClusterState setState(ClusterState oldState, SetResetModeActionRequest request); | ||
|
||
@Override | ||
protected void masterOperation(Task task, | ||
SetResetModeActionRequest request, | ||
ClusterState state, | ||
ActionListener<AcknowledgedResponse> listener) throws Exception { | ||
|
||
final boolean isResetModelEnabled = isResetMode(state); | ||
// Noop, nothing for us to do, simply return fast to the caller | ||
if (request.isEnabled() == isResetModelEnabled) { | ||
logger.debug(() -> new ParameterizedMessage("Reset mode noop for [{}]", featureName())); | ||
listener.onResponse(AcknowledgedResponse.TRUE); | ||
return; | ||
} | ||
|
||
logger.debug( | ||
() -> new ParameterizedMessage( | ||
"Starting to set [reset_mode] for [{}] to [{}] from [{}]", | ||
featureName(), | ||
request.isEnabled(), | ||
isResetModelEnabled | ||
) | ||
); | ||
|
||
ActionListener<AcknowledgedResponse> wrappedListener = ActionListener.wrap( | ||
r -> { | ||
logger.debug(() -> new ParameterizedMessage("Completed reset mode request for [{}]", featureName())); | ||
listener.onResponse(r); | ||
}, | ||
e -> { | ||
logger.debug( | ||
() -> new ParameterizedMessage("Completed reset mode for [{}] request but with failure", featureName()), | ||
e | ||
); | ||
listener.onFailure(e); | ||
} | ||
); | ||
|
||
ActionListener<AcknowledgedResponse> clusterStateUpdateListener = ActionListener.wrap( | ||
acknowledgedResponse -> { | ||
if (acknowledgedResponse.isAcknowledged() == false) { | ||
logger.info(new ParameterizedMessage("Cluster state update is NOT acknowledged for [{}]", featureName())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ looks like a debug leftover to me |
||
wrappedListener.onFailure(new ElasticsearchTimeoutException("Unknown error occurred while updating cluster state")); | ||
return; | ||
} | ||
wrappedListener.onResponse(acknowledgedResponse); | ||
}, | ||
wrappedListener::onFailure | ||
); | ||
|
||
clusterService.submitStateUpdateTask(featureName() + "-set-reset-mode", | ||
new AckedClusterStateUpdateTask(request, clusterStateUpdateListener) { | ||
|
||
@Override | ||
protected AcknowledgedResponse newResponse(boolean acknowledged) { | ||
logger.trace(() -> new ParameterizedMessage("Cluster update response built for [{}]: {}", featureName(), acknowledged)); | ||
return AcknowledgedResponse.of(acknowledged); | ||
} | ||
|
||
@Override | ||
public ClusterState execute(ClusterState currentState) { | ||
logger.trace(() -> new ParameterizedMessage("Executing cluster state update for [{}]", featureName())); | ||
return setState(currentState, request); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(SetResetModeActionRequest request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...gin/core/src/main/java/org/elasticsearch/xpack/core/action/SetResetModeActionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.action; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class SetResetModeActionRequest extends AcknowledgedRequest<SetResetModeActionRequest> implements ToXContentObject { | ||
public static SetResetModeActionRequest enabled() { | ||
return new SetResetModeActionRequest(true); | ||
} | ||
|
||
public static SetResetModeActionRequest disabled() { | ||
return new SetResetModeActionRequest(false); | ||
} | ||
|
||
private final boolean enabled; | ||
|
||
private static final ParseField ENABLED = new ParseField("enabled"); | ||
public static final ConstructingObjectParser<SetResetModeActionRequest, Void> PARSER = | ||
new ConstructingObjectParser<>("set_reset_mode_action_request", a -> new SetResetModeActionRequest((Boolean)a[0])); | ||
|
||
static { | ||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ENABLED); | ||
} | ||
|
||
SetResetModeActionRequest(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public SetResetModeActionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.enabled = in.readBoolean(); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(enabled); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(enabled); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || obj.getClass() != getClass()) { | ||
return false; | ||
} | ||
SetResetModeActionRequest other = (SetResetModeActionRequest) obj; | ||
return Objects.equals(enabled, other.enabled); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ENABLED.getPreferredName(), enabled); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an
l
too much:isResetModelEnabled
->isResetModeEnabled