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] Use String rep of Version in map for serialisation #37416

Merged
merged 1 commit into from
Jan 14, 2019
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 @@ -402,7 +402,8 @@ private void createConfigIndex(ActionListener<Boolean> listener) {
public static Job updateJobForMigration(Job job) {
Job.Builder builder = new Job.Builder(job);
Map<String, Object> custom = job.getCustomSettings() == null ? new HashMap<>() : new HashMap<>(job.getCustomSettings());
custom.put(MIGRATED_FROM_VERSION, job.getJobVersion());
String version = job.getJobVersion() != null ? job.getJobVersion().toString() : null;
custom.put(MIGRATED_FROM_VERSION, version);
builder.setCustomSettings(custom);
// Increase the model memory limit for 6.1 - 6.3 jobs
Version jobVersion = job.getJobVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.ml.MlMetadata;
Expand All @@ -21,9 +22,11 @@
import org.elasticsearch.xpack.core.ml.job.config.Job;
import org.elasticsearch.xpack.core.ml.job.config.JobTests;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -125,7 +128,7 @@ public void testUpdateJobForMigration() {
Job migratedJob = MlConfigMigrator.updateJobForMigration(oldJob.build());
assertEquals(Version.CURRENT, migratedJob.getJobVersion());
assertTrue(migratedJob.getCustomSettings().containsKey(MlConfigMigrator.MIGRATED_FROM_VERSION));
assertEquals(oldVersion, migratedJob.getCustomSettings().get(MlConfigMigrator.MIGRATED_FROM_VERSION));
assertEquals(oldVersion.toString(), migratedJob.getCustomSettings().get(MlConfigMigrator.MIGRATED_FROM_VERSION));
}

public void testUpdateJobForMigration_GivenV54Job() {
Expand All @@ -138,6 +141,12 @@ public void testUpdateJobForMigration_GivenV54Job() {
assertTrue(migratedJob.getCustomSettings().containsKey(MlConfigMigrator.MIGRATED_FROM_VERSION));
}

public void testSerialisationOfUpdatedJob() throws IOException {
Job migratedJob = MlConfigMigrator.updateJobForMigration(JobTests.buildJobBuilder("pre-migration").build(new Date()));
Job copy = copyWriteable(migratedJob, new NamedWriteableRegistry(Collections.emptyList()), Job::new, Version.CURRENT);
assertEquals(migratedJob, copy);
}

public void testFilterFailedJobConfigWrites() {
List<Job> jobs = new ArrayList<>();
jobs.add(JobTests.buildJobBuilder("foo").build());
Expand Down