in src/main/java/org/opensearch/ad/model/AnomalyDetector.java [148:242]
public AnomalyDetector(
String detectorId,
Long version,
String name,
String description,
String timeField,
List<String> indices,
List<Feature> features,
QueryBuilder filterQuery,
TimeConfiguration detectionInterval,
TimeConfiguration windowDelay,
Integer shingleSize,
Map<String, Object> uiMetadata,
Integer schemaVersion,
Instant lastUpdateTime,
List<String> categoryFields,
User user,
String resultIndex
) {
if (Strings.isBlank(name)) {
throw new ADValidationException(
CommonErrorMessages.EMPTY_DETECTOR_NAME,
DetectorValidationIssueType.NAME,
ValidationAspect.DETECTOR
);
}
if (Strings.isBlank(timeField)) {
throw new ADValidationException(
CommonErrorMessages.NULL_TIME_FIELD,
DetectorValidationIssueType.TIMEFIELD_FIELD,
ValidationAspect.DETECTOR
);
}
if (indices == null || indices.isEmpty()) {
throw new ADValidationException(
CommonErrorMessages.EMPTY_INDICES,
DetectorValidationIssueType.INDICES,
ValidationAspect.DETECTOR
);
}
if (detectionInterval == null) {
throw new ADValidationException(
CommonErrorMessages.NULL_DETECTION_INTERVAL,
DetectorValidationIssueType.DETECTION_INTERVAL,
ValidationAspect.DETECTOR
);
}
if (invalidShingleSizeRange(shingleSize)) {
throw new ADValidationException(
"Shingle size must be a positive integer no larger than "
+ AnomalyDetectorSettings.MAX_SHINGLE_SIZE
+ ". Got "
+ shingleSize,
DetectorValidationIssueType.SHINGLE_SIZE_FIELD,
ValidationAspect.DETECTOR
);
}
int maxCategoryFields = NumericSetting.maxCategoricalFields();
if (categoryFields != null && categoryFields.size() > maxCategoryFields) {
throw new ADValidationException(
CommonErrorMessages.getTooManyCategoricalFieldErr(maxCategoryFields),
DetectorValidationIssueType.CATEGORY,
ValidationAspect.DETECTOR
);
}
if (((IntervalTimeConfiguration) detectionInterval).getInterval() <= 0) {
throw new ADValidationException(
CommonErrorMessages.INVALID_DETECTION_INTERVAL,
DetectorValidationIssueType.DETECTION_INTERVAL,
ValidationAspect.DETECTOR
);
}
this.detectorId = detectorId;
this.version = version;
this.name = name;
this.description = description;
this.timeField = timeField;
this.indices = indices;
this.featureAttributes = features == null ? ImmutableList.of() : ImmutableList.copyOf(features);
this.filterQuery = filterQuery;
this.detectionInterval = detectionInterval;
this.windowDelay = windowDelay;
this.shingleSize = getShingleSize(shingleSize);
this.uiMetadata = uiMetadata;
this.schemaVersion = schemaVersion;
this.lastUpdateTime = lastUpdateTime;
this.categoryFields = categoryFields;
this.user = user;
this.detectorType = isMultientityDetector(categoryFields) ? MULTI_ENTITY.name() : SINGLE_ENTITY.name();
this.resultIndex = Strings.trimToNull(resultIndex);
String errorMessage = validateResultIndex(this.resultIndex);
if (errorMessage != null) {
throw new ADValidationException(errorMessage, DetectorValidationIssueType.RESULT_INDEX, ValidationAspect.DETECTOR);
}
}