diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java index c66cf1716cf..e31a63edff5 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java @@ -65,7 +65,7 @@ public class CloseJobAction extends Action implements ToXContent { public int hashCode() { return Objects.hash(config, status); } + + // Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString() + @SuppressWarnings("deprecation") + @Override + public final String toString() { + try { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.prettyPrint(); + toXContent(builder, EMPTY_PARAMS); + return builder.string(); + } catch (Exception e) { + // So we have a stack trace logged somewhere + return "{ \"error\" : \"" + org.elasticsearch.ExceptionsHelper.detailedMessage(e) + "\"}"; + } + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java index ea3c735ce4e..14d7b2fb5ee 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java @@ -126,7 +126,7 @@ public class Allocation extends AbstractDiffable implements ToXConte return Objects.hash(nodeId, jobId, ignoreDowntime, status, statusReason); } - // Class alreadt extends from AbstractDiffable, so copied from ToXContentToBytes#toString() + // Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString() @SuppressWarnings("deprecation") @Override public final String toString() { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/DatafeedStatusObserver.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/DatafeedStatusObserver.java index c26add13b97..8904030665d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/DatafeedStatusObserver.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/DatafeedStatusObserver.java @@ -34,6 +34,7 @@ public class DatafeedStatusObserver { public void waitForStatus(String datafeedId, TimeValue waitTimeout, DatafeedStatus expectedStatus, Consumer handler) { ClusterStateObserver observer = new ClusterStateObserver(clusterService, LOGGER, threadPool.getThreadContext()); + DatafeedPredicate datafeedPredicate = new DatafeedPredicate(datafeedId, expectedStatus); observer.waitForNextChange(new ClusterStateObserver.Listener() { @Override public void onNewClusterState(ClusterState state) { @@ -49,11 +50,15 @@ public class DatafeedStatusObserver { @Override public void onTimeout(TimeValue timeout) { - Exception e = new IllegalArgumentException("Timeout expired while waiting for datafeed status to change to [" - + expectedStatus + "]"); - handler.accept(e); + if (datafeedPredicate.test(clusterService.state())) { + handler.accept(null); + } else { + Exception e = new IllegalArgumentException("Timeout expired while waiting for datafeed status to change to [" + + expectedStatus + "]"); + handler.accept(e); + } } - }, new DatafeedPredicate(datafeedId, expectedStatus), waitTimeout); + }, datafeedPredicate, waitTimeout); } private static class DatafeedPredicate implements Predicate { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/JobStatusObserver.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/JobStatusObserver.java index 764f5d6e925..5500a73adf2 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/JobStatusObserver.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/utils/JobStatusObserver.java @@ -34,6 +34,7 @@ public class JobStatusObserver { public void waitForStatus(String jobId, TimeValue waitTimeout, JobStatus expectedStatus, Consumer handler) { ClusterStateObserver observer = new ClusterStateObserver(clusterService, LOGGER, threadPool.getThreadContext()); + JobStatusPredicate jobStatusPredicate = new JobStatusPredicate(jobId, expectedStatus); observer.waitForNextChange(new ClusterStateObserver.Listener() { @Override public void onNewClusterState(ClusterState state) { @@ -49,11 +50,15 @@ public class JobStatusObserver { @Override public void onTimeout(TimeValue timeout) { - Exception e = new IllegalArgumentException("Timeout expired while waiting for job status to change to [" - + expectedStatus + "]"); - handler.accept(e); + if (jobStatusPredicate.test(clusterService.state())) { + handler.accept(null); + } else { + Exception e = new IllegalArgumentException("Timeout expired while waiting for job status to change to [" + + expectedStatus + "]"); + handler.accept(e); + } } - }, new JobStatusPredicate(jobId, expectedStatus), waitTimeout); + }, jobStatusPredicate, waitTimeout); } private static class JobStatusPredicate implements Predicate {