-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ML: Adds set_upgrade_mode API endpoint (#37837)
* ML: Add MlMetadata.upgrade_mode and API * Adding tests * Adding wait conditionals for the upgrade_mode call to return * Adding tests * adjusting format and tests * Adjusting wait conditions for api return and msgs * adjusting doc tests * adding upgrade mode tests to black list
- Loading branch information
Showing
24 changed files
with
1,133 additions
and
70 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ This is a possible response: | |
"scroll_size" : 1000 | ||
} | ||
}, | ||
"upgrade_mode": false, | ||
"limits" : { } | ||
} | ||
---- | ||
|
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
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
120 changes: 120 additions & 0 deletions
120
...lugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/SetUpgradeModeAction.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,120 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.action.Action; | ||
import org.elasticsearch.action.ActionRequestBuilder; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
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.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class SetUpgradeModeAction extends Action<SetUpgradeModeAction.Request, AcknowledgedResponse, SetUpgradeModeAction.RequestBuilder> { | ||
|
||
public static final SetUpgradeModeAction INSTANCE = new SetUpgradeModeAction(); | ||
public static final String NAME = "cluster:admin/xpack/ml/upgrade_mode"; | ||
|
||
private SetUpgradeModeAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public AcknowledgedResponse newResponse() { | ||
return new AcknowledgedResponse(); | ||
} | ||
|
||
@Override | ||
public RequestBuilder newRequestBuilder(ElasticsearchClient client) { | ||
return new RequestBuilder(client, this); | ||
} | ||
|
||
public static class Request extends AcknowledgedRequest<Request> implements ToXContentObject { | ||
|
||
private boolean enabled; | ||
|
||
private static final ParseField ENABLED = new ParseField("enabled"); | ||
public static final ConstructingObjectParser<Request, Void> PARSER = | ||
new ConstructingObjectParser<>(NAME, a -> new Request((Boolean)a[0])); | ||
|
||
static { | ||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ENABLED); | ||
} | ||
|
||
public Request(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
readFrom(in); | ||
} | ||
|
||
public Request() { | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
this.enabled = in.readBoolean(); | ||
} | ||
|
||
@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; | ||
} | ||
Request other = (Request) obj; | ||
return Objects.equals(enabled, other.enabled); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ENABLED.getPreferredName(), enabled); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
||
static class RequestBuilder extends ActionRequestBuilder<Request, AcknowledgedResponse, RequestBuilder> { | ||
|
||
RequestBuilder(ElasticsearchClient client, SetUpgradeModeAction action) { | ||
super(client, action, new Request()); | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...rc/test/java/org/elasticsearch/xpack/core/ml/action/SetUpgradeModeActionRequestTests.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractSerializingTestCase; | ||
import org.elasticsearch.xpack.core.ml.action.SetUpgradeModeAction.Request; | ||
|
||
public class SetUpgradeModeActionRequestTests extends AbstractSerializingTestCase<Request> { | ||
|
||
@Override | ||
protected Request createTestInstance() { | ||
return new Request(randomBoolean()); | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<Request> instanceReader() { | ||
return Request::new; | ||
} | ||
|
||
@Override | ||
protected Request doParseInstance(XContentParser parser) { | ||
return Request.PARSER.apply(parser, null); | ||
} | ||
} |
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
Oops, something went wrong.