Search in sources :

Example 6 with CacheProvider

use of org.opensearch.ad.caching.CacheProvider in project anomaly-detection by opensearch-project.

the class ProfileTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    modelManager = mock(ModelManager.class);
    featureManager = mock(FeatureManager.class);
    when(featureManager.getShingleSize(any(String.class))).thenReturn(shingleSize);
    EntityCache cache = mock(EntityCache.class);
    cacheProvider = mock(CacheProvider.class);
    when(cacheProvider.get()).thenReturn(cache);
    when(cache.getActiveEntities(anyString())).thenReturn(activeEntities);
    when(cache.getTotalUpdates(anyString())).thenReturn(totalUpdates);
    Map<String, Long> multiEntityModelSizeMap = new HashMap<>();
    String modelId1 = "T4c3dXUBj-2IZN7itix__entity_app_3";
    String modelId2 = "T4c3dXUBj-2IZN7itix__entity_app_2";
    multiEntityModelSizeMap.put(modelId1, multiEntityModelSize);
    multiEntityModelSizeMap.put(modelId2, multiEntityModelSize);
    when(cache.getModelSize(anyString())).thenReturn(multiEntityModelSizeMap);
    List<ModelProfile> modelProfiles = new ArrayList<>();
    String field = "field";
    String fieldVal1 = "value1";
    String fieldVal2 = "value2";
    Entity entity1 = Entity.createSingleAttributeEntity(field, fieldVal1);
    Entity entity2 = Entity.createSingleAttributeEntity(field, fieldVal2);
    modelProfiles.add(new ModelProfile(modelId1, entity1, multiEntityModelSize));
    modelProfiles.add(new ModelProfile(modelId1, entity2, multiEntityModelSize));
    when(cache.getAllModelProfile(anyString())).thenReturn(modelProfiles);
    Map<String, Long> modelSizes = new HashMap<>();
    modelSizes.put(modelId, modelSize);
    when(modelManager.getModelSize(any(String.class))).thenReturn(modelSizes);
    Settings settings = Settings.builder().put("plugins.anomaly_detection.max_model_size_per_node", 100).build();
    action = new ProfileTransportAction(client().threadPool(), clusterService(), mock(TransportService.class), mock(ActionFilters.class), modelManager, featureManager, cacheProvider, settings);
    profilesToRetrieve = new HashSet<DetectorProfileName>();
    profilesToRetrieve.add(DetectorProfileName.COORDINATING_NODE);
}
Also used : Entity(org.opensearch.ad.model.Entity) EntityCache(org.opensearch.ad.caching.EntityCache) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ModelManager(org.opensearch.ad.ml.ModelManager) CacheProvider(org.opensearch.ad.caching.CacheProvider) ModelProfile(org.opensearch.ad.model.ModelProfile) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) FeatureManager(org.opensearch.ad.feature.FeatureManager) AnomalyDetectorSettings(org.opensearch.ad.settings.AnomalyDetectorSettings) Settings(org.opensearch.common.settings.Settings) Before(org.junit.Before)

Example 7 with CacheProvider

use of org.opensearch.ad.caching.CacheProvider 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);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) EntityCache(org.opensearch.ad.caching.EntityCache) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) ModelManager(org.opensearch.ad.ml.ModelManager) CacheProvider(org.opensearch.ad.caching.CacheProvider) NodeStateManager(org.opensearch.ad.NodeStateManager) ClusterService(org.opensearch.cluster.service.ClusterService) EntityColdStarter(org.opensearch.ad.ml.EntityColdStarter) TransportService(org.opensearch.transport.TransportService) ADTaskManager(org.opensearch.ad.task.ADTaskManager) ClusterName(org.opensearch.cluster.ClusterName) FeatureManager(org.opensearch.ad.feature.FeatureManager) Before(org.junit.Before)

Aggregations

CacheProvider (org.opensearch.ad.caching.CacheProvider)7 EntityCache (org.opensearch.ad.caching.EntityCache)7 ModelManager (org.opensearch.ad.ml.ModelManager)6 ClusterService (org.opensearch.cluster.service.ClusterService)5 Before (org.junit.Before)4 FeatureManager (org.opensearch.ad.feature.FeatureManager)4 Settings (org.opensearch.common.settings.Settings)4 ActionFilters (org.opensearch.action.support.ActionFilters)3 ADTaskManager (org.opensearch.ad.task.ADTaskManager)3 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)3 TransportService (org.opensearch.transport.TransportService)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Random (java.util.Random)2 HashRing (org.opensearch.ad.cluster.HashRing)2 EntityColdStarter (org.opensearch.ad.ml.EntityColdStarter)2 Entity (org.opensearch.ad.model.Entity)2 ModelProfile (org.opensearch.ad.model.ModelProfile)2 AnomalyDetectorSettings (org.opensearch.ad.settings.AnomalyDetectorSettings)2