Ensure automatically generated job IDs meet the validation criteria (elastic/elasticsearch#586)
Original commit: elastic/x-pack-elasticsearch@34b67cb509
This commit is contained in:
parent
5b029ee595
commit
3383c67cf2
|
@ -693,7 +693,16 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContent
|
||||||
Date lastDataTime;
|
Date lastDataTime;
|
||||||
String modelSnapshotId;
|
String modelSnapshotId;
|
||||||
if (fromApi) {
|
if (fromApi) {
|
||||||
id = this.id == null ? UUIDs.base64UUID().toLowerCase(Locale.ROOT): this.id;
|
if (this.id != null) {
|
||||||
|
id = this.id;
|
||||||
|
} else {
|
||||||
|
// Base64 UUIDs are not necessarily valid job IDs
|
||||||
|
id = "auto-" + UUIDs.base64UUID().toLowerCase(Locale.ROOT).replaceAll("/\\+=", "_");
|
||||||
|
if (id.endsWith("_")) {
|
||||||
|
// Job IDs cannot end with underscores
|
||||||
|
id = id.substring(0, id.length() - 1) + "z";
|
||||||
|
}
|
||||||
|
}
|
||||||
createTime = this.createTime == null ? new Date() : this.createTime;
|
createTime = this.createTime == null ? new Date() : this.createTime;
|
||||||
finishedTime = null;
|
finishedTime = null;
|
||||||
lastDataTime = null;
|
lastDataTime = null;
|
||||||
|
|
|
@ -82,6 +82,12 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
|
||||||
assertNotNull(buildJobBuilder(null).build(true).getId()); // test auto id generation
|
assertNotNull(buildJobBuilder(null).build(true).getId()); // test auto id generation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNoIdStartsWithAuto() {
|
||||||
|
String autoId = buildJobBuilder(null).build(true).getId();
|
||||||
|
assertTrue(autoId, autoId.startsWith("auto-"));
|
||||||
|
assertFalse(autoId, autoId.endsWith("_"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testEquals_GivenDifferentClass() {
|
public void testEquals_GivenDifferentClass() {
|
||||||
Job job = buildJobBuilder("foo").build();
|
Job job = buildJobBuilder("foo").build();
|
||||||
assertFalse(job.equals("a string"));
|
assertFalse(job.equals("a string"));
|
||||||
|
|
Loading…
Reference in New Issue