├── .eclipseformat.xml ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── draft-release-notes-config.yml └── workflows │ ├── CD.yml │ ├── CI.yml │ ├── draft-release-notes-workflow.yml │ ├── esad-cli-publish-artifact-workflow.yml │ └── esad-cli-test-and-build-workflow.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── THIRD-PARTY ├── build.gradle ├── cli ├── .gitignore ├── .goreleaser.yml ├── Create.png ├── LICENSE ├── NOTICE ├── README.md ├── Start.png ├── cmd │ ├── cat.go │ ├── create.go │ ├── delete.go │ ├── download.go │ ├── profile.go │ ├── root.go │ ├── start_stop.go │ └── update.go ├── go.mod ├── go.sum ├── internal │ ├── client │ │ ├── config.go │ │ ├── mocks │ │ │ └── mock_client.go │ │ └── request.go │ ├── controller │ │ ├── ad │ │ │ ├── ad.go │ │ │ ├── ad_test.go │ │ │ ├── mocks │ │ │ │ └── mock_ad.go │ │ │ └── testdata │ │ │ │ ├── create_failed_response.json │ │ │ │ ├── create_request.json │ │ │ │ ├── create_response.json │ │ │ │ ├── get_response.json │ │ │ │ └── search_response.json │ │ └── es │ │ │ ├── es.go │ │ │ ├── es_test.go │ │ │ ├── mocks │ │ │ └── mock_es.go │ │ │ └── testdata │ │ │ └── search_result.json │ ├── entity │ │ ├── ad │ │ │ ├── ad.go │ │ │ └── ad_test.go │ │ └── es │ │ │ └── es.go │ ├── gateway │ │ ├── ad │ │ │ ├── ad.go │ │ │ ├── ad_test.go │ │ │ ├── mocks │ │ │ │ └── mock_ad.go │ │ │ └── testdata │ │ │ │ ├── create_result.json │ │ │ │ ├── get_result.json │ │ │ │ └── search_result.json │ │ ├── es │ │ │ ├── es.go │ │ │ ├── es_test.go │ │ │ ├── mocks │ │ │ │ └── mock_es.go │ │ │ └── testdata │ │ │ │ └── search_result.json │ │ └── gateway.go │ ├── handler │ │ └── ad │ │ │ ├── ad.go │ │ │ ├── ad_test.go │ │ │ └── testdata │ │ │ ├── create.json │ │ │ ├── invalid.txt │ │ │ └── update.json │ └── mapper │ │ ├── ad │ │ ├── ad.go │ │ ├── ad_test.go │ │ └── testdata │ │ │ └── search_response.json │ │ └── mapper.go ├── main.go ├── pkg │ └── version.go └── rfc-adcli.md ├── codecov.yml ├── docs ├── entity-priority.pdf └── high-cardinality-rfc.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── release-notes ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.10.0.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.10.1.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.11.0.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.12.0.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.13.0.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.7.0.0.md ├── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.8.0.0.md └── opendistro-for-elasticsearch-anomaly-detection.release-notes-1.9.0.0.md ├── settings.gradle └── src ├── forbidden └── ad-signatures.txt ├── main ├── groovy │ └── io │ │ └── pry │ │ └── gradle │ │ └── offline_dependencies │ │ ├── OfflineDependenciesExtension.groovy │ │ ├── OfflineDependenciesPlugin.groovy │ │ ├── UpdateOfflineRepositoryTask.groovy │ │ ├── Utils.groovy │ │ └── maven │ │ └── PomDependencyModelResolver.groovy ├── java │ └── com │ │ └── amazon │ │ └── opendistroforelasticsearch │ │ └── ad │ │ ├── AbstractProfileRunner.java │ │ ├── AnomalyDetectorJobRunner.java │ │ ├── AnomalyDetectorPlugin.java │ │ ├── AnomalyDetectorProfileRunner.java │ │ ├── AnomalyDetectorRunner.java │ │ ├── CleanState.java │ │ ├── DetectorModelSize.java │ │ ├── EntityModelSize.java │ │ ├── EntityProfileRunner.java │ │ ├── ExpiringState.java │ │ ├── MaintenanceState.java │ │ ├── MemoryTracker.java │ │ ├── Name.java │ │ ├── NodeState.java │ │ ├── NodeStateManager.java │ │ ├── annotation │ │ └── Generated.java │ │ ├── breaker │ │ ├── ADCircuitBreakerService.java │ │ ├── BreakerName.java │ │ ├── CircuitBreaker.java │ │ ├── MemoryCircuitBreaker.java │ │ └── ThresholdCircuitBreaker.java │ │ ├── caching │ │ ├── CacheBuffer.java │ │ ├── CacheProvider.java │ │ ├── DoorKeeper.java │ │ ├── EntityCache.java │ │ ├── PriorityCache.java │ │ └── PriorityTracker.java │ │ ├── cluster │ │ ├── ADClusterEventListener.java │ │ ├── DailyCron.java │ │ ├── HashRing.java │ │ ├── HourlyCron.java │ │ ├── MasterEventListener.java │ │ └── diskcleanup │ │ │ ├── IndexCleanup.java │ │ │ └── ModelCheckpointIndexRetention.java │ │ ├── common │ │ └── exception │ │ │ ├── ADTaskCancelledException.java │ │ │ ├── AnomalyDetectionException.java │ │ │ ├── ClientException.java │ │ │ ├── DuplicateTaskException.java │ │ │ ├── EndRunException.java │ │ │ ├── InternalFailure.java │ │ │ ├── LimitExceededException.java │ │ │ └── ResourceNotFoundException.java │ │ ├── constant │ │ ├── CommonErrorMessages.java │ │ ├── CommonMessageAttributes.java │ │ ├── CommonName.java │ │ └── CommonValue.java │ │ ├── dataprocessor │ │ ├── IntegerSensitiveSingleFeatureLinearUniformInterpolator.java │ │ ├── Interpolator.java │ │ ├── LinearUniformInterpolator.java │ │ └── SingleFeatureLinearUniformInterpolator.java │ │ ├── feature │ │ ├── FeatureManager.java │ │ ├── Features.java │ │ ├── SearchFeatureDao.java │ │ └── SinglePointFeatures.java │ │ ├── indices │ │ ├── ADIndex.java │ │ └── AnomalyDetectionIndices.java │ │ ├── ml │ │ ├── CheckpointDao.java │ │ ├── EntityColdStarter.java │ │ ├── EntityModel.java │ │ ├── HybridThresholdingModel.java │ │ ├── KllFloatsSketchSerDe.java │ │ ├── ModelManager.java │ │ ├── ModelPartitioner.java │ │ ├── ModelState.java │ │ ├── RCFMemoryAwareConcurrentHashmap.java │ │ ├── RcfResult.java │ │ ├── ThresholdingModel.java │ │ ├── ThresholdingResult.java │ │ └── rcf │ │ │ └── CombinedRcfResult.java │ │ ├── model │ │ ├── ADTask.java │ │ ├── ADTaskAction.java │ │ ├── ADTaskProfile.java │ │ ├── ADTaskState.java │ │ ├── ADTaskType.java │ │ ├── AnomalyDetector.java │ │ ├── AnomalyDetectorExecutionInput.java │ │ ├── AnomalyDetectorJob.java │ │ ├── AnomalyDetectorType.java │ │ ├── AnomalyResult.java │ │ ├── DetectionDateRange.java │ │ ├── DetectorInternalState.java │ │ ├── DetectorProfile.java │ │ ├── DetectorProfileName.java │ │ ├── DetectorState.java │ │ ├── Entity.java │ │ ├── EntityAnomalyResult.java │ │ ├── EntityProfile.java │ │ ├── EntityProfileName.java │ │ ├── EntityState.java │ │ ├── Feature.java │ │ ├── FeatureData.java │ │ ├── InitProgressProfile.java │ │ ├── IntervalTimeConfiguration.java │ │ ├── Mergeable.java │ │ ├── ModelProfile.java │ │ └── TimeConfiguration.java │ │ ├── rest │ │ ├── AbstractSearchAction.java │ │ ├── RestAnomalyDetectorJobAction.java │ │ ├── RestDeleteAnomalyDetectorAction.java │ │ ├── RestExecuteAnomalyDetectorAction.java │ │ ├── RestGetAnomalyDetectorAction.java │ │ ├── RestIndexAnomalyDetectorAction.java │ │ ├── RestPreviewAnomalyDetectorAction.java │ │ ├── RestSearchADTasksAction.java │ │ ├── RestSearchAnomalyDetectorAction.java │ │ ├── RestSearchAnomalyDetectorInfoAction.java │ │ ├── RestSearchAnomalyResultAction.java │ │ ├── RestStatsAnomalyDetectorAction.java │ │ └── handler │ │ │ ├── AnomalyDetectorActionHandler.java │ │ │ ├── AnomalyDetectorFunction.java │ │ │ ├── IndexAnomalyDetectorActionHandler.java │ │ │ └── IndexAnomalyDetectorJobActionHandler.java │ │ ├── settings │ │ ├── AnomalyDetectorSettings.java │ │ └── EnabledSetting.java │ │ ├── stats │ │ ├── ADStat.java │ │ ├── ADStats.java │ │ ├── ADStatsResponse.java │ │ ├── InternalStatNames.java │ │ ├── StatNames.java │ │ └── suppliers │ │ │ ├── CounterSupplier.java │ │ │ ├── IndexStatusSupplier.java │ │ │ ├── ModelsOnNodeSupplier.java │ │ │ └── SettableSupplier.java │ │ ├── task │ │ ├── ADBatchTaskCache.java │ │ ├── ADBatchTaskRunner.java │ │ ├── ADTaskCacheManager.java │ │ ├── ADTaskCancellationState.java │ │ └── ADTaskManager.java │ │ ├── transport │ │ ├── ADBatchAnomalyResultAction.java │ │ ├── ADBatchAnomalyResultRequest.java │ │ ├── ADBatchAnomalyResultResponse.java │ │ ├── ADBatchAnomalyResultTransportAction.java │ │ ├── ADBatchTaskRemoteExecutionAction.java │ │ ├── ADBatchTaskRemoteExecutionTransportAction.java │ │ ├── ADCancelTaskAction.java │ │ ├── ADCancelTaskNodeRequest.java │ │ ├── ADCancelTaskNodeResponse.java │ │ ├── ADCancelTaskRequest.java │ │ ├── ADCancelTaskResponse.java │ │ ├── ADCancelTaskTransportAction.java │ │ ├── ADResultBulkAction.java │ │ ├── ADResultBulkRequest.java │ │ ├── ADResultBulkTransportAction.java │ │ ├── ADStatsNodeRequest.java │ │ ├── ADStatsNodeResponse.java │ │ ├── ADStatsNodesAction.java │ │ ├── ADStatsNodesResponse.java │ │ ├── ADStatsNodesTransportAction.java │ │ ├── ADStatsRequest.java │ │ ├── ADTaskProfileAction.java │ │ ├── ADTaskProfileNodeRequest.java │ │ ├── ADTaskProfileNodeResponse.java │ │ ├── ADTaskProfileRequest.java │ │ ├── ADTaskProfileResponse.java │ │ ├── ADTaskProfileTransportAction.java │ │ ├── AnomalyDetectorJobAction.java │ │ ├── AnomalyDetectorJobRequest.java │ │ ├── AnomalyDetectorJobResponse.java │ │ ├── AnomalyDetectorJobTransportAction.java │ │ ├── AnomalyResultAction.java │ │ ├── AnomalyResultRequest.java │ │ ├── AnomalyResultResponse.java │ │ ├── AnomalyResultTransportAction.java │ │ ├── BackPressureRouting.java │ │ ├── CronAction.java │ │ ├── CronNodeRequest.java │ │ ├── CronNodeResponse.java │ │ ├── CronRequest.java │ │ ├── CronResponse.java │ │ ├── CronTransportAction.java │ │ ├── DeleteAnomalyDetectorAction.java │ │ ├── DeleteAnomalyDetectorRequest.java │ │ ├── DeleteAnomalyDetectorTransportAction.java │ │ ├── DeleteModelAction.java │ │ ├── DeleteModelNodeRequest.java │ │ ├── DeleteModelNodeResponse.java │ │ ├── DeleteModelRequest.java │ │ ├── DeleteModelResponse.java │ │ ├── DeleteModelTransportAction.java │ │ ├── EntityProfileAction.java │ │ ├── EntityProfileRequest.java │ │ ├── EntityProfileResponse.java │ │ ├── EntityProfileTransportAction.java │ │ ├── EntityResultAction.java │ │ ├── EntityResultRequest.java │ │ ├── EntityResultTransportAction.java │ │ ├── ForwardADTaskAction.java │ │ ├── ForwardADTaskRequest.java │ │ ├── ForwardADTaskTransportAction.java │ │ ├── GetAnomalyDetectorAction.java │ │ ├── GetAnomalyDetectorRequest.java │ │ ├── GetAnomalyDetectorResponse.java │ │ ├── GetAnomalyDetectorTransportAction.java │ │ ├── IndexAnomalyDetectorAction.java │ │ ├── IndexAnomalyDetectorRequest.java │ │ ├── IndexAnomalyDetectorResponse.java │ │ ├── IndexAnomalyDetectorTransportAction.java │ │ ├── PreviewAnomalyDetectorAction.java │ │ ├── PreviewAnomalyDetectorRequest.java │ │ ├── PreviewAnomalyDetectorResponse.java │ │ ├── PreviewAnomalyDetectorTransportAction.java │ │ ├── ProfileAction.java │ │ ├── ProfileNodeRequest.java │ │ ├── ProfileNodeResponse.java │ │ ├── ProfileRequest.java │ │ ├── ProfileResponse.java │ │ ├── ProfileTransportAction.java │ │ ├── RCFPollingAction.java │ │ ├── RCFPollingRequest.java │ │ ├── RCFPollingResponse.java │ │ ├── RCFPollingTransportAction.java │ │ ├── RCFResultAction.java │ │ ├── RCFResultRequest.java │ │ ├── RCFResultResponse.java │ │ ├── RCFResultTransportAction.java │ │ ├── SearchADTasksAction.java │ │ ├── SearchADTasksTransportAction.java │ │ ├── SearchAnomalyDetectorAction.java │ │ ├── SearchAnomalyDetectorInfoAction.java │ │ ├── SearchAnomalyDetectorInfoRequest.java │ │ ├── SearchAnomalyDetectorInfoResponse.java │ │ ├── SearchAnomalyDetectorInfoTransportAction.java │ │ ├── SearchAnomalyDetectorTransportAction.java │ │ ├── SearchAnomalyResultAction.java │ │ ├── SearchAnomalyResultTransportAction.java │ │ ├── StatsAnomalyDetectorAction.java │ │ ├── StatsAnomalyDetectorResponse.java │ │ ├── StatsAnomalyDetectorTransportAction.java │ │ ├── StopDetectorAction.java │ │ ├── StopDetectorRequest.java │ │ ├── StopDetectorResponse.java │ │ ├── StopDetectorTransportAction.java │ │ ├── ThresholdResultAction.java │ │ ├── ThresholdResultRequest.java │ │ ├── ThresholdResultResponse.java │ │ ├── ThresholdResultTransportAction.java │ │ └── handler │ │ │ ├── ADSearchHandler.java │ │ │ ├── AnomalyIndexHandler.java │ │ │ ├── AnomalyResultBulkIndexHandler.java │ │ │ ├── DetectionStateHandler.java │ │ │ └── MultiEntityResultHandler.java │ │ └── util │ │ ├── BulkUtil.java │ │ ├── ClientUtil.java │ │ ├── DiscoveryNodeFilterer.java │ │ ├── ExceptionUtil.java │ │ ├── IndexUtils.java │ │ ├── MultiResponsesDelegateActionListener.java │ │ ├── ParseUtils.java │ │ ├── RestHandlerUtils.java │ │ ├── Throttler.java │ │ ├── ThrowingConsumer.java │ │ ├── ThrowingConsumerWrapper.java │ │ ├── ThrowingSupplier.java │ │ └── ThrowingSupplierWrapper.java ├── plugin-metadata │ └── plugin-security.policy └── resources │ ├── META-INF │ ├── gradle-plugins │ │ └── io.pry.gradle.offline_dependencies.properties │ └── services │ │ └── com.amazon.opendistroforelasticsearch.jobscheduler.spi.JobSchedulerExtension │ ├── es-plugin.properties │ ├── mappings │ ├── anomaly-detection-state.json │ ├── anomaly-detector-jobs.json │ ├── anomaly-detectors.json │ ├── anomaly-results.json │ └── checkpoint.json │ └── plugin-descriptor.properties └── test ├── java ├── com │ └── amazon │ │ └── opendistroforelasticsearch │ │ └── ad │ │ ├── ADIntegTestCase.java │ │ ├── ADUnitTestCase.java │ │ ├── AbstractADTest.java │ │ ├── AbstractProfileRunnerTests.java │ │ ├── AnomalyDetectorJobRunnerTests.java │ │ ├── AnomalyDetectorProfileRunnerTests.java │ │ ├── AnomalyDetectorRestTestCase.java │ │ ├── EntityProfileRunnerTests.java │ │ ├── HistoricalDetectorIntegTestCase.java │ │ ├── HistoricalDetectorRestTestCase.java │ │ ├── MemoryTrackerTests.java │ │ ├── MultiEntityProfileRunnerTests.java │ │ ├── NodeStateManagerTests.java │ │ ├── NodeStateTests.java │ │ ├── ODFERestTestCase.java │ │ ├── TestHelpers.java │ │ ├── breaker │ │ ├── ADCircuitBreakerServiceTests.java │ │ └── MemoryCircuitBreakerTests.java │ │ ├── caching │ │ ├── CacheBufferTests.java │ │ ├── PriorityCacheTests.java │ │ └── PriorityTrackerTests.java │ │ ├── cluster │ │ ├── ADClusterEventListenerTests.java │ │ ├── DailyCronTests.java │ │ ├── HashRingTests.java │ │ ├── HourlyCronTests.java │ │ ├── MasterEventListenerTests.java │ │ └── diskcleanup │ │ │ ├── IndexCleanupTests.java │ │ │ └── ModelCheckpointIndexRetentionTests.java │ │ ├── common │ │ └── exception │ │ │ ├── ADTaskCancelledExceptionTests.java │ │ │ ├── JsonPathNotFoundException.java │ │ │ └── LimitExceededExceptionTests.java │ │ ├── dataprocessor │ │ ├── IntegerSensitiveSingleFeatureLinearUniformInterpolatorTests.java │ │ ├── LinearUniformInterpolatorTests.java │ │ └── SingleFeatureLinearUniformInterpolatorTests.java │ │ ├── e2e │ │ └── DetectionResultEvalutationIT.java │ │ ├── feature │ │ ├── FeatureManagerTests.java │ │ ├── FeaturesTests.java │ │ └── SearchFeatureDaoTests.java │ │ ├── indices │ │ ├── AnomalyDetectionIndicesTests.java │ │ ├── InitAnomalyDetectionIndicesTests.java │ │ └── RolloverTests.java │ │ ├── ml │ │ ├── CheckpointDaoTests.java │ │ ├── CheckpointDeleteTests.java │ │ ├── EntityColdStarterTests.java │ │ ├── HybridThresholdingModelTests.java │ │ ├── KllFloatsSketchSerDeTests.java │ │ ├── ModelManagerTests.java │ │ ├── RcfResultTests.java │ │ ├── ThresholdingResultTests.java │ │ └── rcf │ │ │ └── CombinedRcfResultTests.java │ │ ├── mock │ │ ├── model │ │ │ └── MockSimpleLog.java │ │ ├── plugin │ │ │ └── MockReindexPlugin.java │ │ └── transport │ │ │ ├── MockAnomalyDetectorJobAction.java │ │ │ └── MockAnomalyDetectorJobTransportActionWithUser.java │ │ ├── model │ │ ├── ADTaskTests.java │ │ ├── AnomalyDetectorExecutionInputTests.java │ │ ├── AnomalyDetectorJobTests.java │ │ ├── AnomalyDetectorSerializationTests.java │ │ ├── AnomalyDetectorTests.java │ │ ├── AnomalyResultTests.java │ │ ├── DetectionDateRangeTests.java │ │ ├── EntityAnomalyResultTests.java │ │ ├── EntityProfileTests.java │ │ ├── FeatureDataTests.java │ │ ├── FeatureTests.java │ │ └── IntervalTimeConfigurationTests.java │ │ ├── plugin │ │ └── MockReindexPlugin.java │ │ ├── rest │ │ ├── AnomalyDetectorRestApiIT.java │ │ ├── HistoricalDetectorRestApiIT.java │ │ └── SecureADRestIT.java │ │ ├── stats │ │ ├── ADStatTests.java │ │ ├── ADStatsResponseTests.java │ │ ├── ADStatsTests.java │ │ └── suppliers │ │ │ ├── CounterSupplierTests.java │ │ │ ├── IndexSupplierTests.java │ │ │ ├── ModelsOnNodeSupplierTests.java │ │ │ └── SettableSupplierTests.java │ │ ├── task │ │ ├── ADTaskCacheManagerTests.java │ │ └── ADTaskManagerTests.java │ │ ├── transport │ │ ├── ADBatchAnomalyResultTransportActionTests.java │ │ ├── ADCancelTaskTests.java │ │ ├── ADResultBulkTransportActionTests.java │ │ ├── ADStatsIT.java │ │ ├── ADStatsNodesTransportActionTests.java │ │ ├── ADStatsTests.java │ │ ├── ADTaskProfileTests.java │ │ ├── ADTaskProfileTransportActionTests.java │ │ ├── AnomalyDetectorJobActionTests.java │ │ ├── AnomalyDetectorJobTransportActionTests.java │ │ ├── AnomalyResultTests.java │ │ ├── AnomalyResultTransportActionTests.java │ │ ├── CronTransportActionTests.java │ │ ├── DeleteAnomalyDetectorActionTests.java │ │ ├── DeleteAnomalyDetectorTransportActionTests.java │ │ ├── DeleteIT.java │ │ ├── DeleteModelTransportActionTests.java │ │ ├── DeleteTests.java │ │ ├── EntityProfileTests.java │ │ ├── EntityResultTransportActionTests.java │ │ ├── ForwardADTaskTests.java │ │ ├── GetAnomalyDetectorActionTests.java │ │ ├── GetAnomalyDetectorTests.java │ │ ├── GetAnomalyDetectorTransportActionTests.java │ │ ├── IndexAnomalyDetectorActionTests.java │ │ ├── IndexAnomalyDetectorTransportActionTests.java │ │ ├── MultientityResultTests.java │ │ ├── PreviewAnomalyDetectorActionTests.java │ │ ├── PreviewAnomalyDetectorTransportActionTests.java │ │ ├── ProfileIT.java │ │ ├── ProfileTests.java │ │ ├── ProfileTransportActionTests.java │ │ ├── RCFPollingTests.java │ │ ├── RCFResultIT.java │ │ ├── RCFResultTests.java │ │ ├── SearchADTasksActionTests.java │ │ ├── SearchADTasksTransportActionTests.java │ │ ├── SearchAnomalyDetectorActionTests.java │ │ ├── SearchAnomalyDetectorInfoActionTests.java │ │ ├── SearchAnomalyResultActionTests.java │ │ ├── StatsAnomalyDetectorActionTests.java │ │ ├── StatsAnomalyDetectorTransportActionTests.java │ │ ├── StopDetectorActionTests.java │ │ ├── ThresholdResultIT.java │ │ ├── ThresholdResultTests.java │ │ └── handler │ │ │ ├── ADSearchHandlerTests.java │ │ │ ├── AnomalyResultBulkIndexHandlerTests.java │ │ │ ├── AnomalyResultHandlerTests.java │ │ │ └── DetectorStateHandlerTests.java │ │ └── util │ │ ├── ArrayEqMatcher.java │ │ ├── ExceptionUtilsTests.java │ │ ├── IndexUtilsTests.java │ │ ├── MultiResponsesDelegateActionListenerTests.java │ │ ├── ParseUtilsTests.java │ │ ├── RestHandlerUtilsTests.java │ │ └── ThrottlerTests.java ├── org │ └── elasticsearch │ │ ├── action │ │ └── admin │ │ │ └── indices │ │ │ └── mapping │ │ │ └── get │ │ │ └── IndexAnomalyDetectorActionHandlerTests.java │ │ └── search │ │ └── aggregations │ │ └── metrics │ │ └── CardinalityProfileTests.java └── test │ └── com │ └── amazon │ └── opendistroforelasticsearch │ └── ad │ └── util │ ├── ClusterCreation.java │ ├── FakeNode.java │ ├── JsonDeserializer.java │ └── MLUtil.java └── resources ├── com └── amazon │ └── opendistroforelasticsearch │ └── ad │ └── e2e │ └── data │ ├── synthetic.data │ └── synthetic.label ├── job-scheduler └── opendistro-job-scheduler-1.13.0.0.zip └── security ├── sample.pem └── test-kirk.jks /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Other plugins installed** 14 | Please mention if you are using this plugin along side any other plugin. Security for example. 15 | 16 | **To Reproduce** 17 | Steps to reproduce the behavior: 18 | 1. Go to '...' 19 | 2. Click on '....' 20 | 3. Scroll down to '....' 21 | 4. See error 22 | 23 | **Expected behavior** 24 | A clear and concise description of what you expected to happen. 25 | 26 | **Screenshots** 27 | If applicable, add screenshots to help explain your problem. 28 | 29 | **Desktop (please complete the following information):** 30 | - OS: [e.g. iOS] 31 | - Browser [e.g. chrome, safari] 32 | - Version [e.g. 22] 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/draft-release-notes-config.yml: -------------------------------------------------------------------------------- 1 | # The overall template of the release notes 2 | template: | 3 | Compatible with Elasticsearch (**set version here**). 4 | $CHANGES 5 | 6 | # Setting the formatting and sorting for the release notes body 7 | name-template: Version (set version here) 8 | change-template: "* $TITLE ([#$NUMBER]($URL))" 9 | sort-by: merged_at 10 | sort-direction: ascending 11 | replacers: 12 | - search: "##" 13 | replace: "###" 14 | 15 | # Organizing the tagged PRs into unified ODFE categories 16 | categories: 17 | - title: "Breaking changes" 18 | labels: 19 | - "breaking change" 20 | - title: "Features" 21 | labels: 22 | - "feature" 23 | - title: "Enhancements" 24 | labels: 25 | - "enhancement" 26 | - title: "Bug Fixes" 27 | labels: 28 | - "bug" 29 | - "bug fix" 30 | - title: "Infrastructure" 31 | labels: 32 | - "infra" 33 | - "test" 34 | - "dependencies" 35 | - "github actions" 36 | - title: "Documentation" 37 | labels: 38 | - "documentation" 39 | - title: "Maintenance" 40 | labels: 41 | - "version upgrade" 42 | - "odfe release" 43 | - title: "Refactoring" 44 | labels: 45 | - "refactor" 46 | - "code quality" 47 | -------------------------------------------------------------------------------- /.github/workflows/CD.yml: -------------------------------------------------------------------------------- 1 | name: Build and Release AD 2 | on: 3 | push: 4 | tags: 5 | - v* 6 | 7 | jobs: 8 | Build-AD: 9 | strategy: 10 | matrix: 11 | java: [14] 12 | 13 | name: Build and Release AD Plugin 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout AD 18 | uses: actions/checkout@v1 19 | 20 | - name: Configure AWS 21 | uses: aws-actions/configure-aws-credentials@v1 22 | with: 23 | aws-access-key-id: ${{ secrets.AWS_STAGING_ACCESS_KEY_ID }} 24 | aws-secret-access-key: ${{ secrets.AWS_STAGING_SECRET_ACCESS_KEY }} 25 | aws-region: us-east-1 26 | 27 | - name: Setup Java ${{ matrix.java }} 28 | uses: actions/setup-java@v1 29 | with: 30 | java-version: ${{ matrix.java }} 31 | 32 | - name: Run build 33 | run: | 34 | ./gradlew buildPackages --console=plain -Dbuild.snapshot=false 35 | - name: Upload to S3 36 | shell: bash 37 | run: | 38 | zip=`ls build/distributions/*.zip` 39 | rpm=`ls build/distributions/*.rpm` 40 | deb=`ls build/distributions/*.deb` 41 | 42 | # Inject the build number before the suffix 43 | zip_outfile=`basename ${zip%.zip}-build-${GITHUB_RUN_NUMBER}.zip` 44 | rpm_outfile=`basename ${rpm%.rpm}-build-${GITHUB_RUN_NUMBER}.rpm` 45 | deb_outfile=`basename ${deb%.deb}-build-${GITHUB_RUN_NUMBER}.deb` 46 | 47 | s3_prefix="s3://staging.artifacts.opendistroforelasticsearch.amazon.com/snapshots/elasticsearch-plugins/anomaly-detection/" 48 | 49 | echo "Copying ${zip} to ${s3_prefix}${zip_outfile}" 50 | aws s3 cp --quiet $zip ${s3_prefix}${zip_outfile} 51 | 52 | echo "Copying ${rpm} to ${s3_prefix}${rpm_outfile}" 53 | aws s3 cp --quiet $rpm ${s3_prefix}${rpm_outfile} 54 | 55 | echo "Copying ${deb} to ${s3_prefix}${deb_outfile}" 56 | aws s3 cp --quiet $deb ${s3_prefix}${deb_outfile} -------------------------------------------------------------------------------- /.github/workflows/draft-release-notes-workflow.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | update_release_draft: 10 | name: Update draft release notes 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Update draft release notes 14 | uses: release-drafter/release-drafter@v5 15 | with: 16 | config-name: draft-release-notes-config.yml 17 | name: Version (set here) 18 | tag: (None) 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | -------------------------------------------------------------------------------- /.github/workflows/esad-cli-publish-artifact-workflow.yml: -------------------------------------------------------------------------------- 1 | name: Publish AD CLI 2 | on: 3 | push: 4 | tags: 5 | - v* 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | defaults: 11 | run: 12 | working-directory: cli 13 | steps: 14 | - name: Set up Go ubuntu-latest 15 | uses: actions/setup-go@v2 16 | with: 17 | go-version: 1.14 18 | 19 | - name: Check out AD CLI 20 | uses: actions/checkout@v2 21 | 22 | - name: Run GoReleaser 23 | uses: goreleaser/goreleaser-action@v2 24 | with: 25 | version: latest 26 | args: --snapshot --skip-publish 27 | workdir: cli 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | 31 | - name: Upload macOS(amd64) Artifact 32 | uses: actions/upload-artifact@v2 33 | with: 34 | name: esad-darwin-amd64 35 | path: cli/dist/esad_darwin_amd64/esad 36 | 37 | - name: Upload Linux(amd64) Artifact 38 | uses: actions/upload-artifact@v2 39 | with: 40 | name: esad-linux-amd64 41 | path: cli/dist/esad_linux_amd64/esad 42 | 43 | - name: Upload Linux(arm64) Artifact 44 | uses: actions/upload-artifact@v2 45 | with: 46 | name: esad-linux-arm64 47 | path: cli/dist/esad_linux_arm64/esad 48 | 49 | - name: Upload Windows(i386) Artifact 50 | uses: actions/upload-artifact@v2 51 | with: 52 | name: esad-windows-386 53 | path: cli/dist/esad_windows_386/esad.exe 54 | 55 | - name: Upload Windows(amd64) Artifact 56 | uses: actions/upload-artifact@v2 57 | with: 58 | name: esad-windows-amd64 59 | path: cli/dist/esad_windows_amd64/esad.exe 60 | 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | buildSrc/build 2 | buildSrc/libs 3 | .gradle/ 4 | build/ 5 | .idea/ 6 | !.idea/codeStyles/codeStyleConfig.xml 7 | .DS_Store 8 | offline-repo.zip 9 | *.log 10 | out/ 11 | *.iml 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted an [Open Source Code of Conduct](https://opendistro.github.io/for-elasticsearch/codeofconduct.html). 3 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Contributors to the alpha release (in pseudo-alphabetical order): 2 | 3 | Jiang Lai 4 | Kaituo Li 5 | Jack Mazanec 6 | Mihir Soni 7 | Chris Swierczewski 8 | Yaliang Wu 9 | Hanguang Zhang 10 | Jing Zhang 11 | Pavani Baddepudi 12 | Eli Fisher 13 | Jin Lei 14 | Steve Liu 15 | Sean Zheng 16 | Alolita Sharma 17 | Sudipto Guha 18 | Partha Kanuparthy 19 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Open Distro For Elasticsearch Anomaly Detection 2 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /cli/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # IDE Settings 9 | .idea/* 10 | 11 | #OS Settings 12 | .DS_Store 13 | 14 | # Test binary, built with `go test -c` 15 | *.test 16 | 17 | bin 18 | .go 19 | .push-* 20 | .container-* 21 | .dockerfile-* 22 | 23 | /coverage.out 24 | -------------------------------------------------------------------------------- /cli/.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example goreleaser.yaml file with some sane defaults. 2 | # Make sure to check the documentation at http://goreleaser.com 3 | project_name: esad 4 | dist: ./dist 5 | before: 6 | hooks: 7 | # You may remove this if you don't use go modules. 8 | - go mod download 9 | builds: 10 | - env: 11 | - CGO_ENABLED=0 12 | goos: 13 | - linux 14 | - windows 15 | - darwin 16 | goarch: 17 | - 386 18 | - amd64 19 | - arm 20 | - arm64 21 | ignore: 22 | - goos: darwin 23 | goarch: 386 24 | archives: 25 | - 26 | name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' 27 | replacements: 28 | darwin: Darwin 29 | linux: Linux 30 | windows: Windows 31 | 386: i386 32 | amd64: x86_64 33 | format_overrides: 34 | - goos: windows 35 | format: zip 36 | checksum: 37 | name_template: '{{ .ProjectName }}_checksums.txt' 38 | snapshot: 39 | name_template: '{{ .ProjectName }}_{{ .Version }}' 40 | -------------------------------------------------------------------------------- /cli/Create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/cli/Create.png -------------------------------------------------------------------------------- /cli/NOTICE: -------------------------------------------------------------------------------- 1 | Open Distro for Elasticsearch Anomaly Detection CLI 2 | Copyright 2019-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. -------------------------------------------------------------------------------- /cli/Start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/cli/Start.png -------------------------------------------------------------------------------- /cli/go.mod: -------------------------------------------------------------------------------- 1 | module esad 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/cheggaaa/pb/v3 v3.0.4 7 | github.com/fsnotify/fsnotify v1.4.9 // indirect 8 | github.com/golang/mock v1.4.3 9 | github.com/gosuri/uilive v0.0.4 // indirect 10 | github.com/hashicorp/go-retryablehttp v0.6.6 11 | github.com/mitchellh/go-homedir v1.1.0 12 | github.com/mitchellh/mapstructure v1.3.2 13 | github.com/pelletier/go-toml v1.8.0 // indirect 14 | github.com/spf13/afero v1.3.1 // indirect 15 | github.com/spf13/cast v1.3.1 // indirect 16 | github.com/spf13/cobra v1.0.0 17 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 18 | github.com/spf13/pflag v1.0.5 // indirect 19 | github.com/spf13/viper v1.7.0 20 | github.com/stretchr/testify v1.5.1 21 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 22 | golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect 23 | golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect 24 | golang.org/x/text v0.3.3 // indirect 25 | golang.org/x/tools v0.0.0-20200820180210-c8f393745106 // indirect 26 | gopkg.in/ini.v1 v1.57.0 // indirect 27 | ) 28 | -------------------------------------------------------------------------------- /cli/internal/client/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package client 14 | 15 | //UserConfig represents User configurations 16 | type UserConfig struct { 17 | Endpoint string `json:"endpoint"` 18 | Username string `json:"username"` 19 | Password string `json:"password"` 20 | } 21 | -------------------------------------------------------------------------------- /cli/internal/client/mocks/mock_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package mocks 14 | 15 | import ( 16 | "esad/internal/client" 17 | "fmt" 18 | "net/http" 19 | ) 20 | 21 | // RoundTripFunc . 22 | type RoundTripFunc func(req *http.Request) *http.Response 23 | 24 | // RoundTrip . 25 | func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { 26 | return f(req), nil 27 | } 28 | 29 | //NewTestClient returns *http.Client with Transport replaced to avoid making real calls 30 | func NewTestClient(fn RoundTripFunc) *client.Client { 31 | c, err := client.New(fn) 32 | if err == nil { 33 | fmt.Println("Fatal: failed to get client") 34 | } 35 | return c 36 | } 37 | -------------------------------------------------------------------------------- /cli/internal/client/request.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package client 14 | 15 | import ( 16 | "crypto/tls" 17 | "net/http" 18 | 19 | "github.com/hashicorp/go-retryablehttp" 20 | ) 21 | 22 | //Client is an Abstraction for actual client 23 | type Client struct { 24 | HTTPClient *retryablehttp.Client 25 | } 26 | 27 | //NewDefaultClient return new instance of client 28 | func NewDefaultClient(tripper http.RoundTripper) (*Client, error) { 29 | 30 | client := retryablehttp.NewClient() 31 | client.HTTPClient.Transport = tripper 32 | client.Logger = nil 33 | return &Client{ 34 | HTTPClient: client, 35 | }, nil 36 | } 37 | 38 | //New takes transport and uses accordingly 39 | func New(tripper http.RoundTripper) (*Client, error) { 40 | if tripper == nil { 41 | tripper = &http.Transport{ 42 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 43 | } 44 | } 45 | defaultClient, err := NewDefaultClient(tripper) 46 | if err != nil { 47 | return nil, err 48 | } 49 | return defaultClient, err 50 | } 51 | -------------------------------------------------------------------------------- /cli/internal/controller/ad/testdata/create_failed_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": { 3 | "root_cause": [ 4 | { 5 | "type": "illegal_argument_exception", 6 | "reason": "Cannot create anomaly detector with name [testdata-detector] as it's already used by detector [wR_1XXMBs3q1IVz33Sk-]" 7 | } 8 | ], 9 | "type": "illegal_argument_exception", 10 | "reason": "Cannot create anomaly detector with name [testdata-detector] as it's already used by detector [wR_1XXMBs3q1IVz33Sk-]" 11 | }, 12 | "status": 400 13 | } -------------------------------------------------------------------------------- /cli/internal/controller/ad/testdata/create_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-detector", 3 | "description": "Test detector", 4 | "time_field": "timestamp", 5 | "indices": [ 6 | "order*" 7 | ], 8 | "feature_attributes": [ 9 | { 10 | "feature_name": "total_order", 11 | "feature_enabled": true, 12 | "aggregation_query": { 13 | "total_order": { 14 | "sum": { 15 | "field": "value" 16 | } 17 | } 18 | } 19 | } 20 | ], 21 | "filter_query": { 22 | "bool": { 23 | "filter": [ 24 | { 25 | "exists": { 26 | "field": "value", 27 | "boost": 1 28 | } 29 | } 30 | ] 31 | } 32 | }, 33 | "detection_interval": { 34 | "period": { 35 | "interval": 1, 36 | "unit": "Minutes" 37 | } 38 | }, 39 | "window_delay": { 40 | "period": { 41 | "interval": 1, 42 | "unit": "Minutes" 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /cli/internal/controller/ad/testdata/create_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id": "m4ccEnIBTXsGi3mvMt9p", 3 | "_version": 1, 4 | "_seq_no": 3, 5 | "_primary_term": 1, 6 | "anomaly_detector": { 7 | "name": "test-detector", 8 | "description": "Test detector", 9 | "time_field": "timestamp", 10 | "indices": [ 11 | "order*" 12 | ], 13 | "filter_query": { 14 | "bool": { 15 | "filter": [ 16 | { 17 | "exists": { 18 | "field": "value", 19 | "boost": 1.0 20 | } 21 | } 22 | ], 23 | "adjust_pure_negative": true, 24 | "boost": 1.0 25 | } 26 | }, 27 | "detection_interval": { 28 | "period": { 29 | "interval": 1, 30 | "unit": "Minutes" 31 | } 32 | }, 33 | "window_delay": { 34 | "period": { 35 | "interval": 1, 36 | "unit": "Minutes" 37 | } 38 | }, 39 | "schema_version": 0, 40 | "feature_attributes": [ 41 | { 42 | "feature_id": "mYccEnIBTXsGi3mvMd8_", 43 | "feature_name": "total_order", 44 | "feature_enabled": true, 45 | "aggregation_query": { 46 | "total_order": { 47 | "sum": { 48 | "field": "value" 49 | } 50 | } 51 | } 52 | } 53 | ] 54 | } 55 | } -------------------------------------------------------------------------------- /cli/internal/controller/ad/testdata/get_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id" : "detectorID", 3 | "_version" : 1, 4 | "_primary_term" : 1, 5 | "_seq_no" : 3, 6 | "anomaly_detector" : { 7 | "name" : "detector", 8 | "description" : "Test detector", 9 | "time_field" : "timestamp", 10 | "indices" : [ 11 | "order*" 12 | ], 13 | "filter_query" : {"bool" : {"filter" : [{"exists" : {"field" : "value","boost" : 1.0}}],"adjust_pure_negative" : true,"boost" : 1.0}}, 14 | "detection_interval" : { 15 | "period" : { 16 | "interval" : 5, 17 | "unit" : "Minutes" 18 | } 19 | }, 20 | "window_delay" : { 21 | "period" : { 22 | "interval" : 1, 23 | "unit" : "Minutes" 24 | } 25 | }, 26 | "schema_version" : 0, 27 | "feature_attributes" : [ 28 | { 29 | "feature_id" : "mYccEnIBTXsGi3mvMd8_", 30 | "feature_name" : "total_order", 31 | "feature_enabled" : true, 32 | "aggregation_query" : {"total_order":{"sum":{"field":"value"}}} 33 | } 34 | ], 35 | "last_update_time" : 1589441737319 36 | } 37 | } -------------------------------------------------------------------------------- /cli/internal/controller/es/es.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package es 14 | 15 | import ( 16 | "context" 17 | "encoding/json" 18 | elasticsearch "esad/internal/entity/es" 19 | "esad/internal/gateway/es" 20 | "fmt" 21 | ) 22 | 23 | //go:generate mockgen -destination=mocks/mock_es.go -package=mocks . Controller 24 | 25 | //Controller is an interface for ES Cluster to get distinct values 26 | type Controller interface { 27 | GetDistinctValues(ctx context.Context, index string, field string) ([]interface{}, error) 28 | } 29 | 30 | type controller struct { 31 | gateway es.Gateway 32 | } 33 | 34 | //New returns new instance of Controller 35 | func New(gateway es.Gateway) Controller { 36 | return &controller{ 37 | gateway, 38 | } 39 | } 40 | func (c controller) GetDistinctValues(ctx context.Context, index string, field string) ([]interface{}, error) { 41 | if len(index) == 0 || len(field) == 0 { 42 | return nil, fmt.Errorf("index and field cannot be empty") 43 | } 44 | response, err := c.gateway.SearchDistinctValues(ctx, index, field) 45 | if err != nil { 46 | return nil, err 47 | } 48 | var data elasticsearch.Response 49 | err = json.Unmarshal(response, &data) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | var values []interface{} 55 | for _, bucket := range data.Aggregations.Items.Buckets { 56 | values = append(values, bucket.Key) 57 | } 58 | return values, nil 59 | } 60 | -------------------------------------------------------------------------------- /cli/internal/controller/es/mocks/mock_es.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: esad/internal/controller/es (interfaces: Controller) 3 | 4 | // Package mocks is a generated GoMock package. 5 | package mocks 6 | 7 | import ( 8 | context "context" 9 | reflect "reflect" 10 | 11 | gomock "github.com/golang/mock/gomock" 12 | ) 13 | 14 | // MockController is a mock of Controller interface 15 | type MockController struct { 16 | ctrl *gomock.Controller 17 | recorder *MockControllerMockRecorder 18 | } 19 | 20 | // MockControllerMockRecorder is the mock recorder for MockController 21 | type MockControllerMockRecorder struct { 22 | mock *MockController 23 | } 24 | 25 | // NewMockController creates a new mock instance 26 | func NewMockController(ctrl *gomock.Controller) *MockController { 27 | mock := &MockController{ctrl: ctrl} 28 | mock.recorder = &MockControllerMockRecorder{mock} 29 | return mock 30 | } 31 | 32 | // EXPECT returns an object that allows the caller to indicate expected use 33 | func (m *MockController) EXPECT() *MockControllerMockRecorder { 34 | return m.recorder 35 | } 36 | 37 | // GetDistinctValues mocks base method 38 | func (m *MockController) GetDistinctValues(arg0 context.Context, arg1, arg2 string) ([]interface{}, error) { 39 | m.ctrl.T.Helper() 40 | ret := m.ctrl.Call(m, "GetDistinctValues", arg0, arg1, arg2) 41 | ret0, _ := ret[0].([]interface{}) 42 | ret1, _ := ret[1].(error) 43 | return ret0, ret1 44 | } 45 | 46 | // GetDistinctValues indicates an expected call of GetDistinctValues 47 | func (mr *MockControllerMockRecorder) GetDistinctValues(arg0, arg1, arg2 interface{}) *gomock.Call { 48 | mr.mock.ctrl.T.Helper() 49 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDistinctValues", reflect.TypeOf((*MockController)(nil).GetDistinctValues), arg0, arg1, arg2) 50 | } 51 | -------------------------------------------------------------------------------- /cli/internal/controller/es/testdata/search_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "took": 80, 3 | "timed_out": false, 4 | "_shards": { 5 | "total": 5, 6 | "successful": 5, 7 | "skipped": 0, 8 | "failed": 0 9 | }, 10 | "hits": { 11 | "total": 14, 12 | "max_score": 0, 13 | "hits": [] 14 | }, 15 | "aggregations": { 16 | "items": { 17 | "doc_count_error_upper_bound": 0, 18 | "sum_other_doc_count": 0, 19 | "buckets": [ 20 | { 21 | "key": "Packaged Foods", 22 | "doc_count": 4 23 | }, 24 | { 25 | "key": "Dairy", 26 | "doc_count": 3 27 | }, 28 | { 29 | "key": "Meat and Seafood", 30 | "doc_count": 2 31 | } 32 | ] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /cli/internal/entity/es/es.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package es 14 | 15 | //Terms contains fields 16 | type Terms struct { 17 | Field string `json:"field"` 18 | } 19 | 20 | //DistinctGroups contains terms 21 | type DistinctGroups struct { 22 | Term Terms `json:"terms"` 23 | } 24 | 25 | //Aggregate contains list of items 26 | type Aggregate struct { 27 | Group DistinctGroups `json:"items"` 28 | } 29 | 30 | //SearchRequest structure for request 31 | type SearchRequest struct { 32 | Agg Aggregate `json:"aggs"` 33 | Size int32 `json:"size"` 34 | } 35 | 36 | //Bucket represents bucket used by ES for aggregations 37 | type Bucket struct { 38 | Key interface{} `json:"key"` 39 | DocCount int64 `json:"doc_count"` 40 | } 41 | 42 | //Items contains buckets defined by es response 43 | type Items struct { 44 | Buckets []Bucket `json:"buckets"` 45 | } 46 | 47 | //Aggregations contains items defined by es response 48 | type Aggregations struct { 49 | Items Items `json:"items"` 50 | } 51 | 52 | //Response response defined by es response 53 | type Response struct { 54 | Aggregations Aggregations `json:"aggregations"` 55 | } 56 | -------------------------------------------------------------------------------- /cli/internal/gateway/ad/testdata/create_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id" : "m4ccEnIBTXsGi3mvMt9p", 3 | "_version" : 1, 4 | "_seq_no" : 3, 5 | "_primary_term" : 1, 6 | "anomaly_detector" : { 7 | "name" : "test-detector", 8 | "description" : "Test detector", 9 | "time_field" : "timestamp", 10 | "indices" : [ 11 | "order*" 12 | ], 13 | "filter_query" : { 14 | "bool" : { 15 | "filter" : [ 16 | { 17 | "exists" : { 18 | "field" : "value", 19 | "boost" : 1.0 20 | } 21 | } 22 | ], 23 | "adjust_pure_negative" : true, 24 | "boost" : 1.0 25 | } 26 | }, 27 | "detection_interval" : { 28 | "period" : { 29 | "interval" : 1, 30 | "unit" : "Minutes" 31 | } 32 | }, 33 | "window_delay" : { 34 | "period" : { 35 | "interval" : 1, 36 | "unit" : "Minutes" 37 | } 38 | }, 39 | "schema_version" : 0, 40 | "feature_attributes" : [ 41 | { 42 | "feature_id" : "mYccEnIBTXsGi3mvMd8_", 43 | "feature_name" : "total_order", 44 | "feature_enabled" : true, 45 | "aggregation_query" : { 46 | "total_order" : { 47 | "sum" : { 48 | "field" : "value" 49 | } 50 | } 51 | } 52 | } 53 | ] 54 | } 55 | } -------------------------------------------------------------------------------- /cli/internal/gateway/ad/testdata/get_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id" : "m4ccEnIBTXsGi3mvMt9p", 3 | "_version" : 1, 4 | "_primary_term" : 1, 5 | "_seq_no" : 3, 6 | "anomaly_detector" : { 7 | "name" : "test-detector", 8 | "description" : "Test detector", 9 | "time_field" : "timestamp", 10 | "indices" : [ 11 | "order*" 12 | ], 13 | "filter_query" : { 14 | "bool" : { 15 | "filter" : [ 16 | { 17 | "exists" : { 18 | "field" : "value", 19 | "boost" : 1.0 20 | } 21 | } 22 | ], 23 | "adjust_pure_negative" : true, 24 | "boost" : 1.0 25 | } 26 | }, 27 | "detection_interval" : { 28 | "period" : { 29 | "interval" : 1, 30 | "unit" : "Minutes" 31 | } 32 | }, 33 | "window_delay" : { 34 | "period" : { 35 | "interval" : 1, 36 | "unit" : "Minutes" 37 | } 38 | }, 39 | "schema_version" : 0, 40 | "feature_attributes" : [ 41 | { 42 | "feature_id" : "mYccEnIBTXsGi3mvMd8_", 43 | "feature_name" : "total_order", 44 | "feature_enabled" : true, 45 | "aggregation_query" : { 46 | "total_order" : { 47 | "sum" : { 48 | "field" : "value" 49 | } 50 | } 51 | } 52 | } 53 | ], 54 | "last_update_time" : 1589441737319 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cli/internal/gateway/ad/testdata/search_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "took": 13, 3 | "timed_out": false, 4 | "_shards": { 5 | "total": 5, 6 | "successful": 5, 7 | "skipped": 0, 8 | "failed": 0 9 | }, 10 | "hits": { 11 | "total": { 12 | "value": 994, 13 | "relation": "eq" 14 | }, 15 | "max_score": 3.5410638, 16 | "hits": [ 17 | { 18 | "_index": ".opendistro-anomaly-detectors", 19 | "_type": "_doc", 20 | "_id": "m4ccEnIBTXsGi3mvMt9p", 21 | "_version": 2, 22 | "_seq_no": 221, 23 | "_primary_term": 1, 24 | "_score": 3.5410638, 25 | "_source": { 26 | "name": "test-detector", 27 | "description": "Test detector", 28 | "time_field": "timestamp", 29 | "indices": [ 30 | "order*" 31 | ], 32 | "filter_query": { 33 | "bool": { 34 | "filter": [ 35 | { 36 | "exists": { 37 | "field": "value", 38 | "boost": 1 39 | } 40 | } 41 | ], 42 | "adjust_pure_negative": true, 43 | "boost": 1 44 | } 45 | }, 46 | "detection_interval": { 47 | "period": { 48 | "interval": 10, 49 | "unit": "Minutes" 50 | } 51 | }, 52 | "window_delay": { 53 | "period": { 54 | "interval": 1, 55 | "unit": "Minutes" 56 | } 57 | }, 58 | "schema_version": 0, 59 | "feature_attributes": [ 60 | { 61 | "feature_id": "xxokEnIBcpeWMD987A1X", 62 | "feature_name": "total_order", 63 | "feature_enabled": true, 64 | "aggregation_query": { 65 | "total_order": { 66 | "sum": { 67 | "field": "value" 68 | } 69 | } 70 | } 71 | } 72 | ], 73 | "last_update_time": 1589442309241 74 | } 75 | } 76 | ] 77 | } 78 | } -------------------------------------------------------------------------------- /cli/internal/gateway/es/mocks/mock_es.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: esad/internal/gateway/es (interfaces: Gateway) 3 | 4 | // Package mocks is a generated GoMock package. 5 | package mocks 6 | 7 | import ( 8 | context "context" 9 | reflect "reflect" 10 | 11 | gomock "github.com/golang/mock/gomock" 12 | ) 13 | 14 | // MockGateway is a mock of Gateway interface 15 | type MockGateway struct { 16 | ctrl *gomock.Controller 17 | recorder *MockGatewayMockRecorder 18 | } 19 | 20 | // MockGatewayMockRecorder is the mock recorder for MockGateway 21 | type MockGatewayMockRecorder struct { 22 | mock *MockGateway 23 | } 24 | 25 | // NewMockGateway creates a new mock instance 26 | func NewMockGateway(ctrl *gomock.Controller) *MockGateway { 27 | mock := &MockGateway{ctrl: ctrl} 28 | mock.recorder = &MockGatewayMockRecorder{mock} 29 | return mock 30 | } 31 | 32 | // EXPECT returns an object that allows the caller to indicate expected use 33 | func (m *MockGateway) EXPECT() *MockGatewayMockRecorder { 34 | return m.recorder 35 | } 36 | 37 | // SearchDistinctValues mocks base method 38 | func (m *MockGateway) SearchDistinctValues(arg0 context.Context, arg1, arg2 string) ([]byte, error) { 39 | m.ctrl.T.Helper() 40 | ret := m.ctrl.Call(m, "SearchDistinctValues", arg0, arg1, arg2) 41 | ret0, _ := ret[0].([]byte) 42 | ret1, _ := ret[1].(error) 43 | return ret0, ret1 44 | } 45 | 46 | // SearchDistinctValues indicates an expected call of SearchDistinctValues 47 | func (mr *MockGatewayMockRecorder) SearchDistinctValues(arg0, arg1, arg2 interface{}) *gomock.Call { 48 | mr.mock.ctrl.T.Helper() 49 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDistinctValues", reflect.TypeOf((*MockGateway)(nil).SearchDistinctValues), arg0, arg1, arg2) 50 | } 51 | -------------------------------------------------------------------------------- /cli/internal/gateway/es/testdata/search_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "took": 80, 3 | "timed_out": false, 4 | "_shards": { 5 | "total": 5, 6 | "successful": 5, 7 | "skipped": 0, 8 | "failed": 0 9 | }, 10 | "hits": { 11 | "total": 14, 12 | "max_score": 0, 13 | "hits": [] 14 | }, 15 | "aggregations": { 16 | "items": { 17 | "doc_count_error_upper_bound": 0, 18 | "sum_other_doc_count": 0, 19 | "buckets": [ 20 | { 21 | "key": "Packaged Foods", 22 | "doc_count": 4 23 | }, 24 | { 25 | "key": "Dairy", 26 | "doc_count": 3 27 | }, 28 | { 29 | "key": "Meat and Seafood", 30 | "doc_count": 2 31 | } 32 | ] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /cli/internal/handler/ad/testdata/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-detector-ecommerce0", 3 | "description": "Test detector", 4 | "time_field": "utc_time", 5 | "index": ["kibana_sample_data_ecommerce*"], 6 | "features": [{ 7 | "aggregation_type": ["sum", "average"], 8 | "enabled": true, 9 | "field":["total_quantity"] 10 | }], 11 | "filter": { 12 | "bool": { 13 | "filter": { 14 | "term": { 15 | "currency": "EUR" 16 | } 17 | }} 18 | }, 19 | "interval": "1m", 20 | "window_delay": "1m", 21 | "start": true, 22 | "partition_field": "day_of_week" 23 | } -------------------------------------------------------------------------------- /cli/internal/handler/ad/testdata/invalid.txt: -------------------------------------------------------------------------------- 1 | invalid content -------------------------------------------------------------------------------- /cli/internal/handler/ad/testdata/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "ID": "m4ccEnIBTXsGi3mvMt9p", 3 | "name": "test-detector", 4 | "description": "Test detector", 5 | "time_field": "timestamp", 6 | "indices": [ 7 | "order*" 8 | ], 9 | "features": [ 10 | { 11 | "feature_name": "total_order", 12 | "feature_enabled": true, 13 | "aggregation_query":{"total_order":{"sum":{"field":"value"}}} 14 | } 15 | ], 16 | "filter_query": {"bool" : {"filter" : [{"exists" : {"field" : "value","boost" : 1.0}}],"adjust_pure_negative" : true,"boost" : 1.0}}, 17 | "detection_interval": "5m", 18 | "window_delay": "1m", 19 | "last_update_time": 1589441737319, 20 | "schema_version": 0 21 | } 22 | 23 | -------------------------------------------------------------------------------- /cli/internal/mapper/mapper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | // Package mapper provides a collection of simple mapper functions. 14 | package mapper 15 | 16 | import ( 17 | "fmt" 18 | "math" 19 | ) 20 | 21 | // IntToInt32 maps an int to an int32. 22 | func IntToInt32(r int) (int32, error) { 23 | if r < math.MinInt32 || r > math.MaxInt32 { 24 | return 0, fmt.Errorf("integer overflow, cannot map %d to int32", r) 25 | } 26 | return int32(r), nil 27 | } 28 | 29 | // IntToInt32Ptr maps an int to an *int32. 30 | func IntToInt32Ptr(r int) (*int32, error) { 31 | rr, err := IntToInt32(r) 32 | return &rr, err 33 | } 34 | 35 | // Int32PtrToInt32 maps an *int32 to an int32, 36 | // defaulting to 0 if the pointer is nil. 37 | func Int32PtrToInt32(r *int32) int32 { 38 | if r == nil { 39 | return 0 40 | } 41 | return *r 42 | } 43 | 44 | // StringToStringPtr maps a string to a *string. 45 | func StringToStringPtr(r string) *string { 46 | return &r 47 | } 48 | 49 | // StringPtrToString maps a *string to a string, 50 | // defaulting to "" if the pointer is nil. 51 | func StringPtrToString(r *string) string { 52 | if r == nil { 53 | return "" 54 | } 55 | return *r 56 | } 57 | -------------------------------------------------------------------------------- /cli/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | // ESAD is a command lint tool for AD Plugin 14 | package main 15 | 16 | import ( 17 | "esad/cmd" 18 | "os" 19 | ) 20 | 21 | func main() { 22 | if err := cmd.Execute(); err != nil { 23 | // By default every command should handle their error message 24 | os.Exit(1) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cli/pkg/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"). 4 | * You may not use this file except in compliance with the License. 5 | * A copy of the License is located at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * or in the "license" file accompanying this file. This file is distributed 8 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | * express or implied. See the License for the specific language governing 10 | * permissions and limitations under the License. 11 | */ 12 | 13 | package pkg 14 | 15 | // VERSION represents the version of CLI 16 | var VERSION = "0.1" 17 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | threshold: 5 6 | target: auto 7 | plugin: 8 | target: 70% 9 | paths: 10 | - "!cli/" 11 | flags: 12 | - plugin 13 | cli: 14 | target: 78% 15 | paths: 16 | - "cli/" 17 | flags: 18 | - cli 19 | patch: off 20 | comment: 21 | layout: "reach, diff, flags, files" 22 | behavior: default 23 | require_changes: false 24 | require_base: no 25 | require_head: no 26 | branches: null 27 | flags: 28 | plugin: 29 | carryforward: true 30 | cli: 31 | carryforward: true -------------------------------------------------------------------------------- /docs/entity-priority.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/docs/entity-priority.pdf -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | zipStoreBase=GRADLE_USER_HOME 19 | zipStorePath=wrapper/dists 20 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip 21 | -------------------------------------------------------------------------------- /release-notes/opendistro-for-elasticsearch-anomaly-detection.release-notes-1.10.1.0.md: -------------------------------------------------------------------------------- 1 | ## Version 1.10.1.0 Release Notes 2 | 3 | Compatible with Elasticsearch 7.9.1 4 | 5 | ### Documentation 6 | 7 | * Include release notes for 1.10.0.0 ([#219](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/219)) 8 | * Update README.md ([#222](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/222)) 9 | 10 | ### Maintenance 11 | 12 | * Upgrade from 1.10.0 to 1.10.1 ([#224](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/224)) -------------------------------------------------------------------------------- /release-notes/opendistro-for-elasticsearch-anomaly-detection.release-notes-1.8.0.0.md: -------------------------------------------------------------------------------- 1 | ## Open Distro for Elasticsearch Anomaly Detection Plugin 1.8.0.0 Release Notes 2 | 3 | Compatible with Elasticsearch 7.7.0 and Open Distro for Elasticsearch 1.8.0. 4 | 5 | ## Breaking Changes 6 | 7 | * Artifact Name of Anomaly Detection Plugin for **_*DEB*_** and **_*RPM*_** distribution is updated from **opendistro-anomaly-detector** to **opendistro-anomaly-detection**. In order to reduce the impact of this change, we recommend removing the old **opendistro-anomaly-detector** plugin first with your package manager, before installing the upgraded **opendistro-anomaly-detection**. 8 | 9 | ## New Features 10 | * Add settings to disable/enable AD dynamically (#105) [PR #127](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/127) 11 | 12 | ## Enhancements 13 | * Ultrawarm integration [PR #125](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/125) 14 | * Add shingle size, total model size, and model's hash ring to profile API [PR #128](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/128) 15 | * Prevent creating detector with duplicate name. [PR #134](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/134) 16 | 17 | ## Bug Fixes 18 | * Fix that AD job cannot be terminated due to missing training data [PR #126](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/126) 19 | * Fix incorrect detector count in stats APIs [PR #129](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/129) 20 | * fix dynamic setting of max detector/feature limit [PR #130](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/130) 21 | 22 | ## Infra Changes 23 | * Add CI/CD workflows [PR #133](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/133) 24 | * Use spotless to manage license headers and imports [PR #136](https://github.com/opendistro-for-elasticsearch/anomaly-detection/pull/136) 25 | 26 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | rootProject.name = 'opendistro-anomaly-detection' 17 | -------------------------------------------------------------------------------- /src/forbidden/ad-signatures.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | @defaultMessage use format with Locale 17 | java.lang.String#format(java.lang.String,java.lang.Object[]) -------------------------------------------------------------------------------- /src/main/groovy/io/pry/gradle/offline_dependencies/OfflineDependenciesExtension.groovy: -------------------------------------------------------------------------------- 1 | package io.pry.gradle.offline_dependencies 2 | 3 | import org.gradle.api.artifacts.dsl.RepositoryHandler 4 | 5 | class OfflineDependenciesExtension { 6 | 7 | // deps 8 | private RepositoryHandler repositoryHandler; 9 | 10 | // config properties 11 | def configurations = [] as Set 12 | def buildScriptConfigurations = [] as Set 13 | 14 | def includeSources = true 15 | def includeJavadocs = true 16 | def includePoms = true 17 | def includeIvyXmls = true 18 | def includeBuildscriptDependencies = true 19 | 20 | // init 21 | OfflineDependenciesExtension(RepositoryHandler repositoryHandler) { 22 | this.repositoryHandler = repositoryHandler 23 | } 24 | 25 | // expose 'repositories' closure to build script, just like the default 'repositories' closure 26 | public void repositories(Closure repoConfigurator) { 27 | def configurator = repoConfigurator.clone() 28 | configurator.delegate = this.repositoryHandler 29 | configurator() 30 | } 31 | 32 | public void configurations(String... configurationNames) { 33 | this.configurations.addAll(configurationNames) 34 | } 35 | 36 | public void buildScriptConfigurations(String... configurationNames) { 37 | this.buildScriptConfigurations.addAll(configurationNames) 38 | } 39 | 40 | // used by task depending on the repository definitions 41 | protected RepositoryHandler getRepositoryHandler() { 42 | return this.repositoryHandler 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/groovy/io/pry/gradle/offline_dependencies/Utils.groovy: -------------------------------------------------------------------------------- 1 | package io.pry.gradle.offline_dependencies 2 | 3 | public final class Utils { 4 | public static void addToMultimap(Map> map, K key, V value) { 5 | if (!map.containsKey(key)) { 6 | map.put(key, [] as Set) 7 | } 8 | map.get(key).add(value) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/AbstractProfileRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | import java.util.Locale; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.model.InitProgressProfile; 21 | 22 | public abstract class AbstractProfileRunner { 23 | protected long requiredSamples; 24 | 25 | public AbstractProfileRunner(long requiredSamples) { 26 | this.requiredSamples = requiredSamples; 27 | } 28 | 29 | protected InitProgressProfile computeInitProgressProfile(long totalUpdates, long intervalMins) { 30 | float percent = Math.min((100.0f * totalUpdates) / requiredSamples, 100.0f); 31 | int neededPoints = (int) (requiredSamples - totalUpdates); 32 | return new InitProgressProfile( 33 | // rounding: 93.456 => 93%, 93.556 => 94% 34 | // Without Locale.ROOT, sometimes conversions use localized decimal digits 35 | // rather than the usual ASCII digits. See https://tinyurl.com/y5sdr5tp 36 | String.format(Locale.ROOT, "%.0f%%", percent), 37 | intervalMins * neededPoints, 38 | neededPoints 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/CleanState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | /** 19 | * Represent a state organized via detectorId. When deleting a detector's state, 20 | * we can remove it from the state. 21 | * 22 | * 23 | */ 24 | public interface CleanState { 25 | /** 26 | * Remove state associated with a detector Id 27 | * @param detectorId Detector Id 28 | */ 29 | void clear(String detectorId); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/DetectorModelSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | import java.util.Map; 19 | 20 | public interface DetectorModelSize { 21 | /** 22 | * Gets all of a detector's model sizes hosted on a node 23 | * 24 | * @param detectorId Detector Id 25 | * @return a map of model id to its memory size 26 | */ 27 | Map getModelSize(String detectorId); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/EntityModelSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | public interface EntityModelSize { 19 | /** 20 | * Gets an entity's model sizes 21 | * 22 | * @param detectorId Detector Id 23 | * @param entityModelId Entity's model Id 24 | * @return the entity's memory size 25 | */ 26 | long getModelSize(String detectorId, String entityModelId); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/ExpiringState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | import java.time.Duration; 19 | import java.time.Instant; 20 | 21 | /** 22 | * Represent a state that can be expired with a duration if not accessed 23 | * 24 | */ 25 | public interface ExpiringState { 26 | default boolean expired(Instant lastAccessTime, Duration stateTtl, Instant now) { 27 | return lastAccessTime.plus(stateTtl).isBefore(now); 28 | } 29 | 30 | boolean expired(Duration stateTtl); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/MaintenanceState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | import java.time.Duration; 19 | import java.util.Map; 20 | 21 | /** 22 | * Represent a state that needs to maintain its metadata regularly 23 | * 24 | * 25 | */ 26 | public interface MaintenanceState { 27 | default void maintenance(Map stateToClean, Duration stateTtl) { 28 | stateToClean.entrySet().stream().forEach(entry -> { 29 | K detectorId = entry.getKey(); 30 | 31 | V state = entry.getValue(); 32 | if (state.expired(stateTtl)) { 33 | stateToClean.remove(detectorId); 34 | } 35 | 36 | }); 37 | } 38 | 39 | void maintenance(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/Name.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad; 17 | 18 | import java.util.Collection; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | import java.util.function.Function; 22 | 23 | /** 24 | * A super type for enum types returning names 25 | * 26 | */ 27 | public interface Name { 28 | String getName(); 29 | 30 | static Set getNameFromCollection(Collection names, Function getName) { 31 | Set res = new HashSet<>(); 32 | for (String name : names) { 33 | res.add(getName.apply(name)); 34 | } 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/annotation/Generated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Jacoco will ignore the annotated code. 25 | * Similar to Lombok Generated annotation. Create this similar annotation as we don't involve Lombok. 26 | */ 27 | @Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE }) 28 | @Retention(RetentionPolicy.CLASS) 29 | public @interface Generated { 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/breaker/BreakerName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.breaker; 17 | 18 | public enum BreakerName { 19 | 20 | MEM("memory"), 21 | CPU("cpu"); 22 | 23 | private String name; 24 | 25 | BreakerName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/breaker/CircuitBreaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.breaker; 17 | 18 | /** 19 | * An interface for circuit breaker. 20 | * 21 | * We use circuit breaker to protect a certain system resource like memory, cpu etc. 22 | */ 23 | public interface CircuitBreaker { 24 | 25 | boolean isOpen(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/breaker/MemoryCircuitBreaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.breaker; 17 | 18 | import org.elasticsearch.monitor.jvm.JvmService; 19 | 20 | /** 21 | * A circuit breaker for memory usage. 22 | */ 23 | public class MemoryCircuitBreaker extends ThresholdCircuitBreaker { 24 | 25 | public static final short DEFAULT_JVM_HEAP_USAGE_THRESHOLD = 85; 26 | private final JvmService jvmService; 27 | 28 | public MemoryCircuitBreaker(JvmService jvmService) { 29 | super(DEFAULT_JVM_HEAP_USAGE_THRESHOLD); 30 | this.jvmService = jvmService; 31 | } 32 | 33 | public MemoryCircuitBreaker(short threshold, JvmService jvmService) { 34 | super(threshold); 35 | this.jvmService = jvmService; 36 | } 37 | 38 | @Override 39 | public boolean isOpen() { 40 | return jvmService.stats().getMem().getHeapUsedPercent() > this.getThreshold(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/breaker/ThresholdCircuitBreaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.breaker; 17 | 18 | /** 19 | * An abstract class for all breakers with threshold. 20 | * @param data type of threshold 21 | */ 22 | public abstract class ThresholdCircuitBreaker implements CircuitBreaker { 23 | 24 | private T threshold; 25 | 26 | public ThresholdCircuitBreaker(T threshold) { 27 | this.threshold = threshold; 28 | } 29 | 30 | public T getThreshold() { 31 | return threshold; 32 | } 33 | 34 | @Override 35 | public abstract boolean isOpen(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/caching/CacheProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.caching; 17 | 18 | import org.elasticsearch.common.inject.Provider; 19 | 20 | /** 21 | * A wrapper to call concrete implementation of caching. Used in transport 22 | * action. Don't use interface because transport action handler constructor 23 | * requires a concrete class as input. 24 | * 25 | */ 26 | public class CacheProvider implements Provider { 27 | private EntityCache cache; 28 | 29 | public CacheProvider(EntityCache cache) { 30 | this.cache = cache; 31 | } 32 | 33 | @Override 34 | public EntityCache get() { 35 | return cache; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/ADTaskCancelledException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | public class ADTaskCancelledException extends AnomalyDetectionException { 19 | private String cancelledBy; 20 | 21 | public ADTaskCancelledException(String msg, String user) { 22 | super(msg); 23 | this.cancelledBy = user; 24 | this.countedInStats(false); 25 | } 26 | 27 | public String getCancelledBy() { 28 | return cancelledBy; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/ClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | /** 19 | * All exception visible to AD transport layer's client is under ClientException. 20 | */ 21 | public class ClientException extends AnomalyDetectionException { 22 | 23 | public ClientException(String message) { 24 | super(message); 25 | } 26 | 27 | public ClientException(String anomalyDetectorId, String message) { 28 | super(anomalyDetectorId, message); 29 | } 30 | 31 | public ClientException(String anomalyDetectorId, String message, Throwable throwable) { 32 | super(anomalyDetectorId, message, throwable); 33 | } 34 | 35 | public ClientException(String anomalyDetectorId, Throwable cause) { 36 | super(anomalyDetectorId, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/DuplicateTaskException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | public class DuplicateTaskException extends AnomalyDetectionException { 19 | 20 | public DuplicateTaskException(String msg) { 21 | super(msg); 22 | this.countedInStats(false); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/EndRunException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | /** 19 | * Exception for failures that might impact the customer. 20 | * 21 | */ 22 | public class EndRunException extends ClientException { 23 | private boolean endNow; 24 | 25 | public EndRunException(String message, boolean endNow) { 26 | super(message); 27 | this.endNow = endNow; 28 | } 29 | 30 | public EndRunException(String anomalyDetectorId, String message, boolean endNow) { 31 | super(anomalyDetectorId, message); 32 | this.endNow = endNow; 33 | } 34 | 35 | public EndRunException(String anomalyDetectorId, String message, Throwable throwable, boolean endNow) { 36 | super(anomalyDetectorId, message, throwable); 37 | this.endNow = endNow; 38 | } 39 | 40 | /** 41 | * @return true for "unrecoverable issue". We want to terminate the detector run immediately. 42 | * false for "maybe unrecoverable issue but worth retrying a few more times." We want 43 | * to wait for a few more times on different requests before terminating the detector run. 44 | */ 45 | public boolean isEndNow() { 46 | return endNow; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/InternalFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | /** 19 | * Exception for root cause unknown failure. Maybe transient. Client can continue the detector running. 20 | * 21 | */ 22 | public class InternalFailure extends ClientException { 23 | 24 | public InternalFailure(String anomalyDetectorId, String message) { 25 | super(anomalyDetectorId, message); 26 | } 27 | 28 | public InternalFailure(String anomalyDetectorId, String message, Throwable cause) { 29 | super(anomalyDetectorId, message, cause); 30 | } 31 | 32 | public InternalFailure(String anomalyDetectorId, Throwable cause) { 33 | super(anomalyDetectorId, cause); 34 | } 35 | 36 | public InternalFailure(AnomalyDetectionException cause) { 37 | super(cause.getAnomalyDetectorId(), cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/common/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | /** 19 | * This exception is thrown when a resource is not found. 20 | */ 21 | public class ResourceNotFoundException extends AnomalyDetectionException { 22 | 23 | /** 24 | * Constructor with an anomaly detector ID and a message. 25 | * 26 | * @param detectorId ID of the detector related to the resource 27 | * @param message explains which resource is not found 28 | */ 29 | public ResourceNotFoundException(String detectorId, String message) { 30 | super(detectorId, message); 31 | countedInStats(false); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/constant/CommonMessageAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.constant; 17 | 18 | public class CommonMessageAttributes { 19 | 20 | // ====================================== 21 | // Json keys 22 | // ====================================== 23 | public static final String RCF_SCORE_JSON_KEY = "rCFScore"; 24 | public static final String ID_JSON_KEY = "adID"; 25 | public static final String MODEL_ID_JSON_KEY = "modelID"; 26 | public static final String FEATURE_JSON_KEY = "features"; 27 | public static final String CONFIDENCE_JSON_KEY = "confidence"; 28 | public static final String ANOMALY_GRADE_JSON_KEY = "anomalyGrade"; 29 | public static final String QUEUE_JSON_KEY = "queue"; 30 | public static final String START_JSON_KEY = "start"; 31 | public static final String END_JSON_KEY = "end"; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/constant/CommonValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.constant; 17 | 18 | public class CommonValue { 19 | // unknown or no schema version 20 | public static Integer NO_SCHEMA_VERSION = 0; 21 | public static String INTERNAL_ACTION_PREFIX = "cluster:admin/opendistro/adinternal/"; 22 | public static String EXTERNAL_ACTION_PREFIX = "cluster:admin/opendistro/ad/"; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/dataprocessor/IntegerSensitiveSingleFeatureLinearUniformInterpolator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.dataprocessor; 17 | 18 | import java.util.Arrays; 19 | 20 | import com.google.common.math.DoubleMath; 21 | 22 | /** 23 | * Interpolator sensitive to integral values. 24 | */ 25 | public class IntegerSensitiveSingleFeatureLinearUniformInterpolator extends SingleFeatureLinearUniformInterpolator { 26 | 27 | /** 28 | * Interpolates integral/floating-point results. 29 | * 30 | * If all samples are integral, the results are integral. 31 | * Else, the results are floating points. 32 | * 33 | * @param samples integral/floating-point samples 34 | * @param numInterpolants the number of interpolants 35 | * @return {code numInterpolants} interpolated results 36 | */ 37 | public double[] interpolate(double[] samples, int numInterpolants) { 38 | double[] interpolants = super.interpolate(samples, numInterpolants); 39 | if (Arrays.stream(samples).allMatch(DoubleMath::isMathematicalInteger)) { 40 | interpolants = Arrays.stream(interpolants).map(Math::rint).toArray(); 41 | } 42 | return interpolants; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/dataprocessor/Interpolator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.dataprocessor; 17 | 18 | /* 19 | * An object for interpolating feature vectors. 20 | * 21 | * In certain situations, due to time and compute cost, we are only allowed to 22 | * query a sparse sample of data points / feature vectors from a cluster. 23 | * However, we need a large sample of feature vectors in order to train our 24 | * anomaly detection algorithms. An Interpolator approximates the data points 25 | * between a given, ordered list of samples. 26 | */ 27 | public interface Interpolator { 28 | 29 | /* 30 | * Interpolates the given sample feature vectors. 31 | * 32 | * Computes a list `numInterpolants` feature vectors using the ordered list 33 | * of `numSamples` input sample vectors where each sample vector has size 34 | * `numFeatures`. 35 | * 36 | * @param samples A `numFeatures x numSamples` list of feature vectors. 37 | * @param numInterpolants The desired number of interpolating vectors. 38 | * @return A `numFeatures x numInterpolants` list of feature vectors. 39 | */ 40 | double[][] interpolate(double[][] samples, int numInterpolants); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/feature/SinglePointFeatures.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.feature; 17 | 18 | import java.util.Optional; 19 | 20 | /** 21 | * Features for one data point. 22 | * 23 | * A data point consists of unprocessed features (raw search results) and corresponding processed ML features. 24 | */ 25 | public class SinglePointFeatures { 26 | 27 | private final Optional unprocessedFeatures; 28 | private final Optional processedFeatures; 29 | 30 | /** 31 | * Constructor. 32 | * 33 | * @param unprocessedFeatures unprocessed features 34 | * @param processedFeatures processed features 35 | */ 36 | public SinglePointFeatures(Optional unprocessedFeatures, Optional processedFeatures) { 37 | this.unprocessedFeatures = unprocessedFeatures; 38 | this.processedFeatures = processedFeatures; 39 | } 40 | 41 | /** 42 | * Returns unprocessed features. 43 | * 44 | * @return unprocessed features 45 | */ 46 | public Optional getUnprocessedFeatures() { 47 | return this.unprocessedFeatures; 48 | } 49 | 50 | /** 51 | * Returns processed features. 52 | * 53 | * @return processed features 54 | */ 55 | public Optional getProcessedFeatures() { 56 | return this.processedFeatures; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/ml/KllFloatsSketchSerDe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.ml; 17 | 18 | import java.lang.reflect.Type; 19 | import java.util.Base64; 20 | 21 | import com.google.gson.JsonDeserializationContext; 22 | import com.google.gson.JsonDeserializer; 23 | import com.google.gson.JsonElement; 24 | import com.google.gson.JsonPrimitive; 25 | import com.google.gson.JsonSerializationContext; 26 | import com.google.gson.JsonSerializer; 27 | import com.yahoo.memory.Memory; 28 | import com.yahoo.sketches.kll.KllFloatsSketch; 29 | 30 | /** 31 | * Serializes/deserailizes KllFloatsSketch. 32 | * 33 | * A sketch is serialized to a byte array and then encoded in Base64. 34 | */ 35 | public class KllFloatsSketchSerDe implements JsonSerializer, JsonDeserializer { 36 | 37 | @Override 38 | public JsonElement serialize(KllFloatsSketch src, Type typeOfSrc, JsonSerializationContext context) { 39 | return new JsonPrimitive(Base64.getEncoder().encodeToString(src.toByteArray())); 40 | } 41 | 42 | @Override 43 | public KllFloatsSketch deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { 44 | return KllFloatsSketch.heapify(Memory.wrap(Base64.getDecoder().decode(json.getAsString()))); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/ADTaskAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public enum ADTaskAction { 19 | START, 20 | STOP 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/ADTaskType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public enum ADTaskType { 19 | REALTIME, 20 | HISTORICAL 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public enum AnomalyDetectorType { 19 | REALTIME_SINGLE_ENTITY, 20 | REALTIME_MULTI_ENTITY, 21 | HISTORICAL_SINGLE_ENTITY, 22 | HISTORICAL_MULTI_ENTITY 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/DetectorState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public enum DetectorState { 19 | DISABLED, 20 | INIT, 21 | RUNNING 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/EntityAnomalyResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | import java.util.List; 19 | 20 | public class EntityAnomalyResult implements Mergeable { 21 | 22 | private List anomalyResults; 23 | 24 | public EntityAnomalyResult(List anomalyResults) { 25 | this.anomalyResults = anomalyResults; 26 | } 27 | 28 | public List getAnomalyResults() { 29 | return anomalyResults; 30 | } 31 | 32 | @Override 33 | public void merge(Mergeable other) { 34 | if (this == other || other == null || getClass() != other.getClass()) { 35 | return; 36 | } 37 | EntityAnomalyResult otherEntityAnomalyResult = (EntityAnomalyResult) other; 38 | if (otherEntityAnomalyResult.getAnomalyResults() != null) { 39 | this.anomalyResults.addAll(otherEntityAnomalyResult.getAnomalyResults()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/EntityState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public enum EntityState { 19 | UNKNOWN, 20 | INIT, 21 | RUNNING 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/model/Mergeable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | public interface Mergeable { 19 | void merge(Mergeable other); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchADTasksAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.rest; 17 | 18 | import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; 19 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonName; 20 | import com.amazon.opendistroforelasticsearch.ad.model.ADTask; 21 | import com.amazon.opendistroforelasticsearch.ad.transport.SearchADTasksAction; 22 | 23 | /** 24 | * This class consists of the REST handler to search AD tasks. 25 | */ 26 | public class RestSearchADTasksAction extends AbstractSearchAction { 27 | 28 | private static final String URL_PATH = AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI + "/tasks/_search"; 29 | private final String SEARCH_ANOMALY_DETECTION_TASKS = "search_anomaly_detection_tasks"; 30 | 31 | public RestSearchADTasksAction() { 32 | super(URL_PATH, CommonName.DETECTION_STATE_INDEX, ADTask.class, SearchADTasksAction.INSTANCE); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | return SEARCH_ANOMALY_DETECTION_TASKS; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.rest; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; 21 | import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector; 22 | import com.amazon.opendistroforelasticsearch.ad.transport.SearchAnomalyDetectorAction; 23 | 24 | /** 25 | * This class consists of the REST handler to search anomaly detectors. 26 | */ 27 | public class RestSearchAnomalyDetectorAction extends AbstractSearchAction { 28 | 29 | private static final String URL_PATH = AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI + "/_search"; 30 | private final String SEARCH_ANOMALY_DETECTOR_ACTION = "search_anomaly_detector"; 31 | 32 | public RestSearchAnomalyDetectorAction() { 33 | super(URL_PATH, ANOMALY_DETECTORS_INDEX, AnomalyDetector.class, SearchAnomalyDetectorAction.INSTANCE); 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return SEARCH_ANOMALY_DETECTOR_ACTION; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.rest; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.indices.AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; 21 | import com.amazon.opendistroforelasticsearch.ad.model.AnomalyResult; 22 | import com.amazon.opendistroforelasticsearch.ad.transport.SearchAnomalyResultAction; 23 | 24 | /** 25 | * This class consists of the REST handler to search anomaly results. 26 | */ 27 | public class RestSearchAnomalyResultAction extends AbstractSearchAction { 28 | 29 | private static final String URL_PATH = AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI + "/results/_search"; 30 | private final String SEARCH_ANOMALY_DETECTOR_ACTION = "search_anomaly_result"; 31 | 32 | public RestSearchAnomalyResultAction() { 33 | super(URL_PATH, ALL_AD_RESULTS_INDEX_PATTERN, AnomalyResult.class, SearchAnomalyResultAction.INSTANCE); 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return SEARCH_ANOMALY_DETECTOR_ACTION; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/AnomalyDetectorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.rest.handler; 17 | 18 | @FunctionalInterface 19 | public interface AnomalyDetectorFunction { 20 | 21 | /** 22 | * Performs this operation. 23 | * 24 | * Notes: don't forget to send back responses via channel if you process response with this method. 25 | */ 26 | void execute(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/stats/InternalStatNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats; 17 | 18 | /** 19 | * Enum containing names of all internal stats which will not be returned 20 | * in AD stats REST API. 21 | */ 22 | public enum InternalStatNames { 23 | JVM_HEAP_USAGE("jvm_heap_usage"); 24 | 25 | private String name; 26 | 27 | InternalStatNames(String name) { 28 | this.name = name; 29 | } 30 | 31 | /** 32 | * Get internal stat name 33 | * 34 | * @return name 35 | */ 36 | public String getName() { 37 | return name; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/stats/suppliers/CounterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats.suppliers; 17 | 18 | import java.util.concurrent.atomic.LongAdder; 19 | import java.util.function.Supplier; 20 | 21 | /** 22 | * CounterSupplier provides a stateful count as the value 23 | */ 24 | public class CounterSupplier implements Supplier { 25 | private LongAdder counter; 26 | 27 | /** 28 | * Constructor 29 | */ 30 | public CounterSupplier() { 31 | this.counter = new LongAdder(); 32 | } 33 | 34 | @Override 35 | public Long get() { 36 | return counter.longValue(); 37 | } 38 | 39 | /** 40 | * Increments the value of the counter by 1 41 | */ 42 | public void increment() { 43 | counter.increment(); 44 | } 45 | 46 | /** 47 | * Decrease the value of the counter by 1 48 | */ 49 | public void decrement() { 50 | counter.decrement(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/stats/suppliers/IndexStatusSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats.suppliers; 17 | 18 | import java.util.function.Supplier; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.util.IndexUtils; 21 | 22 | /** 23 | * IndexStatusSupplier provides the status of an index as the value 24 | */ 25 | public class IndexStatusSupplier implements Supplier { 26 | private IndexUtils indexUtils; 27 | private String indexName; 28 | 29 | public static final String UNABLE_TO_RETRIEVE_HEALTH_MESSAGE = "unable to retrieve health"; 30 | 31 | /** 32 | * Constructor 33 | * 34 | * @param indexUtils Utility for getting information about indices 35 | * @param indexName Name of index to extract stats from 36 | */ 37 | public IndexStatusSupplier(IndexUtils indexUtils, String indexName) { 38 | this.indexUtils = indexUtils; 39 | this.indexName = indexName; 40 | } 41 | 42 | @Override 43 | public String get() { 44 | try { 45 | return indexUtils.getIndexHealthStatus(indexName); 46 | } catch (IllegalArgumentException e) { 47 | return UNABLE_TO_RETRIEVE_HEALTH_MESSAGE; 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/stats/suppliers/SettableSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats.suppliers; 17 | 18 | import java.util.concurrent.atomic.AtomicLong; 19 | import java.util.function.Supplier; 20 | 21 | /** 22 | * SettableSupplier allows a user to set the value of the supplier to be returned 23 | */ 24 | public class SettableSupplier implements Supplier { 25 | protected AtomicLong value; 26 | 27 | /** 28 | * Constructor 29 | */ 30 | public SettableSupplier() { 31 | this.value = new AtomicLong(0L); 32 | } 33 | 34 | @Override 35 | public Long get() { 36 | return value.get(); 37 | } 38 | 39 | /** 40 | * Set value to be returned by get 41 | * 42 | * @param value to set 43 | */ 44 | public void set(Long value) { 45 | this.value.set(value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/task/ADTaskCancellationState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.task; 17 | 18 | public enum ADTaskCancellationState { 19 | NOT_FOUND, 20 | CANCELLED, 21 | ALREADY_CANCELLED 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.constant.CommonName.AD_TASK; 19 | 20 | import org.elasticsearch.action.ActionType; 21 | 22 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 23 | 24 | public class ADBatchAnomalyResultAction extends ActionType { 25 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detector/" + AD_TASK; 26 | public static final ADBatchAnomalyResultAction INSTANCE = new ADBatchAnomalyResultAction(); 27 | 28 | private ADBatchAnomalyResultAction() { 29 | super(NAME, ADBatchAnomalyResultResponse::new); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.ActionResponse; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | 24 | public class ADBatchAnomalyResultResponse extends ActionResponse { 25 | public String nodeId; 26 | public boolean runTaskRemotely; 27 | 28 | public ADBatchAnomalyResultResponse(String nodeId, boolean runTaskRemotely) { 29 | this.nodeId = nodeId; 30 | this.runTaskRemotely = runTaskRemotely; 31 | } 32 | 33 | public ADBatchAnomalyResultResponse(StreamInput in) throws IOException { 34 | super(in); 35 | nodeId = in.readString(); 36 | runTaskRemotely = in.readBoolean(); 37 | } 38 | 39 | @Override 40 | public void writeTo(StreamOutput out) throws IOException { 41 | out.writeString(nodeId); 42 | out.writeBoolean(runTaskRemotely); 43 | } 44 | 45 | public String getNodeId() { 46 | return nodeId; 47 | } 48 | 49 | public boolean isRunTaskRemotely() { 50 | return runTaskRemotely; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchTaskRemoteExecutionAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.constant.CommonName.AD_TASK_REMOTE; 19 | 20 | import org.elasticsearch.action.ActionType; 21 | 22 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 23 | 24 | public class ADBatchTaskRemoteExecutionAction extends ActionType { 25 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detector/" + AD_TASK_REMOTE; 26 | public static final ADBatchTaskRemoteExecutionAction INSTANCE = new ADBatchTaskRemoteExecutionAction(); 27 | 28 | private ADBatchTaskRemoteExecutionAction() { 29 | super(NAME, ADBatchAnomalyResultResponse::new); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADCancelTaskAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.constant.CommonName.CANCEL_TASK; 19 | 20 | import org.elasticsearch.action.ActionType; 21 | 22 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 23 | 24 | public class ADCancelTaskAction extends ActionType { 25 | 26 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detectors/" + CANCEL_TASK; 27 | public static final ADCancelTaskAction INSTANCE = new ADCancelTaskAction(); 28 | 29 | private ADCancelTaskAction() { 30 | super(NAME, ADCancelTaskResponse::new); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADCancelTaskNodeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeRequest; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | 24 | public class ADCancelTaskNodeRequest extends BaseNodeRequest { 25 | private String detectorId; 26 | private String userName; 27 | 28 | public ADCancelTaskNodeRequest(StreamInput in) throws IOException { 29 | super(in); 30 | this.detectorId = in.readOptionalString(); 31 | this.userName = in.readOptionalString(); 32 | } 33 | 34 | public ADCancelTaskNodeRequest(ADCancelTaskRequest request) { 35 | this.detectorId = request.getDetectorId(); 36 | this.userName = request.getUserName(); 37 | } 38 | 39 | @Override 40 | public void writeTo(StreamOutput out) throws IOException { 41 | super.writeTo(out); 42 | out.writeOptionalString(detectorId); 43 | out.writeOptionalString(userName); 44 | } 45 | 46 | public String getDetectorId() { 47 | return detectorId; 48 | } 49 | 50 | public String getUserName() { 51 | return userName; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADCancelTaskNodeResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeResponse; 21 | import org.elasticsearch.cluster.node.DiscoveryNode; 22 | import org.elasticsearch.common.io.stream.StreamInput; 23 | import org.elasticsearch.common.io.stream.StreamOutput; 24 | 25 | import com.amazon.opendistroforelasticsearch.ad.task.ADTaskCancellationState; 26 | 27 | public class ADCancelTaskNodeResponse extends BaseNodeResponse { 28 | 29 | private ADTaskCancellationState state; 30 | 31 | public ADCancelTaskNodeResponse(DiscoveryNode node, ADTaskCancellationState state) { 32 | super(node); 33 | this.state = state; 34 | } 35 | 36 | public ADCancelTaskNodeResponse(StreamInput in) throws IOException { 37 | super(in); 38 | this.state = in.readEnum(ADTaskCancellationState.class); 39 | } 40 | 41 | @Override 42 | public void writeTo(StreamOutput out) throws IOException { 43 | super.writeTo(out); 44 | out.writeEnum(state); 45 | } 46 | 47 | public static ADCancelTaskNodeResponse readNodeResponse(StreamInput in) throws IOException { 48 | return new ADCancelTaskNodeResponse(in); 49 | } 50 | 51 | public ADTaskCancellationState getState() { 52 | return state; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADCancelTaskResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | import java.util.List; 20 | 21 | import org.elasticsearch.action.FailedNodeException; 22 | import org.elasticsearch.action.support.nodes.BaseNodesResponse; 23 | import org.elasticsearch.cluster.ClusterName; 24 | import org.elasticsearch.common.io.stream.StreamInput; 25 | import org.elasticsearch.common.io.stream.StreamOutput; 26 | 27 | public class ADCancelTaskResponse extends BaseNodesResponse { 28 | 29 | public ADCancelTaskResponse(StreamInput in) throws IOException { 30 | super(new ClusterName(in), in.readList(ADCancelTaskNodeResponse::readNodeResponse), in.readList(FailedNodeException::new)); 31 | } 32 | 33 | public ADCancelTaskResponse(ClusterName clusterName, List nodes, List failures) { 34 | super(clusterName, nodes, failures); 35 | } 36 | 37 | @Override 38 | public void writeNodesTo(StreamOutput out, List nodes) throws IOException { 39 | out.writeList(nodes); 40 | } 41 | 42 | @Override 43 | public List readNodesFrom(StreamInput in) throws IOException { 44 | return in.readList(ADCancelTaskNodeResponse::readNodeResponse); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADResultBulkAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.bulk.BulkResponse; 20 | import org.elasticsearch.common.settings.Settings; 21 | import org.elasticsearch.transport.TransportRequestOptions; 22 | 23 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 24 | 25 | public class ADResultBulkAction extends ActionType { 26 | 27 | // Internal Action which is not used for public facing RestAPIs. 28 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "write/bulk"; 29 | public static final ADResultBulkAction INSTANCE = new ADResultBulkAction(); 30 | 31 | private ADResultBulkAction() { 32 | super(NAME, BulkResponse::new); 33 | } 34 | 35 | @Override 36 | public TransportRequestOptions transportOptions(Settings settings) { 37 | return TransportRequestOptions.builder().withType(TransportRequestOptions.Type.BULK).build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeRequest; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | 24 | /** 25 | * ADStatsNodeRequest to get a nodes stat 26 | */ 27 | public class ADStatsNodeRequest extends BaseNodeRequest { 28 | private ADStatsRequest request; 29 | 30 | /** 31 | * Constructor 32 | */ 33 | public ADStatsNodeRequest() { 34 | super(); 35 | } 36 | 37 | public ADStatsNodeRequest(StreamInput in) throws IOException { 38 | super(in); 39 | this.request = new ADStatsRequest(in); 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param request ADStatsRequest 46 | */ 47 | public ADStatsNodeRequest(ADStatsRequest request) { 48 | this.request = request; 49 | } 50 | 51 | /** 52 | * Get ADStatsRequest 53 | * 54 | * @return ADStatsRequest for this node 55 | */ 56 | public ADStatsRequest getADStatsRequest() { 57 | return request; 58 | } 59 | 60 | @Override 61 | public void writeTo(StreamOutput out) throws IOException { 62 | super.writeTo(out); 63 | request.writeTo(out); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodesAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | /** 23 | * ADStatsNodesAction class 24 | */ 25 | public class ADStatsNodesAction extends ActionType { 26 | 27 | // Internal Action which is not used for public facing RestAPIs. 28 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "stats/nodes"; 29 | public static final ADStatsNodesAction INSTANCE = new ADStatsNodesAction(); 30 | 31 | /** 32 | * Constructor 33 | */ 34 | private ADStatsNodesAction() { 35 | super(NAME, ADStatsNodesResponse::new); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADTaskProfileAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.constant.CommonName.AD_TASK; 19 | 20 | import org.elasticsearch.action.ActionType; 21 | 22 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 23 | 24 | public class ADTaskProfileAction extends ActionType { 25 | 26 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detectors/profile/" + AD_TASK; 27 | public static final ADTaskProfileAction INSTANCE = new ADTaskProfileAction(); 28 | 29 | private ADTaskProfileAction() { 30 | super(NAME, ADTaskProfileResponse::new); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADTaskProfileNodeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeRequest; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | 24 | public class ADTaskProfileNodeRequest extends BaseNodeRequest { 25 | private String detectorId; 26 | 27 | public ADTaskProfileNodeRequest(StreamInput in) throws IOException { 28 | super(in); 29 | this.detectorId = in.readString(); 30 | } 31 | 32 | public ADTaskProfileNodeRequest(ADTaskProfileRequest request) { 33 | this.detectorId = request.getDetectorId(); 34 | } 35 | 36 | @Override 37 | public void writeTo(StreamOutput out) throws IOException { 38 | super.writeTo(out); 39 | out.writeString(detectorId); 40 | } 41 | 42 | public String getDetectorId() { 43 | return detectorId; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADTaskProfileResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | import java.util.List; 20 | 21 | import org.elasticsearch.action.FailedNodeException; 22 | import org.elasticsearch.action.support.nodes.BaseNodesResponse; 23 | import org.elasticsearch.cluster.ClusterName; 24 | import org.elasticsearch.common.io.stream.StreamInput; 25 | import org.elasticsearch.common.io.stream.StreamOutput; 26 | 27 | public class ADTaskProfileResponse extends BaseNodesResponse { 28 | 29 | public ADTaskProfileResponse(StreamInput in) throws IOException { 30 | super(new ClusterName(in), in.readList(ADTaskProfileNodeResponse::readNodeResponse), in.readList(FailedNodeException::new)); 31 | } 32 | 33 | public ADTaskProfileResponse(ClusterName clusterName, List nodes, List failures) { 34 | super(clusterName, nodes, failures); 35 | } 36 | 37 | @Override 38 | public void writeNodesTo(StreamOutput out, List nodes) throws IOException { 39 | out.writeList(nodes); 40 | } 41 | 42 | @Override 43 | public List readNodesFrom(StreamInput in) throws IOException { 44 | return in.readList(ADTaskProfileNodeResponse::readNodeResponse); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyDetectorJobAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class AnomalyDetectorJobAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/jobmanagement"; 25 | public static final AnomalyDetectorJobAction INSTANCE = new AnomalyDetectorJobAction(); 26 | 27 | private AnomalyDetectorJobAction() { 28 | super(NAME, AnomalyDetectorJobResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class AnomalyResultAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/run"; 25 | public static final AnomalyResultAction INSTANCE = new AnomalyResultAction(); 26 | 27 | private AnomalyResultAction() { 28 | super(NAME, AnomalyResultResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class CronAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "cron"; 25 | public static final CronAction INSTANCE = new CronAction(); 26 | 27 | private CronAction() { 28 | super(NAME, CronResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeRequest; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | 23 | /** 24 | * Delete model represents the request to an individual node 25 | */ 26 | public class CronNodeRequest extends BaseNodeRequest { 27 | 28 | public CronNodeRequest() {} 29 | 30 | public CronNodeRequest(StreamInput in) throws IOException { 31 | super(in); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeResponse; 21 | import org.elasticsearch.cluster.node.DiscoveryNode; 22 | import org.elasticsearch.common.io.stream.StreamInput; 23 | import org.elasticsearch.common.xcontent.ToXContentObject; 24 | import org.elasticsearch.common.xcontent.XContentBuilder; 25 | 26 | public class CronNodeResponse extends BaseNodeResponse implements ToXContentObject { 27 | static String NODE_ID = "node_id"; 28 | 29 | public CronNodeResponse(StreamInput in) throws IOException { 30 | super(in); 31 | } 32 | 33 | public CronNodeResponse(DiscoveryNode node) { 34 | super(node); 35 | } 36 | 37 | public static CronNodeResponse readNodeResponse(StreamInput in) throws IOException { 38 | 39 | return new CronNodeResponse(in); 40 | } 41 | 42 | @Override 43 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { 44 | builder.startObject(); 45 | builder.field(NODE_ID, getNode().getId()); 46 | builder.endObject(); 47 | return builder; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodesRequest; 21 | import org.elasticsearch.cluster.node.DiscoveryNode; 22 | import org.elasticsearch.common.io.stream.StreamInput; 23 | 24 | /** 25 | * Request should be sent from the handler logic of transport delete detector API 26 | * 27 | */ 28 | public class CronRequest extends BaseNodesRequest { 29 | 30 | public CronRequest() { 31 | super((String[]) null); 32 | } 33 | 34 | public CronRequest(StreamInput in) throws IOException { 35 | super(in); 36 | } 37 | 38 | public CronRequest(DiscoveryNode... nodes) { 39 | super(nodes); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.delete.DeleteResponse; 20 | 21 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 22 | 23 | public class DeleteAnomalyDetectorAction extends ActionType { 24 | // External Action which used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/delete"; 26 | public static final DeleteAnomalyDetectorAction INSTANCE = new DeleteAnomalyDetectorAction(); 27 | 28 | private DeleteAnomalyDetectorAction() { 29 | super(NAME, DeleteResponse::new); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class DeleteModelAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "model/delete"; 25 | public static final DeleteModelAction INSTANCE = new DeleteModelAction(); 26 | 27 | private DeleteModelAction() { 28 | super(NAME, DeleteModelResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeRequest; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | 24 | /** 25 | * Delete model represents the request to an individual node 26 | */ 27 | public class DeleteModelNodeRequest extends BaseNodeRequest { 28 | 29 | private String adID; 30 | 31 | DeleteModelNodeRequest() {} 32 | 33 | DeleteModelNodeRequest(StreamInput in) throws IOException { 34 | super(in); 35 | this.adID = in.readString(); 36 | } 37 | 38 | DeleteModelNodeRequest(DeleteModelRequest request) { 39 | this.adID = request.getAdID(); 40 | } 41 | 42 | @Override 43 | public void writeTo(StreamOutput out) throws IOException { 44 | super.writeTo(out); 45 | out.writeString(adID); 46 | } 47 | 48 | public String getAdID() { 49 | return adID; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.support.nodes.BaseNodeResponse; 21 | import org.elasticsearch.cluster.node.DiscoveryNode; 22 | import org.elasticsearch.common.io.stream.StreamInput; 23 | import org.elasticsearch.common.xcontent.ToXContentObject; 24 | import org.elasticsearch.common.xcontent.XContentBuilder; 25 | 26 | public class DeleteModelNodeResponse extends BaseNodeResponse implements ToXContentObject { 27 | static String NODE_ID = "node_id"; 28 | 29 | public DeleteModelNodeResponse(StreamInput in) throws IOException { 30 | super(in); 31 | } 32 | 33 | public DeleteModelNodeResponse(DiscoveryNode node) { 34 | super(node); 35 | } 36 | 37 | public static DeleteModelNodeResponse readNodeResponse(StreamInput in) throws IOException { 38 | 39 | return new DeleteModelNodeResponse(in); 40 | } 41 | 42 | @Override 43 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { 44 | builder.startObject(); 45 | builder.field(NODE_ID, getNode().getId()); 46 | builder.endObject(); 47 | return builder; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityProfileAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class EntityProfileAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detectors/profile/entity"; 25 | public static final EntityProfileAction INSTANCE = new EntityProfileAction(); 26 | 27 | private EntityProfileAction() { 28 | super(NAME, EntityProfileResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.support.master.AcknowledgedResponse; 20 | 21 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 22 | 23 | public class EntityResultAction extends ActionType { 24 | // Internal Action which is not used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "entity/result"; 26 | public static final EntityResultAction INSTANCE = new EntityResultAction(); 27 | 28 | private EntityResultAction() { 29 | super(NAME, AcknowledgedResponse::new); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ForwardADTaskAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import static com.amazon.opendistroforelasticsearch.ad.constant.CommonName.AD_TASK; 19 | 20 | import org.elasticsearch.action.ActionType; 21 | 22 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 23 | 24 | public class ForwardADTaskAction extends ActionType { 25 | // Internal Action which is not used for public facing RestAPIs. 26 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detector/" + AD_TASK + "/forward"; 27 | public static final ForwardADTaskAction INSTANCE = new ForwardADTaskAction(); 28 | 29 | private ForwardADTaskAction() { 30 | super(NAME, AnomalyDetectorJobResponse::new); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/GetAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class GetAnomalyDetectorAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detectors/get"; 25 | public static final GetAnomalyDetectorAction INSTANCE = new GetAnomalyDetectorAction(); 26 | 27 | private GetAnomalyDetectorAction() { 28 | super(NAME, GetAnomalyDetectorResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/IndexAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class IndexAnomalyDetectorAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/write"; 25 | public static final IndexAnomalyDetectorAction INSTANCE = new IndexAnomalyDetectorAction(); 26 | 27 | private IndexAnomalyDetectorAction() { 28 | super(NAME, IndexAnomalyDetectorResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/PreviewAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class PreviewAnomalyDetectorAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/preview"; 25 | public static final PreviewAnomalyDetectorAction INSTANCE = new PreviewAnomalyDetectorAction(); 26 | 27 | private PreviewAnomalyDetectorAction() { 28 | super(NAME, PreviewAnomalyDetectorResponse::new); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ProfileAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | /** 23 | * Profile transport action 24 | */ 25 | public class ProfileAction extends ActionType { 26 | // Internal Action which is not used for public facing RestAPIs. 27 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detectors/profile"; 28 | public static final ProfileAction INSTANCE = new ProfileAction(); 29 | 30 | /** 31 | * Constructor 32 | */ 33 | private ProfileAction() { 34 | super(NAME, ProfileResponse::new); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFPollingAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class RCFPollingAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "rcfpolling"; 25 | public static final RCFPollingAction INSTANCE = new RCFPollingAction(); 26 | 27 | private RCFPollingAction() { 28 | super(NAME, RCFPollingResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFPollingResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.ActionResponse; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | import org.elasticsearch.common.xcontent.ToXContentObject; 24 | import org.elasticsearch.common.xcontent.XContentBuilder; 25 | 26 | public class RCFPollingResponse extends ActionResponse implements ToXContentObject { 27 | public static final String TOTAL_UPDATES_KEY = "totalUpdates"; 28 | 29 | private final long totalUpdates; 30 | 31 | public RCFPollingResponse(long totalUpdates) { 32 | this.totalUpdates = totalUpdates; 33 | } 34 | 35 | public RCFPollingResponse(StreamInput in) throws IOException { 36 | super(in); 37 | totalUpdates = in.readVLong(); 38 | } 39 | 40 | public long getTotalUpdates() { 41 | return totalUpdates; 42 | } 43 | 44 | @Override 45 | public void writeTo(StreamOutput out) throws IOException { 46 | out.writeVLong(totalUpdates); 47 | } 48 | 49 | @Override 50 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { 51 | builder.startObject(); 52 | builder.field(TOTAL_UPDATES_KEY, totalUpdates); 53 | builder.endObject(); 54 | return builder; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class RCFResultAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "rcf/result"; 25 | public static final RCFResultAction INSTANCE = new RCFResultAction(); 26 | 27 | private RCFResultAction() { 28 | super(NAME, RCFResultResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchADTasksAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.search.SearchResponse; 20 | 21 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 22 | 23 | public class SearchADTasksAction extends ActionType { 24 | // External Action which used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "tasks/search"; 26 | public static final SearchADTasksAction INSTANCE = new SearchADTasksAction(); 27 | 28 | private SearchADTasksAction() { 29 | super(NAME, SearchResponse::new); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchADTasksTransportAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionListener; 19 | import org.elasticsearch.action.search.SearchRequest; 20 | import org.elasticsearch.action.search.SearchResponse; 21 | import org.elasticsearch.action.support.ActionFilters; 22 | import org.elasticsearch.action.support.HandledTransportAction; 23 | import org.elasticsearch.common.inject.Inject; 24 | import org.elasticsearch.tasks.Task; 25 | import org.elasticsearch.transport.TransportService; 26 | 27 | import com.amazon.opendistroforelasticsearch.ad.transport.handler.ADSearchHandler; 28 | 29 | public class SearchADTasksTransportAction extends HandledTransportAction { 30 | private ADSearchHandler searchHandler; 31 | 32 | @Inject 33 | public SearchADTasksTransportAction(TransportService transportService, ActionFilters actionFilters, ADSearchHandler searchHandler) { 34 | super(SearchADTasksAction.NAME, transportService, actionFilters, SearchRequest::new); 35 | this.searchHandler = searchHandler; 36 | } 37 | 38 | @Override 39 | protected void doExecute(Task task, SearchRequest request, ActionListener listener) { 40 | searchHandler.search(request, listener); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.search.SearchResponse; 20 | 21 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 22 | 23 | public class SearchAnomalyDetectorAction extends ActionType { 24 | // External Action which used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/search"; 26 | public static final SearchAnomalyDetectorAction INSTANCE = new SearchAnomalyDetectorAction(); 27 | 28 | private SearchAnomalyDetectorAction() { 29 | super(NAME, SearchResponse::new); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorInfoAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class SearchAnomalyDetectorInfoAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/info"; 25 | public static final SearchAnomalyDetectorInfoAction INSTANCE = new SearchAnomalyDetectorInfoAction(); 26 | 27 | private SearchAnomalyDetectorInfoAction() { 28 | super(NAME, SearchAnomalyDetectorInfoResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorInfoRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.ActionRequest; 21 | import org.elasticsearch.action.ActionRequestValidationException; 22 | import org.elasticsearch.common.io.stream.StreamInput; 23 | import org.elasticsearch.common.io.stream.StreamOutput; 24 | 25 | public class SearchAnomalyDetectorInfoRequest extends ActionRequest { 26 | 27 | private String name; 28 | private String rawPath; 29 | 30 | public SearchAnomalyDetectorInfoRequest(StreamInput in) throws IOException { 31 | super(in); 32 | name = in.readOptionalString(); 33 | rawPath = in.readString(); 34 | } 35 | 36 | public SearchAnomalyDetectorInfoRequest(String name, String rawPath) throws IOException { 37 | super(); 38 | this.name = name; 39 | this.rawPath = rawPath; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public String getRawPath() { 47 | return rawPath; 48 | } 49 | 50 | @Override 51 | public void writeTo(StreamOutput out) throws IOException { 52 | super.writeTo(out); 53 | out.writeOptionalString(name); 54 | out.writeString(rawPath); 55 | } 56 | 57 | @Override 58 | public ActionRequestValidationException validate() { 59 | return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorTransportAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionListener; 19 | import org.elasticsearch.action.search.SearchRequest; 20 | import org.elasticsearch.action.search.SearchResponse; 21 | import org.elasticsearch.action.support.ActionFilters; 22 | import org.elasticsearch.action.support.HandledTransportAction; 23 | import org.elasticsearch.common.inject.Inject; 24 | import org.elasticsearch.tasks.Task; 25 | import org.elasticsearch.transport.TransportService; 26 | 27 | import com.amazon.opendistroforelasticsearch.ad.transport.handler.ADSearchHandler; 28 | 29 | public class SearchAnomalyDetectorTransportAction extends HandledTransportAction { 30 | private ADSearchHandler searchHandler; 31 | 32 | @Inject 33 | public SearchAnomalyDetectorTransportAction( 34 | TransportService transportService, 35 | ActionFilters actionFilters, 36 | ADSearchHandler searchHandler 37 | ) { 38 | super(SearchAnomalyDetectorAction.NAME, transportService, actionFilters, SearchRequest::new); 39 | this.searchHandler = searchHandler; 40 | } 41 | 42 | @Override 43 | protected void doExecute(Task task, SearchRequest request, ActionListener listener) { 44 | searchHandler.search(request, listener); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | import org.elasticsearch.action.search.SearchResponse; 20 | 21 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 22 | 23 | public class SearchAnomalyResultAction extends ActionType { 24 | // External Action which used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "result/search"; 26 | public static final SearchAnomalyResultAction INSTANCE = new SearchAnomalyResultAction(); 27 | 28 | private SearchAnomalyResultAction() { 29 | super(NAME, SearchResponse::new); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyResultTransportAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionListener; 19 | import org.elasticsearch.action.search.SearchRequest; 20 | import org.elasticsearch.action.search.SearchResponse; 21 | import org.elasticsearch.action.support.ActionFilters; 22 | import org.elasticsearch.action.support.HandledTransportAction; 23 | import org.elasticsearch.common.inject.Inject; 24 | import org.elasticsearch.tasks.Task; 25 | import org.elasticsearch.transport.TransportService; 26 | 27 | import com.amazon.opendistroforelasticsearch.ad.transport.handler.ADSearchHandler; 28 | 29 | public class SearchAnomalyResultTransportAction extends HandledTransportAction { 30 | private ADSearchHandler searchHandler; 31 | 32 | @Inject 33 | public SearchAnomalyResultTransportAction( 34 | TransportService transportService, 35 | ActionFilters actionFilters, 36 | ADSearchHandler searchHandler 37 | ) { 38 | super(SearchAnomalyResultAction.NAME, transportService, actionFilters, SearchRequest::new); 39 | this.searchHandler = searchHandler; 40 | } 41 | 42 | @Override 43 | protected void doExecute(Task task, SearchRequest request, ActionListener listener) { 44 | searchHandler.search(request, listener); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StatsAnomalyDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class StatsAnomalyDetectorAction extends ActionType { 23 | // External Action which used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/stats"; 25 | public static final StatsAnomalyDetectorAction INSTANCE = new StatsAnomalyDetectorAction(); 26 | 27 | private StatsAnomalyDetectorAction() { 28 | super(NAME, StatsAnomalyDetectorResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StatsAnomalyDetectorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.io.IOException; 19 | 20 | import org.elasticsearch.action.ActionResponse; 21 | import org.elasticsearch.common.io.stream.StreamInput; 22 | import org.elasticsearch.common.io.stream.StreamOutput; 23 | import org.elasticsearch.common.xcontent.ToXContentObject; 24 | import org.elasticsearch.common.xcontent.XContentBuilder; 25 | 26 | import com.amazon.opendistroforelasticsearch.ad.stats.ADStatsResponse; 27 | 28 | public class StatsAnomalyDetectorResponse extends ActionResponse implements ToXContentObject { 29 | private ADStatsResponse adStatsResponse; 30 | 31 | public StatsAnomalyDetectorResponse(StreamInput in) throws IOException { 32 | super(in); 33 | adStatsResponse = new ADStatsResponse(in); 34 | } 35 | 36 | public StatsAnomalyDetectorResponse(ADStatsResponse adStatsResponse) { 37 | this.adStatsResponse = adStatsResponse; 38 | } 39 | 40 | @Override 41 | public void writeTo(StreamOutput out) throws IOException { 42 | adStatsResponse.writeTo(out); 43 | } 44 | 45 | @Override 46 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { 47 | adStatsResponse.toXContent(builder, params); 48 | return builder; 49 | } 50 | 51 | protected ADStatsResponse getAdStatsResponse() { 52 | return adStatsResponse; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class StopDetectorAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "detector/stop"; 25 | public static final StopDetectorAction INSTANCE = new StopDetectorAction(); 26 | 27 | private StopDetectorAction() { 28 | super(NAME, StopDetectorResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | 22 | public class ThresholdResultAction extends ActionType { 23 | // Internal Action which is not used for public facing RestAPIs. 24 | public static final String NAME = CommonValue.INTERNAL_ACTION_PREFIX + "threshold/result"; 25 | public static final ThresholdResultAction INSTANCE = new ThresholdResultAction(); 26 | 27 | private ThresholdResultAction() { 28 | super(NAME, ThresholdResultResponse::new); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/util/BulkUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashSet; 20 | import java.util.List; 21 | import java.util.Set; 22 | 23 | import org.apache.logging.log4j.LogManager; 24 | import org.apache.logging.log4j.Logger; 25 | import org.elasticsearch.action.DocWriteRequest; 26 | import org.elasticsearch.action.bulk.BulkItemResponse; 27 | import org.elasticsearch.action.bulk.BulkRequest; 28 | import org.elasticsearch.action.bulk.BulkResponse; 29 | 30 | public class BulkUtil { 31 | private static final Logger logger = LogManager.getLogger(BulkUtil.class); 32 | 33 | public static List> getIndexRequestToRetry(BulkRequest bulkRequest, BulkResponse bulkResponse) { 34 | List> res = new ArrayList<>(); 35 | 36 | Set failedId = new HashSet<>(); 37 | for (BulkItemResponse response : bulkResponse.getItems()) { 38 | if (response.isFailed()) { 39 | failedId.add(response.getId()); 40 | } 41 | } 42 | 43 | for (DocWriteRequest request : bulkRequest.requests()) { 44 | if (failedId.contains(request.id())) { 45 | res.add(request); 46 | } 47 | } 48 | return res; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ThrowingConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | /** 19 | * A consumer that can throw checked exception 20 | * 21 | * @param method parameter type 22 | * @param Exception type 23 | */ 24 | @FunctionalInterface 25 | public interface ThrowingConsumer { 26 | void accept(T t) throws E; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ThrowingConsumerWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | import java.util.function.Consumer; 19 | 20 | public class ThrowingConsumerWrapper { 21 | /** 22 | * Utility method to use a method throwing checked exception inside a function 23 | * that does not throw the corresponding checked exception. This happens 24 | * when we are in a ES function that we have no control over its signature. 25 | * Convert the checked exception thrown by by throwingConsumer to a RuntimeException 26 | * so that the compiler won't complain. 27 | * @param the method's parameter type 28 | * @param throwingConsumer the method reference that can throw checked exception 29 | * @return converted method reference 30 | */ 31 | public static Consumer throwingConsumerWrapper(ThrowingConsumer throwingConsumer) { 32 | 33 | return i -> { 34 | try { 35 | throwingConsumer.accept(i); 36 | } catch (Exception ex) { 37 | throw new RuntimeException(ex); 38 | } 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ThrowingSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | /** 19 | * A supplier that can throw checked exception 20 | * 21 | * @param method parameter type 22 | * @param Exception type 23 | */ 24 | @FunctionalInterface 25 | public interface ThrowingSupplier { 26 | T get() throws E; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ThrowingSupplierWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | import java.util.function.Supplier; 19 | 20 | public class ThrowingSupplierWrapper { 21 | /** 22 | * Utility method to use a method throwing checked exception inside a place 23 | * that does not allow throwing the corresponding checked exception (e.g., 24 | * enum initialization). 25 | * Convert the checked exception thrown by by throwingConsumer to a RuntimeException 26 | * so that the compiler won't complain. 27 | * @param the method's return type 28 | * @param throwingSupplier the method reference that can throw checked exception 29 | * @return converted method reference 30 | */ 31 | public static Supplier throwingSupplierWrapper(ThrowingSupplier throwingSupplier) { 32 | 33 | return () -> { 34 | try { 35 | return throwingSupplier.get(); 36 | } catch (Exception ex) { 37 | throw new RuntimeException(ex); 38 | } 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/plugin-metadata/plugin-security.policy: -------------------------------------------------------------------------------- 1 | grant { 2 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 3 | permission java.lang.RuntimePermission "accessDeclaredMembers"; 4 | permission java.lang.RuntimePermission "accessClassInPackage.sun.misc"; 5 | permission java.net.SocketPermission "*", "connect,resolve"; 6 | }; -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/io.pry.gradle.offline_dependencies.properties: -------------------------------------------------------------------------------- 1 | implementation-class=io.pry.gradle.offline_dependencies.OfflineDependenciesPlugin -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/com.amazon.opendistroforelasticsearch.jobscheduler.spi.JobSchedulerExtension: -------------------------------------------------------------------------------- 1 | com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin 2 | -------------------------------------------------------------------------------- /src/main/resources/es-plugin.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # or in the "license" file accompanying this file. This file is distributed 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | # express or implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | 16 | plugin=com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin 17 | version=${project.version} -------------------------------------------------------------------------------- /src/main/resources/mappings/checkpoint.json: -------------------------------------------------------------------------------- 1 | { 2 | "dynamic": true, 3 | "_meta": { 4 | "schema_version": 2 5 | }, 6 | "properties": { 7 | "detectorId": { 8 | "type": "keyword" 9 | }, 10 | "model": { 11 | "type": "text", 12 | "fields": { 13 | "keyword": { 14 | "type": "keyword", 15 | "ignore_above": 256 16 | } 17 | } 18 | }, 19 | "timestamp": { 20 | "type": "date" 21 | }, 22 | "schema_version": { 23 | "type": "integer" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/plugin-descriptor.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # or in the "license" file accompanying this file. This file is distributed 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | # express or implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | 16 | 17 | description=${project.description} 18 | 19 | version=${project.version} 20 | 21 | name=${elasticsearch.plugin.name} 22 | 23 | classname=${elasticsearch.plugin.classname} 24 | 25 | java.version=1.8 26 | 27 | elasticsearch.version=${elasticsearch.version} -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/common/exception/ADTaskCancelledExceptionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | import org.elasticsearch.test.ESTestCase; 19 | 20 | public class ADTaskCancelledExceptionTests extends ESTestCase { 21 | 22 | public void testConstructor() { 23 | String message = randomAlphaOfLength(5); 24 | String user = randomAlphaOfLength(5); 25 | ADTaskCancelledException exception = new ADTaskCancelledException(message, user); 26 | assertEquals(message, exception.getMessage()); 27 | assertEquals(user, exception.getCancelledBy()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/common/exception/JsonPathNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | public class JsonPathNotFoundException extends Exception { 19 | 20 | public JsonPathNotFoundException() { 21 | super("Invalid Json path"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/common/exception/LimitExceededExceptionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.common.exception; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.junit.Test; 21 | 22 | public class LimitExceededExceptionTests { 23 | 24 | @Test 25 | public void testConstructorWithIdAndExplanation() { 26 | String id = "test id"; 27 | String message = "test message"; 28 | LimitExceededException limitExceeded = new LimitExceededException(id, message); 29 | assertEquals(id, limitExceeded.getAnomalyDetectorId()); 30 | assertEquals(message, limitExceeded.getMessage()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/dataprocessor/IntegerSensitiveSingleFeatureLinearUniformInterpolatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.dataprocessor; 17 | 18 | import static org.junit.Assert.assertTrue; 19 | 20 | import java.util.Arrays; 21 | 22 | import junitparams.JUnitParamsRunner; 23 | import junitparams.Parameters; 24 | 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | 29 | @RunWith(JUnitParamsRunner.class) 30 | public class IntegerSensitiveSingleFeatureLinearUniformInterpolatorTests { 31 | 32 | private IntegerSensitiveSingleFeatureLinearUniformInterpolator interpolator; 33 | 34 | @Before 35 | public void setup() { 36 | interpolator = new IntegerSensitiveSingleFeatureLinearUniformInterpolator(); 37 | } 38 | 39 | private Object[] interpolateData() { 40 | return new Object[] { 41 | new Object[] { new double[] { 25.25, 25.75 }, 3, new double[] { 25.25, 25.5, 25.75 } }, 42 | new Object[] { new double[] { 25, 75 }, 3, new double[] { 25, 50, 75 } }, 43 | new Object[] { new double[] { 25, 75.5 }, 3, new double[] { 25, 50.25, 75.5 } }, }; 44 | } 45 | 46 | @Test 47 | @Parameters(method = "interpolateData") 48 | public void interpolate_returnExpected(double[] samples, int num, double[] expected) { 49 | assertTrue(Arrays.equals(expected, interpolator.interpolate(samples, num))); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/mock/transport/MockAnomalyDetectorJobAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.mock.transport; 17 | 18 | import org.elasticsearch.action.ActionType; 19 | 20 | import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue; 21 | import com.amazon.opendistroforelasticsearch.ad.transport.AnomalyDetectorJobResponse; 22 | 23 | public class MockAnomalyDetectorJobAction extends ActionType { 24 | // External Action which used for public facing RestAPIs. 25 | public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/mockjobmanagement"; 26 | public static final MockAnomalyDetectorJobAction INSTANCE = new MockAnomalyDetectorJobAction(); 27 | 28 | private MockAnomalyDetectorJobAction() { 29 | super(NAME, AnomalyDetectorJobResponse::new); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorJobTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | import java.io.IOException; 19 | import java.util.Locale; 20 | 21 | import org.elasticsearch.common.xcontent.ToXContent; 22 | import org.elasticsearch.test.ESTestCase; 23 | 24 | import com.amazon.opendistroforelasticsearch.ad.TestHelpers; 25 | 26 | public class AnomalyDetectorJobTests extends ESTestCase { 27 | 28 | public void testParseAnomalyDetectorJob() throws IOException { 29 | AnomalyDetectorJob anomalyDetectorJob = TestHelpers.randomAnomalyDetectorJob(); 30 | String anomalyDetectorJobString = TestHelpers 31 | .xContentBuilderToString(anomalyDetectorJob.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS)); 32 | anomalyDetectorJobString = anomalyDetectorJobString 33 | .replaceFirst("\\{", String.format(Locale.ROOT, "{\"%s\":\"%s\",", randomAlphaOfLength(5), randomAlphaOfLength(5))); 34 | 35 | AnomalyDetectorJob parsedAnomalyDetectorJob = AnomalyDetectorJob.parse(TestHelpers.parser(anomalyDetectorJobString)); 36 | assertEquals("Parsing anomaly detect result doesn't work", anomalyDetectorJob, parsedAnomalyDetectorJob); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/model/FeatureDataTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | import java.io.IOException; 19 | import java.util.Locale; 20 | 21 | import org.elasticsearch.common.xcontent.ToXContent; 22 | import org.elasticsearch.test.ESTestCase; 23 | 24 | import com.amazon.opendistroforelasticsearch.ad.TestHelpers; 25 | 26 | public class FeatureDataTests extends ESTestCase { 27 | 28 | public void testParseAnomalyDetector() throws IOException { 29 | FeatureData featureData = TestHelpers.randomFeatureData(); 30 | String featureDataString = TestHelpers 31 | .xContentBuilderToString(featureData.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS)); 32 | featureDataString = featureDataString 33 | .replaceFirst("\\{", String.format(Locale.ROOT, "{\"%s\":\"%s\",", randomAlphaOfLength(5), randomAlphaOfLength(5))); 34 | FeatureData parsedFeatureData = FeatureData.parse(TestHelpers.parser(featureDataString)); 35 | assertEquals("Parsing feature data doesn't work", featureData, parsedFeatureData); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/model/FeatureTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.model; 17 | 18 | import java.io.IOException; 19 | import java.util.Locale; 20 | 21 | import org.elasticsearch.common.xcontent.ToXContent; 22 | import org.elasticsearch.test.ESTestCase; 23 | 24 | import com.amazon.opendistroforelasticsearch.ad.TestHelpers; 25 | 26 | public class FeatureTests extends ESTestCase { 27 | 28 | public void testParseFeature() throws IOException { 29 | Feature feature = TestHelpers.randomFeature(); 30 | String featureString = TestHelpers.xContentBuilderToString(feature.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS)); 31 | featureString = featureString 32 | .replaceFirst("\\{", String.format(Locale.ROOT, "{\"%s\":\"%s\",", randomAlphaOfLength(5), randomAlphaOfLength(5))); 33 | Feature parsedFeature = Feature.parse(TestHelpers.parser(featureString)); 34 | assertEquals("Parsing feature doesn't work", feature, parsedFeature); 35 | } 36 | 37 | public void testNullName() throws Exception { 38 | TestHelpers 39 | .assertFailWith( 40 | IllegalArgumentException.class, 41 | () -> new Feature(randomAlphaOfLength(5), null, true, TestHelpers.randomAggregation()) 42 | ); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/stats/suppliers/CounterSupplierTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats.suppliers; 17 | 18 | import org.elasticsearch.test.ESTestCase; 19 | import org.junit.Test; 20 | 21 | public class CounterSupplierTests extends ESTestCase { 22 | @Test 23 | public void testGetAndIncrement() { 24 | CounterSupplier counterSupplier = new CounterSupplier(); 25 | assertEquals("get returns incorrect value", (Long) 0L, counterSupplier.get()); 26 | counterSupplier.increment(); 27 | assertEquals("get returns incorrect value", (Long) 1L, counterSupplier.get()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/stats/suppliers/SettableSupplierTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.stats.suppliers; 17 | 18 | import org.elasticsearch.test.ESTestCase; 19 | import org.junit.Test; 20 | 21 | public class SettableSupplierTests extends ESTestCase { 22 | @Test 23 | public void testSetGet() { 24 | Long setCount = 15L; 25 | SettableSupplier settableSupplier = new SettableSupplier(); 26 | settableSupplier.set(setCount); 27 | assertEquals("Get/Set fails", setCount, settableSupplier.get()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.concurrent.ExecutionException; 21 | 22 | import org.elasticsearch.plugins.Plugin; 23 | import org.elasticsearch.test.ESIntegTestCase; 24 | 25 | import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; 26 | 27 | @ESIntegTestCase.ClusterScope(transportClientRatio = 0.9) 28 | public class ADStatsIT extends ESIntegTestCase { 29 | 30 | @Override 31 | protected Collection> nodePlugins() { 32 | return Collections.singletonList(AnomalyDetectorPlugin.class); 33 | } 34 | 35 | @Override 36 | protected Collection> transportClientPlugins() { 37 | return Collections.singletonList(AnomalyDetectorPlugin.class); 38 | } 39 | 40 | public void testNormalADStats() throws ExecutionException, InterruptedException { 41 | ADStatsRequest adStatsRequest = new ADStatsRequest(new String[0]); 42 | 43 | ADStatsNodesResponse response = client().execute(ADStatsNodesAction.INSTANCE, adStatsRequest).get(); 44 | assertTrue("getting stats failed", !response.hasFailures()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ProfileIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.HashSet; 21 | import java.util.concurrent.ExecutionException; 22 | 23 | import org.elasticsearch.plugins.Plugin; 24 | import org.elasticsearch.test.ESIntegTestCase; 25 | 26 | import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; 27 | import com.amazon.opendistroforelasticsearch.ad.model.DetectorProfileName; 28 | 29 | @ESIntegTestCase.ClusterScope(transportClientRatio = 0.9) 30 | public class ProfileIT extends ESIntegTestCase { 31 | 32 | @Override 33 | protected Collection> nodePlugins() { 34 | return Collections.singletonList(AnomalyDetectorPlugin.class); 35 | } 36 | 37 | @Override 38 | protected Collection> transportClientPlugins() { 39 | return Collections.singletonList(AnomalyDetectorPlugin.class); 40 | } 41 | 42 | public void testNormalProfile() throws ExecutionException, InterruptedException { 43 | ProfileRequest profileRequest = new ProfileRequest("123", new HashSet(), false); 44 | 45 | ProfileResponse response = client().execute(ProfileAction.INSTANCE, profileRequest).get(); 46 | assertTrue("getting profile failed", !response.hasFailures()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorActionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.transport; 17 | 18 | import org.elasticsearch.test.ESIntegTestCase; 19 | import org.junit.Assert; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | public class StopDetectorActionTests extends ESIntegTestCase { 24 | 25 | @Override 26 | @Before 27 | public void setUp() throws Exception { 28 | super.setUp(); 29 | } 30 | 31 | @Test 32 | public void testStopDetectorAction() { 33 | Assert.assertNotNull(StopDetectorAction.INSTANCE.name()); 34 | Assert.assertEquals(StopDetectorAction.INSTANCE.name(), StopDetectorAction.NAME); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/amazon/opendistroforelasticsearch/ad/util/ArrayEqMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.opendistroforelasticsearch.ad.util; 17 | 18 | import java.util.Arrays; 19 | 20 | import org.mockito.ArgumentMatcher; 21 | 22 | /** 23 | * An argument matcher based on deep equality needed for array types. 24 | * 25 | * The default eq or aryEq from Mockito fails on nested array types, such as a matrix. 26 | * This matcher takes the expected argument and returns a match result based on deep equality. 27 | */ 28 | public class ArrayEqMatcher implements ArgumentMatcher { 29 | 30 | private final T expected; 31 | 32 | /** 33 | * Constructor with expected value. 34 | * 35 | * @param expected the value expected to match by equality 36 | */ 37 | public ArrayEqMatcher(T expected) { 38 | this.expected = expected; 39 | } 40 | 41 | @Override 42 | public boolean matches(T actual) { 43 | return Arrays.deepEquals((Object[]) expected, (Object[]) actual); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/resources/com/amazon/opendistroforelasticsearch/ad/e2e/data/synthetic.label: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | "2019-11-03T20:00:00Z", 4 | "2019-11-03T22:08:00Z" 5 | ], 6 | [ 7 | "2019-11-04T23:00:00Z", 8 | "2019-11-05T01:08:00Z" 9 | ], 10 | [ 11 | "2019-11-06T08:00:00Z", 12 | "2019-11-06T15:00:00Z" 13 | ], 14 | [ 15 | "2019-11-07T04:00:00Z", 16 | "2019-11-07T16:00:00Z" 17 | ] 18 | ] 19 | -------------------------------------------------------------------------------- /src/test/resources/job-scheduler/opendistro-job-scheduler-1.13.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/src/test/resources/job-scheduler/opendistro-job-scheduler-1.13.0.0.zip -------------------------------------------------------------------------------- /src/test/resources/security/sample.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEyTCCA7GgAwIBAgIGAWLrc1O2MA0GCSqGSIb3DQEBCwUAMIGPMRMwEQYKCZIm 3 | iZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEZMBcGA1UECgwQ 4 | RXhhbXBsZSBDb20gSW5jLjEhMB8GA1UECwwYRXhhbXBsZSBDb20gSW5jLiBSb290 5 | IENBMSEwHwYDVQQDDBhFeGFtcGxlIENvbSBJbmMuIFJvb3QgQ0EwHhcNMTgwNDIy 6 | MDM0MzQ3WhcNMjgwNDE5MDM0MzQ3WjBeMRIwEAYKCZImiZPyLGQBGRYCZGUxDTAL 7 | BgNVBAcMBHRlc3QxDTALBgNVBAoMBG5vZGUxDTALBgNVBAsMBG5vZGUxGzAZBgNV 8 | BAMMEm5vZGUtMC5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC 9 | AQoCggEBAJa+f476vLB+AwK53biYByUwN+40D8jMIovGXm6wgT8+9Sbs899dDXgt 10 | 9CE1Beo65oP1+JUz4c7UHMrCY3ePiDt4cidHVzEQ2g0YoVrQWv0RedS/yx/DKhs8 11 | Pw1O715oftP53p/2ijD5DifFv1eKfkhFH+lwny/vMSNxellpl6NxJTiJVnQ9HYOL 12 | gf2t971ITJHnAuuxUF48HcuNovW4rhtkXef8kaAN7cE3LU+A9T474ULNCKkEFPIl 13 | ZAKN3iJNFdVsxrTU+CUBHzk73Do1cCkEvJZ0ZFjp0Z3y8wLY/gqWGfGVyA9l2CUq 14 | eIZNf55PNPtGzOrvvONiui48vBKH1LsCAwEAAaOCAVkwggFVMIG8BgNVHSMEgbQw 15 | gbGAFJI1DOAPHitF9k0583tfouYSl0BzoYGVpIGSMIGPMRMwEQYKCZImiZPyLGQB 16 | GRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEZMBcGA1UECgwQRXhhbXBs 17 | ZSBDb20gSW5jLjEhMB8GA1UECwwYRXhhbXBsZSBDb20gSW5jLiBSb290IENBMSEw 18 | HwYDVQQDDBhFeGFtcGxlIENvbSBJbmMuIFJvb3QgQ0GCAQEwHQYDVR0OBBYEFKyv 19 | 78ZmFjVKM9g7pMConYH7FVBHMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXg 20 | MCAGA1UdJQEB/wQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjA1BgNVHREELjAsiAUq 21 | AwQFBYISbm9kZS0wLmV4YW1wbGUuY29tgglsb2NhbGhvc3SHBH8AAAEwDQYJKoZI 22 | hvcNAQELBQADggEBAIOKuyXsFfGv1hI/Lkpd/73QNqjqJdxQclX57GOMWNbOM5H0 23 | 5/9AOIZ5JQsWULNKN77aHjLRr4owq2jGbpc/Z6kAd+eiatkcpnbtbGrhKpOtoEZy 24 | 8KuslwkeixpzLDNISSbkeLpXz4xJI1ETMN/VG8ZZP1bjzlHziHHDu0JNZ6TnNzKr 25 | XzCGMCohFfem8vnKNnKUneMQMvXd3rzUaAgvtf7Hc2LTBlf4fZzZF1EkwdSXhaMA 26 | 1lkfHiqOBxtgeDLxCHESZ2fqgVqsWX+t3qHQfivcPW6txtDyrFPRdJOGhiMGzT/t 27 | e/9kkAtQRgpTb3skYdIOOUOV0WGQ60kJlFhAzIs= 28 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /src/test/resources/security/test-kirk.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opendistro-for-elasticsearch/anomaly-detection/df9c89b6e4bf23c84014959d071353f641d0bd91/src/test/resources/security/test-kirk.jks --------------------------------------------------------------------------------