Search in sources :

Example 6 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project k-NN by opensearch-project.

the class RemoveModelFromCacheTransportActionTests method testNodeOperation_modelInCache.

@Ignore
public void testNodeOperation_modelInCache() throws ExecutionException, InterruptedException {
    ClusterService clusterService = mock(ClusterService.class);
    Settings settings = Settings.builder().put(MODEL_CACHE_SIZE_LIMIT_SETTING.getKey(), "10%").build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ImmutableSet.of(MODEL_CACHE_SIZE_LIMIT_SETTING));
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    when(clusterService.getSettings()).thenReturn(settings);
    ModelDao modelDao = mock(ModelDao.class);
    String modelId = "test-model-id";
    Model model = new Model(new ModelMetadata(KNNEngine.DEFAULT, SpaceType.L2, 16, ModelState.CREATED, "timestamp", "description", ""), new byte[128], modelId);
    when(modelDao.get(modelId)).thenReturn(model);
    ModelCache.initialize(modelDao, clusterService);
    // Load the model into the cache
    ModelCache modelCache = ModelCache.getInstance();
    modelCache.get(modelId);
    // Remove the model from the cache
    RemoveModelFromCacheTransportAction action = node().injector().getInstance(RemoveModelFromCacheTransportAction.class);
    RemoveModelFromCacheNodeRequest request = new RemoveModelFromCacheNodeRequest(modelId);
    action.nodeOperation(request);
    assertEquals(0L, modelCache.getTotalWeightInKB());
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Model(org.opensearch.knn.indices.Model) ModelDao(org.opensearch.knn.indices.ModelDao) ModelMetadata(org.opensearch.knn.indices.ModelMetadata) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ModelCache(org.opensearch.knn.indices.ModelCache) Ignore(org.junit.Ignore)

Example 7 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project k-NN by opensearch-project.

the class RemoveModelFromCacheTransportActionTests method testNodeOperation_modelNotInCache.

@Ignore
public void testNodeOperation_modelNotInCache() {
    ClusterService clusterService = mock(ClusterService.class);
    Settings settings = Settings.builder().put(MODEL_CACHE_SIZE_LIMIT_SETTING.getKey(), "10%").build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ImmutableSet.of(MODEL_CACHE_SIZE_LIMIT_SETTING));
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    when(clusterService.getSettings()).thenReturn(settings);
    ModelDao modelDao = mock(ModelDao.class);
    ModelCache.initialize(modelDao, clusterService);
    // Check that model cache is initially empty
    ModelCache modelCache = ModelCache.getInstance();
    assertEquals(0, modelCache.getTotalWeightInKB());
    // Remove the model from the cache
    RemoveModelFromCacheTransportAction action = node().injector().getInstance(RemoveModelFromCacheTransportAction.class);
    RemoveModelFromCacheNodeRequest request = new RemoveModelFromCacheNodeRequest("invalid-model");
    action.nodeOperation(request);
    assertEquals(0L, modelCache.getTotalWeightInKB());
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ModelDao(org.opensearch.knn.indices.ModelDao) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ModelCache(org.opensearch.knn.indices.ModelCache) Ignore(org.junit.Ignore)

Example 8 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project anomaly-detection by opensearch-project.

the class NoPowermockSearchFeatureDaoTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    serviceField = "service";
    hostField = "host";
    detector = mock(AnomalyDetector.class);
    when(detector.isMultientityDetector()).thenReturn(true);
    when(detector.getCategoryField()).thenReturn(Arrays.asList(new String[] { serviceField, hostField }));
    detectorId = "123";
    when(detector.getDetectorId()).thenReturn(detectorId);
    when(detector.getTimeField()).thenReturn("testTimeField");
    when(detector.getIndices()).thenReturn(Arrays.asList("testIndices"));
    IntervalTimeConfiguration detectionInterval = new IntervalTimeConfiguration(1, ChronoUnit.MINUTES);
    when(detector.getDetectionInterval()).thenReturn(detectionInterval);
    when(detector.getFilterQuery()).thenReturn(QueryBuilders.matchAllQuery());
    client = mock(Client.class);
    interpolator = new LinearUniformInterpolator(new SingleFeatureLinearUniformInterpolator());
    clientUtil = mock(ClientUtil.class);
    settings = Settings.EMPTY;
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, AnomalyDetectorSettings.PAGE_SIZE))));
    clusterService = mock(ClusterService.class);
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    clock = mock(Clock.class);
    searchFeatureDao = new SearchFeatureDao(client, // Important. Without this, ParseUtils cannot parse anything
    xContentRegistry(), interpolator, clientUtil, settings, clusterService, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE, clock, 1, 1, 60_000L);
    String app0 = "app_0";
    String server1 = "server_1";
    attrs1 = new HashMap<>();
    attrs1.put(serviceField, app0);
    attrs1.put(hostField, server1);
    String server2 = "server_2";
    attrs1 = new HashMap<>();
    attrs1.put(serviceField, app0);
    attrs1.put(hostField, server2);
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) ClientUtil(org.opensearch.ad.util.ClientUtil) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) Clock(java.time.Clock) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) ClusterService(org.opensearch.cluster.service.ClusterService) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) LinearUniformInterpolator(org.opensearch.ad.dataprocessor.LinearUniformInterpolator) Client(org.opensearch.client.Client) HashSet(java.util.HashSet)

