use of org.opensearch.ad.NodeStateManager in project anomaly-detection by opensearch-project.
the class CronTransportActionTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
ThreadPool threadPool = mock(ThreadPool.class);
ClusterService clusterService = mock(ClusterService.class);
localNodeID = "foo";
when(clusterService.localNode()).thenReturn(new DiscoveryNode(localNodeID, buildNewFakeTransportAddress(), Version.CURRENT));
when(clusterService.getClusterName()).thenReturn(new ClusterName("test"));
TransportService transportService = mock(TransportService.class);
ActionFilters actionFilters = mock(ActionFilters.class);
NodeStateManager tarnsportStatemanager = mock(NodeStateManager.class);
ModelManager modelManager = mock(ModelManager.class);
FeatureManager featureManager = mock(FeatureManager.class);
CacheProvider cacheProvider = mock(CacheProvider.class);
EntityCache entityCache = mock(EntityCache.class);
EntityColdStarter entityColdStarter = mock(EntityColdStarter.class);
when(cacheProvider.get()).thenReturn(entityCache);
ADTaskManager adTaskManager = mock(ADTaskManager.class);
action = new CronTransportAction(threadPool, clusterService, transportService, actionFilters, tarnsportStatemanager, modelManager, featureManager, cacheProvider, entityColdStarter, adTaskManager);
}
use of org.opensearch.ad.NodeStateManager in project anomaly-detection by opensearch-project.
the class ModelManagerTests method getEmptyStateFullSamples.
@Test
public void getEmptyStateFullSamples() {
SearchFeatureDao searchFeatureDao = mock(SearchFeatureDao.class);
SingleFeatureLinearUniformInterpolator singleFeatureLinearUniformInterpolator = new IntegerSensitiveSingleFeatureLinearUniformInterpolator();
LinearUniformInterpolator interpolator = new LinearUniformInterpolator(singleFeatureLinearUniformInterpolator);
NodeStateManager stateManager = mock(NodeStateManager.class);
featureManager = new FeatureManager(searchFeatureDao, interpolator, clock, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.TRAIN_SAMPLE_TIME_RANGE_IN_HOURS, AnomalyDetectorSettings.MIN_TRAIN_SAMPLES, AnomalyDetectorSettings.MAX_SHINGLE_PROPORTION_MISSING, AnomalyDetectorSettings.MAX_IMPUTATION_NEIGHBOR_DISTANCE, AnomalyDetectorSettings.PREVIEW_SAMPLE_RATE, AnomalyDetectorSettings.MAX_PREVIEW_SAMPLES, AnomalyDetectorSettings.HOURLY_MAINTENANCE, threadPool, AnomalyDetectorPlugin.AD_THREAD_POOL_NAME);
CheckpointWriteWorker checkpointWriteQueue = mock(CheckpointWriteWorker.class);
entityColdStarter = new EntityColdStarter(clock, threadPool, stateManager, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE, AnomalyDetectorSettings.NUM_TREES, AnomalyDetectorSettings.TIME_DECAY, numMinSamples, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, interpolator, searchFeatureDao, AnomalyDetectorSettings.THRESHOLD_MIN_PVALUE, featureManager, settings, AnomalyDetectorSettings.HOURLY_MAINTENANCE, checkpointWriteQueue, AnomalyDetectorSettings.MAX_COLD_START_ROUNDS);
modelManager = spy(new ModelManager(checkpointDao, clock, numTrees, numSamples, rcfTimeDecay, numMinSamples, thresholdMinPvalue, minPreviewSize, modelTtl, checkpointInterval, entityColdStarter, featureManager, memoryTracker));
ModelState<EntityModel> state = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(false).sampleSize(numMinSamples).build());
EntityModel model = state.getModel();
assertTrue(!model.getTrcf().isPresent());
ThresholdingResult result = modelManager.getAnomalyResultForEntity(new double[] { -1 }, state, "", null, shingleSize);
// model outputs scores
assertTrue(result.getRcfScore() != 0);
// added the sample to score since our model is empty
assertEquals(0, model.getSamples().size());
}
Aggregations