Skip to content

[ML-Dataframe] add stop and delete endpoints #33597

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

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -19,26 +19,36 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.persistent.PersistentTaskParams;
import org.elasticsearch.persistent.PersistentTaskState;
import org.elasticsearch.persistent.PersistentTasksExecutor;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.PersistentTaskPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.scheduler.SchedulerEngine;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.DeleteFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.PutFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.StartFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.StopFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.TransportDeleteFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.TransportPutFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.TransportStartFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.TransportStopFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJob;
import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJobPersistentTasksExecutor;
import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJobState;
import org.elasticsearch.xpack.ml.featureindexbuilder.rest.action.RestDeleteFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.rest.action.RestPutFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.rest.action.RestStartFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.rest.action.RestStopFeatureIndexBuilderJobAction;

import java.time.Clock;
import java.util.ArrayList;
Expand All @@ -64,22 +74,30 @@ public class FeatureIndexBuilder extends Plugin implements ActionPlugin, Persist

private final boolean enabled;
private final Settings settings;
private final boolean transportClientMode;

public FeatureIndexBuilder(Settings settings) {
this.settings = settings;

// todo: XPackSettings.FEATURE_INDEX_BUILDER_ENABLED.get(settings);
this.enabled = true;
this.transportClientMode = XPackPlugin.transportClientMode(settings);
}

@Override
public Collection<Module> createGuiceModules() {
List<Module> modules = new ArrayList<>();

if (transportClientMode) {
return modules;
}

modules.add(b -> XPackPlugin.bindFeatureSet(b, FeatureIndexBuilderFeatureSet.class));
return modules;
}

protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }

@Override
public List<RestHandler> getRestHandlers(final Settings settings, final RestController restController,
final ClusterSettings clusterSettings, final IndexScopedSettings indexScopedSettings, final SettingsFilter settingsFilter,
Expand All @@ -91,7 +109,9 @@ public List<RestHandler> getRestHandlers(final Settings settings, final RestCont

return Arrays.asList(
new RestPutFeatureIndexBuilderJobAction(settings, restController),
new RestStartFeatureIndexBuilderJobAction(settings, restController)
new RestStartFeatureIndexBuilderJobAction(settings, restController),
new RestStopFeatureIndexBuilderJobAction(settings, restController),
new RestDeleteFeatureIndexBuilderJobAction(settings, restController)
);
}

Expand All @@ -103,13 +123,15 @@ public List<RestHandler> getRestHandlers(final Settings settings, final RestCont

return Arrays.asList(
new ActionHandler<>(PutFeatureIndexBuilderJobAction.INSTANCE, TransportPutFeatureIndexBuilderJobAction.class),
new ActionHandler<>(StartFeatureIndexBuilderJobAction.INSTANCE, TransportStartFeatureIndexBuilderJobAction.class)
new ActionHandler<>(StartFeatureIndexBuilderJobAction.INSTANCE, TransportStartFeatureIndexBuilderJobAction.class),
new ActionHandler<>(StopFeatureIndexBuilderJobAction.INSTANCE, TransportStopFeatureIndexBuilderJobAction.class),
new ActionHandler<>(DeleteFeatureIndexBuilderJobAction.INSTANCE, TransportDeleteFeatureIndexBuilderJobAction.class)
);
}

@Override
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
if (false == enabled) {
if (false == enabled || transportClientMode) {
return emptyList();
}

Expand All @@ -122,22 +144,27 @@ public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
@Override
public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(ClusterService clusterService, ThreadPool threadPool,
Client client) {
if (enabled == false) {
if (enabled == false || transportClientMode) {
return emptyList();
}

SchedulerEngine schedulerEngine = new SchedulerEngine(settings, Clock.systemUTC());
return Collections.singletonList(new FeatureIndexBuilderJobPersistentTasksExecutor(settings, client,
schedulerEngine, threadPool));
}

@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
if (enabled == false) {
return emptyList();
}
return Collections.singletonList(
return Arrays.asList(
new NamedXContentRegistry.Entry(PersistentTaskParams.class, new ParseField("xpack/feature_index_builder/job"),
FeatureIndexBuilderJob::fromXContent)
FeatureIndexBuilderJob::fromXContent),
new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(FeatureIndexBuilderJobState.NAME),
FeatureIndexBuilderJobState::fromXContent),
new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(FeatureIndexBuilderJobState.NAME),
FeatureIndexBuilderJobState::fromXContent)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.ml.featureindexbuilder.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJob;

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

public class DeleteFeatureIndexBuilderJobAction extends Action<AcknowledgedResponse> {

public static final DeleteFeatureIndexBuilderJobAction INSTANCE = new DeleteFeatureIndexBuilderJobAction();
public static final String NAME = "cluster:admin/xpack/feature_index_builder/delete";

private DeleteFeatureIndexBuilderJobAction() {
super(NAME);
}

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

public static class Request extends AcknowledgedRequest<Request> implements ToXContent {
private String id;

public Request(String id) {
this.id = ExceptionsHelper.requireNonNull(id, FeatureIndexBuilderJob.ID.getPreferredName());
}

public Request() {
}

public String getId() {
return id;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(FeatureIndexBuilderJob.ID.getPreferredName(), id);
return builder;
}

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

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) {
return false;
}
Request other = (Request) obj;
return Objects.equals(id, other.id);
}
}

public static class RequestBuilder extends MasterNodeOperationRequestBuilder<Request, AcknowledgedResponse, RequestBuilder> {

protected RequestBuilder(ElasticsearchClient client, DeleteFeatureIndexBuilderJobAction action) {
super(client, action, new Request());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
import org.elasticsearch.xpack.core.rollup.RollupField;
import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJob;

import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
Expand All @@ -42,7 +43,7 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
private String id;

public Request(String id) {
this.id = ExceptionsHelper.requireNonNull(id, RollupField.ID.getPreferredName());
this.id = ExceptionsHelper.requireNonNull(id, FeatureIndexBuilderJob.ID.getPreferredName());
}

public Request() {
Expand Down Expand Up @@ -71,7 +72,7 @@ public ActionRequestValidationException validate() {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(RollupField.ID.getPreferredName(), id);
builder.field(FeatureIndexBuilderJob.ID.getPreferredName(), id);
return builder;
}

Expand All @@ -92,7 +93,7 @@ public boolean equals(Object obj) {
return Objects.equals(id, other.id);
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, StartFeatureIndexBuilderJobAction action) {
Expand Down Expand Up @@ -142,12 +143,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

@Override
public boolean equals(Object o) {
if (this == o)
public boolean equals(Object obj) {
if (this == obj) {
return true;
if (o == null || getClass() != o.getClass())
}

if (obj == null || getClass() != obj.getClass()) {
return false;
Response response = (Response) o;
}
Response response = (Response) obj;
return started == response.started;
}

Expand Down
Loading