use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.
the class BroadcastReplicationTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
MockNioTransport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), circuitBreakerService);
clusterService = createClusterService(threadPool);
transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
transportService.start();
transportService.acceptIncomingRequests();
broadcastReplicationAction = new TestBroadcastReplicationAction(clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), null);
}
use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.
the class SearchIndexNameMatcherTests method setUpMatchers.
@Before
public void setUpMatchers() {
Metadata.Builder metadataBuilder = Metadata.builder().put(indexBuilder("index1").putAlias(AliasMetadata.builder("alias"))).put(indexBuilder("index2").putAlias(AliasMetadata.builder("alias"))).put(indexBuilder("index3"));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(metadataBuilder).build();
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.state()).thenReturn(state);
matcher = new SearchIndexNameMatcher("index1", "", clusterService, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
remoteMatcher = new SearchIndexNameMatcher("index1", "cluster", clusterService, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
}
use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.
the class IndexModuleTests method testRegisterCustomRecoveryStateFactory.
public void testRegisterCustomRecoveryStateFactory() throws IOException {
final Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexModule.INDEX_RECOVERY_TYPE_SETTING.getKey(), "test_recovery").build();
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
RecoveryState recoveryState = mock(RecoveryState.class);
final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories = singletonMap("test_recovery", (shardRouting, targetNode, sourceNode) -> recoveryState);
final IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), new EngineConfigFactory(indexSettings), Collections.emptyMap(), () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), recoveryStateFactories);
final IndexService indexService = newIndexService(module);
ShardRouting shard = createInitializedShardRouting();
assertThat(indexService.createRecoveryState(shard, mock(DiscoveryNode.class), mock(DiscoveryNode.class)), is(recoveryState));
indexService.close("closing", false);
}
use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.
the class IndexModuleTests method testRegisterIndexStore.
public void testRegisterIndexStore() throws IOException {
final Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "foo_store").build();
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
final Map<String, IndexStorePlugin.DirectoryFactory> indexStoreFactories = singletonMap("foo_store", new FooFunction());
final IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), new EngineConfigFactory(indexSettings), indexStoreFactories, () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap());
final IndexService indexService = newIndexService(module);
assertThat(indexService.getDirectoryFactory(), instanceOf(FooFunction.class));
indexService.close("simon says", false);
}
use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project ml-commons by opensearch-project.
the class AnomalyLocalizerImplTests method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
MockitoAnnotations.openMocks(this);
settings = Settings.builder().build();
testState = setupTestClusterState();
IndicesOptions = new String[] { "indexName" };
invalidIndicesOptions = new String[] {};
anomalyLocalizer = spy(new AnomalyLocalizerImpl(client, settings, clusterService, indexNameExpressionResolver));
input = new AnomalyLocalizationInput(indexName, Arrays.asList(attributeFieldNameOne), Arrays.asList(agg), timeFieldName, startTime, endTime, minTimeInterval, numOutput, Optional.empty(), Optional.empty());
when(valueOne.value()).thenReturn(0.);
when(valueOne.getName()).thenReturn(agg.getName());
SearchResponse respOne = mock(SearchResponse.class);
when(respOne.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueOne)));
MultiSearchResponse.Item itemOne = new MultiSearchResponse.Item(respOne, null);
when(valueTwo.value()).thenReturn(10.);
when(valueTwo.getName()).thenReturn(agg.getName());
SearchResponse respTwo = mock(SearchResponse.class);
when(respTwo.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueTwo)));
MultiSearchResponse.Item itemTwo = new MultiSearchResponse.Item(respTwo, null);
MultiSearchResponse multiSearchResponse = new MultiSearchResponse(new MultiSearchResponse.Item[] { itemOne, itemTwo }, 0);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<MultiSearchResponse> listener = (ActionListener<MultiSearchResponse>) args[1];
listener.onResponse(multiSearchResponse);
return null;
}).when(client).multiSearch(any(), any());
CompositeAggregation.Bucket bucketOne = mock(CompositeAggregation.Bucket.class);
Map<String, Object> bucketOneKey = new HashMap<>();
String bucketOneKeyValue = "bucketOneKeyValue";
bucketOneKey.put(attributeFieldNameOne, bucketOneKeyValue);
when(bucketOne.getKey()).thenReturn(bucketOneKey);
when(bucketOne.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueOne)));
CompositeAggregation compositeOne = mock(CompositeAggregation.class);
when(compositeOne.getName()).thenReturn(agg.getName());
doReturn(Arrays.asList(bucketOne)).when(compositeOne).getBuckets();
when(compositeOne.afterKey()).thenReturn(bucketOneKey);
SearchResponse respBucketOne = mock(SearchResponse.class);
when(respBucketOne.getAggregations()).thenReturn(new Aggregations(Arrays.asList(compositeOne))).thenReturn(new Aggregations(Collections.emptyList()));
CompositeAggregation.Bucket bucketOneNew = mock(CompositeAggregation.Bucket.class);
when(bucketOneNew.getKey()).thenReturn(bucketOneKey);
when(bucketOneNew.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueTwo)));
Map<String, Object> bucketTwoKey = new HashMap<>();
String bucketTwoKeyValue = "bucketTwoKeyValue";
bucketTwoKey.put(attributeFieldNameOne, bucketTwoKeyValue);
when(valueThree.value()).thenReturn(0.);
when(valueThree.getName()).thenReturn(agg.getName());
CompositeAggregation.Bucket bucketTwoNew = mock(CompositeAggregation.Bucket.class);
when(bucketTwoNew.getKey()).thenReturn(bucketTwoKey);
when(bucketTwoNew.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueThree)));
CompositeAggregation compositeTwo = mock(CompositeAggregation.class);
when(compositeTwo.getName()).thenReturn(agg.getName());
doReturn(Arrays.asList(bucketTwoNew, bucketOneNew, bucketTwoNew)).when(compositeTwo).getBuckets();
when(compositeTwo.afterKey()).thenReturn(bucketOneKey);
SearchResponse respBucketTwo = mock(SearchResponse.class);
when(respBucketTwo.getAggregations()).thenReturn(new Aggregations(Arrays.asList(compositeTwo))).thenReturn(new Aggregations(Collections.emptyList()));
Filters.Bucket filterBucketOne = mock(Filters.Bucket.class);
when(filterBucketOne.getKeyAsString()).thenReturn(String.valueOf(0));
when(filterBucketOne.getAggregations()).thenReturn(new Aggregations(Arrays.asList(valueOne)));
Filters filters = mock(Filters.class);
when(filters.getName()).thenReturn(agg.getName());
doReturn(Arrays.asList(filterBucketOne)).when(filters).getBuckets();
SearchResponse filtersResp = mock(SearchResponse.class);
when(filtersResp.getAggregations()).thenReturn(new Aggregations(Arrays.asList(filters)));
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
listener.onResponse(respBucketOne);
return null;
}).doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
listener.onResponse(respBucketOne);
return null;
}).doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
listener.onResponse(respBucketTwo);
return null;
}).doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
listener.onResponse(respBucketTwo);
return null;
}).doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
listener.onResponse(filtersResp);
return null;
}).when(client).search(any(), any());
expectedOutput = new AnomalyLocalizationOutput();
AnomalyLocalizationOutput.Result result = new AnomalyLocalizationOutput.Result();
expectedBucketOne = new AnomalyLocalizationOutput.Bucket();
expectedBucketOne.setStartTime(0);
expectedBucketOne.setEndTime(1);
expectedBucketOne.setOverallAggValue(0);
expectedBucketTwo = new AnomalyLocalizationOutput.Bucket();
expectedBucketTwo.setStartTime(1);
expectedBucketTwo.setEndTime(2);
expectedBucketTwo.setOverallAggValue(10);
entity = new AnomalyLocalizationOutput.Entity();
entity.setKey(Arrays.asList(bucketOneKeyValue));
entity.setNewValue(valueTwo.value());
entity.setBaseValue(valueOne.value());
entity.setContributionValue(valueTwo.value());
expectedBucketTwo.setEntities(Arrays.asList(entity));
result.getBuckets().add(expectedBucketOne);
result.getBuckets().add(expectedBucketTwo);
expectedOutput.getResults().put(agg.getName(), result);
}
Aggregations