Collapsed JobProvider and JobResultsProvider and renamed ElasticsearchJobProvider to JobProvider
Original commit: elastic/x-pack-elasticsearch@05d5969d73
This commit is contained in:
parent
631ff9386a
commit
c8bda6b1d9
|
@ -60,7 +60,7 @@ import org.elasticsearch.xpack.prelert.job.metadata.PrelertInitializationService
|
|||
import org.elasticsearch.xpack.prelert.job.metadata.PrelertMetadata;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataDeleterFactory;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataCountsPersister;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobResultsPersister;
|
||||
import org.elasticsearch.xpack.prelert.job.process.NativeController;
|
||||
import org.elasticsearch.xpack.prelert.job.process.ProcessCtrl;
|
||||
|
@ -148,14 +148,8 @@ public class PrelertPlugin extends Plugin implements ActionPlugin {
|
|||
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
|
||||
SearchRequestParsers searchRequestParsers) {
|
||||
|
||||
// All components get binded in the guice context to the instances returned here
|
||||
// and interfaces are not bound to their concrete classes.
|
||||
// instead of `bind(Interface.class).to(Implementation.class);` this happens:
|
||||
// `bind(Implementation.class).toInstance(INSTANCE);`
|
||||
// For this reason we can't use interfaces in the constructor of transport actions.
|
||||
// This ok for now as we will remove Guice soon
|
||||
JobResultsPersister jobResultsPersister = new JobResultsPersister(settings, client);
|
||||
ElasticsearchJobProvider jobProvider = new ElasticsearchJobProvider(client, 0, parseFieldMatcherSupplier.getParseFieldMatcher());
|
||||
JobProvider jobProvider = new JobProvider(client, 0, parseFieldMatcherSupplier.getParseFieldMatcher());
|
||||
JobDataCountsPersister jobDataCountsPersister = new JobDataCountsPersister(settings, client);
|
||||
|
||||
JobManager jobManager = new JobManager(settings, jobProvider, jobResultsPersister, clusterService);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.prelert.action;
|
||||
|
||||
|
||||
import org.elasticsearch.ResourceNotFoundException;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -30,9 +29,8 @@ import org.elasticsearch.xpack.prelert.job.ModelSnapshot;
|
|||
import org.elasticsearch.xpack.prelert.job.manager.JobManager;
|
||||
import org.elasticsearch.xpack.prelert.job.messages.Messages;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataDeleterFactory;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataDeleter;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataDeleter;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
|
||||
|
||||
|
@ -139,7 +137,7 @@ public class DeleteModelSnapshotAction extends Action<DeleteModelSnapshotAction.
|
|||
@Inject
|
||||
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool,
|
||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
||||
ElasticsearchJobProvider jobProvider, JobManager jobManager, ClusterService clusterService,
|
||||
JobProvider jobProvider, JobManager jobManager, ClusterService clusterService,
|
||||
JobDataDeleterFactory bulkDeleterFactory) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.transport.TransportService;
|
|||
import org.elasticsearch.xpack.prelert.job.Job;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.BucketQueryBuilder;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.BucketsQueryBuilder;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.results.Bucket;
|
||||
|
@ -363,7 +362,7 @@ public class GetBucketsAction extends Action<GetBucketsAction.Request, GetBucket
|
|||
@Inject
|
||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService,
|
||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
||||
ElasticsearchJobProvider jobProvider) {
|
||||
JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.xpack.prelert.job.Job;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.results.CategoryDefinition;
|
||||
|
@ -220,7 +219,7 @@ Action<GetCategoriesDefinitionAction.Request, GetCategoriesDefinitionAction.Resp
|
|||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, ElasticsearchJobProvider jobProvider) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
}
|
||||
|
|
|
@ -29,9 +29,8 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.xpack.prelert.job.Job;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.InfluencersQueryBuilder;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.InfluencersQueryBuilder;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.results.Influencer;
|
||||
import org.elasticsearch.xpack.prelert.job.results.PageParams;
|
||||
|
@ -311,7 +310,7 @@ extends Action<GetInfluencersAction.Request, GetInfluencersAction.Response, GetI
|
|||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, ElasticsearchJobProvider jobProvider) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.elasticsearch.xpack.prelert.job.ModelSizeStats;
|
|||
import org.elasticsearch.xpack.prelert.job.SchedulerState;
|
||||
import org.elasticsearch.xpack.prelert.job.manager.AutodetectProcessManager;
|
||||
import org.elasticsearch.xpack.prelert.job.manager.JobManager;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.results.PageParams;
|
||||
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
|
||||
|
@ -459,12 +459,12 @@ public class GetJobsAction extends Action<GetJobsAction.Request, GetJobsAction.R
|
|||
|
||||
private final JobManager jobManager;
|
||||
private final AutodetectProcessManager processManager;
|
||||
private final ElasticsearchJobProvider jobProvider;
|
||||
private final JobProvider jobProvider;
|
||||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
||||
JobManager jobManager, AutodetectProcessManager processManager, ElasticsearchJobProvider jobProvider) {
|
||||
JobManager jobManager, AutodetectProcessManager processManager, JobProvider jobProvider) {
|
||||
super(settings, GetJobsAction.NAME, transportService, clusterService, threadPool, actionFilters,
|
||||
indexNameExpressionResolver, Request::new);
|
||||
this.jobManager = jobManager;
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.xpack.prelert.job.Job;
|
||||
import org.elasticsearch.xpack.prelert.job.ModelSnapshot;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.results.PageParams;
|
||||
|
@ -310,7 +309,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
|
|||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, ElasticsearchJobProvider jobProvider) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.xpack.prelert.job.Job;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.RecordsQueryBuilder;
|
||||
|
@ -349,7 +348,7 @@ public class GetRecordsAction extends Action<GetRecordsAction.Request, GetRecord
|
|||
@Inject
|
||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService,
|
||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
||||
ElasticsearchJobProvider jobProvider) {
|
||||
JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobProvider = jobProvider;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.elasticsearch.xpack.prelert.job.Job;
|
|||
import org.elasticsearch.xpack.prelert.job.ModelSnapshot;
|
||||
import org.elasticsearch.xpack.prelert.job.manager.JobManager;
|
||||
import org.elasticsearch.xpack.prelert.job.messages.Messages;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -248,11 +248,11 @@ PutModelSnapshotDescriptionAction.RequestBuilder> {
|
|||
public static class TransportAction extends HandledTransportAction<Request, Response> {
|
||||
|
||||
private final JobManager jobManager;
|
||||
private final ElasticsearchJobProvider jobProvider;
|
||||
private final JobProvider jobProvider;
|
||||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobManager jobManager, ElasticsearchJobProvider jobProvider) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobManager jobManager, JobProvider jobProvider) {
|
||||
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
this.jobManager = jobManager;
|
||||
this.jobProvider = jobProvider;
|
||||
|
|
|
@ -44,9 +44,8 @@ import org.elasticsearch.xpack.prelert.job.manager.JobManager;
|
|||
import org.elasticsearch.xpack.prelert.job.messages.Messages;
|
||||
import org.elasticsearch.xpack.prelert.job.metadata.Allocation;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataDeleterFactory;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataCountsPersister;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobDataCountsPersister;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.OldDataRemover;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
|
||||
|
@ -316,7 +315,7 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
|
|||
|
||||
@Inject
|
||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobManager jobManager, ElasticsearchJobProvider jobProvider,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, JobManager jobManager, JobProvider jobProvider,
|
||||
ClusterService clusterService, JobDataDeleterFactory bulkDeleterFactory,
|
||||
JobDataCountsPersister jobDataCountsPersister) {
|
||||
super(settings, NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, Request::new);
|
||||
|
|
|
@ -15,16 +15,16 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
|
||||
public class PrelertInitializationService extends AbstractComponent implements ClusterStateListener {
|
||||
|
||||
private final ThreadPool threadPool;
|
||||
private final ClusterService clusterService;
|
||||
private final ElasticsearchJobProvider jobProvider;
|
||||
private final JobProvider jobProvider;
|
||||
|
||||
public PrelertInitializationService(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
||||
ElasticsearchJobProvider jobProvider) {
|
||||
JobProvider jobProvider) {
|
||||
super(settings);
|
||||
this.threadPool = threadPool;
|
||||
this.clusterService = clusterService;
|
||||
|
@ -55,7 +55,7 @@ public class PrelertInitializationService extends AbstractComponent implements C
|
|||
});
|
||||
});
|
||||
}
|
||||
if (metaData.hasIndex(ElasticsearchJobProvider.PRELERT_USAGE_INDEX) == false) {
|
||||
if (metaData.hasIndex(JobProvider.PRELERT_USAGE_INDEX) == false) {
|
||||
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> {
|
||||
jobProvider.createUsageMeteringIndex((result, error) -> {
|
||||
if (result) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.prelert.job.persistence;
|
||||
|
||||
/**
|
||||
* Get a {@linkplain JobProvider}
|
||||
* This may create a new JobProvider or return an existing
|
||||
* one if it is thread safe and shareable.
|
||||
*/
|
||||
public interface JobProviderFactory {
|
||||
/**
|
||||
* Get a {@linkplain JobProvider}
|
||||
*/
|
||||
JobProvider jobProvider();
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.prelert.job.persistence;
|
||||
|
||||
import org.elasticsearch.ResourceNotFoundException;
|
||||
import org.elasticsearch.xpack.prelert.job.ModelSizeStats;
|
||||
import org.elasticsearch.xpack.prelert.job.ModelSnapshot;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.InfluencersQueryBuilder.InfluencersQuery;
|
||||
import org.elasticsearch.xpack.prelert.job.results.AnomalyRecord;
|
||||
import org.elasticsearch.xpack.prelert.job.results.Bucket;
|
||||
import org.elasticsearch.xpack.prelert.job.results.CategoryDefinition;
|
||||
import org.elasticsearch.xpack.prelert.job.results.Influencer;
|
||||
import org.elasticsearch.xpack.prelert.job.results.ModelDebugOutput;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface JobResultsProvider {
|
||||
/**
|
||||
* Search for buckets with the parameters in the {@link BucketsQueryBuilder}
|
||||
* @return QueryPage of Buckets
|
||||
* @throws ResourceNotFoundException If the job id is no recognised
|
||||
*/
|
||||
QueryPage<Bucket> buckets(String jobId, BucketsQueryBuilder.BucketsQuery query)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* Get the bucket at time <code>timestampMillis</code> from the job.
|
||||
*
|
||||
* @param jobId the job id
|
||||
* @param query The bucket query
|
||||
* @return QueryPage Bucket
|
||||
* @throws ResourceNotFoundException If the job id is not recognised
|
||||
*/
|
||||
QueryPage<Bucket> bucket(String jobId, BucketQueryBuilder.BucketQuery query)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* Returns a {@link BatchedDocumentsIterator} that allows querying
|
||||
* and iterating over a large number of buckets of the given job
|
||||
*
|
||||
* @param jobId the id of the job for which buckets are requested
|
||||
* @return a bucket {@link BatchedDocumentsIterator}
|
||||
*/
|
||||
BatchedDocumentsIterator<Bucket> newBatchedBucketsIterator(String jobId);
|
||||
|
||||
/**
|
||||
* Expand a bucket to include the associated records.
|
||||
*
|
||||
* @param jobId the job id
|
||||
* @param includeInterim Include interim results
|
||||
* @param bucket The bucket to be expanded
|
||||
* @return The number of records added to the bucket
|
||||
*/
|
||||
int expandBucket(String jobId, boolean includeInterim, Bucket bucket);
|
||||
|
||||
/**
|
||||
* Get a page of {@linkplain CategoryDefinition}s for the given <code>jobId</code>.
|
||||
*
|
||||
* @param jobId the job id
|
||||
* @param from Skip the first N categories. This parameter is for paging
|
||||
* @param size Take only this number of categories
|
||||
* @return QueryPage of CategoryDefinition
|
||||
*/
|
||||
QueryPage<CategoryDefinition> categoryDefinitions(String jobId, int from, int size);
|
||||
|
||||
/**
|
||||
* Get the specific CategoryDefinition for the given job and category id.
|
||||
*
|
||||
* @param jobId the job id
|
||||
* @param categoryId Unique id
|
||||
* @return QueryPage CategoryDefinition
|
||||
*/
|
||||
QueryPage<CategoryDefinition> categoryDefinition(String jobId, String categoryId);
|
||||
|
||||
/**
|
||||
* Search for anomaly records with the parameters in the
|
||||
* {@link org.elasticsearch.xpack.prelert.job.persistence.RecordsQueryBuilder.RecordsQuery}
|
||||
* @return QueryPage of AnomalyRecords
|
||||
*/
|
||||
QueryPage<AnomalyRecord> records(String jobId, RecordsQueryBuilder.RecordsQuery query);
|
||||
|
||||
/**
|
||||
* Return a page of influencers for the given job and within the given date
|
||||
* range
|
||||
*
|
||||
* @param jobId
|
||||
* The job ID for which influencers are requested
|
||||
* @param query
|
||||
* the query
|
||||
* @return QueryPage of Influencer
|
||||
*/
|
||||
QueryPage<Influencer> influencers(String jobId, InfluencersQuery query)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* Get the influencer for the given job for id
|
||||
*
|
||||
* @param jobId the job id
|
||||
* @param influencerId The unique influencer Id
|
||||
* @return Optional Influencer
|
||||
*/
|
||||
Optional<Influencer> influencer(String jobId, String influencerId);
|
||||
|
||||
/**
|
||||
* Returns a {@link BatchedDocumentsIterator} that allows querying
|
||||
* and iterating over a large number of influencers of the given job
|
||||
*
|
||||
* @param jobId the id of the job for which influencers are requested
|
||||
* @return an influencer {@link BatchedDocumentsIterator}
|
||||
*/
|
||||
BatchedDocumentsIterator<Influencer> newBatchedInfluencersIterator(String jobId);
|
||||
|
||||
/**
|
||||
* Returns a {@link BatchedDocumentsIterator} that allows querying
|
||||
* and iterating over a number of model snapshots of the given job
|
||||
*
|
||||
* @param jobId the id of the job for which model snapshots are requested
|
||||
* @return a model snapshot {@link BatchedDocumentsIterator}
|
||||
*/
|
||||
BatchedDocumentsIterator<ModelSnapshot> newBatchedModelSnapshotIterator(String jobId);
|
||||
|
||||
/**
|
||||
* Returns a {@link BatchedDocumentsIterator} that allows querying
|
||||
* and iterating over a number of ModelDebugOutputs of the given job
|
||||
*
|
||||
* @param jobId the id of the job for which model snapshots are requested
|
||||
* @return a model snapshot {@link BatchedDocumentsIterator}
|
||||
*/
|
||||
BatchedDocumentsIterator<ModelDebugOutput> newBatchedModelDebugOutputIterator(String jobId);
|
||||
|
||||
/**
|
||||
* Returns a {@link BatchedDocumentsIterator} that allows querying
|
||||
* and iterating over a number of ModelSizeStats of the given job
|
||||
*
|
||||
* @param jobId the id of the job for which model snapshots are requested
|
||||
* @return a model snapshot {@link BatchedDocumentsIterator}
|
||||
*/
|
||||
BatchedDocumentsIterator<ModelSizeStats> newBatchedModelSizeStatsIterator(String jobId);
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.prelert.job.persistence;
|
||||
|
||||
import static org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider.PRELERT_USAGE_INDEX;
|
||||
import static org.elasticsearch.xpack.prelert.job.persistence.JobProvider.PRELERT_USAGE_INDEX;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.transport.LocalTransportAddress;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.ElasticsearchJobProvider;
|
||||
import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class PrelertInitializationServiceTests extends ESTestCase {
|
|||
when(threadPool.executor(ThreadPool.Names.GENERIC)).thenReturn(executorService);
|
||||
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
ElasticsearchJobProvider jobProvider = mock(ElasticsearchJobProvider.class);
|
||||
JobProvider jobProvider = mock(JobProvider.class);
|
||||
PrelertInitializationService initializationService =
|
||||
new PrelertInitializationService(Settings.EMPTY, threadPool, clusterService, jobProvider);
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class PrelertInitializationServiceTests extends ESTestCase {
|
|||
when(threadPool.executor(ThreadPool.Names.GENERIC)).thenReturn(executorService);
|
||||
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
ElasticsearchJobProvider jobProvider = mock(ElasticsearchJobProvider.class);
|
||||
JobProvider jobProvider = mock(JobProvider.class);
|
||||
PrelertInitializationService initializationService =
|
||||
new PrelertInitializationService(Settings.EMPTY, threadPool, clusterService, jobProvider);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class PrelertInitializationServiceTests extends ESTestCase {
|
|||
when(threadPool.executor(ThreadPool.Names.GENERIC)).thenReturn(executorService);
|
||||
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
ElasticsearchJobProvider jobProvider = mock(ElasticsearchJobProvider.class);
|
||||
JobProvider jobProvider = mock(JobProvider.class);
|
||||
PrelertInitializationService initializationService =
|
||||
new PrelertInitializationService(Settings.EMPTY, threadPool, clusterService, jobProvider);
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class PrelertInitializationServiceTests extends ESTestCase {
|
|||
.localNodeId("_node_id")
|
||||
.masterNodeId("_node_id"))
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexMetaData.builder(ElasticsearchJobProvider.PRELERT_USAGE_INDEX).settings(Settings.builder()
|
||||
.put(IndexMetaData.builder(JobProvider.PRELERT_USAGE_INDEX).settings(Settings.builder()
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
|
|
|
@ -56,7 +56,7 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ElasticsearchJobProviderTests extends ESTestCase {
|
||||
public class JobProviderTests extends ESTestCase {
|
||||
private static final String CLUSTER_NAME = "myCluster";
|
||||
private static final String JOB_ID = "foo";
|
||||
private static final String INDEX_NAME = "prelertresults-foo";
|
||||
|
@ -67,10 +67,10 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
public void testGetQuantiles_GivenNoIndexForJob() throws InterruptedException, ExecutionException {
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.throwMissingIndexOnPrepareGet(INDEX_NAME, Quantiles.TYPE.getPreferredName(), Quantiles.QUANTILES_ID);
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
ESTestCase.expectThrows(IndexNotFoundException.class, () -> provider.getQuantiles(JOB_ID));
|
||||
}
|
||||
|
@ -79,10 +79,10 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
GetResponse getResponse = createGetResponse(false, null);
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareGet(INDEX_NAME, Quantiles.TYPE.getPreferredName(), Quantiles.QUANTILES_ID, getResponse);
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
Optional<Quantiles> quantiles = provider.getQuantiles(JOB_ID);
|
||||
|
||||
|
@ -97,10 +97,10 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
GetResponse getResponse = createGetResponse(true, source);
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareGet(INDEX_NAME, Quantiles.TYPE.getPreferredName(), Quantiles.QUANTILES_ID, getResponse);
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
Optional<Quantiles> quantiles = provider.getQuantiles(JOB_ID);
|
||||
|
||||
|
@ -116,10 +116,10 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
GetResponse getResponse = createGetResponse(true, source);
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareGet(INDEX_NAME, Quantiles.TYPE.getPreferredName(), Quantiles.QUANTILES_ID, getResponse);
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
Optional<Quantiles> quantiles = provider.getQuantiles(JOB_ID);
|
||||
|
||||
|
@ -129,13 +129,13 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
|
||||
public void testCreateUsageMetering() throws InterruptedException, ExecutionException {
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, false)
|
||||
.prepareCreate(ElasticsearchJobProvider.PRELERT_USAGE_INDEX)
|
||||
.addClusterStatusYellowResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX);
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, false)
|
||||
.prepareCreate(JobProvider.PRELERT_USAGE_INDEX)
|
||||
.addClusterStatusYellowResponse(JobProvider.PRELERT_USAGE_INDEX);
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
provider.createUsageMeteringIndex((result, error) -> logger.info("result={}", result));
|
||||
clientBuilder.verifyIndexCreated(ElasticsearchJobProvider.PRELERT_USAGE_INDEX);
|
||||
clientBuilder.verifyIndexCreated(JobProvider.PRELERT_USAGE_INDEX);
|
||||
}
|
||||
|
||||
public void testCreateJob() throws InterruptedException, ExecutionException {
|
||||
|
@ -147,7 +147,7 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).createIndexRequest("prelertresults-" + job.getId());
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
AtomicReference<Boolean> resultHolder = new AtomicReference<>();
|
||||
provider.createJobRelatedIndices(job.build(), new ActionListener<Boolean>() {
|
||||
@Override
|
||||
|
@ -169,9 +169,9 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ActionListener<DeleteJobAction.Response> actionListener = mock(ActionListener.class);
|
||||
String jobId = "ThisIsMyJob";
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true);
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true);
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
clientBuilder.resetIndices();
|
||||
clientBuilder.addIndicesExistsResponse("prelertresults-" + jobId, true).addIndicesDeleteResponse("prelertresults-" + jobId, true,
|
||||
false, actionListener);
|
||||
|
@ -189,9 +189,9 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ActionListener<DeleteJobAction.Response> actionListener = mock(ActionListener.class);
|
||||
String jobId = "ThisIsMyJob";
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true);
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true);
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
clientBuilder.resetIndices();
|
||||
clientBuilder.addIndicesExistsResponse("prelertresults-" + jobId, true).addIndicesDeleteResponse("prelertresults-" + jobId, true,
|
||||
true, actionListener);
|
||||
|
@ -221,11 +221,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
int from = 0;
|
||||
int size = 10;
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketsQueryBuilder bq = new BucketsQueryBuilder().from(from).size(size).anomalyScoreThreshold(0.0)
|
||||
.normalizedProbabilityThreshold(1.0);
|
||||
|
@ -256,11 +256,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
int from = 99;
|
||||
int size = 17;
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketsQueryBuilder bq = new BucketsQueryBuilder().from(from).size(size).anomalyScoreThreshold(5.1)
|
||||
.normalizedProbabilityThreshold(10.9).includeInterim(true);
|
||||
|
@ -291,11 +291,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
int from = 99;
|
||||
int size = 17;
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketsQueryBuilder bq = new BucketsQueryBuilder();
|
||||
bq.from(from);
|
||||
|
@ -327,11 +327,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(false, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), 0, 0, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketQueryBuilder bq = new BucketQueryBuilder(Long.toString(timestamp));
|
||||
|
||||
|
@ -354,11 +354,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), 0, 0, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketQueryBuilder bq = new BucketQueryBuilder(Long.toString(now.getTime()));
|
||||
|
||||
|
@ -384,11 +384,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), 0, 0, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
BucketQueryBuilder bq = new BucketQueryBuilder(Long.toString(now.getTime()));
|
||||
|
||||
|
@ -424,11 +424,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
RecordsQueryBuilder rqb = new RecordsQueryBuilder().from(from).size(size).epochStart(String.valueOf(now.getTime()))
|
||||
.epochEnd(String.valueOf(now.getTime())).includeInterim(true).sortField(sortfield).anomalyScoreThreshold(11.1)
|
||||
|
@ -474,11 +474,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
RecordsQueryBuilder rqb = new RecordsQueryBuilder();
|
||||
rqb.from(from);
|
||||
|
@ -531,11 +531,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
QueryPage<AnomalyRecord> recordPage = provider.bucketRecords(jobId, bucket, from, size, true, sortfield, true, "");
|
||||
|
||||
|
@ -569,11 +569,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearchAnySize("prelertresults-" + jobId, Result.TYPE.getPreferredName(), response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
int records = provider.expandBucket(jobId, false, bucket);
|
||||
assertEquals(400L, records);
|
||||
|
@ -600,11 +600,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearchAnySize("prelertresults-" + jobId, Result.TYPE.getPreferredName(), response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
int records = provider.expandBucket(jobId, false, bucket);
|
||||
// This is not realistic, but is an artifact of the fact that the mock
|
||||
|
@ -631,11 +631,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
int from = 0;
|
||||
int size = 10;
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, CategoryDefinition.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
QueryPage<CategoryDefinition> categoryDefinitions = provider.categoryDefinitions(jobId, from, size);
|
||||
assertEquals(1L, categoryDefinitions.count());
|
||||
assertEquals(terms, categoryDefinitions.results().get(0).getTerms());
|
||||
|
@ -655,11 +655,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
GetResponse getResponse = createGetResponse(true, source);
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareGet("prelertresults-" + jobId, CategoryDefinition.TYPE.getPreferredName(), categoryId, getResponse);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
QueryPage<CategoryDefinition> categoryDefinitions = provider.categoryDefinition(jobId, categoryId);
|
||||
assertEquals(1L, categoryDefinitions.count());
|
||||
assertEquals(terms, categoryDefinitions.results().get(0).getTerms());
|
||||
|
@ -695,12 +695,12 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(),
|
||||
from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
InfluencersQuery query = new InfluencersQueryBuilder().from(from).size(size).includeInterim(false).build();
|
||||
QueryPage<Influencer> page = provider.influencers(jobId, query);
|
||||
|
@ -756,12 +756,12 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, Result.TYPE.getPreferredName(), from, size, response,
|
||||
queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
InfluencersQuery query = new InfluencersQueryBuilder().from(from).size(size).start("0").end("0").sortField("sort")
|
||||
.sortDescending(true).anomalyScoreThreshold(0.0).includeInterim(true).build();
|
||||
|
@ -792,10 +792,10 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
String influencerId = "ThisIsAnInfluencerId";
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true);
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
try {
|
||||
provider.influencer(jobId, influencerId);
|
||||
|
@ -833,11 +833,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, ModelSnapshot.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
QueryPage<ModelSnapshot> page = provider.modelSnapshots(jobId, from, size);
|
||||
assertEquals(2L, page.count());
|
||||
|
@ -889,11 +889,11 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
ArgumentCaptor<QueryBuilder> queryBuilder = ArgumentCaptor.forClass(QueryBuilder.class);
|
||||
SearchResponse response = createSearchResponse(true, source);
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareSearch("prelertresults-" + jobId, ModelSnapshot.TYPE.getPreferredName(), from, size, response, queryBuilder);
|
||||
|
||||
Client client = clientBuilder.build();
|
||||
ElasticsearchJobProvider provider = createProvider(client);
|
||||
JobProvider provider = createProvider(client);
|
||||
|
||||
QueryPage<ModelSnapshot> page = provider.modelSnapshots(jobId, from, size, null, null, "sortfield", true, "snappyId",
|
||||
"description1");
|
||||
|
@ -920,9 +920,9 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
|
||||
public void testMergePartitionScoresIntoBucket() throws InterruptedException, ExecutionException {
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME)
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true).addClusterStatusYellowResponse();
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true).addClusterStatusYellowResponse();
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
List<PerPartitionMaxProbabilities> partitionMaxProbs = new ArrayList<>();
|
||||
|
||||
|
@ -976,9 +976,9 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
|
||||
public void testMergePartitionScoresIntoBucket_WithEmptyScoresList() throws InterruptedException, ExecutionException {
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME)
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true).addClusterStatusYellowResponse();
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true).addClusterStatusYellowResponse();
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
List<PerPartitionMaxProbabilities> scores = new ArrayList<>();
|
||||
|
||||
|
@ -1007,13 +1007,13 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
GetResponse modelStateGetResponse2 = createGetResponse(true, modelState);
|
||||
|
||||
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
|
||||
.addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.addIndicesExistsResponse(JobProvider.PRELERT_USAGE_INDEX, true)
|
||||
.prepareGet(INDEX_NAME, CategorizerState.TYPE, "1", categorizerStateGetResponse1)
|
||||
.prepareGet(INDEX_NAME, CategorizerState.TYPE, "2", categorizerStateGetResponse2)
|
||||
.prepareGet(INDEX_NAME, ModelState.TYPE.getPreferredName(), "123_1", modelStateGetResponse1)
|
||||
.prepareGet(INDEX_NAME, ModelState.TYPE.getPreferredName(), "123_2", modelStateGetResponse2);
|
||||
|
||||
ElasticsearchJobProvider provider = createProvider(clientBuilder.build());
|
||||
JobProvider provider = createProvider(clientBuilder.build());
|
||||
|
||||
ModelSnapshot modelSnapshot = new ModelSnapshot(randomAsciiOfLengthBetween(1, 20));
|
||||
modelSnapshot.setSnapshotId("123");
|
||||
|
@ -1036,8 +1036,8 @@ public class ElasticsearchJobProviderTests extends ESTestCase {
|
|||
return b;
|
||||
}
|
||||
|
||||
private ElasticsearchJobProvider createProvider(Client client) {
|
||||
return new ElasticsearchJobProvider(client, 0, ParseFieldMatcher.STRICT);
|
||||
private JobProvider createProvider(Client client) {
|
||||
return new JobProvider(client, 0, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
private static GetResponse createGetResponse(boolean exists, Map<String, Object> source) throws IOException {
|
Loading…
Reference in New Issue