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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations