From b37ebd1adf4ffad1a4733d6da740d8c797a744c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Witek?= Date: Tue, 20 Aug 2019 16:03:50 +0200 Subject: [PATCH] Prepare the codebase for new Auditor subclasses (#45716) (#45731) --- .../{Auditor.java => AbstractAuditor.java} | 14 +++++------ .../persistence/ElasticsearchMappings.java | 10 ++++---- ...java => AnomalyDetectionAuditMessage.java} | 18 ++++++------- ...orTests.java => AbstractAuditorTests.java} | 25 ++++++++++++------- .../core/common/notifications/LevelTests.java | 18 ++++++------- .../integration/DataFrameAuditorIT.java | 2 +- .../notifications/DataFrameAuditor.java | 4 +-- .../xpack/ml/MachineLearning.java | 4 +-- .../xpack/ml/MlAssignmentNotifier.java | 10 +++++--- .../ml/action/TransportCloseJobAction.java | 12 +++++---- .../TransportDeleteExpiredDataAction.java | 4 +-- .../ml/action/TransportDeleteJobAction.java | 6 ++--- .../TransportDeleteModelSnapshotAction.java | 6 ++--- .../ml/action/TransportKillProcessAction.java | 6 ++--- .../action/TransportStartDatafeedAction.java | 9 ++++--- .../xpack/ml/datafeed/DatafeedJob.java | 6 ++--- .../xpack/ml/datafeed/DatafeedJobBuilder.java | 11 ++++---- .../xpack/ml/datafeed/DatafeedManager.java | 7 +++--- .../xpack/ml/datafeed/ProblemTracker.java | 6 ++--- .../xpack/ml/job/JobManager.java | 9 ++++--- .../autodetect/AutodetectProcessManager.java | 6 ++--- .../output/AutodetectResultProcessor.java | 8 +++--- .../job/retention/ExpiredResultsRemover.java | 6 ++--- ...itor.java => AnomalyDetectionAuditor.java} | 9 ++++--- .../xpack/ml/MlAssignmentNotifierTests.java | 6 ++--- .../action/TransportCloseJobActionTests.java | 9 ++++--- .../TransportStartDatafeedActionTests.java | 6 ++--- .../ml/datafeed/DatafeedJobBuilderTests.java | 6 ++--- .../xpack/ml/datafeed/DatafeedJobTests.java | 6 ++--- .../ml/datafeed/DatafeedManagerTests.java | 8 +++--- .../ml/datafeed/ProblemTrackerTests.java | 6 ++--- .../ml/integration/AnnotationIndexIT.java | 4 +-- .../AutodetectResultProcessorIT.java | 4 +-- .../xpack/ml/job/JobManagerTests.java | 6 ++--- .../AutodetectProcessManagerTests.java | 6 ++--- .../AutodetectResultProcessorTests.java | 6 ++--- .../retention/ExpiredResultsRemoverTests.java | 4 +-- 37 files changed, 155 insertions(+), 138 deletions(-) rename x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/{Auditor.java => AbstractAuditor.java} (87%) rename x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/{AuditMessage.java => AnomalyDetectionAuditMessage.java} (68%) rename x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/{AuditorTests.java => AbstractAuditorTests.java} (86%) rename x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/{Auditor.java => AnomalyDetectionAuditor.java} (59%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/Auditor.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java similarity index 87% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/Auditor.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java index d4a1f14f188..102e07dc4c1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/Auditor.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java @@ -21,20 +21,20 @@ import java.util.Objects; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; -public class Auditor { +public abstract class AbstractAuditor { - private static final Logger logger = LogManager.getLogger(Auditor.class); + private static final Logger logger = LogManager.getLogger(AbstractAuditor.class); private final Client client; private final String nodeName; private final String auditIndex; private final String executionOrigin; private final AbstractAuditMessage.AbstractBuilder messageBuilder; - public Auditor(Client client, - String nodeName, - String auditIndex, - String executionOrigin, - AbstractAuditMessage.AbstractBuilder messageBuilder) { + public AbstractAuditor(Client client, + String nodeName, + String auditIndex, + String executionOrigin, + AbstractAuditMessage.AbstractBuilder messageBuilder) { this.client = Objects.requireNonNull(client); this.nodeName = Objects.requireNonNull(nodeName); this.auditIndex = auditIndex; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java index 11674bf26f4..13dd077f605 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java @@ -58,7 +58,7 @@ import org.elasticsearch.xpack.core.ml.job.results.Influencer; import org.elasticsearch.xpack.core.ml.job.results.ModelPlot; import org.elasticsearch.xpack.core.ml.job.results.ReservedFieldNames; import org.elasticsearch.xpack.core.ml.job.results.Result; -import org.elasticsearch.xpack.core.ml.notifications.AuditMessage; +import org.elasticsearch.xpack.core.ml.notifications.AnomalyDetectionAuditMessage; import org.elasticsearch.xpack.core.ml.utils.ExponentialAverageCalculationContext; import java.io.IOException; @@ -1122,10 +1122,10 @@ public class ElasticsearchMappings { .startObject(Job.ID.getPreferredName()) .field(TYPE, KEYWORD) .endObject() - .startObject(AuditMessage.LEVEL.getPreferredName()) + .startObject(AnomalyDetectionAuditMessage.LEVEL.getPreferredName()) .field(TYPE, KEYWORD) .endObject() - .startObject(AuditMessage.MESSAGE.getPreferredName()) + .startObject(AnomalyDetectionAuditMessage.MESSAGE.getPreferredName()) .field(TYPE, TEXT) .startObject(FIELDS) .startObject(RAW) @@ -1133,10 +1133,10 @@ public class ElasticsearchMappings { .endObject() .endObject() .endObject() - .startObject(AuditMessage.TIMESTAMP.getPreferredName()) + .startObject(AnomalyDetectionAuditMessage.TIMESTAMP.getPreferredName()) .field(TYPE, DATE) .endObject() - .startObject(AuditMessage.NODE_NAME.getPreferredName()) + .startObject(AnomalyDetectionAuditMessage.NODE_NAME.getPreferredName()) .field(TYPE, KEYWORD) .endObject() .endObject() diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AuditMessage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AnomalyDetectionAuditMessage.java similarity index 68% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AuditMessage.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AnomalyDetectionAuditMessage.java index 6daa4223afd..3c00a1f032b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AuditMessage.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AnomalyDetectionAuditMessage.java @@ -18,12 +18,12 @@ import java.util.Date; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; -public class AuditMessage extends AbstractAuditMessage { +public class AnomalyDetectionAuditMessage extends AbstractAuditMessage { - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "ml_audit_message", true, - a -> new AuditMessage((String)a[0], (String)a[1], (Level)a[2], (Date)a[3], (String)a[4])); + a -> new AnomalyDetectionAuditMessage((String)a[0], (String)a[1], (Level)a[2], (Date)a[3], (String)a[4])); static { PARSER.declareString(optionalConstructorArg(), Job.ID); @@ -41,11 +41,11 @@ public class AuditMessage extends AbstractAuditMessage { PARSER.declareString(optionalConstructorArg(), NODE_NAME); } - public AuditMessage(String resourceId, String message, Level level, String nodeName) { + public AnomalyDetectionAuditMessage(String resourceId, String message, Level level, String nodeName) { super(resourceId, message, level, nodeName); } - protected AuditMessage(String resourceId, String message, Level level, Date timestamp, String nodeName) { + protected AnomalyDetectionAuditMessage(String resourceId, String message, Level level, Date timestamp, String nodeName) { super(resourceId, message, level, timestamp, nodeName); } @@ -54,11 +54,11 @@ public class AuditMessage extends AbstractAuditMessage { return Job.ID.getPreferredName(); } - public static AbstractBuilder builder() { - return new AbstractBuilder() { + public static AbstractBuilder builder() { + return new AbstractBuilder() { @Override - protected AuditMessage newMessage(Level level, String resourceId, String message, String nodeName) { - return new AuditMessage(resourceId, message, level, nodeName); + protected AnomalyDetectionAuditMessage newMessage(Level level, String resourceId, String message, String nodeName) { + return new AnomalyDetectionAuditMessage(resourceId, message, level, nodeName); } }; } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AuditorTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java similarity index 86% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AuditorTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java index 1389af62dc7..a3c168d391d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AuditorTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java @@ -28,14 +28,15 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class AuditorTests extends ESTestCase { - private Client client; - private ArgumentCaptor indexRequestCaptor; +public class AbstractAuditorTests extends ESTestCase { + + private static final String TEST_NODE_NAME = "node_1"; private static final String TEST_ORIGIN = "test_origin"; private static final String TEST_INDEX = "test_index"; - private static final AbstractAuditMessage.AbstractBuilder builder = - AbstractAuditMessageTests.TestAuditMessage.newBuilder(); - + + private Client client; + private ArgumentCaptor indexRequestCaptor; + @Before public void setUpMocks() { client = mock(Client.class); @@ -47,7 +48,7 @@ public class AuditorTests extends ESTestCase { } public void testInfo() throws IOException { - Auditor auditor = new Auditor<>(client, "node_1", TEST_INDEX, TEST_ORIGIN, builder); + AbstractAuditor auditor = new TestAuditor(client); auditor.info("foo", "Here is my info"); verify(client).index(indexRequestCaptor.capture(), any()); @@ -61,7 +62,7 @@ public class AuditorTests extends ESTestCase { } public void testWarning() throws IOException { - Auditor auditor = new Auditor<>(client, "node_1", TEST_INDEX, TEST_ORIGIN, builder); + AbstractAuditor auditor = new TestAuditor(client); auditor.warning("bar", "Here is my warning"); verify(client).index(indexRequestCaptor.capture(), any()); @@ -75,7 +76,7 @@ public class AuditorTests extends ESTestCase { } public void testError() throws IOException { - Auditor auditor = new Auditor<>(client, "node_1", TEST_INDEX, TEST_ORIGIN, builder); + AbstractAuditor auditor = new TestAuditor(client); auditor.error("foobar", "Here is my error"); verify(client).index(indexRequestCaptor.capture(), any()); @@ -93,4 +94,10 @@ public class AuditorTests extends ESTestCase { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, msg.streamInput()); return AbstractAuditMessageTests.TestAuditMessage.PARSER.apply(parser, null); } + + static class TestAuditor extends AbstractAuditor { + TestAuditor(Client client) { + super(client, TEST_NODE_NAME, TEST_INDEX, TEST_ORIGIN, AbstractAuditMessageTests.TestAuditMessage.newBuilder()); + } + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/LevelTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/LevelTests.java index a66d230b467..78952c6d75c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/LevelTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/LevelTests.java @@ -12,18 +12,18 @@ import static org.hamcrest.Matchers.equalTo; public class LevelTests extends ESTestCase { public void testFromString() { - assertEquals(Level.INFO, Level.fromString("info")); - assertEquals(Level.INFO, Level.fromString("INFO")); - assertEquals(Level.WARNING, Level.fromString("warning")); - assertEquals(Level.WARNING, Level.fromString("WARNING")); - assertEquals(Level.ERROR, Level.fromString("error")); - assertEquals(Level.ERROR, Level.fromString("ERROR")); + assertThat(Level.fromString("info"), equalTo(Level.INFO)); + assertThat(Level.fromString("INFO"), equalTo(Level.INFO)); + assertThat(Level.fromString("warning"), equalTo(Level.WARNING)); + assertThat(Level.fromString("WARNING"), equalTo(Level.WARNING)); + assertThat(Level.fromString("error"), equalTo(Level.ERROR)); + assertThat(Level.fromString("ERROR"), equalTo(Level.ERROR)); } public void testToString() { - assertEquals("info", Level.INFO.toString()); - assertEquals("warning", Level.WARNING.toString()); - assertEquals("error", Level.ERROR.toString()); + assertThat(Level.INFO.toString(), equalTo("info")); + assertThat(Level.WARNING.toString(), equalTo("warning")); + assertThat(Level.ERROR.toString(), equalTo("error")); } public void testValidOrdinals() { diff --git a/x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameAuditorIT.java b/x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameAuditorIT.java index 0877fe22c78..b7aaa5c567c 100644 --- a/x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameAuditorIT.java +++ b/x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameAuditorIT.java @@ -68,7 +68,7 @@ public class DataFrameAuditorIT extends DataFrameRestTestCase { assertBusy(() -> { assertTrue(indexExists(DataFrameInternalIndex.AUDIT_INDEX)); }); - // Since calls to write the Auditor are sent and forgot (async) we could have returned from the start, + // Since calls to write the AbstractAuditor are sent and forgot (async) we could have returned from the start, // finished the job (as this is a very short DF job), all without the audit being fully written. assertBusy(() -> { refreshIndex(DataFrameInternalIndex.AUDIT_INDEX); diff --git a/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/notifications/DataFrameAuditor.java b/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/notifications/DataFrameAuditor.java index e02954a280b..e756182f9c5 100644 --- a/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/notifications/DataFrameAuditor.java +++ b/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/notifications/DataFrameAuditor.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.dataframe.notifications; import org.elasticsearch.client.Client; -import org.elasticsearch.xpack.core.common.notifications.Auditor; +import org.elasticsearch.xpack.core.common.notifications.AbstractAuditor; import org.elasticsearch.xpack.core.dataframe.notifications.DataFrameAuditMessage; import org.elasticsearch.xpack.dataframe.persistence.DataFrameInternalIndex; @@ -15,7 +15,7 @@ import static org.elasticsearch.xpack.core.ClientHelper.DATA_FRAME_ORIGIN; /** * DataFrameAuditor class that abstracts away generic templating for easier injection */ -public class DataFrameAuditor extends Auditor { +public class DataFrameAuditor extends AbstractAuditor { public DataFrameAuditor(Client client, String nodeName) { super(client, nodeName, DataFrameInternalIndex.AUDIT_INDEX, DATA_FRAME_ORIGIN, DataFrameAuditMessage.builder()); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 93968015f2d..c04cb0c73a8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -215,7 +215,7 @@ import org.elasticsearch.xpack.ml.job.process.normalizer.MultiplyingNormalizerPr import org.elasticsearch.xpack.ml.job.process.normalizer.NativeNormalizerProcessFactory; import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerFactory; import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerProcessFactory; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.process.MlMemoryTracker; import org.elasticsearch.xpack.ml.process.NativeController; import org.elasticsearch.xpack.ml.process.NativeControllerHolder; @@ -469,7 +469,7 @@ public class MachineLearning extends Plugin implements ActionPlugin, AnalysisPlu return Collections.singletonList(new JobManagerHolder()); } - Auditor auditor = new Auditor(client, clusterService.getNodeName()); + AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client, clusterService.getNodeName()); JobResultsProvider jobResultsProvider = new JobResultsProvider(client, settings); JobResultsPersister jobResultsPersister = new JobResultsPersister(client); JobDataCountsPersister jobDataCountsPersister = new JobDataCountsPersister(client); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlAssignmentNotifier.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlAssignmentNotifier.java index a2c9f6eeaaf..6ce313f9539 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlAssignmentNotifier.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlAssignmentNotifier.java @@ -21,7 +21,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.MlTasks; import org.elasticsearch.xpack.core.ml.action.OpenJobAction; import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.Objects; @@ -29,18 +29,20 @@ import java.util.Objects; public class MlAssignmentNotifier implements ClusterStateListener { private static final Logger logger = LogManager.getLogger(MlAssignmentNotifier.class); - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final MlConfigMigrator mlConfigMigrator; private final ThreadPool threadPool; - MlAssignmentNotifier(Settings settings, Auditor auditor, ThreadPool threadPool, Client client, ClusterService clusterService) { + MlAssignmentNotifier(Settings settings, AnomalyDetectionAuditor auditor, ThreadPool threadPool, Client client, + ClusterService clusterService) { this.auditor = auditor; this.mlConfigMigrator = new MlConfigMigrator(settings, client, clusterService); this.threadPool = threadPool; clusterService.addListener(this); } - MlAssignmentNotifier(Auditor auditor, ThreadPool threadPool, MlConfigMigrator mlConfigMigrator, ClusterService clusterService) { + MlAssignmentNotifier(AnomalyDetectionAuditor auditor, ThreadPool threadPool, MlConfigMigrator mlConfigMigrator, + ClusterService clusterService) { this.auditor = auditor; this.mlConfigMigrator = mlConfigMigrator; this.threadPool = threadPool; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportCloseJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportCloseJobAction.java index 1a8aea05c45..8816807948a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportCloseJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportCloseJobAction.java @@ -37,7 +37,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.ArrayList; import java.util.Collection; @@ -53,14 +53,14 @@ public class TransportCloseJobAction extends TransportTasksAction openJobIds, List closingJobIds, - PersistentTasksCustomMetaData tasks, Auditor auditor) { + static TransportCloseJobAction.WaitForCloseRequest buildWaitForCloseRequest(List openJobIds, + List closingJobIds, + PersistentTasksCustomMetaData tasks, + AnomalyDetectionAuditor auditor) { TransportCloseJobAction.WaitForCloseRequest waitForCloseRequest = new TransportCloseJobAction.WaitForCloseRequest(); for (String jobId : openJobIds) { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java index 36d9802e991..c33dd591a91 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.ml.job.retention.ExpiredModelSnapshotsRemover; import org.elasticsearch.xpack.ml.job.retention.ExpiredResultsRemover; import org.elasticsearch.xpack.ml.job.retention.MlDataRemover; import org.elasticsearch.xpack.ml.job.retention.UnusedStateRemover; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.utils.VolatileCursorIterator; import java.util.Arrays; @@ -54,7 +54,7 @@ public class TransportDeleteExpiredDataAction extends HandledTransportAction listener) { - Auditor auditor = new Auditor(client, clusterService.getNodeName()); + AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client, clusterService.getNodeName()); List dataRemovers = Arrays.asList( new ExpiredResultsRemover(client, auditor), new ExpiredForecastsRemover(client, threadPool), diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java index 5921bbc5c7e..83acc262dda 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobAction.java @@ -70,7 +70,7 @@ import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobDataDeleter; import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.process.MlMemoryTracker; import org.elasticsearch.xpack.ml.utils.MlIndicesUtils; @@ -94,7 +94,7 @@ public class TransportDeleteJobAction extends TransportMasterNodeAction { - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; @Inject public TransportKillProcessAction(TransportService transportService, ClusterService clusterService, ActionFilters actionFilters, - AutodetectProcessManager processManager, Auditor auditor) { + AutodetectProcessManager processManager, AnomalyDetectionAuditor auditor) { super(KillProcessAction.NAME, clusterService, transportService, actionFilters, KillProcessAction.Request::new, KillProcessAction.Response::new, MachineLearning.UTILITY_THREAD_POOL_NAME, processManager); this.auditor = auditor; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java index 5edcf2202a2..45e24419b05 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java @@ -55,7 +55,7 @@ import org.elasticsearch.xpack.ml.datafeed.DatafeedTimingStatsReporter; import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory; import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.io.IOException; import java.util.ArrayList; @@ -81,7 +81,7 @@ public class TransportStartDatafeedAction extends TransportMasterNodeAction deprecationWarnings = new ArrayList<>(); deprecationWarnings.addAll(datafeed.getAggDeprecations(xContentRegistry)); deprecationWarnings.addAll(datafeed.getQueryDeprecations(xContentRegistry)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJob.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJob.java index 8837d3f03f9..85ed2f531f8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJob.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJob.java @@ -35,7 +35,7 @@ import org.elasticsearch.xpack.core.security.user.XPackUser; import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetector; import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorFactory.BucketWithMissingData; import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.io.IOException; import java.io.InputStream; @@ -54,7 +54,7 @@ class DatafeedJob { private static final int NEXT_TASK_DELAY_MS = 100; static final long MISSING_DATA_CHECK_INTERVAL_MS = 900_000; //15 minutes in ms - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final String jobId; private final DataDescription dataDescription; private final long frequencyMs; @@ -76,7 +76,7 @@ class DatafeedJob { DatafeedJob(String jobId, DataDescription dataDescription, long frequencyMs, long queryDelayMs, DataExtractorFactory dataExtractorFactory, DatafeedTimingStatsReporter timingStatsReporter, Client client, - Auditor auditor, Supplier currentTimeSupplier, DelayedDataDetector delayedDataDetector, + AnomalyDetectionAuditor auditor, Supplier currentTimeSupplier, DelayedDataDetector delayedDataDetector, long latestFinalBucketEndTimeMs, long latestRecordTimeMs) { this.jobId = jobId; this.dataDescription = Objects.requireNonNull(dataDescription); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java index a592f410226..728e14f6f4f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java @@ -27,7 +27,7 @@ import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.Collections; import java.util.Objects; @@ -39,16 +39,17 @@ public class DatafeedJobBuilder { private final Client client; private final NamedXContentRegistry xContentRegistry; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final Supplier currentTimeSupplier; private final JobConfigProvider jobConfigProvider; private final JobResultsProvider jobResultsProvider; private final DatafeedConfigProvider datafeedConfigProvider; private final JobResultsPersister jobResultsPersister; - public DatafeedJobBuilder(Client client, NamedXContentRegistry xContentRegistry, Auditor auditor, Supplier currentTimeSupplier, - JobConfigProvider jobConfigProvider, JobResultsProvider jobResultsProvider, - DatafeedConfigProvider datafeedConfigProvider, JobResultsPersister jobResultsPersister) { + public DatafeedJobBuilder(Client client, NamedXContentRegistry xContentRegistry, AnomalyDetectionAuditor auditor, + Supplier currentTimeSupplier, JobConfigProvider jobConfigProvider, + JobResultsProvider jobResultsProvider, DatafeedConfigProvider datafeedConfigProvider, + JobResultsPersister jobResultsPersister) { this.client = client; this.xContentRegistry = Objects.requireNonNull(xContentRegistry); this.auditor = Objects.requireNonNull(auditor); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java index 4425b624a06..a60797562d0 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java @@ -32,7 +32,7 @@ import org.elasticsearch.xpack.core.ml.job.messages.Messages; import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.ml.action.TransportStartDatafeedAction; import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.ArrayList; import java.util.Iterator; @@ -58,7 +58,7 @@ public class DatafeedManager { private final ClusterService clusterService; private final ThreadPool threadPool; private final Supplier currentTimeSupplier; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; // Use allocationId as key instead of datafeed id private final ConcurrentMap runningDatafeedsOnThisNode = new ConcurrentHashMap<>(); private final DatafeedJobBuilder datafeedJobBuilder; @@ -66,7 +66,8 @@ public class DatafeedManager { private final AutodetectProcessManager autodetectProcessManager; public DatafeedManager(ThreadPool threadPool, Client client, ClusterService clusterService, DatafeedJobBuilder datafeedJobBuilder, - Supplier currentTimeSupplier, Auditor auditor, AutodetectProcessManager autodetectProcessManager) { + Supplier currentTimeSupplier, AnomalyDetectionAuditor auditor, + AutodetectProcessManager autodetectProcessManager) { this.client = Objects.requireNonNull(client); this.clusterService = Objects.requireNonNull(clusterService); this.threadPool = threadPool; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/ProblemTracker.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/ProblemTracker.java index 9844631c7b5..69a821d4246 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/ProblemTracker.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/ProblemTracker.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.ml.datafeed; import org.elasticsearch.xpack.core.ml.job.messages.Messages; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.Objects; @@ -26,7 +26,7 @@ class ProblemTracker { private static final int EMPTY_DATA_WARN_COUNT = 10; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final String jobId; private volatile boolean hasProblems; @@ -34,7 +34,7 @@ class ProblemTracker { private volatile String previousProblem; private volatile int emptyDataCount; - ProblemTracker(Auditor auditor, String jobId) { + ProblemTracker(AnomalyDetectionAuditor auditor, String jobId) { this.auditor = Objects.requireNonNull(auditor); this.jobId = Objects.requireNonNull(jobId); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java index 683fbb7c65c..aa7771ac21f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java @@ -57,7 +57,7 @@ import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; import org.elasticsearch.xpack.ml.job.process.autodetect.UpdateParams; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.utils.VoidChainTaskExecutor; import java.io.IOException; @@ -91,7 +91,7 @@ public class JobManager { private final JobResultsProvider jobResultsProvider; private final JobResultsPersister jobResultsPersister; private final ClusterService clusterService; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final Client client; private final ThreadPool threadPool; private final UpdateJobProcessNotifier updateJobProcessNotifier; @@ -104,8 +104,9 @@ public class JobManager { * Create a JobManager */ public JobManager(Environment environment, Settings settings, JobResultsProvider jobResultsProvider, - JobResultsPersister jobResultsPersister, ClusterService clusterService, Auditor auditor, ThreadPool threadPool, - Client client, UpdateJobProcessNotifier updateJobProcessNotifier, NamedXContentRegistry xContentRegistry) { + JobResultsPersister jobResultsPersister, ClusterService clusterService, AnomalyDetectionAuditor auditor, + ThreadPool threadPool, Client client, UpdateJobProcessNotifier updateJobProcessNotifier, + NamedXContentRegistry xContentRegistry) { this.environment = environment; this.jobResultsProvider = Objects.requireNonNull(jobResultsProvider); this.jobResultsPersister = Objects.requireNonNull(jobResultsPersister); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java index 4745228285e..9ef73319811 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java @@ -66,7 +66,7 @@ import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerFactory; import org.elasticsearch.xpack.ml.job.process.normalizer.Renormalizer; import org.elasticsearch.xpack.ml.job.process.normalizer.ScoresUpdater; import org.elasticsearch.xpack.ml.job.process.normalizer.ShortCircuitingRenormalizer; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.process.NativeStorageProvider; import java.io.IOException; @@ -109,12 +109,12 @@ public class AutodetectProcessManager implements ClusterStateListener { private final NamedXContentRegistry xContentRegistry; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private volatile boolean upgradeInProgress; public AutodetectProcessManager(Environment environment, Settings settings, Client client, ThreadPool threadPool, - NamedXContentRegistry xContentRegistry, Auditor auditor, ClusterService clusterService, + NamedXContentRegistry xContentRegistry, AnomalyDetectionAuditor auditor, ClusterService clusterService, JobManager jobManager, JobResultsProvider jobResultsProvider, JobResultsPersister jobResultsPersister, JobDataCountsPersister jobDataCountsPersister, AutodetectProcessFactory autodetectProcessFactory, NormalizerFactory normalizerFactory, NativeStorageProvider nativeStorageProvider) { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java index f596fbc669a..282dfa2c2f9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java @@ -38,7 +38,7 @@ import org.elasticsearch.xpack.ml.job.persistence.TimingStatsReporter; import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcess; import org.elasticsearch.xpack.ml.job.process.normalizer.Renormalizer; import org.elasticsearch.xpack.ml.job.results.AutodetectResult; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.time.Duration; import java.util.Iterator; @@ -74,7 +74,7 @@ public class AutodetectResultProcessor { private static final Logger LOGGER = LogManager.getLogger(AutodetectResultProcessor.class); private final Client client; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; private final String jobId; private final Renormalizer renormalizer; private final JobResultsPersister persister; @@ -96,7 +96,7 @@ public class AutodetectResultProcessor { private volatile ModelSizeStats latestModelSizeStats; public AutodetectResultProcessor(Client client, - Auditor auditor, + AnomalyDetectionAuditor auditor, String jobId, Renormalizer renormalizer, JobResultsPersister persister, @@ -107,7 +107,7 @@ public class AutodetectResultProcessor { } // Visible for testing - AutodetectResultProcessor(Client client, Auditor auditor, String jobId, Renormalizer renormalizer, + AutodetectResultProcessor(Client client, AnomalyDetectionAuditor auditor, String jobId, Renormalizer renormalizer, JobResultsPersister persister, AutodetectProcess autodetectProcess, ModelSizeStats latestModelSizeStats, TimingStats timingStats, FlushListener flushListener) { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java index e24ecfbe8b0..3cdcdff2ed9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeSta import org.elasticsearch.xpack.core.ml.job.results.Forecast; import org.elasticsearch.xpack.core.ml.job.results.ForecastRequestStats; import org.elasticsearch.xpack.core.ml.job.results.Result; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.time.Instant; import java.time.ZoneOffset; @@ -46,9 +46,9 @@ public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover { private static final Logger LOGGER = LogManager.getLogger(ExpiredResultsRemover.class); private final Client client; - private final Auditor auditor; + private final AnomalyDetectionAuditor auditor; - public ExpiredResultsRemover(Client client, Auditor auditor) { + public ExpiredResultsRemover(Client client, AnomalyDetectionAuditor auditor) { super(client); this.client = Objects.requireNonNull(client); this.auditor = Objects.requireNonNull(auditor); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/Auditor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AnomalyDetectionAuditor.java similarity index 59% rename from x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/Auditor.java rename to x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AnomalyDetectionAuditor.java index 25c827829b2..64397893048 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/Auditor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AnomalyDetectionAuditor.java @@ -6,14 +6,15 @@ package org.elasticsearch.xpack.ml.notifications; import org.elasticsearch.client.Client; +import org.elasticsearch.xpack.core.common.notifications.AbstractAuditor; import org.elasticsearch.xpack.core.ml.notifications.AuditorField; -import org.elasticsearch.xpack.core.ml.notifications.AuditMessage; +import org.elasticsearch.xpack.core.ml.notifications.AnomalyDetectionAuditMessage; import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; -public class Auditor extends org.elasticsearch.xpack.core.common.notifications.Auditor { +public class AnomalyDetectionAuditor extends AbstractAuditor { - public Auditor(Client client, String nodeName) { - super(client, nodeName, AuditorField.NOTIFICATIONS_INDEX, ML_ORIGIN, AuditMessage.builder()); + public AnomalyDetectionAuditor(Client client, String nodeName) { + super(client, nodeName, AuditorField.NOTIFICATIONS_INDEX, ML_ORIGIN, AnomalyDetectionAuditMessage.builder()); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java index 3e31c8d564b..e4384138056 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import java.net.InetAddress; @@ -38,7 +38,7 @@ import static org.mockito.Mockito.when; public class MlAssignmentNotifierTests extends ESTestCase { - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private ClusterService clusterService; private ThreadPool threadPool; private MlConfigMigrator configMigrator; @@ -46,7 +46,7 @@ public class MlAssignmentNotifierTests extends ESTestCase { @Before @SuppressWarnings("unchecked") private void setupMocks() { - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); clusterService = mock(ClusterService.class); threadPool = mock(ThreadPool.class); configMigrator = mock(MlConfigMigrator.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java index c4deb22e7ae..61059e08480 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; import org.elasticsearch.xpack.core.ml.job.config.JobState; import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase; import org.junit.Before; @@ -255,14 +255,15 @@ public class TransportCloseJobActionTests extends ESTestCase { addJobTask("closingjob1", null, JobState.CLOSING, tasksBuilder); TransportCloseJobAction.WaitForCloseRequest waitForCloseRequest = - TransportCloseJobAction.buildWaitForCloseRequest(openJobIds, closingJobIds, tasksBuilder.build(), mock(Auditor.class)); + TransportCloseJobAction.buildWaitForCloseRequest( + openJobIds, closingJobIds, tasksBuilder.build(), mock(AnomalyDetectionAuditor.class)); assertEquals(waitForCloseRequest.jobsToFinalize, Arrays.asList("openjob1", "openjob2")); assertEquals(waitForCloseRequest.persistentTaskIds, Arrays.asList("job-openjob1", "job-openjob2", "job-closingjob1")); assertTrue(waitForCloseRequest.hasJobsToWaitFor()); waitForCloseRequest = TransportCloseJobAction.buildWaitForCloseRequest(Collections.emptyList(), Collections.emptyList(), - tasksBuilder.build(), mock(Auditor.class)); + tasksBuilder.build(), mock(AnomalyDetectionAuditor.class)); assertFalse(waitForCloseRequest.hasJobsToWaitFor()); } @@ -275,7 +276,7 @@ public class TransportCloseJobActionTests extends ESTestCase { private TransportCloseJobAction createAction() { return new TransportCloseJobAction(mock(TransportService.class), mock(ThreadPool.class), mock(ActionFilters.class), - clusterService, mock(Client.class), mock(Auditor.class), mock(PersistentTasksService.class), + clusterService, mock(Client.class), mock(AnomalyDetectionAuditor.class), mock(PersistentTasksService.class), jobConfigProvider, datafeedConfigProvider); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java index 2216aa0c391..9a22110dc02 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.JobState; import org.elasticsearch.xpack.ml.datafeed.DatafeedManager; import org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import java.util.Collections; import java.util.Date; @@ -78,7 +78,7 @@ public class TransportStartDatafeedActionTests extends ESTestCase { doReturn(Collections.singletonList("Deprecated Agg")).when(config).getAggDeprecations(any(NamedXContentRegistry.class)); doReturn(Collections.singletonList("Deprecated Query")).when(config).getQueryDeprecations(any(NamedXContentRegistry.class)); - Auditor auditor = mock(Auditor.class); + AnomalyDetectionAuditor auditor = mock(AnomalyDetectionAuditor.class); TransportStartDatafeedAction.auditDeprecations(config, job1, auditor, xContentRegistry()); @@ -93,7 +93,7 @@ public class TransportStartDatafeedActionTests extends ESTestCase { doReturn(Collections.emptyList()).when(config).getAggDeprecations(any(NamedXContentRegistry.class)); doReturn(Collections.emptyList()).when(config).getQueryDeprecations(any(NamedXContentRegistry.class)); - Auditor auditor = mock(Auditor.class); + AnomalyDetectionAuditor auditor = mock(AnomalyDetectionAuditor.class); TransportStartDatafeedAction.auditDeprecations(config, job1, auditor, xContentRegistry()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java index 609b0f8612e..11335236bfb 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider; import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import java.util.Collections; @@ -44,7 +44,7 @@ import static org.mockito.Mockito.when; public class DatafeedJobBuilderTests extends ESTestCase { private Client client; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private Consumer taskHandler; private JobResultsProvider jobResultsProvider; private JobConfigProvider jobConfigProvider; @@ -61,7 +61,7 @@ public class DatafeedJobBuilderTests extends ESTestCase { when(client.threadPool()).thenReturn(threadPool); when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY)); when(client.settings()).thenReturn(Settings.EMPTY); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); taskHandler = mock(Consumer.class); jobResultsPersister = mock(JobResultsPersister.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobTests.java index 7b33a59d048..b7f960cc4b8 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorF import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory; import org.elasticsearch.xpack.core.ml.job.config.DataDescription; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -70,7 +70,7 @@ public class DatafeedJobTests extends ESTestCase { private static final String jobId = "_job_id"; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private DataExtractorFactory dataExtractorFactory; private DataExtractor dataExtractor; private DatafeedTimingStatsReporter timingStatsReporter; @@ -90,7 +90,7 @@ public class DatafeedJobTests extends ESTestCase { @Before @SuppressWarnings("unchecked") public void setup() throws Exception { - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); dataExtractorFactory = mock(DataExtractorFactory.class); dataExtractor = mock(DataExtractor.class); when(dataExtractorFactory.newExtractor(anyLong(), anyLong())).thenReturn(dataExtractor); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java index 4ae2ba4d095..765c70e00ad 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java @@ -37,7 +37,7 @@ import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.ml.action.TransportStartDatafeedAction.DatafeedTask; import org.elasticsearch.xpack.ml.action.TransportStartDatafeedActionTests; import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -71,7 +71,7 @@ public class DatafeedManagerTests extends ESTestCase { private DatafeedJob datafeedJob; private DatafeedManager datafeedManager; private long currentTime = 120000; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private ArgumentCaptor capturedClusterStateListener = ArgumentCaptor.forClass(ClusterStateListener.class); private AtomicBoolean hasOpenAutodetectCommunicator; @@ -97,9 +97,9 @@ public class DatafeedManagerTests extends ESTestCase { DiscoveryNode dNode = mock(DiscoveryNode.class); when(dNode.getName()).thenReturn("this_node_has_a_name"); when(clusterService.localNode()).thenReturn(dNode); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); threadPool = mock(ThreadPool.class); when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY)); ExecutorService executorService = mock(ExecutorService.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/ProblemTrackerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/ProblemTrackerTests.java index 4d3458d8577..bfbd85ca944 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/ProblemTrackerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/ProblemTrackerTests.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.ml.datafeed; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import org.mockito.Mockito; @@ -16,13 +16,13 @@ import static org.mockito.Mockito.verify; public class ProblemTrackerTests extends ESTestCase { - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private ProblemTracker problemTracker; @Before public void setUpTests() { - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); problemTracker = new ProblemTracker(auditor, "foo"); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AnnotationIndexIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AnnotationIndexIT.java index b19266956cb..a797053d013 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AnnotationIndexIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AnnotationIndexIT.java @@ -14,7 +14,7 @@ import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.ml.annotations.AnnotationIndex; import org.elasticsearch.xpack.ml.LocalStateMachineLearning; import org.elasticsearch.xpack.ml.MlSingleNodeTestCase; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import java.util.Collection; @@ -53,7 +53,7 @@ public class AnnotationIndexIT extends MlSingleNodeTestCase { public void testCreatedWhenAfterOtherMlIndex() throws Exception { - Auditor auditor = new Auditor(client(), "node_1"); + AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client(), "node_1"); auditor.info("whatever", "blah"); // Creating a document in the .ml-notifications index should cause .ml-annotations diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java index 976f414f11f..f6ec2fc9b89 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.ml.job.results.AutodetectResult; import org.elasticsearch.xpack.ml.job.results.BucketTests; import org.elasticsearch.xpack.ml.job.results.CategoryDefinitionTests; import org.elasticsearch.xpack.ml.job.results.ModelPlotTests; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.After; import org.junit.Before; @@ -87,7 +87,7 @@ public class AutodetectResultProcessorIT extends MlSingleNodeTestCase { public void createComponents() throws Exception { Settings.Builder builder = Settings.builder() .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueSeconds(1)); - Auditor auditor = new Auditor(client(), "test_node"); + AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client(), "test_node"); jobResultsProvider = new JobResultsProvider(client(), builder.build()); renormalizer = mock(Renormalizer.class); process = mock(AutodetectProcess.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java index 5160cafb0cd..d193a6e155f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java @@ -62,7 +62,7 @@ import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; import org.elasticsearch.xpack.ml.job.persistence.MockClientBuilder; import org.elasticsearch.xpack.ml.job.process.autodetect.UpdateParams; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import org.mockito.ArgumentCaptor; import org.mockito.Matchers; @@ -105,7 +105,7 @@ public class JobManagerTests extends ESTestCase { private ThreadPool threadPool; private JobResultsProvider jobResultsProvider; private JobResultsPersister jobResultsPersister; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private UpdateJobProcessNotifier updateJobProcessNotifier; @Override @@ -126,7 +126,7 @@ public class JobManagerTests extends ESTestCase { jobResultsProvider = mock(JobResultsProvider.class); jobResultsPersister = mock(JobResultsPersister.class); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); updateJobProcessNotifier = mock(UpdateJobProcessNotifier.class); ExecutorService executorService = mock(ExecutorService.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java index 519a81fe7d0..72bdf45a96c 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java @@ -52,7 +52,7 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams; import org.elasticsearch.xpack.ml.job.process.autodetect.params.FlushJobParams; import org.elasticsearch.xpack.ml.job.process.autodetect.params.TimeRange; import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerFactory; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.process.NativeStorageProvider; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -118,7 +118,7 @@ public class AutodetectProcessManagerTests extends ESTestCase { private AutodetectCommunicator autodetectCommunicator; private AutodetectProcessFactory autodetectFactory; private NormalizerFactory normalizerFactory; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private ClusterState clusterState; private ClusterService clusterService; private NativeStorageProvider nativeStorageProvider; @@ -148,7 +148,7 @@ public class AutodetectProcessManagerTests extends ESTestCase { autodetectCommunicator = mock(AutodetectCommunicator.class); autodetectFactory = mock(AutodetectProcessFactory.class); normalizerFactory = mock(NormalizerFactory.class); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); clusterService = mock(ClusterService.class); ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.singleton(MachineLearning.MAX_OPEN_JOBS_PER_NODE)); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java index 586f3c039e2..d76f87b5e54 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java @@ -37,7 +37,7 @@ import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcess; import org.elasticsearch.xpack.ml.job.process.normalizer.Renormalizer; import org.elasticsearch.xpack.ml.job.results.AutodetectResult; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.After; import org.junit.Before; import org.mockito.InOrder; @@ -75,7 +75,7 @@ public class AutodetectResultProcessorTests extends ESTestCase { private ThreadPool threadPool; private Client client; - private Auditor auditor; + private AnomalyDetectionAuditor auditor; private Renormalizer renormalizer; private JobResultsPersister persister; private JobResultsPersister.Builder bulkBuilder; @@ -91,7 +91,7 @@ public class AutodetectResultProcessorTests extends ESTestCase { threadPool = mock(ThreadPool.class); when(client.threadPool()).thenReturn(threadPool); when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY)); - auditor = mock(Auditor.class); + auditor = mock(AnomalyDetectionAuditor.class); renormalizer = mock(Renormalizer.class); persister = mock(JobResultsPersister.class); bulkBuilder = mock(JobResultsPersister.Builder.class); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemoverTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemoverTests.java index 5bca7b36436..9c34c448561 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemoverTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemoverTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.JobTests; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; -import org.elasticsearch.xpack.ml.notifications.Auditor; +import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.junit.Before; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -163,6 +163,6 @@ public class ExpiredResultsRemoverTests extends ESTestCase { } private ExpiredResultsRemover createExpiredResultsRemover() { - return new ExpiredResultsRemover(client, mock(Auditor.class)); + return new ExpiredResultsRemover(client, mock(AnomalyDetectionAuditor.class)); } }