diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/ModelState.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/ModelState.java index 6cc9d16b179..ce9787b80f8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/ModelState.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/ModelState.java @@ -12,21 +12,18 @@ import org.elasticsearch.common.ParseField; * The serialised models can get very large and only the C++ code * understands how to decode them, hence there is no reason to load * them into the Java process. - * * However, the Java process DOES set up a mapping on the Elasticsearch * index to tell Elasticsearch not to analyse the model state documents * in any way. (Otherwise Elasticsearch would go into a spin trying to * make sense of such large JSON documents.) */ -public class ModelState -{ +public class ModelState { /** * The type of this class used when persisting the data */ public static final ParseField TYPE = new ParseField("model_state"); - private ModelState() - { + private ModelState() { } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/config/DefaultFrequency.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/config/DefaultFrequency.java index 7fa3c924cbf..c17f077e575 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/config/DefaultFrequency.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/config/DefaultFrequency.java @@ -10,8 +10,7 @@ import java.time.Duration; /** * Factory methods for a sensible default for the scheduler frequency */ -public final class DefaultFrequency -{ +public final class DefaultFrequency { private static final int SECONDS_IN_MINUTE = 60; private static final int TWO_MINS_SECONDS = 2 * SECONDS_IN_MINUTE; private static final int TWENTY_MINS_SECONDS = 20 * SECONDS_IN_MINUTE; @@ -19,42 +18,36 @@ public final class DefaultFrequency private static final Duration TEN_MINUTES = Duration.ofMinutes(10); private static final Duration ONE_HOUR = Duration.ofHours(1); - private DefaultFrequency() - { + private DefaultFrequency() { // Do nothing } /** * Creates a sensible default frequency for a given bucket span. - * + *

* The default depends on the bucket span: *

* * @param bucketSpanSeconds the bucket span in seconds * @return the default frequency */ - public static Duration ofBucketSpan(long bucketSpanSeconds) - { - if (bucketSpanSeconds <= 0) - { + public static Duration ofBucketSpan(long bucketSpanSeconds) { + if (bucketSpanSeconds <= 0) { throw new IllegalArgumentException("Bucket span has to be > 0"); } - if (bucketSpanSeconds <= TWO_MINS_SECONDS) - { + if (bucketSpanSeconds <= TWO_MINS_SECONDS) { return Duration.ofSeconds(SECONDS_IN_MINUTE); } - if (bucketSpanSeconds <= TWENTY_MINS_SECONDS) - { + if (bucketSpanSeconds <= TWENTY_MINS_SECONDS) { return Duration.ofSeconds(bucketSpanSeconds / 2); } - if (bucketSpanSeconds <= HALF_DAY_SECONDS) - { + if (bucketSpanSeconds <= HALF_DAY_SECONDS) { return TEN_MINUTES; } return ONE_HOUR; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/detectionrules/RuleAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/detectionrules/RuleAction.java index 4a01c08be4b..550f16fc399 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/detectionrules/RuleAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/detectionrules/RuleAction.java @@ -7,8 +7,7 @@ package org.elasticsearch.xpack.prelert.job.detectionrules; import java.util.Locale; -public enum RuleAction -{ +public enum RuleAction { FILTER_RESULTS; /** @@ -17,8 +16,7 @@ public enum RuleAction * @param value String representation * @return The rule action */ - public static RuleAction forString(String value) - { + public static RuleAction forString(String value) { return RuleAction.valueOf(value.toUpperCase(Locale.ROOT)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractor.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractor.java index f451bb9f10e..b0e834f5771 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractor.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractor.java @@ -11,8 +11,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Optional; -public interface DataExtractor -{ +public interface DataExtractor { /** * Set-up the extractor for a new search * diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractorFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractorFactory.java index 360712935b7..96988d5211a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractorFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/extraction/DataExtractorFactory.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.prelert.job.extraction; import org.elasticsearch.xpack.prelert.job.Job; -public interface DataExtractorFactory -{ +public interface DataExtractorFactory { DataExtractor newExtractor(Job job); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/messages/Messages.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/messages/Messages.java index e15e26ffef7..27494116d1e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/messages/Messages.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/messages/Messages.java @@ -12,8 +12,7 @@ import java.util.ResourceBundle; /** * Defines the keys for all the message strings */ -public final class Messages -{ +public final class Messages { /** * The base name of the bundle without the .properties extension * or locale @@ -266,12 +265,10 @@ public final class Messages public static final String SUPPORT_BUNDLE_SCRIPT_ERROR = "support.bundle.script.error"; - private Messages() - { + private Messages() { } - public static ResourceBundle load() - { + public static ResourceBundle load() { return ResourceBundle.getBundle(Messages.BUNDLE_NAME, Locale.getDefault()); } @@ -280,8 +277,7 @@ public final class Messages * * @param key Must be one of the statics defined in this file] */ - public static String getMessage(String key) - { + public static String getMessage(String key) { return load().getString(key); } @@ -291,8 +287,7 @@ public final class Messages * @param key the key for the message * @param args MessageFormat arguments. See {@linkplain MessageFormat#format(Object)}] */ - public static String getMessage(String key, Object...args) - { + public static String getMessage(String key, Object...args) { return new MessageFormat(load().getString(key), Locale.ROOT).format(args); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BatchedDocumentsIterator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BatchedDocumentsIterator.java index 933c881a680..fc24531673f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BatchedDocumentsIterator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BatchedDocumentsIterator.java @@ -12,8 +12,7 @@ import java.util.NoSuchElementException; * An iterator useful to fetch a big number of documents of type T * and iterate through them in batches. */ -public interface BatchedDocumentsIterator -{ +public interface BatchedDocumentsIterator { /** * Query documents whose timestamp is within the given time range * diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedInfluencersIterator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedInfluencersIterator.java index 72f84fec43d..087a5ebdea2 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedInfluencersIterator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedInfluencersIterator.java @@ -17,17 +17,14 @@ import java.io.IOException; import org.elasticsearch.xpack.prelert.job.results.Influencer; -class ElasticsearchBatchedInfluencersIterator extends ElasticsearchBatchedResultsIterator -{ +class ElasticsearchBatchedInfluencersIterator extends ElasticsearchBatchedResultsIterator { public ElasticsearchBatchedInfluencersIterator(Client client, String jobId, - ParseFieldMatcher parserFieldMatcher) - { + ParseFieldMatcher parserFieldMatcher) { super(client, jobId, Influencer.RESULT_TYPE_VALUE, parserFieldMatcher); } @Override - protected Influencer map(SearchHit hit) - { + protected Influencer map(SearchHit hit) { BytesReference source = hit.getSourceRef(); XContentParser parser; try { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelDebugOutputIterator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelDebugOutputIterator.java index 2688b97ffc8..e9a2dd1b8d7 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelDebugOutputIterator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelDebugOutputIterator.java @@ -16,22 +16,18 @@ import org.elasticsearch.xpack.prelert.job.results.ModelDebugOutput; import java.io.IOException; -class ElasticsearchBatchedModelDebugOutputIterator extends ElasticsearchBatchedDocumentsIterator -{ - public ElasticsearchBatchedModelDebugOutputIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) - { +class ElasticsearchBatchedModelDebugOutputIterator extends ElasticsearchBatchedDocumentsIterator { + public ElasticsearchBatchedModelDebugOutputIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) { super(client, JobResultsPersister.getJobIndexName(jobId), parserFieldMatcher); } @Override - protected String getType() - { + protected String getType() { return ModelDebugOutput.TYPE.getPreferredName(); } @Override - protected ModelDebugOutput map(SearchHit hit) - { + protected ModelDebugOutput map(SearchHit hit) { BytesReference source = hit.getSourceRef(); XContentParser parser; try { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSizeStatsIterator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSizeStatsIterator.java index a9b758bfde2..5bbb7add070 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSizeStatsIterator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSizeStatsIterator.java @@ -17,22 +17,18 @@ import java.io.IOException; import org.elasticsearch.xpack.prelert.job.ModelSizeStats; -public class ElasticsearchBatchedModelSizeStatsIterator extends ElasticsearchBatchedDocumentsIterator -{ - public ElasticsearchBatchedModelSizeStatsIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) - { +public class ElasticsearchBatchedModelSizeStatsIterator extends ElasticsearchBatchedDocumentsIterator { + public ElasticsearchBatchedModelSizeStatsIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) { super(client, JobResultsPersister.getJobIndexName(jobId), parserFieldMatcher); } @Override - protected String getType() - { + protected String getType() { return ModelSizeStats.TYPE.getPreferredName(); } @Override - protected ModelSizeStats map(SearchHit hit) - { + protected ModelSizeStats map(SearchHit hit) { BytesReference source = hit.getSourceRef(); XContentParser parser; try { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSnapshotIterator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSnapshotIterator.java index fd3151d0a36..a689aaf8b79 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSnapshotIterator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedModelSnapshotIterator.java @@ -17,22 +17,18 @@ import java.io.IOException; import org.elasticsearch.xpack.prelert.job.ModelSnapshot; -class ElasticsearchBatchedModelSnapshotIterator extends ElasticsearchBatchedDocumentsIterator -{ - public ElasticsearchBatchedModelSnapshotIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) - { +class ElasticsearchBatchedModelSnapshotIterator extends ElasticsearchBatchedDocumentsIterator { + public ElasticsearchBatchedModelSnapshotIterator(Client client, String jobId, ParseFieldMatcher parserFieldMatcher) { super(client, JobResultsPersister.getJobIndexName(jobId), parserFieldMatcher); } @Override - protected String getType() - { + protected String getType() { return ModelSnapshot.TYPE.getPreferredName(); } @Override - protected ModelSnapshot map(SearchHit hit) - { + protected ModelSnapshot map(SearchHit hit) { BytesReference source = hit.getSourceRef(); XContentParser parser; try { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchDotNotationReverser.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchDotNotationReverser.java index cd99f0a31aa..a119f011b44 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchDotNotationReverser.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchDotNotationReverser.java @@ -16,15 +16,13 @@ import org.elasticsearch.xpack.prelert.job.results.ReservedFieldNames; * Interprets field names containing dots as nested JSON structures. * This matches what Elasticsearch does. */ -class ElasticsearchDotNotationReverser -{ +class ElasticsearchDotNotationReverser { private static final char DOT = '.'; private static final Pattern DOT_PATTERN = Pattern.compile("\\."); private final Map resultsMap; - public ElasticsearchDotNotationReverser() - { + public ElasticsearchDotNotationReverser() { resultsMap = new TreeMap<>(); } @@ -33,6 +31,7 @@ class ElasticsearchDotNotationReverser // results are only strings, so it's not "minimum viable product" right // now. Hence this method only takes fieldValue as a String and there are // no overloads. + /** * Given a field name and value, convert it to a map representation of the * (potentially nested) JSON structure Elasticsearch would use to store it. @@ -41,18 +40,14 @@ class ElasticsearchDotNotationReverser * foo.bar = y goes to { "foo" : { "bar" : "y" } } */ @SuppressWarnings("unchecked") - public void add(String fieldName, String fieldValue) - { - if (fieldName == null || fieldValue == null) - { + public void add(String fieldName, String fieldValue) { + if (fieldName == null || fieldValue == null) { return; } // Minimise processing in the simple case of no dots in the field name. - if (fieldName.indexOf(DOT) == -1) - { - if (ReservedFieldNames.RESERVED_FIELD_NAMES.contains(fieldName)) - { + if (fieldName.indexOf(DOT) == -1) { + if (ReservedFieldNames.RESERVED_FIELD_NAMES.contains(fieldName)) { return; } resultsMap.put(fieldName, fieldValue); @@ -63,39 +58,27 @@ class ElasticsearchDotNotationReverser // If any segment created by the split is a reserved word then ignore // the whole field. - for (String segment : segments) - { - if (ReservedFieldNames.RESERVED_FIELD_NAMES.contains(segment)) - { + for (String segment : segments) { + if (ReservedFieldNames.RESERVED_FIELD_NAMES.contains(segment)) { return; } } Map layerMap = resultsMap; - for (int i = 0; i < segments.length; ++i) - { + for (int i = 0; i < segments.length; ++i) { String segment = segments[i]; - if (i == segments.length - 1) - { + if (i == segments.length - 1) { layerMap.put(segment, fieldValue); - } - else - { + } else { Object existingLayerValue = layerMap.get(segment); - if (existingLayerValue == null) - { + if (existingLayerValue == null) { Map nextLayerMap = new TreeMap<>(); layerMap.put(segment, nextLayerMap); layerMap = nextLayerMap; - } - else - { - if (existingLayerValue instanceof Map) - { - layerMap = (Map)existingLayerValue; - } - else - { + } else { + if (existingLayerValue instanceof Map) { + layerMap = (Map) existingLayerValue; + } else { // This implies an inconsistency - different additions // imply the same path leads to both an object and a // value. For example: @@ -108,8 +91,7 @@ class ElasticsearchDotNotationReverser } } - public Map getResultsMap() - { + public Map getResultsMap() { return resultsMap; } @@ -117,35 +99,27 @@ class ElasticsearchDotNotationReverser * Mappings for a given hierarchical structure are more complex than the * basic results. */ - public Map getMappingsMap() - { + public Map getMappingsMap() { Map mappingsMap = new TreeMap<>(); recurseMappingsLevel(resultsMap, mappingsMap); return mappingsMap; } @SuppressWarnings("unchecked") - private void recurseMappingsLevel(Map resultsMap, - Map mappingsMap) - { - for (Map.Entry entry : resultsMap.entrySet()) - { + private void recurseMappingsLevel(Map resultsMap, Map mappingsMap) { + for (Map.Entry entry : resultsMap.entrySet()) { Map typeMap = new TreeMap<>(); String name = entry.getKey(); Object value = entry.getValue(); - if (value instanceof Map) - { + if (value instanceof Map) { Map propertiesMap = new TreeMap<>(); - recurseMappingsLevel((Map)value, propertiesMap); + recurseMappingsLevel((Map) value, propertiesMap); - typeMap.put(ElasticsearchMappings.TYPE, - ElasticsearchMappings.OBJECT); + typeMap.put(ElasticsearchMappings.TYPE, ElasticsearchMappings.OBJECT); typeMap.put(ElasticsearchMappings.PROPERTIES, propertiesMap); mappingsMap.put(name, typeMap); - } - else - { + } else { String fieldType = value.getClass().getSimpleName().toLowerCase(Locale.ROOT); if ("string".equals(fieldType)) { fieldType = "keyword"; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java index 532abaf2cf8..db96c3cddf9 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java @@ -443,8 +443,7 @@ public class ElasticsearchJobProvider implements JobProvider { private List partitionMaxNormalisedProbabilities(String jobId, Object epochStart, Object epochEnd, String partitionFieldValue) - throws ResourceNotFoundException - { + throws ResourceNotFoundException { QueryBuilder timeRangeQuery = new ResultsFilterBuilder() .timeRange(ElasticsearchMappings.ES_TIMESTAMP, epochStart, epochEnd) .build(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchScripts.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchScripts.java index e3881ca88f5..b7bf98c4207 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchScripts.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchScripts.java @@ -37,21 +37,18 @@ public final class ElasticsearchScripts { public static final int UPDATE_JOB_RETRY_COUNT = 3; - private ElasticsearchScripts() - { + private ElasticsearchScripts() { // Do nothing } - public static Script newUpdateBucketCount(long count) - { + public static Script newUpdateBucketCount(long count) { Map scriptParams = new HashMap<>(); scriptParams.put(COUNT_PARAM, count); return new Script(ScriptType.INLINE, PAINLESS, UPDATE_BUCKET_COUNT, scriptParams); } public static Script newUpdateUsage(long additionalBytes, long additionalFields, - long additionalRecords) - { + long additionalRecords) { Map scriptParams = new HashMap<>(); scriptParams.put(BYTES_PARAM, additionalBytes); scriptParams.put(FIELD_COUNT_PARAM, additionalFields); @@ -59,8 +56,7 @@ public final class ElasticsearchScripts { return new Script(ScriptType.INLINE, PAINLESS, UPDATE_USAGE, scriptParams); } - public static Script updateProcessingTime(Long processingTimeMs) - { + public static Script updateProcessingTime(Long processingTimeMs) { Map scriptParams = new HashMap<>(); scriptParams.put(PROCESSING_TIME_PARAM, processingTimeMs); return new Script(ScriptType.INLINE, PAINLESS, UPDATE_AVERAGE_PROCESSING_TIME, scriptParams); @@ -111,7 +107,7 @@ public final class ElasticsearchScripts { * @return {@code} true if successful, {@code} false otherwise */ public static boolean upsertViaScript(Client client, String index, String type, String docId, Script script, - Map upsertMap) { + Map upsertMap) { try { client.prepareUpdate(index, type, docId) .setScript(script) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobDataDeleterFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobDataDeleterFactory.java index b3a8eb7aff4..1bf8c9e2ad6 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobDataDeleterFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobDataDeleterFactory.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.prelert.job.persistence; -public interface JobDataDeleterFactory -{ +public interface JobDataDeleterFactory { JobDataDeleter newDeleter(String jobId); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobProviderFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobProviderFactory.java index a49d63269e0..27855cff837 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobProviderFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobProviderFactory.java @@ -10,8 +10,7 @@ package org.elasticsearch.xpack.prelert.job.persistence; * This may create a new JobProvider or return an existing * one if it is thread safe and shareable. */ -public interface JobProviderFactory -{ +public interface JobProviderFactory { /** * Get a {@linkplain JobProvider} */ diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsProvider.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsProvider.java index 6cff79dabb8..edb3adc2dba 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsProvider.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsProvider.java @@ -17,8 +17,7 @@ import org.elasticsearch.xpack.prelert.job.results.ModelDebugOutput; import java.util.Optional; -public interface JobResultsProvider -{ +public interface JobResultsProvider { /** * Search for buckets with the parameters in the {@link BucketsQueryBuilder} * @return QueryPage of Buckets diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/writer/CsvDataToProcessWriter.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/writer/CsvDataToProcessWriter.java index 1a2f970c9b8..167dfd20284 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/writer/CsvDataToProcessWriter.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/process/autodetect/writer/CsvDataToProcessWriter.java @@ -74,8 +74,8 @@ class CsvDataToProcessWriter extends AbstractDataToProcessWriter { try (CsvListReader csvReader = new CsvListReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), csvPref)) { String[] header = csvReader.getHeader(true); - if (header == null) // null if EoF - { + if (header == null) { // null if EoF + return statusReporter.incrementalStats(); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/AnomalyCause.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/AnomalyCause.java index 26a74b66f2b..210cbb8b6d1 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/AnomalyCause.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/AnomalyCause.java @@ -21,8 +21,7 @@ import java.util.Objects; * Anomaly Cause POJO. * Used as a nested level inside population anomaly records. */ -public class AnomalyCause extends ToXContentToBytes implements Writeable -{ +public class AnomalyCause extends ToXContentToBytes implements Writeable { public static final ParseField ANOMALY_CAUSE = new ParseField("anomaly_cause"); /** * Result fields @@ -188,150 +187,121 @@ public class AnomalyCause extends ToXContentToBytes implements Writeable } - public double getProbability() - { + public double getProbability() { return probability; } - public void setProbability(double value) - { + public void setProbability(double value) { probability = value; } - public String getByFieldName() - { + public String getByFieldName() { return byFieldName; } - public void setByFieldName(String value) - { + public void setByFieldName(String value) { byFieldName = value.intern(); } - public String getByFieldValue() - { + public String getByFieldValue() { return byFieldValue; } - public void setByFieldValue(String value) - { + public void setByFieldValue(String value) { byFieldValue = value.intern(); } - public String getCorrelatedByFieldValue() - { + public String getCorrelatedByFieldValue() { return correlatedByFieldValue; } - public void setCorrelatedByFieldValue(String value) - { + public void setCorrelatedByFieldValue(String value) { correlatedByFieldValue = value.intern(); } - public String getPartitionFieldName() - { + public String getPartitionFieldName() { return partitionFieldName; } - public void setPartitionFieldName(String field) - { + public void setPartitionFieldName(String field) { partitionFieldName = field.intern(); } - public String getPartitionFieldValue() - { + public String getPartitionFieldValue() { return partitionFieldValue; } - public void setPartitionFieldValue(String value) - { + public void setPartitionFieldValue(String value) { partitionFieldValue = value.intern(); } - public String getFunction() - { + public String getFunction() { return function; } - public void setFunction(String name) - { + public void setFunction(String name) { function = name.intern(); } - public String getFunctionDescription() - { + public String getFunctionDescription() { return functionDescription; } - public void setFunctionDescription(String functionDescription) - { + public void setFunctionDescription(String functionDescription) { this.functionDescription = functionDescription.intern(); } - public List getTypical() - { + public List getTypical() { return typical; } - public void setTypical(List typical) - { + public void setTypical(List typical) { this.typical = typical; } - public List getActual() - { + public List getActual() { return actual; } - public void setActual(List actual) - { + public void setActual(List actual) { this.actual = actual; } - public String getFieldName() - { + public String getFieldName() { return fieldName; } - public void setFieldName(String field) - { + public void setFieldName(String field) { fieldName = field.intern(); } - public String getOverFieldName() - { + public String getOverFieldName() { return overFieldName; } - public void setOverFieldName(String name) - { + public void setOverFieldName(String name) { overFieldName = name.intern(); } - public String getOverFieldValue() - { + public String getOverFieldValue() { return overFieldValue; } - public void setOverFieldValue(String value) - { + public void setOverFieldValue(String value) { overFieldValue = value.intern(); } - public List getInfluencers() - { + public List getInfluencers() { return influencers; } - public void setInfluencers(List influencers) - { + public void setInfluencers(List influencers) { this.influencers = influencers; } @Override - public int hashCode() - { + public int hashCode() { return Objects.hash(probability, actual, typical, @@ -349,15 +319,12 @@ public class AnomalyCause extends ToXContentToBytes implements Writeable } @Override - public boolean equals(Object other) - { - if (this == other) - { + public boolean equals(Object other) { + if (this == other) { return true; } - if (other instanceof AnomalyCause == false) - { + if (other instanceof AnomalyCause == false) { return false; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/ModelDebugOutput.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/ModelDebugOutput.java index b0317edbc32..9bf2208354b 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/ModelDebugOutput.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/results/ModelDebugOutput.java @@ -27,8 +27,7 @@ import java.util.Objects; * reserved words that are likely to clash with fields in the input data (due to * the restrictions on Elasticsearch mappings). */ -public class ModelDebugOutput extends ToXContentToBytes implements Writeable -{ +public class ModelDebugOutput extends ToXContentToBytes implements Writeable { public static final ParseField TYPE = new ParseField("model_debug_output"); public static final ParseField TIMESTAMP = new ParseField("timestamp"); public static final ParseField PARTITION_FIELD_NAME = new ParseField("partition_field_name"); @@ -169,145 +168,116 @@ public class ModelDebugOutput extends ToXContentToBytes implements Writeable return jobId; } - public String getId() - { + public String getId() { return id; } - public void setId(String id) - { + public void setId(String id) { this.id = id; } - public Date getTimestamp() - { + public Date getTimestamp() { return timestamp; } - public void setTimestamp(Date timestamp) - { + public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } - public String getPartitionFieldName() - { + public String getPartitionFieldName() { return partitionFieldName; } - public void setPartitionFieldName(String partitionFieldName) - { + public void setPartitionFieldName(String partitionFieldName) { this.partitionFieldName = partitionFieldName; } - public String getPartitionFieldValue() - { + public String getPartitionFieldValue() { return partitionFieldValue; } - public void setPartitionFieldValue(String partitionFieldValue) - { + public void setPartitionFieldValue(String partitionFieldValue) { this.partitionFieldValue = partitionFieldValue; } - public String getOverFieldName() - { + public String getOverFieldName() { return overFieldName; } - public void setOverFieldName(String overFieldName) - { + public void setOverFieldName(String overFieldName) { this.overFieldName = overFieldName; } - public String getOverFieldValue() - { + public String getOverFieldValue() { return overFieldValue; } - public void setOverFieldValue(String overFieldValue) - { + public void setOverFieldValue(String overFieldValue) { this.overFieldValue = overFieldValue; } - public String getByFieldName() - { + public String getByFieldName() { return byFieldName; } - public void setByFieldName(String byFieldName) - { + public void setByFieldName(String byFieldName) { this.byFieldName = byFieldName; } - public String getByFieldValue() - { + public String getByFieldValue() { return byFieldValue; } - public void setByFieldValue(String byFieldValue) - { + public void setByFieldValue(String byFieldValue) { this.byFieldValue = byFieldValue; } - public String getDebugFeature() - { + public String getDebugFeature() { return debugFeature; } - public void setDebugFeature(String debugFeature) - { + public void setDebugFeature(String debugFeature) { this.debugFeature = debugFeature; } - public double getDebugLower() - { + public double getDebugLower() { return debugLower; } - public void setDebugLower(double debugLower) - { + public void setDebugLower(double debugLower) { this.debugLower = debugLower; } - public double getDebugUpper() - { + public double getDebugUpper() { return debugUpper; } - public void setDebugUpper(double debugUpper) - { + public void setDebugUpper(double debugUpper) { this.debugUpper = debugUpper; } - public double getDebugMedian() - { + public double getDebugMedian() { return debugMedian; } - public void setDebugMedian(double debugMedian) - { + public void setDebugMedian(double debugMedian) { this.debugMedian = debugMedian; } - public double getActual() - { + public double getActual() { return actual; } - public void setActual(double actual) - { + public void setActual(double actual) { this.actual = actual; } @Override - public boolean equals(Object other) - { - if (this == other) - { + public boolean equals(Object other) { + if (this == other) { return true; } - if (other instanceof ModelDebugOutput == false) - { + if (other instanceof ModelDebugOutput == false) { return false; } // id excluded here as it is generated by the datastore @@ -328,8 +298,7 @@ public class ModelDebugOutput extends ToXContentToBytes implements Writeable } @Override - public int hashCode() - { + public int hashCode() { // id excluded here as it is generated by the datastore return Objects.hash(jobId, timestamp, partitionFieldName, partitionFieldValue, overFieldName, overFieldValue, byFieldName, byFieldValue, diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/ArgumentVerifier.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/ArgumentVerifier.java index 702c47acf54..8be07ee41ef 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/ArgumentVerifier.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/ArgumentVerifier.java @@ -10,7 +10,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.xpack.prelert.job.transform.TransformConfig; @FunctionalInterface -public interface ArgumentVerifier -{ +public interface ArgumentVerifier { void verify(String argument, TransformConfig tc) throws ElasticsearchParseException; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexExtractVerifier.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexExtractVerifier.java index 85b53fb3d91..694937803e6 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexExtractVerifier.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexExtractVerifier.java @@ -12,8 +12,7 @@ import org.elasticsearch.xpack.prelert.job.transform.TransformConfig; import java.util.List; import java.util.regex.Pattern; -public class RegexExtractVerifier implements ArgumentVerifier -{ +public class RegexExtractVerifier implements ArgumentVerifier { @Override public void verify(String arg, TransformConfig tc) { new RegexPatternVerifier().verify(arg, tc); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexPatternVerifier.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexPatternVerifier.java index 6515726dbe9..eabe488e958 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexPatternVerifier.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/RegexPatternVerifier.java @@ -12,8 +12,7 @@ import org.elasticsearch.xpack.prelert.job.transform.TransformConfig; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -public class RegexPatternVerifier implements ArgumentVerifier -{ +public class RegexPatternVerifier implements ArgumentVerifier { @Override public void verify(String arg, TransformConfig tc) throws ElasticsearchParseException { try { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigVerifier.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigVerifier.java index bd5f7efcd1f..506c7929587 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigVerifier.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigVerifier.java @@ -13,10 +13,8 @@ import org.elasticsearch.xpack.prelert.job.transform.TransformType; import java.util.List; -public final class TransformConfigVerifier -{ - private TransformConfigVerifier() - { +public final class TransformConfigVerifier { + private TransformConfigVerifier() { // Hide default constructor } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigsVerifier.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigsVerifier.java index 3bb6b9dff89..dca697811e8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigsVerifier.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/transform/verification/TransformConfigsVerifier.java @@ -14,10 +14,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class TransformConfigsVerifier -{ - private TransformConfigsVerifier() - { +public class TransformConfigsVerifier { + private TransformConfigsVerifier() { } /** @@ -28,24 +26,20 @@ public class TransformConfigsVerifier *
  • Check there are no circular dependencies in the transforms
  • * */ - public static boolean verify(List transforms) throws ElasticsearchParseException - { - for (TransformConfig tr : transforms) - { + public static boolean verify(List transforms) throws ElasticsearchParseException { + for (TransformConfig tr : transforms) { TransformConfigVerifier.verify(tr); } String duplicatedName = outputNamesAreUnique(transforms); - if (duplicatedName != null) - { + if (duplicatedName != null) { String msg = Messages.getMessage(Messages.JOB_CONFIG_TRANSFORM_OUTPUT_NAME_USED_MORE_THAN_ONCE, duplicatedName); throw new IllegalArgumentException(msg); } // Check for circular dependencies int index = checkForCircularDependencies(transforms); - if (index >= 0) - { + if (index >= 0) { TransformConfig tc = transforms.get(index); String msg = Messages.getMessage(Messages.JOB_CONFIG_TRANSFORM_CIRCULAR_DEPENDENCY, tc.type(), tc.getInputs()); throw new IllegalArgumentException(msg); @@ -60,15 +54,11 @@ public class TransformConfigsVerifier * unique or the first duplicate name if there are * duplications */ - private static String outputNamesAreUnique(List transforms) - { + private static String outputNamesAreUnique(List transforms) { Set fields = new HashSet<>(); - for (TransformConfig t : transforms) - { - for (String output : t.getOutputs()) - { - if (fields.contains(output)) - { + for (TransformConfig t : transforms) { + for (String output : t.getOutputs()) { + if (fields.contains(output)) { return output; } fields.add(output); @@ -78,8 +68,6 @@ public class TransformConfigsVerifier return null; } - - /** * Find circular dependencies in the list of transforms. * This might be because a transform's input is its output @@ -92,16 +80,13 @@ public class TransformConfigsVerifier * @return -1 if no circular dependencies else the index of the * transform at the start of the circular chain */ - public static int checkForCircularDependencies(List transforms) - { - for (int i=0; i transforms) { + for (int i=0; i chain = new HashSet(); chain.add(new Integer(i)); TransformConfig tc = transforms.get(i); - if (checkCircularDependenciesRecursive(tc, transforms, chain) == false) - { + if (checkCircularDependenciesRecursive(tc, transforms, chain) == false) { return i; } } @@ -110,23 +95,17 @@ public class TransformConfigsVerifier } - private static boolean checkCircularDependenciesRecursive(TransformConfig transform, - List transforms, - Set chain) - { + private static boolean checkCircularDependenciesRecursive(TransformConfig transform, List transforms, + Set chain) { boolean result = true; - for (int i=0; i Objects of this class are immutable and thread-safe * */ -public class DateTimeFormatterTimestampConverter implements TimestampConverter -{ +public class DateTimeFormatterTimestampConverter implements TimestampConverter { private final DateTimeFormatter formatter; private final boolean hasTimeZone; private final ZoneId defaultZoneId; - private DateTimeFormatterTimestampConverter(DateTimeFormatter dateTimeFormatter, - boolean hasTimeZone, ZoneId defaultTimezone) - { + private DateTimeFormatterTimestampConverter(DateTimeFormatter dateTimeFormatter, boolean hasTimeZone, ZoneId defaultTimezone) { formatter = dateTimeFormatter; this.hasTimeZone = hasTimeZone; defaultZoneId = defaultTimezone; @@ -48,8 +45,7 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter * @throws IllegalArgumentException if the pattern is invalid or cannot produce a full timestamp * (e.g. contains a date but not a time) */ - public static TimestampConverter ofPattern(String pattern) - { + public static TimestampConverter ofPattern(String pattern) { return ofPattern(pattern, ZoneOffset.systemDefault()); } @@ -62,8 +58,7 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter * @throws IllegalArgumentException if the pattern is invalid or cannot produce a full timestamp * (e.g. contains a date but not a time) */ - public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezone) - { + public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezone) { DateTimeFormatter formatter = new DateTimeFormatterBuilder() .parseLenient() .appendPattern(pattern) @@ -71,43 +66,35 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter .toFormatter(); String now = formatter.format(ZonedDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneOffset.UTC)); - try - { + try { TemporalAccessor parsed = formatter.parse(now); boolean hasTimeZone = parsed.isSupported(ChronoField.INSTANT_SECONDS); - if (hasTimeZone) - { + if (hasTimeZone) { Instant.from(parsed); } - else - { + else { LocalDateTime.from(parsed); } return new DateTimeFormatterTimestampConverter(formatter, hasTimeZone, defaultTimezone); } - catch (DateTimeException e) - { + catch (DateTimeException e) { throw new IllegalArgumentException("Timestamp cannot be derived from pattern: " + pattern); } } @Override - public long toEpochSeconds(String timestamp) - { + public long toEpochSeconds(String timestamp) { return toInstant(timestamp).getEpochSecond(); } @Override - public long toEpochMillis(String timestamp) - { + public long toEpochMillis(String timestamp) { return toInstant(timestamp).toEpochMilli(); } - private Instant toInstant(String timestamp) - { + private Instant toInstant(String timestamp) { TemporalAccessor parsed = formatter.parse(timestamp); - if (hasTimeZone) - { + if (hasTimeZone) { return Instant.from(parsed); } return LocalDateTime.from(parsed).atZone(defaultZoneId).toInstant(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtils.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtils.java index cb29b393a97..c947923e393 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtils.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtils.java @@ -27,8 +27,7 @@ public final class TimeUtils { public static long dateStringToEpoch(String date) { try { long epoch = Long.parseLong(date); - if (date.trim().length() <= 10) // seconds - { + if (date.trim().length() <= 10) { // seconds return epoch * 1000; } else { return epoch; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimestampConverter.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimestampConverter.java index 6917fc9961c..56441c931d8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimestampConverter.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/utils/time/TimestampConverter.java @@ -11,8 +11,7 @@ import java.time.format.DateTimeParseException; * A converter that enables conversions of textual timestamps to epoch seconds * or milliseconds according to a given pattern. */ -public interface TimestampConverter -{ +public interface TimestampConverter { /** * Converts the a textual timestamp into an epoch in seconds * diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/scheduler/ProblemTrackerTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/scheduler/ProblemTrackerTests.java index 19e8a31b425..c40289379f5 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/scheduler/ProblemTrackerTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/scheduler/ProblemTrackerTests.java @@ -21,8 +21,7 @@ public class ProblemTrackerTests extends ESTestCase { private ProblemTracker problemTracker; @Before - public void setUpTests() - { + public void setUpTests() { auditor = mock(Auditor.class); problemTracker = new ProblemTracker(() -> auditor); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtilsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtilsTests.java index aa1b0cdf0dd..1526851087f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtilsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/utils/time/TimeUtilsTests.java @@ -7,8 +7,7 @@ package org.elasticsearch.xpack.prelert.utils.time; import org.elasticsearch.test.ESTestCase; -public class TimeUtilsTests extends ESTestCase -{ +public class TimeUtilsTests extends ESTestCase { public void testdateStringToEpoch() { assertEquals(1462096800000L, TimeUtils.dateStringToEpoch("2016-05-01T10:00:00Z")); assertEquals(1462096800333L, TimeUtils.dateStringToEpoch("2016-05-01T10:00:00.333Z"));