Skip to content

Commit 9db6f09

Browse files
committed
ML: adjusting for backport of #36643
1 parent dcf9d3c commit 9db6f09

File tree

11 files changed

+73
-59
lines changed

11 files changed

+73
-59
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlUpgradeAction.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import java.util.Objects;
2929

3030

31-
public class MlUpgradeAction extends Action<AcknowledgedResponse> {
31+
public class MlUpgradeAction extends Action<MlUpgradeAction.Request, AcknowledgedResponse, MlUpgradeAction.RequestBuilder> {
32+
3233
public static final MlUpgradeAction INSTANCE = new MlUpgradeAction();
3334
public static final String NAME = "cluster:admin/xpack/ml/upgrade";
3435

@@ -41,6 +42,11 @@ public AcknowledgedResponse newResponse() {
4142
return new AcknowledgedResponse();
4243
}
4344

45+
@Override
46+
public RequestBuilder newRequestBuilder(ElasticsearchClient client) {
47+
return new RequestBuilder(client, this);
48+
}
49+
4450
public static class Request extends MasterNodeReadRequest<Request> implements ToXContentObject {
4551

4652
private static final ParseField REINDEX_BATCH_SIZE = new ParseField("reindex_batch_size");
@@ -60,6 +66,7 @@ public static class Request extends MasterNodeReadRequest<Request> implements To
6066

6167
// for serialization
6268
public Request() {
69+
super();
6370
}
6471

6572
public Request(StreamInput in) throws IOException {
@@ -73,6 +80,12 @@ public void writeTo(StreamOutput out) throws IOException {
7380
out.writeInt(reindexBatchSize);
7481
}
7582

83+
@Override
84+
public void readFrom(StreamInput in) throws IOException {
85+
super.readFrom(in);
86+
reindexBatchSize = in.readInt();
87+
}
88+
7689
public String[] indices() {
7790
return new String[]{INDEX};
7891
}
@@ -152,8 +165,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
152165

153166
public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder<Request, AcknowledgedResponse, RequestBuilder> {
154167

155-
public RequestBuilder(ElasticsearchClient client) {
156-
super(client, INSTANCE, new Request());
168+
public RequestBuilder(ElasticsearchClient client, MlUpgradeAction action) {
169+
super(client, action, new Request());
157170
}
158171
}
159172

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlUpgradeIT.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.cluster.ClusterState;
1616
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1717
import org.elasticsearch.common.collect.Tuple;
18+
import org.elasticsearch.common.settings.Settings;
1819
import org.elasticsearch.common.unit.TimeValue;
1920
import org.elasticsearch.index.query.QueryBuilders;
2021
import org.elasticsearch.index.reindex.ReindexAction;
@@ -88,7 +89,7 @@ public void testMigrationWhenItIsNotNecessary() throws Exception {
8889
assertThat(getTotalDocCount(job3Index), equalTo(job3Total));
8990

9091
ClusterState state = admin().cluster().state(new ClusterStateRequest()).actionGet().getState();
91-
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
92+
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
9293
String[] indices = indexNameExpressionResolver.concreteIndexNames(state,
9394
IndicesOptions.strictExpandOpenAndForbidClosed(),
9495
AnomalyDetectorsIndex.jobResultsIndexPrefix() + "*");
@@ -120,7 +121,7 @@ public void testMigration() throws Exception {
120121
long job2Total = getJobResultsCount(job2.getId());
121122
long job3Total = getJobResultsCount(job3.getId());
122123

123-
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
124+
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
124125

125126
ResultsIndexUpgradeService resultsIndexUpgradeService = new ResultsIndexUpgradeService(indexNameExpressionResolver,
126127
ThreadPool.Names.SAME,
@@ -203,7 +204,7 @@ public void testMigrationWithManuallyCreatedIndexThatNeedsMigrating() throws Exc
203204
String manuallyCreatedIndex = job1Index + "-" + Version.CURRENT.major;
204205
client().admin().indices().prepareCreate(manuallyCreatedIndex).execute().actionGet();
205206

206-
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
207+
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
207208

208209
ResultsIndexUpgradeService resultsIndexUpgradeService = new ResultsIndexUpgradeService(indexNameExpressionResolver,
209210
ThreadPool.Names.SAME,
@@ -257,7 +258,7 @@ public void testMigrationWithExistingIndexWithData() throws Exception {
257258
String alreadyMigratedWriteIndex = job1Index + "-" + Version.CURRENT.major;
258259
client().admin().indices().prepareCreate(alreadyMigratedWriteIndex).execute().actionGet();
259260

260-
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
261+
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
261262

262263
ResultsIndexUpgradeService resultsIndexUpgradeService = new ResultsIndexUpgradeService(indexNameExpressionResolver,
263264
ThreadPool.Names.SAME,
@@ -315,7 +316,7 @@ private long getTotalDocCount(String indexName) {
315316
.setTrackTotalHits(true)
316317
.setQuery(QueryBuilders.matchAllQuery())
317318
.execute().actionGet();
318-
return searchResponse.getHits().getTotalHits().value;
319+
return searchResponse.getHits().getTotalHits();
319320
}
320321

321322
private long getJobResultsCount(String jobId) {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/ResultsIndexUpgradeService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ResultsIndexUpgradeService {
6363

6464
// Adjust the following constants as necessary for various versions and backports.
6565
private static final int INDEX_VERSION = Version.CURRENT.major;
66-
private static final Version MIN_REQUIRED_VERSION = Version.CURRENT.minimumCompatibilityVersion();
66+
private static final Version MIN_REQUIRED_VERSION = Version.V_5_6_0;
6767

6868
private final IndexNameExpressionResolver indexNameExpressionResolver;
6969
private final Predicate<IndexMetaData> shouldUpgrade;

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlUpgradeAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1818
import org.elasticsearch.cluster.service.ClusterService;
1919
import org.elasticsearch.common.inject.Inject;
20+
import org.elasticsearch.common.settings.Settings;
2021
import org.elasticsearch.tasks.Task;
2122
import org.elasticsearch.tasks.TaskId;
2223
import org.elasticsearch.threadpool.ThreadPool;
@@ -33,11 +34,11 @@ public class TransportMlUpgradeAction
3334
private final ResultsIndexUpgradeService resultsIndexUpgradeService;
3435

3536
@Inject
36-
public TransportMlUpgradeAction(TransportService transportService, ClusterService clusterService,
37+
public TransportMlUpgradeAction(Settings settings, TransportService transportService, ClusterService clusterService,
3738
ThreadPool threadPool, ActionFilters actionFilters, Client client,
3839
IndexNameExpressionResolver indexNameExpressionResolver) {
39-
super(MlUpgradeAction.NAME, transportService, clusterService, threadPool,
40-
actionFilters, MlUpgradeAction.Request::new, indexNameExpressionResolver);
40+
super(settings, MlUpgradeAction.NAME, transportService, clusterService, threadPool,
41+
actionFilters, indexNameExpressionResolver, MlUpgradeAction.Request::new);
4142
this.client = client;
4243
this.resultsIndexUpgradeService = new ResultsIndexUpgradeService(indexNameExpressionResolver,
4344
executor(),

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestUpgradeMlAction.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest.results;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.common.settings.Settings;
1210
import org.elasticsearch.common.xcontent.XContentBuilder;
1311
import org.elasticsearch.common.xcontent.XContentParser;
@@ -28,18 +26,10 @@
2826

2927
public class RestUpgradeMlAction extends BaseRestHandler {
3028

31-
private static final DeprecationLogger deprecationLogger =
32-
new DeprecationLogger(LogManager.getLogger(RestUpgradeMlAction.class));
33-
3429
public RestUpgradeMlAction(Settings settings, RestController controller) {
3530
super(settings);
36-
controller.registerWithDeprecatedHandler(
37-
POST,
38-
MachineLearning.BASE_PATH + "_upgrade",
39-
this,
40-
POST,
41-
MachineLearning.PRE_V7_BASE_PATH + "_upgrade",
42-
deprecationLogger);
31+
controller.registerHandler(POST, MachineLearning.BASE_PATH + "_upgrade", this);
32+
controller.registerHandler(POST,MachineLearning.V7_BASE_PATH + "_upgrade", this);
4333
}
4434

4535
@Override

x-pack/plugin/src/test/resources/rest-api-spec/api/ml.upgrade.json renamed to x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ml.upgrade.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"ml.upgrade": {
2+
"xpack.ml.upgrade": {
33
"documentation": "TODO",
44
"methods": [ "POST" ],
55
"url": {
6-
"path": "/_ml/_upgrade",
7-
"paths": [ "/_ml/_upgrade" ],
6+
"path": "/_xpack/ml/_upgrade",
7+
"paths": [ "/_xpack/ml/_upgrade" ],
88
"params": {
99
"wait_for_completion": {
1010
"type": "boolean",

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/ml_upgrade.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ setup:
44
- do:
55
headers:
66
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
7-
ml.put_job:
7+
xpack.ml.put_job:
88
job_id: jobs-upgrade-results
99
body: >
1010
{
@@ -43,7 +43,7 @@ setup:
4343
---
4444
"Upgrade results when there is nothing to upgrade":
4545
- do:
46-
ml.upgrade:
46+
xpack.ml.upgrade:
4747
wait_for_completion: true
4848

4949
- match: { acknowledged: true }
@@ -56,7 +56,7 @@ setup:
5656
---
5757
"Upgrade results when there is nothing to upgrade not waiting for results":
5858
- do:
59-
ml.upgrade:
59+
xpack.ml.upgrade:
6060
wait_for_completion: false
6161

6262
- match: {task: '/.+:\d+/'}

x-pack/qa/rolling-upgrade/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,17 @@ subprojects {
295295
systemProperty 'tests.rest.blacklist', '/20_security/Verify default password migration results in upgraded cluster'
296296
}
297297
}
298+
def toBlackList = []
299+
// If we are upgrading on a minor version, these tests fail
300+
// They only work if we are upgrading between major versions
301+
if (versionParts[0].equals("6")) {
302+
toBlackList << 'upgraded_cluster/80_ml_results_upgrade/Migrate results data to latest index binary version'
303+
}
298304
if (version.before('6.1.0') || version.onOrAfter('6.3.0')) {
299-
systemProperty 'tests.rest.blacklist', '/30_ml_jobs_crud/Test model memory limit is updated'
305+
toBlackList << '/30_ml_jobs_crud/Test model memory limit is updated'
306+
}
307+
if (!toBlackList.empty) {
308+
systemProperty 'tests.rest.blacklist', toBlackList.join(',')
300309
}
301310
}
302311

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
"Verify jobs exist":
33
- do:
4-
ml.get_jobs:
4+
xpack.ml.get_jobs:
55
job_id: old-cluster-job-to-upgrade
66
- match: { count: 1 }
77

88
- do:
9-
ml.get_jobs:
9+
xpack.ml.get_jobs:
1010
job_id: old-cluster-job-to-upgrade-custom
1111
- match: { count: 1 }

x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/80_ml_results_upgrade.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Put job on the old cluster and post some data":
33

44
- do:
5-
ml.put_job:
5+
xpack.ml.put_job:
66
job_id: old-cluster-job-to-upgrade
77
body: >
88
{
@@ -23,11 +23,11 @@
2323
- match: { job_id: old-cluster-job-to-upgrade }
2424

2525
- do:
26-
ml.open_job:
26+
xpack.ml.open_job:
2727
job_id: old-cluster-job-to-upgrade
2828

2929
- do:
30-
ml.post_data:
30+
xpack.ml.post_data:
3131
job_id: old-cluster-job-to-upgrade
3232
body:
3333
- airline: AAL
@@ -41,11 +41,11 @@
4141
- match: { processed_record_count: 2 }
4242

4343
- do:
44-
ml.close_job:
44+
xpack.ml.close_job:
4545
job_id: old-cluster-job-to-upgrade
4646

4747
- do:
48-
ml.get_buckets:
48+
xpack.ml.get_buckets:
4949
job_id: old-cluster-job-to-upgrade
5050
- match: { count: 1 }
5151

@@ -59,7 +59,7 @@
5959
---
6060
"Put job on the old cluster with a custom index":
6161
- do:
62-
ml.put_job:
62+
xpack.ml.put_job:
6363
job_id: old-cluster-job-to-upgrade-custom
6464
body: >
6565
{
@@ -81,11 +81,11 @@
8181
- match: { job_id: old-cluster-job-to-upgrade-custom }
8282

8383
- do:
84-
ml.open_job:
84+
xpack.ml.open_job:
8585
job_id: old-cluster-job-to-upgrade-custom
8686

8787
- do:
88-
ml.post_data:
88+
xpack.ml.post_data:
8989
job_id: old-cluster-job-to-upgrade-custom
9090
body:
9191
- airline: AAL
@@ -103,11 +103,11 @@
103103
- match: { processed_record_count: 3 }
104104

105105
- do:
106-
ml.close_job:
106+
xpack.ml.close_job:
107107
job_id: old-cluster-job-to-upgrade-custom
108108

109109
- do:
110-
ml.get_buckets:
110+
xpack.ml.get_buckets:
111111
job_id: old-cluster-job-to-upgrade-custom
112112
- match: { count: 3 }
113113

0 commit comments

Comments
 (0)