From 2fdf848df51a5aa62093191814efa8125ff4910a Mon Sep 17 00:00:00 2001 From: David Kyle Date: Thu, 1 Dec 2016 10:30:37 +0000 Subject: [PATCH] Add jobid to job response (elastic/elasticsearch#434) * Add jobId to job info responses * Remove getJobId() accessor from job - use getId() Original commit: elastic/x-pack-elasticsearch@faacef121797633212a0a58d1512176e0299357b --- .../xpack/prelert/action/GetJobsAction.java | 56 ++++++++++++------- .../elasticsearch/xpack/prelert/job/Job.java | 13 +---- .../job/manager/AutodetectProcessManager.java | 4 +- .../autodetect/AutodetectCommunicator.java | 2 +- .../NativeAutodetectProcessFactory.java | 2 +- .../job/scheduler/ScheduledJobService.java | 8 +-- .../action/GetJobActionResponseTests.java | 2 +- .../prelert/job/manager/JobManagerTests.java | 2 +- 8 files changed, 48 insertions(+), 41 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java index 7e4b4ffbf65..be7c8536aeb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java @@ -62,6 +62,12 @@ public class GetJobsAction extends Action(Collections.singletonList(jobInfo), 1, Job.RESULTS_FIELD); } else { @@ -483,11 +500,12 @@ public class GetJobsAction extends Action jobInfoList = new ArrayList<>(); for (Job job : jobsPage.results()) { Job jobConfig = request.config() ? job : null; - DataCounts dataCounts = readDataCounts(request.dataCounts(), job.getJobId()); - ModelSizeStats modelSizeStats = readModelSizeStats(request.modelSizeStats(), job.getJobId()); - SchedulerState schedulerStatus = readSchedulerState(request.schedulerStatus(), job.getJobId()); - JobStatus jobStatus = readJobStatus(request.status(), job.getJobId()); - Response.JobInfo jobInfo = new Response.JobInfo(jobConfig, dataCounts, modelSizeStats, schedulerStatus, jobStatus); + DataCounts dataCounts = readDataCounts(request.dataCounts(), job.getId()); + ModelSizeStats modelSizeStats = readModelSizeStats(request.modelSizeStats(), job.getId()); + SchedulerState schedulerStatus = readSchedulerState(request.schedulerStatus(), job.getId()); + JobStatus jobStatus = readJobStatus(request.status(), job.getId()); + Response.JobInfo jobInfo = new Response.JobInfo(job.getId(), jobConfig, dataCounts, modelSizeStats, + schedulerStatus, jobStatus); jobInfoList.add(jobInfo); } response = new QueryPage<>(jobInfoList, jobsPage.count(), Job.RESULTS_FIELD); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java index 173cd182f02..8e1a2d6cd47 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java @@ -202,8 +202,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent } /** - * Return the Job Id. This name is preferred when serialising to the REST - * API. + * Return the Job Id. * * @return The job Id string */ @@ -211,16 +210,6 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent return jobId; } - /** - * Return the Job Id. This name is preferred when serialising to the data - * store. - * - * @return The job Id string - */ - public String getJobId() { - return jobId; - } - /** * The job description * diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/manager/AutodetectProcessManager.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/manager/AutodetectProcessManager.java index eed604418de..4f6a1d93450 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/manager/AutodetectProcessManager.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/manager/AutodetectProcessManager.java @@ -131,8 +131,8 @@ public class AutodetectProcessManager extends AbstractComponent implements DataP // A TP with no queue, so that we fail immediately if there are no threads available ExecutorService executorService = threadPool.executor(PrelertPlugin.AUTODETECT_PROCESS_THREAD_POOL_NAME); - UsageReporter usageReporter = new UsageReporter(settings, job.getJobId(), usagePersister); - StatusReporter statusReporter = new StatusReporter(threadPool, settings, job.getJobId(), + UsageReporter usageReporter = new UsageReporter(settings, job.getId(), usagePersister); + StatusReporter statusReporter = new StatusReporter(threadPool, settings, job.getId(), jobProvider.dataCounts(jobId), usageReporter, jobDataCountsPersister); AutoDetectResultProcessor processor = new AutoDetectResultProcessor(new NoOpRenormaliser(), jobResultsPersister, parser); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/AutodetectCommunicator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/AutodetectCommunicator.java index 2741873c34d..e713135cf8d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/AutodetectCommunicator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/AutodetectCommunicator.java @@ -52,7 +52,7 @@ public class AutodetectCommunicator implements Closeable { public AutodetectCommunicator(ExecutorService autoDetectExecutor, Job job, AutodetectProcess process, StatusReporter statusReporter, AutoDetectResultProcessor autoDetectResultProcessor, StateProcessor stateProcessor) { - this.jobId = job.getJobId(); + this.jobId = job.getId(); this.autodetectProcess = process; this.statusReporter = statusReporter; this.autoDetectResultProcessor = autoDetectResultProcessor; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/NativeAutodetectProcessFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/NativeAutodetectProcessFactory.java index 5bb1aefc48e..dab96d3088a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/NativeAutodetectProcessFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/NativeAutodetectProcessFactory.java @@ -76,7 +76,7 @@ public class NativeAutodetectProcessFactory implements AutodetectProcessFactory // until restore it is done before we can accept data. executorService.execute(() -> { try (OutputStream r = processPipes.getRestoreStream().get()) { - jobProvider.restoreStateToStream(job.getJobId(), modelSnapshot, r); + jobProvider.restoreStateToStream(job.getId(), modelSnapshot, r); } catch (Exception e) { LOGGER.error("Error restoring model state for job " + job.getId(), e); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/scheduler/ScheduledJobService.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/scheduler/ScheduledJobService.java index 5b5f107a7b3..a2717888c75 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/scheduler/ScheduledJobService.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/scheduler/ScheduledJobService.java @@ -93,7 +93,7 @@ public class ScheduledJobService extends AbstractComponent { holder.problemTracker.reportAnalysisProblem(e.getCause().getMessage()); } catch (ScheduledJob.EmptyDataCountException e) { if (holder.problemTracker.updateEmptyDataCount(true)) { - requestStopping(job.getJobId()); + requestStopping(job.getId()); } } catch (Exception e) { logger.error("Failed lookback import for job[" + job.getId() + "]", e); @@ -162,13 +162,13 @@ public class ScheduledJobService extends AbstractComponent { } Holder createJobScheduler(Job job) { - Auditor auditor = jobProvider.audit(job.getJobId()); + Auditor auditor = jobProvider.audit(job.getId()); Duration frequency = getFrequencyOrDefault(job); Duration queryDelay = Duration.ofSeconds(job.getSchedulerConfig().getQueryDelay()); DataExtractor dataExtractor = dataExtractorFactory.newExtractor(job); - ScheduledJob scheduledJob = new ScheduledJob(job.getJobId(), frequency.toMillis(), queryDelay.toMillis(), + ScheduledJob scheduledJob = new ScheduledJob(job.getId(), frequency.toMillis(), queryDelay.toMillis(), dataExtractor, dataProcessor, auditor, currentTimeSupplier, getLatestFinalBucketEndTimeMs(job), - getLatestRecordTimestamp(job.getJobId())); + getLatestRecordTimestamp(job.getId())); return new Holder(scheduledJob, new ProblemTracker(() -> auditor)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/action/GetJobActionResponseTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/action/GetJobActionResponseTests.java index ce7d269cf64..2660899b066 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/action/GetJobActionResponseTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/action/GetJobActionResponseTests.java @@ -97,7 +97,7 @@ public class GetJobActionResponseTests extends AbstractStreamableTestCase doc = jobManager.getJob("foo", clusterState); assertTrue(doc.count() > 0); - assertThat(doc.results().get(0).getJobId(), equalTo("foo")); + assertThat(doc.results().get(0).getId(), equalTo("foo")); } public void testFilter() {