Search in sources :

Example 16 with ModelManager

use of org.opensearch.ad.ml.ModelManager in project anomaly-detection by opensearch-project.

the class AnomalyResultTests method testInsufficientCapacityExceptionDuringColdStart.

@SuppressWarnings("unchecked")
public void testInsufficientCapacityExceptionDuringColdStart() {
    ModelManager rcfManager = mock(ModelManager.class);
    doThrow(ResourceNotFoundException.class).when(rcfManager).getTRcfResult(any(String.class), any(String.class), any(double[].class), any(ActionListener.class));
    when(stateManager.fetchExceptionAndClear(any(String.class))).thenReturn(Optional.of(new LimitExceededException(adID, CommonErrorMessages.MEMORY_LIMIT_EXCEEDED_ERR_MSG)));
    // These constructors register handler in transport service
    new RCFResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, rcfManager, adCircuitBreakerService, hashRing);
    new ThresholdResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, normalModelManager);
    AnomalyResultTransportAction action = new AnomalyResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, settings, client, stateManager, featureQuery, normalModelManager, hashRing, clusterService, indexNameResolver, adCircuitBreakerService, adStats, threadPool, NamedXContentRegistry.EMPTY, adTaskManager);
    AnomalyResultRequest request = new AnomalyResultRequest(adID, 100, 200);
    PlainActionFuture<AnomalyResultResponse> listener = new PlainActionFuture<>();
    action.doExecute(null, request, listener);
    assertException(listener, LimitExceededException.class);
}
Also used : ActionListener(org.opensearch.action.ActionListener) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.anyString(org.mockito.Mockito.anyString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ActionFilters(org.opensearch.action.support.ActionFilters) ModelManager(org.opensearch.ad.ml.ModelManager)

Example 17 with ModelManager

use of org.opensearch.ad.ml.ModelManager in project anomaly-detection by opensearch-project.

the class AnomalyResultTests method testInsufficientCapacityExceptionDuringRestoringModel.

@SuppressWarnings("unchecked")
public void testInsufficientCapacityExceptionDuringRestoringModel() {
    ModelManager rcfManager = mock(ModelManager.class);
    doThrow(new NotSerializableExceptionWrapper(new LimitExceededException(adID, CommonErrorMessages.MEMORY_LIMIT_EXCEEDED_ERR_MSG))).when(rcfManager).getTRcfResult(any(String.class), any(String.class), any(double[].class), any(ActionListener.class));
    // These constructors register handler in transport service
    new RCFResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, rcfManager, adCircuitBreakerService, hashRing);
    new ThresholdResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, normalModelManager);
    AnomalyResultTransportAction action = new AnomalyResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, settings, client, stateManager, featureQuery, normalModelManager, hashRing, clusterService, indexNameResolver, adCircuitBreakerService, adStats, threadPool, NamedXContentRegistry.EMPTY, adTaskManager);
    AnomalyResultRequest request = new AnomalyResultRequest(adID, 100, 200);
    PlainActionFuture<AnomalyResultResponse> listener = new PlainActionFuture<>();
    action.doExecute(null, request, listener);
    assertException(listener, LimitExceededException.class);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.anyString(org.mockito.Mockito.anyString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ActionFilters(org.opensearch.action.support.ActionFilters) ModelManager(org.opensearch.ad.ml.ModelManager) ActionListener(org.opensearch.action.ActionListener) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper)

Example 18 with ModelManager

use of org.opensearch.ad.ml.ModelManager 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

ModelManager (org.opensearch.ad.ml.ModelManager)18 ActionFilters (org.opensearch.action.support.ActionFilters)11 ActionListener (org.opensearch.action.ActionListener)9 Before (org.junit.Before)8 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)8 TransportService (org.opensearch.transport.TransportService)8 CacheProvider (org.opensearch.ad.caching.CacheProvider)7 EntityCache (org.opensearch.ad.caching.EntityCache)7 ADCircuitBreakerService (org.opensearch.ad.breaker.ADCircuitBreakerService)6 ClusterService (org.opensearch.cluster.service.ClusterService)6 Task (org.opensearch.tasks.Task)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 FeatureManager (org.opensearch.ad.feature.FeatureManager)5 ThresholdingResult (org.opensearch.ad.ml.ThresholdingResult)5 ClusterSettings (org.opensearch.common.settings.ClusterSettings)5 ThreadPool (org.opensearch.threadpool.ThreadPool)5 Transport (org.opensearch.transport.Transport)5 HashSet (java.util.HashSet)4 Settings (org.opensearch.common.settings.Settings)4 Clock (java.time.Clock)3