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-Dataframe] Feature/dataframe basictests #32783

Merged
merged 6 commits into from
Aug 14, 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
5 changes: 5 additions & 0 deletions docs/reference/rest-api/info.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Example response:
"status" : "active"
},
"features" : {
"fib" : {
"description" : "Time series feature index creation",
"available" : false,
"enabled" : true
},
"graph" : {
"description" : "Graph Data Exploration for the Elastic Stack",
"available" : false,
Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugin/ml-feature-index-builder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ import org.elasticsearch.gradle.BuildPlugin
evaluationDependsOn(xpackModule('core'))

apply plugin: 'elasticsearch.esplugin'

esplugin {
name 'ml-feature-index-builder'
description 'A plugin to build feature indexes'
classname 'org.elasticsearch.xpack.ml.featureindexbuilder.FeatureIndexBuilder'
extendedPlugins = ['x-pack-core']
}

compileJava.options.compilerArgs << "-Xlint:-rawtypes"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes"

dependencies {
compileOnly "org.elasticsearch:elasticsearch:${version}"

compileOnly "org.elasticsearch.plugin:x-pack-core:${version}"
compileOnly project(path: xpackModule('core'), configuration: 'shadow')
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
}


run {
plugin xpackModule('core')
}

integTest.enabled = false
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.rollup.RollupField;
import org.elasticsearch.xpack.core.rollup.job.RollupJob;
import org.elasticsearch.xpack.core.scheduler.SchedulerEngine;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.PutFeatureIndexBuilderJobAction;
import org.elasticsearch.xpack.ml.featureindexbuilder.action.StartFeatureIndexBuilderJobAction;
Expand All @@ -58,7 +56,7 @@ public class FeatureIndexBuilder extends Plugin implements ActionPlugin, Persist

public static final String NAME = "feature_index_builder";
public static final String BASE_PATH = "/_xpack/feature_index_builder/";
public static final String TASK_THREAD_POOL_NAME = "feature_index_builder_indexing";
public static final String TASK_THREAD_POOL_NAME = "ml_feature_index_builder_indexing";

// list of headers that will be stored when a job is created
public static final Set<String> HEADER_FILTERS = new HashSet<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public Request() {

}

public static Request parseRequest(String id, XContentParser parser) {
FeatureIndexBuilderJobConfig.Builder config = FeatureIndexBuilderJobConfig.Builder.fromXContent(id, parser);
return new Request(config.build());
public static Request fromXContent(final XContentParser parser, final String id) throws IOException {
return new Request(FeatureIndexBuilderJobConfig.fromXContent(parser, id));
}

@Override
Expand Down Expand Up @@ -107,7 +106,7 @@ protected RequestBuilder(ElasticsearchClient client, PutFeatureIndexBuilderJobAc
super(client, action, new Request());
}
}

public static class Response extends AcknowledgedResponse {
public Response() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ protected void masterOperation(Request request, ClusterState clusterState, Actio
FeatureIndexBuilderJob job = createFeatureIndexBuilderJob(request.getConfig(), threadPool);

startPersistentTask(job, listener, persistentTasksService);

}

private static FeatureIndexBuilderJob createFeatureIndexBuilderJob(FeatureIndexBuilderJobConfig config, ThreadPool threadPool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,30 @@
import java.util.function.Consumer;

public class TransportStartFeatureIndexBuilderJobAction extends
TransportTasksAction<FeatureIndexBuilderJobTask, StartFeatureIndexBuilderJobAction.Request, StartFeatureIndexBuilderJobAction.Response, StartFeatureIndexBuilderJobAction.Response> {
TransportTasksAction<FeatureIndexBuilderJobTask, StartFeatureIndexBuilderJobAction.Request,
StartFeatureIndexBuilderJobAction.Response, StartFeatureIndexBuilderJobAction.Response> {

private final XPackLicenseState licenseState;

@Inject
public TransportStartFeatureIndexBuilderJobAction(Settings settings, TransportService transportService,
ActionFilters actionFilters, ClusterService clusterService, XPackLicenseState licenseState) {
super(settings, StartFeatureIndexBuilderJobAction.NAME, clusterService, transportService, actionFilters,
StartFeatureIndexBuilderJobAction.Request::new, StartFeatureIndexBuilderJobAction.Response::new, ThreadPool.Names.SAME);
this.licenseState = licenseState;
}
@Inject
public TransportStartFeatureIndexBuilderJobAction(Settings settings, TransportService transportService, ActionFilters actionFilters,
ClusterService clusterService, XPackLicenseState licenseState) {
super(settings, StartFeatureIndexBuilderJobAction.NAME, clusterService, transportService, actionFilters,
StartFeatureIndexBuilderJobAction.Request::new, StartFeatureIndexBuilderJobAction.Response::new, ThreadPool.Names.SAME);
this.licenseState = licenseState;
}

@Override
protected void processTasks(StartFeatureIndexBuilderJobAction.Request request, Consumer<FeatureIndexBuilderJobTask> operation) {
FeatureIndexBuilderJobTask matchingTask = null;

// todo: re-factor, see rollup TransportTaskHelper
for (Task task : taskManager.getTasks().values()) {
if (task instanceof FeatureIndexBuilderJobTask && ((FeatureIndexBuilderJobTask)task).getConfig().getId().equals(request.getId())) {
if (task instanceof FeatureIndexBuilderJobTask
&& ((FeatureIndexBuilderJobTask) task).getConfig().getId().equals(request.getId())) {
if (matchingTask != null) {
throw new IllegalArgumentException("Found more than one matching task for feature index builder job [" + request.getId() + "] when " +
"there should only be one.");
throw new IllegalArgumentException("Found more than one matching task for feature index builder job [" + request.getId()
+ "] when " + "there should only be one.");
}
matchingTask = (FeatureIndexBuilderJobTask) task;
}
Expand All @@ -69,7 +71,7 @@ protected void doExecute(Task task, StartFeatureIndexBuilderJobAction.Request re
listener.onFailure(LicenseUtils.newComplianceException(XPackField.FIB));
return;
}

super.doExecute(task, request, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.XPackPlugin;

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

public class FeatureIndexBuilderJob implements XPackPlugin.XPackPersistentTaskParams {

public static final String NAME = "xpack/feature_index_builder/job";

private FeatureIndexBuilderJobConfig config;

private static final ParseField CONFIG = new ParseField("config");

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<FeatureIndexBuilderJob, Void> PARSER
= new ConstructingObjectParser<>(NAME, a -> new FeatureIndexBuilderJob((FeatureIndexBuilderJobConfig) a[0]));

public static final ConstructingObjectParser<FeatureIndexBuilderJob, Void> PARSER = new ConstructingObjectParser<>(NAME,
a -> new FeatureIndexBuilderJob((FeatureIndexBuilderJobConfig) a[0]));

static {
PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> FeatureIndexBuilderJobConfig.PARSER.apply(p,c).build(), CONFIG);
PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> FeatureIndexBuilderJobConfig.fromXContent(p, null),
CONFIG);
}


public FeatureIndexBuilderJob(FeatureIndexBuilderJobConfig config) {
this.config = Objects.requireNonNull(config);
}

public FeatureIndexBuilderJob(StreamInput in) throws IOException {
this.config = new FeatureIndexBuilderJobConfig(in);
}

@Override
public String getWriteableName() {
return NAME;
Expand All @@ -68,11 +68,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public FeatureIndexBuilderJobConfig getConfig() {
return config;
}

public static FeatureIndexBuilderJob fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

@Override
public boolean equals(Object other) {
if (this == other) {
Expand All @@ -87,7 +87,7 @@ public boolean equals(Object other) {

return Objects.equals(this.config, that.config);
}

@Override
public int hashCode() {
return Objects.hash(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,49 @@

package org.elasticsearch.xpack.ml.featureindexbuilder.job;

import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;

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

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;

/**
* This class holds the configuration details of a feature index builder job
*/
public class FeatureIndexBuilderJobConfig implements NamedWriteable, ToXContentObject {
private static final String NAME = "xpack/feature_index_builder/jobconfig";

public static final ParseField ID = new ParseField("id");
private static final String NAME = "xpack/feature_index_builder/jobconfig";
private static final ParseField ID = new ParseField("id");

private String id;
private final String id;

public static final ObjectParser<FeatureIndexBuilderJobConfig.Builder, Void> PARSER = new ObjectParser<>(NAME, false,
FeatureIndexBuilderJobConfig.Builder::new);
private static final ConstructingObjectParser<FeatureIndexBuilderJobConfig, String> PARSER = new ConstructingObjectParser<>(NAME, false,
(args, optionalId) -> {
String id = args[0] != null ? (String) args[0] : optionalId;
return new FeatureIndexBuilderJobConfig(id);
});

static {
PARSER.declareString(FeatureIndexBuilderJobConfig.Builder::setId, ID);
PARSER.declareString(optionalConstructorArg(), ID);
}

FeatureIndexBuilderJobConfig(String id) {
public FeatureIndexBuilderJobConfig(final String id) {
this.id = id;
}

public FeatureIndexBuilderJobConfig(StreamInput in) throws IOException {
public FeatureIndexBuilderJobConfig(final StreamInput in) throws IOException {
id = in.readString();
}

public FeatureIndexBuilderJobConfig() {
}

public String getId() {
return id;
}
Expand All @@ -56,16 +57,13 @@ public String getCron() {
return "*";
}

public void writeTo(StreamOutput out) throws IOException {
public void writeTo(final StreamOutput out) throws IOException {
out.writeString(id);
}

public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
builder.startObject();
if (id != null) {
// to be replace by constant
builder.field("id", id);
}
builder.field(ID.getPreferredName(), id);
builder.endObject();
return builder;
}
Expand All @@ -85,7 +83,7 @@ public boolean equals(Object other) {
return false;
}

FeatureIndexBuilderJobConfig that = (FeatureIndexBuilderJobConfig) other;
final FeatureIndexBuilderJobConfig that = (FeatureIndexBuilderJobConfig) other;

return Objects.equals(this.id, that.id);
}
Expand All @@ -100,48 +98,8 @@ public String toString() {
return Strings.toString(this, true, true);
}

public static class Builder implements Writeable, ToXContentObject {
private String id;

public Builder() {}

public Builder(FeatureIndexBuilderJobConfig job) {
this.setId(job.getId());
}

public static FeatureIndexBuilderJobConfig.Builder fromXContent(String id, XContentParser parser) {
FeatureIndexBuilderJobConfig.Builder config = FeatureIndexBuilderJobConfig.PARSER.apply(parser, null);
if (id != null) {
config.setId(id);
}
return config;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (id != null) {
builder.field(ID.getPreferredName(), id);
}
builder.endObject();
return builder;
}

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

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public FeatureIndexBuilderJobConfig build() {
return new FeatureIndexBuilderJobConfig(id);
}
public static FeatureIndexBuilderJobConfig fromXContent(final XContentParser parser, @Nullable final String optionalJobId)
throws IOException {
return PARSER.parse(parser, optionalJobId);
}
}
Loading