-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[FEATURE][ML] Write data frame configuration to process #35914
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
dimitris-athanasiou
merged 2 commits into
elastic:feature-ml-data-frame-analytics
from
dimitris-athanasiou:write-data-frame-configuration-to-process
Nov 27, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
32 changes: 32 additions & 0 deletions
32
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/analytics/DataFrameAnalysis.java
This file contains hidden or 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,32 @@ | ||
/* | ||
* 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.analytics; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; | ||
|
||
import java.io.IOException; | ||
|
||
public class DataFrameAnalysis implements ToXContentObject { | ||
|
||
private static final ParseField NAME = new ParseField("name"); | ||
|
||
private final String name; | ||
|
||
public DataFrameAnalysis(String name) { | ||
this.name = ExceptionsHelper.requireNonNull(name, NAME.getPreferredName()); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(NAME.getPreferredName(), name); | ||
builder.endObject(); | ||
return null; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,10 +5,19 @@ | |
*/ | ||
package org.elasticsearch.xpack.ml.analytics.process; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.xpack.core.watcher.watch.Payload; | ||
import org.elasticsearch.xpack.ml.process.NativeController; | ||
import org.elasticsearch.xpack.ml.process.ProcessPipes; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
@@ -19,13 +28,21 @@ public class AnalyticsBuilder { | |
private static final String ANALYTICS_PATH = "./" + ANALYTICS; | ||
|
||
private static final String LENGTH_ENCODED_INPUT_ARG = "--lengthEncodedInput"; | ||
private static final String CONFIG_ARG = "--config="; | ||
|
||
private final Environment env; | ||
private final NativeController nativeController; | ||
private final ProcessPipes processPipes; | ||
private final AnalyticsProcessConfig config; | ||
private final List<Path> filesToDelete; | ||
|
||
public AnalyticsBuilder(NativeController nativeController, ProcessPipes processPipes) { | ||
public AnalyticsBuilder(Environment env, NativeController nativeController, ProcessPipes processPipes, AnalyticsProcessConfig config, | ||
List<Path> filesToDelete) { | ||
this.env = Objects.requireNonNull(env); | ||
this.nativeController = Objects.requireNonNull(nativeController); | ||
this.processPipes = Objects.requireNonNull(processPipes); | ||
this.config = Objects.requireNonNull(config); | ||
this.filesToDelete = Objects.requireNonNull(filesToDelete); | ||
} | ||
|
||
public void build() throws IOException { | ||
|
@@ -34,10 +51,24 @@ public void build() throws IOException { | |
nativeController.startProcess(command); | ||
} | ||
|
||
List<String> buildAnalyticsCommand() { | ||
List<String> buildAnalyticsCommand() throws IOException { | ||
List<String> command = new ArrayList<>(); | ||
command.add(ANALYTICS_PATH); | ||
command.add(LENGTH_ENCODED_INPUT_ARG); | ||
addConfigFile(command); | ||
return command; | ||
} | ||
|
||
private void addConfigFile(List<String> command) throws IOException { | ||
Path configFile = Files.createTempFile(env.tmpFile(), "analysis", ".conf"); | ||
filesToDelete.add(configFile); | ||
try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(configFile),StandardCharsets.UTF_8); | ||
XContentBuilder jsonBuilder = JsonXContent.contentBuilder()) { | ||
|
||
config.toXContent(jsonBuilder, Payload.XContent.EMPTY_PARAMS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
osw.write(Strings.toString(jsonBuilder)); | ||
} | ||
|
||
command.add(CONFIG_ARG + configFile.toString()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ml/src/main/java/org/elasticsearch/xpack/ml/analytics/process/AnalyticsProcessConfig.java
This file contains hidden or 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,50 @@ | ||
/* | ||
* 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.analytics.process; | ||
|
||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.xpack.ml.analytics.DataFrameAnalysis; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class AnalyticsProcessConfig implements ToXContentObject { | ||
|
||
private static final String ROWS = "rows"; | ||
private static final String COLS = "cols"; | ||
private static final String MEMORY_LIMIT = "memory_limit"; | ||
private static final String THREADS = "threads"; | ||
private static final String ANALYSIS = "analysis"; | ||
|
||
private final long rows; | ||
private final long cols; | ||
private final ByteSizeValue memoryLimit; | ||
private final int threads; | ||
private final DataFrameAnalysis analysis; | ||
|
||
|
||
public AnalyticsProcessConfig(long rows, long cols, ByteSizeValue memoryLimit, int threads, DataFrameAnalysis analysis) { | ||
this.rows = rows; | ||
this.cols = cols; | ||
this.memoryLimit = Objects.requireNonNull(memoryLimit); | ||
this.threads = threads; | ||
this.analysis = Objects.requireNonNull(analysis); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ROWS, rows); | ||
builder.field(COLS, cols); | ||
builder.field(MEMORY_LIMIT, memoryLimit.getBytes()); | ||
builder.field(THREADS, threads); | ||
builder.field(ANALYSIS, analysis); | ||
builder.endObject(); | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return builder? |
||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return builder I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups! Indeed!