Skip to content

Commit

Permalink
[ML] Refactor ProcessCtrl into Autodetect and Normalizer builders (#3…
Browse files Browse the repository at this point in the history
…2720)

This moves the helper functionality for creating the autodetect
and mormalizer processes into corresponding builders.
  • Loading branch information
dimitris-athanasiou committed Aug 10, 2018
1 parent f72cf57 commit 3db5292
Show file tree
Hide file tree
Showing 12 changed files with 484 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@
import org.elasticsearch.xpack.ml.job.categorization.MlClassicTokenizer;
import org.elasticsearch.xpack.ml.job.categorization.MlClassicTokenizerFactory;
import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister;
import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider;
import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider;
import org.elasticsearch.xpack.ml.job.process.DataCountsReporter;
import org.elasticsearch.xpack.ml.job.process.NativeController;
import org.elasticsearch.xpack.ml.job.process.NativeControllerHolder;
import org.elasticsearch.xpack.ml.job.process.ProcessCtrl;
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectBuilder;
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessFactory;
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager;
import org.elasticsearch.xpack.ml.job.process.autodetect.BlackHoleAutodetectProcess;
Expand Down Expand Up @@ -289,8 +289,8 @@ public List<Setting<?>> getSettings() {
CONCURRENT_JOB_ALLOCATIONS,
MachineLearningField.MAX_MODEL_MEMORY_LIMIT,
MAX_MACHINE_MEMORY_PERCENT,
ProcessCtrl.DONT_PERSIST_MODEL_STATE_SETTING,
ProcessCtrl.MAX_ANOMALY_RECORDS_SETTING,
AutodetectBuilder.DONT_PERSIST_MODEL_STATE_SETTING,
AutodetectBuilder.MAX_ANOMALY_RECORDS_SETTING,
DataCountsReporter.ACCEPTABLE_PERCENTAGE_DATE_PARSE_ERRORS_SETTING,
DataCountsReporter.ACCEPTABLE_PERCENTAGE_OUT_OF_ORDER_ERRORS_SETTING,
AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
public class NativeController {
private static final Logger LOGGER = Loggers.getLogger(NativeController.class);

/**
* Process controller native program name
*/
private static final String CONTROLLER = "controller";

// The controller process should already be running by the time this class tries to connect to it, so the timeout
// can be short (although there's a gotcha with EBS volumes restored from snapshot, so not TOO short)
private static final Duration CONTROLLER_CONNECT_TIMEOUT = Duration.ofSeconds(10);
Expand All @@ -50,7 +55,7 @@ public class NativeController {
private final OutputStream commandStream;

NativeController(Environment env, NamedPipeHelper namedPipeHelper) throws IOException {
ProcessPipes processPipes = new ProcessPipes(env, namedPipeHelper, ProcessCtrl.CONTROLLER, null,
ProcessPipes processPipes = new ProcessPipes(env, namedPipeHelper, CONTROLLER, null,
true, true, false, false, false, false);
processPipes.connectStreams(CONTROLLER_CONNECT_TIMEOUT);
cppLogHandler = new CppLogMessageHandler(null, processPipes.getLogStream().get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.job.process;

import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.xpack.core.XPackPlugin;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public final class ProcessBuilderUtils {

private ProcessBuilderUtils() {}

/**
* Name of the model config file
*/
public static final String ML_MODEL_CONF = "mlmodel.conf";

public static <T> void addIfNotNull(T object, String argKey, List<String> command) {
if (object != null) {
String param = argKey + object;
command.add(param);
}
}

public static void addIfNotNull(TimeValue timeValue, String argKey, List<String> command) {
addIfNotNull(timeValue == null ? null : timeValue.getSeconds(), argKey, command);
}

/**
* Return true if there is a file ES_HOME/config/mlmodel.conf
*/
public static boolean modelConfigFilePresent(Environment env) {
Path modelConfPath = XPackPlugin.resolveConfigFile(env, ML_MODEL_CONF);

return Files.isRegularFile(modelConfPath);
}
}

This file was deleted.

Loading

0 comments on commit 3db5292

Please sign in to comment.