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;
|
||||
String modelSnapshotId;
|
||||
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;
|
||||
finishedTime = null;
|
||||
lastDataTime = null;
|
||||
|
|
|
@ -82,6 +82,12 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
|
|||
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() {
|
||||
Job job = buildJobBuilder("foo").build();
|
||||
assertFalse(job.equals("a string"));
|
||||
|
|
Loading…
Reference in New Issue