Skip to content

Commit

Permalink
[ML] Job config document CRUD operations (#32738)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Oct 2, 2018
1 parent cd18952 commit af6c1b9
Show file tree
Hide file tree
Showing 7 changed files with 1,039 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ public Job(StreamInput in) throws IOException {
deleted = in.readBoolean();
}

/**
* Get the persisted job document name from the Job Id.
* Throws if {@code jobId} is not a valid job Id.
*
* @param jobId The job id
* @return The id of document the job is persisted in
*/
public static String documentId(String jobId) {
if (!MlStrings.isValidId(jobId)) {
throw new IllegalArgumentException(Messages.getMessage(Messages.INVALID_ID, ID.getPreferredName(), jobId));
}
if (!MlStrings.hasValidLengthForId(jobId)) {
throw new IllegalArgumentException(Messages.getMessage(Messages.JOB_CONFIG_ID_TOO_LONG, MlStrings.ID_LENGTH_LIMIT));
}

return "job-" + jobId;
}


/**
* Return the Job Id.
*
Expand Down Expand Up @@ -759,6 +778,10 @@ public void setGroups(List<String> groups) {
this.groups = groups == null ? Collections.emptyList() : groups;
}

public List<String> getGroups() {
return groups;
}

public Builder setCustomSettings(Map<String, Object> customSettings) {
this.customSettings = customSettings;
return this;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
*/
package org.elasticsearch.xpack.ml;

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ml.MachineLearningField;

import java.util.Collection;

/**
* An extention to {@link ESSingleNodeTestCase} that adds node settings specifically needed for ML test cases.
*/
Expand All @@ -18,10 +24,31 @@ public abstract class MlSingleNodeTestCase extends ESSingleNodeTestCase {
@Override
protected Settings nodeSettings() {
Settings.Builder newSettings = Settings.builder();
newSettings.put(super.nodeSettings());

// Disable native ML autodetect_process as the c++ controller won't be available
newSettings.put(MachineLearningField.AUTODETECT_PROCESS.getKey(), false);
newSettings.put(MachineLearningField.MAX_MODEL_MEMORY_LIMIT.getKey(), new ByteSizeValue(1024));
newSettings.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial");
// Disable security otherwise delete-by-query action fails to get authorized
newSettings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
newSettings.put(XPackSettings.MONITORING_ENABLED.getKey(), false);
newSettings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
return newSettings.build();
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(LocalStateMachineLearning.class);
}

protected void waitForMlTemplates() throws Exception {
// block until the templates are installed
assertBusy(() -> {
ClusterState state = client().admin().cluster().prepareState().get().getState();
assertTrue("Timed out waiting for the ML templates to be installed",
MachineLearning.allTemplatesInstalled(state));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
package org.elasticsearch.xpack.ml.integration;

import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.index.reindex.ReindexPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ml.action.DeleteJobAction;
import org.elasticsearch.xpack.core.ml.action.PutJobAction;
import org.elasticsearch.xpack.core.ml.action.util.QueryPage;
Expand All @@ -33,7 +31,6 @@
import org.elasticsearch.xpack.core.ml.job.results.Influencer;
import org.elasticsearch.xpack.core.ml.job.results.ModelPlot;
import org.elasticsearch.xpack.ml.LocalStateMachineLearning;
import org.elasticsearch.xpack.ml.MachineLearning;
import org.elasticsearch.xpack.ml.MlSingleNodeTestCase;
import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder;
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder;
Expand Down Expand Up @@ -78,17 +75,6 @@ public class AutodetectResultProcessorIT extends MlSingleNodeTestCase {
private AutoDetectResultProcessor resultProcessor;
private Renormalizer renormalizer;

@Override
protected Settings nodeSettings() {
Settings.Builder newSettings = Settings.builder();
newSettings.put(super.nodeSettings());
// Disable security otherwise delete-by-query action fails to get authorized
newSettings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
newSettings.put(XPackSettings.MONITORING_ENABLED.getKey(), false);
newSettings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
return newSettings.build();
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(LocalStateMachineLearning.class, ReindexPlugin.class);
Expand All @@ -109,7 +95,7 @@ protected void updateModelSnapshotIdOnJob(ModelSnapshot modelSnapshot) {
capturedUpdateModelSnapshotOnJobRequests.add(modelSnapshot);
}
};
putIndexTemplates();
waitForMlTemplates();
putJob();
}

Expand Down Expand Up @@ -288,15 +274,6 @@ public void testEndOfStreamTriggersPersisting() throws Exception {
assertResultsAreSame(allRecords, persistedRecords);
}

private void putIndexTemplates() throws Exception {
// block until the templates are installed
assertBusy(() -> {
ClusterState state = client().admin().cluster().prepareState().get().getState();
assertTrue("Timed out waiting for the ML templates to be installed",
MachineLearning.allTemplatesInstalled(state));
});
}

private void putJob() {
Detector detector = new Detector.Builder("dc", "by_instance").build();
Job.Builder jobBuilder = new Job.Builder(JOB_ID);
Expand Down
Loading

0 comments on commit af6c1b9

Please sign in to comment.