|
@@ -83,6 +83,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
public static final ParseField RESULTS_INDEX_NAME = new ParseField("results_index_name");
|
|
|
public static final ParseField DELETING = new ParseField("deleting");
|
|
|
public static final ParseField ALLOW_LAZY_OPEN = new ParseField("allow_lazy_open");
|
|
|
+ public static final ParseField BLOCKED = new ParseField("blocked");
|
|
|
|
|
|
// Used for QueryPage
|
|
|
public static final ParseField RESULTS_FIELD = new ParseField("jobs");
|
|
@@ -136,6 +137,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
parser.declareString(Builder::setResultsIndexName, RESULTS_INDEX_NAME);
|
|
|
parser.declareBoolean(Builder::setDeleting, DELETING);
|
|
|
parser.declareBoolean(Builder::setAllowLazyOpen, ALLOW_LAZY_OPEN);
|
|
|
+ parser.declareObject(Builder::setBlocked, ignoreUnknownFields ? Blocked.LENIENT_PARSER : Blocked.STRICT_PARSER, BLOCKED);
|
|
|
|
|
|
return parser;
|
|
|
}
|
|
@@ -170,6 +172,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
private final String resultsIndexName;
|
|
|
private final boolean deleting;
|
|
|
private final boolean allowLazyOpen;
|
|
|
+ private final Blocked blocked;
|
|
|
|
|
|
private Job(String jobId, String jobType, Version jobVersion, List<String> groups, String description,
|
|
|
Date createTime, Date finishedTime,
|
|
@@ -177,7 +180,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
ModelPlotConfig modelPlotConfig, Long renormalizationWindowDays, TimeValue backgroundPersistInterval,
|
|
|
Long modelSnapshotRetentionDays, Long dailyModelSnapshotRetentionAfterDays, Long resultsRetentionDays,
|
|
|
Map<String, Object> customSettings, String modelSnapshotId, Version modelSnapshotMinVersion, String resultsIndexName,
|
|
|
- boolean deleting, boolean allowLazyOpen) {
|
|
|
+ boolean deleting, boolean allowLazyOpen, Blocked blocked) {
|
|
|
|
|
|
this.jobId = jobId;
|
|
|
this.jobType = jobType;
|
|
@@ -199,8 +202,19 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
this.modelSnapshotId = modelSnapshotId;
|
|
|
this.modelSnapshotMinVersion = modelSnapshotMinVersion;
|
|
|
this.resultsIndexName = resultsIndexName;
|
|
|
- this.deleting = deleting;
|
|
|
this.allowLazyOpen = allowLazyOpen;
|
|
|
+
|
|
|
+ if (deleting == false && blocked.getReason() == Blocked.Reason.DELETE) {
|
|
|
+ this.deleting = true;
|
|
|
+ } else {
|
|
|
+ this.deleting = deleting;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (deleting && blocked.getReason() != Blocked.Reason.DELETE) {
|
|
|
+ this.blocked = new Blocked(Blocked.Reason.DELETE, null);
|
|
|
+ } else {
|
|
|
+ this.blocked = blocked;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Job(StreamInput in) throws IOException {
|
|
@@ -231,6 +245,11 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
resultsIndexName = in.readString();
|
|
|
deleting = in.readBoolean();
|
|
|
allowLazyOpen = in.readBoolean();
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ blocked = new Blocked(in);
|
|
|
+ } else {
|
|
|
+ blocked = deleting ? new Blocked(Blocked.Reason.DELETE, null) : Blocked.none();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -416,6 +435,10 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
return allowLazyOpen;
|
|
|
}
|
|
|
|
|
|
+ public Blocked getBlocked() {
|
|
|
+ return blocked;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get all input data fields mentioned in the job configuration,
|
|
|
* namely analysis fields and the time field.
|
|
@@ -503,6 +526,9 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
out.writeString(resultsIndexName);
|
|
|
out.writeBoolean(deleting);
|
|
|
out.writeBoolean(allowLazyOpen);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ blocked.writeTo(out);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -578,6 +604,9 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
}
|
|
|
builder.field(RESULTS_INDEX_NAME.getPreferredName(), resultsIndexName);
|
|
|
builder.field(ALLOW_LAZY_OPEN.getPreferredName(), allowLazyOpen);
|
|
|
+ if (blocked.getReason() != Blocked.Reason.NONE) {
|
|
|
+ builder.field(BLOCKED.getPreferredName(), blocked);
|
|
|
+ }
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
@@ -613,7 +642,8 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
&& Objects.equals(this.modelSnapshotMinVersion, that.modelSnapshotMinVersion)
|
|
|
&& Objects.equals(this.resultsIndexName, that.resultsIndexName)
|
|
|
&& Objects.equals(this.deleting, that.deleting)
|
|
|
- && Objects.equals(this.allowLazyOpen, that.allowLazyOpen);
|
|
|
+ && Objects.equals(this.allowLazyOpen, that.allowLazyOpen)
|
|
|
+ && Objects.equals(this.blocked, that.blocked);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -621,7 +651,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
return Objects.hash(jobId, jobType, jobVersion, groups, description, createTime, finishedTime,
|
|
|
analysisConfig, analysisLimits, dataDescription, modelPlotConfig, renormalizationWindowDays,
|
|
|
backgroundPersistInterval, modelSnapshotRetentionDays, dailyModelSnapshotRetentionAfterDays, resultsRetentionDays,
|
|
|
- customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen);
|
|
|
+ customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen, blocked);
|
|
|
}
|
|
|
|
|
|
// Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString()
|
|
@@ -671,6 +701,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
private String resultsIndexName;
|
|
|
private boolean deleting;
|
|
|
private boolean allowLazyOpen;
|
|
|
+ private Blocked blocked = Blocked.none();
|
|
|
|
|
|
public Builder() {
|
|
|
}
|
|
@@ -702,6 +733,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
this.resultsIndexName = job.getResultsIndexNameNoPrefix();
|
|
|
this.deleting = job.isDeleting();
|
|
|
this.allowLazyOpen = job.allowLazyOpen();
|
|
|
+ this.blocked = job.getBlocked();
|
|
|
}
|
|
|
|
|
|
public Builder(StreamInput in) throws IOException {
|
|
@@ -731,6 +763,11 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
resultsIndexName = in.readOptionalString();
|
|
|
deleting = in.readBoolean();
|
|
|
allowLazyOpen = in.readBoolean();
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ blocked = new Blocked(in);
|
|
|
+ } else {
|
|
|
+ blocked = Blocked.none();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Builder setId(String id) {
|
|
@@ -865,6 +902,11 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public Builder setBlocked(Blocked blocked) {
|
|
|
+ this.blocked = ExceptionsHelper.requireNonNull(blocked, BLOCKED);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return the list of fields that have been set and are invalid to
|
|
|
* be set when the job is created e.g. model snapshot Id should not
|
|
@@ -930,9 +972,11 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
out.writeOptionalString(resultsIndexName);
|
|
|
out.writeBoolean(deleting);
|
|
|
out.writeBoolean(allowLazyOpen);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ blocked.writeTo(out);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public boolean equals(Object o) {
|
|
|
if (this == o) return true;
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
@@ -959,7 +1003,8 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
&& Objects.equals(this.modelSnapshotMinVersion, that.modelSnapshotMinVersion)
|
|
|
&& Objects.equals(this.resultsIndexName, that.resultsIndexName)
|
|
|
&& Objects.equals(this.deleting, that.deleting)
|
|
|
- && Objects.equals(this.allowLazyOpen, that.allowLazyOpen);
|
|
|
+ && Objects.equals(this.allowLazyOpen, that.allowLazyOpen)
|
|
|
+ && Objects.equals(this.blocked, that.blocked);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -967,7 +1012,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
return Objects.hash(id, jobType, jobVersion, groups, description, analysisConfig, analysisLimits, dataDescription,
|
|
|
createTime, finishedTime, modelPlotConfig, renormalizationWindowDays,
|
|
|
backgroundPersistInterval, modelSnapshotRetentionDays, dailyModelSnapshotRetentionAfterDays, resultsRetentionDays,
|
|
|
- customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen);
|
|
|
+ customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen, blocked);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1126,7 +1171,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
|
|
|
id, jobType, jobVersion, groups, description, createTime, finishedTime,
|
|
|
analysisConfig, analysisLimits, dataDescription, modelPlotConfig, renormalizationWindowDays,
|
|
|
backgroundPersistInterval, modelSnapshotRetentionDays, dailyModelSnapshotRetentionAfterDays, resultsRetentionDays,
|
|
|
- customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen);
|
|
|
+ customSettings, modelSnapshotId, modelSnapshotMinVersion, resultsIndexName, deleting, allowLazyOpen, blocked);
|
|
|
}
|
|
|
|
|
|
private void checkValidBackgroundPersistInterval() {
|