Example 9 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project anomaly-detection by opensearch-project.

the class RolloverTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Client client = mock(Client.class);
    indicesClient = mock(IndicesAdminClient.class);
    AdminClient adminClient = mock(AdminClient.class);
    clusterService = mock(ClusterService.class);
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD, AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, AnomalyDetectorSettings.MAX_PRIMARY_SHARDS))));
    clusterName = new ClusterName("test");
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    ThreadPool threadPool = mock(ThreadPool.class);
    Settings settings = Settings.EMPTY;
    when(client.admin()).thenReturn(adminClient);
    when(adminClient.indices()).thenReturn(indicesClient);
    DiscoveryNodeFilterer nodeFilter = mock(DiscoveryNodeFilterer.class);
    numberOfNodes = 2;
    when(nodeFilter.getNumberOfEligibleDataNodes()).thenReturn(numberOfNodes);
    adIndices = new AnomalyDetectionIndices(client, clusterService, threadPool, settings, nodeFilter, AnomalyDetectorSettings.MAX_UPDATE_RETRY_TIMES);
    clusterAdminClient = mock(ClusterAdminClient.class);
    when(adminClient.cluster()).thenReturn(clusterAdminClient);
    doAnswer(invocation -> {
        ClusterStateRequest clusterStateRequest = invocation.getArgument(0);
        assertEquals(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, clusterStateRequest.indices()[0]);
        @SuppressWarnings("unchecked") ActionListener<ClusterStateResponse> listener = (ActionListener<ClusterStateResponse>) invocation.getArgument(1);
        listener.onResponse(new ClusterStateResponse(clusterName, clusterState, true));
        return null;
    }).when(clusterAdminClient).state(any(), any());
    defaultMaxDocs = AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD.getDefault(Settings.EMPTY);
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) ClusterAdminClient(org.opensearch.client.ClusterAdminClient) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) IndicesAdminClient(org.opensearch.client.IndicesAdminClient) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) ClusterName(org.opensearch.cluster.ClusterName) Client(org.opensearch.client.Client) AdminClient(org.opensearch.client.AdminClient) ClusterAdminClient(org.opensearch.client.ClusterAdminClient) IndicesAdminClient(org.opensearch.client.IndicesAdminClient) AnomalyDetectorSettings(org.opensearch.ad.settings.AnomalyDetectorSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) AdminClient(org.opensearch.client.AdminClient) ClusterAdminClient(org.opensearch.client.ClusterAdminClient) IndicesAdminClient(org.opensearch.client.IndicesAdminClient) HashSet(java.util.HashSet)

Example 10 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project anomaly-detection by opensearch-project.

the class NodeStateManagerTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    client = mock(Client.class);
    settings = Settings.builder().put("plugins.anomaly_detection.max_retry_for_unresponsive_node", 3).put("plugins.anomaly_detection.ad_mute_minutes", TimeValue.timeValueMinutes(10)).build();
    clock = mock(Clock.class);
    duration = Duration.ofHours(1);
    context = TestHelpers.createThreadPool();
    throttler = new Throttler(clock);
    clientUtil = new ClientUtil(Settings.EMPTY, client, throttler, mock(ThreadPool.class));
    Set<Setting<?>> nodestateSetting = new HashSet<>(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    nodestateSetting.add(MAX_RETRY_FOR_UNRESPONSIVE_NODE);
    nodestateSetting.add(BACKOFF_MINUTES);
    clusterSettings = new ClusterSettings(Settings.EMPTY, nodestateSetting);
    DiscoveryNode discoveryNode = new DiscoveryNode("node1", OpenSearchTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), DiscoveryNodeRole.BUILT_IN_ROLES, Version.CURRENT);
    clusterService = ClusterServiceUtils.createClusterService(threadPool, discoveryNode, clusterSettings);
    stateManager = new NodeStateManager(client, xContentRegistry(), settings, clientUtil, clock, duration, clusterService);
    checkpointResponse = mock(GetResponse.class);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ClientUtil(org.opensearch.ad.util.ClientUtil) Setting(org.opensearch.common.settings.Setting) Client(org.opensearch.client.Client) Clock(java.time.Clock) GetResponse(org.opensearch.action.get.GetResponse) Throttler(org.opensearch.ad.util.Throttler) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ClusterSettings (org.opensearch.common.settings.ClusterSettings)218 Settings (org.opensearch.common.settings.Settings)136 ClusterState (org.opensearch.cluster.ClusterState)70 ClusterService (org.opensearch.cluster.service.ClusterService)67 HashSet (java.util.HashSet)46 Metadata (org.opensearch.cluster.metadata.Metadata)37 Matchers.containsString (org.hamcrest.Matchers.containsString)36 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)36 Before (org.junit.Before)33 ArrayList (java.util.ArrayList)31 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)31 ClusterName (org.opensearch.cluster.ClusterName)30 ThreadPool (org.opensearch.threadpool.ThreadPool)29 RoutingTable (org.opensearch.cluster.routing.RoutingTable)26 TestThreadPool (org.opensearch.threadpool.TestThreadPool)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 Setting (org.opensearch.common.settings.Setting)23 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)23 IOException (java.io.IOException)19 BalancedShardsAllocator (org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)19