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

ML: add migrate anomalies assistant #36643

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7effc73
ML: add migrate anomalies assistant
benwtrent Dec 5, 2018
d578d1b
adjusting failure handling for reindex
benwtrent Dec 14, 2018
a74bcfe
Fixing request and tests
benwtrent Dec 14, 2018
9a43a54
Adding tests to blacklist
benwtrent Dec 14, 2018
b3fccc6
adjusting test
benwtrent Dec 14, 2018
07ed2a1
test fix: posting data directly to the job instead of relying on data…
benwtrent Dec 17, 2018
bf9e223
adjusting API usage
benwtrent Dec 17, 2018
4a92d35
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 2, 2019
064ac69
adding Todos and adjusting endpoint
benwtrent Jan 2, 2019
ba0df3a
Adding types to reindexRequest
benwtrent Jan 2, 2019
a4c5e86
removing unreliable "live" data test
benwtrent Jan 2, 2019
28576fd
adding index refresh to test
benwtrent Jan 3, 2019
8e9451e
adding index refresh to test
benwtrent Jan 3, 2019
cb9607d
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 3, 2019
1d6c66c
adding index refresh to yaml test
benwtrent Jan 3, 2019
fa56850
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 4, 2019
b341424
fixing bad exists call
benwtrent Jan 4, 2019
3f47ce0
removing todo
benwtrent Jan 7, 2019
5c1683c
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 7, 2019
02603ef
Addressing remove comments
benwtrent Jan 7, 2019
4e926f9
Adjusting rest endpoint name
benwtrent Jan 7, 2019
1661c45
making service have its own logger
benwtrent Jan 7, 2019
cd9c747
adjusting validity check for newindex names
benwtrent Jan 7, 2019
1594b49
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 8, 2019
0650294
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 8, 2019
674463c
fixing typos
benwtrent Jan 8, 2019
c4cf94f
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent Jan 9, 2019
2d67895
fixing renaming
benwtrent Jan 9, 2019
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 @@ -103,6 +103,7 @@
import org.elasticsearch.xpack.core.ml.action.PutDatafeedAction;
import org.elasticsearch.xpack.core.ml.action.PutFilterAction;
import org.elasticsearch.xpack.core.ml.action.PutJobAction;
import org.elasticsearch.xpack.core.ml.action.ResultsIndexUpgradeAction;
import org.elasticsearch.xpack.core.ml.action.RevertModelSnapshotAction;
import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction;
import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction;
Expand Down Expand Up @@ -287,6 +288,7 @@ public List<Action<? extends ActionResponse>> getClientActions() {
PostCalendarEventsAction.INSTANCE,
PersistJobAction.INSTANCE,
FindFileStructureAction.INSTANCE,
ResultsIndexUpgradeAction.INSTANCE,
// security
ClearRealmCacheAction.INSTANCE,
ClearRolesCacheAction.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* 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.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
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.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;


public class ResultsIndexUpgradeAction extends Action<AcknowledgedResponse> {
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
public static final ResultsIndexUpgradeAction INSTANCE = new ResultsIndexUpgradeAction();
public static final String NAME = "cluster:admin/xpack/ml/results/upgrade";

private ResultsIndexUpgradeAction() {
super(NAME);
}

@Override
public AcknowledgedResponse newResponse() {
return new AcknowledgedResponse();
}

public static class Request
extends MasterNodeReadRequest<ResultsIndexUpgradeAction.Request>
implements IndicesRequest, ToXContentObject {
benwtrent marked this conversation as resolved.
Show resolved Hide resolved

private static final ParseField REINDEX_BATCH_SIZE = new ParseField("reindex_batch_size");
benwtrent marked this conversation as resolved.
Show resolved Hide resolved

public static ObjectParser<Request, Void> PARSER = new ObjectParser<>("ml_results_index_upgrade", true, Request::new);
static {
PARSER.declareInt(Request::setReindexBatchSize, REINDEX_BATCH_SIZE);
}

static final String INDEX = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*";
private int reindexBatchSize = 1000;

/**
* Should this task store its result?
*/
private boolean shouldStoreResult;

// for serialization
public Request() {
}

public Request(StreamInput in) throws IOException {
super(in);
reindexBatchSize = in.readInt();
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeInt(reindexBatchSize);
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String[] indices() {
return new String[]{INDEX};
}

@Override
public IndicesOptions indicesOptions() {
//TODO consider lenientExpandOpen() ?
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
return IndicesOptions.strictExpandOpenAndForbidClosed();
}

/**
* Should this task store its result after it has finished?
*/
public ResultsIndexUpgradeAction.Request setShouldStoreResult(boolean shouldStoreResult) {
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
this.shouldStoreResult = shouldStoreResult;
return this;
}

@Override
public boolean getShouldStoreResult() {
return shouldStoreResult;
}

public ResultsIndexUpgradeAction.Request setReindexBatchSize(int reindexBatchSize) {
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
this.reindexBatchSize = reindexBatchSize;
return this;
}

public int getReindexBatchSize() {
return reindexBatchSize;
}

@Override
public ActionRequestValidationException validate() {
return null;
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResultsIndexUpgradeAction.Request request = (ResultsIndexUpgradeAction.Request) o;
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
return Objects.equals(reindexBatchSize, request.reindexBatchSize);
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public int hashCode() {
return Objects.hash(reindexBatchSize);
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, getDescription(), parentTaskId, headers) {
@Override
public boolean shouldCancelChildrenOnCancellation() {
return true;
}
};
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(REINDEX_BATCH_SIZE.getPreferredName(), reindexBatchSize);
builder.endObject();
return builder;
}
}

public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder<ResultsIndexUpgradeAction.Request,
benwtrent marked this conversation as resolved.
Show resolved Hide resolved
AcknowledgedResponse,
ResultsIndexUpgradeAction.RequestBuilder> {

public RequestBuilder(ElasticsearchClient client) {
super(client, INSTANCE, new ResultsIndexUpgradeAction.Request());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.test.AbstractStreamableTestCase;

public class ResultsIndexUpgradeRequestTests extends AbstractStreamableTestCase<ResultsIndexUpgradeAction.Request> {

@Override
protected ResultsIndexUpgradeAction.Request createTestInstance() {
ResultsIndexUpgradeAction.Request request = new ResultsIndexUpgradeAction.Request();
request.setReindexBatchSize(randomIntBetween(1, 10_000));
request.setShouldStoreResult(randomBoolean());
return request;
}

@Override
protected ResultsIndexUpgradeAction.Request createBlankInstance() {
return new ResultsIndexUpgradeAction.Request();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.ReindexPlugin;
import org.elasticsearch.persistent.PersistentTaskParams;
import org.elasticsearch.persistent.PersistentTaskState;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -120,7 +121,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {

@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return Arrays.asList(XPackClientPlugin.class, Netty4Plugin.class);
return Arrays.asList(XPackClientPlugin.class, Netty4Plugin.class, ReindexPlugin.class);
}

@Override
Expand Down
Loading