use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class DocTableInfoBuilderTest method testNoTableInfoFromOrphanedPartition.
@Test
public void testNoTableInfoFromOrphanedPartition() throws Exception {
String schemaName = randomSchema();
PartitionName partitionName = new PartitionName(schemaName, "test", Collections.singletonList(new BytesRef("boo")));
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(partitionName.asIndexName()).settings(Settings.builder().put("index.version.created", Version.CURRENT).build()).numberOfReplicas(0).numberOfShards(5).putMapping(Constants.DEFAULT_MAPPING_TYPE, "{" + " \"default\": {" + " \"properties\":{" + " \"id\": {" + " \"type\": \"integer\"," + " \"index\": \"not_analyzed\"" + " }" + " }" + " }" + "}");
MetaData metaData = MetaData.builder().put(indexMetaDataBuilder).build();
NoopClusterService clusterService = new NoopClusterService(ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build());
DocTableInfoBuilder builder = new DocTableInfoBuilder(functions, new TableIdent(schemaName, "test"), clusterService, new IndexNameExpressionResolver(Settings.EMPTY), mock(TransportPutIndexTemplateAction.class), executorService, false);
expectedException.expect(TableUnknownException.class);
expectedException.expectMessage(String.format(Locale.ENGLISH, "Table '%s.test' unknown", schemaName));
builder.build();
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class DocIndexMetaDataTest method getDocIndexMetaDataFromStatement.
private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
Statement statement = SqlParser.createStatement(stmt);
ClusterService clusterService = new NoopClusterService();
final TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
Provider<TransportPutIndexTemplateAction> indexTemplateActionProvider = new Provider<TransportPutIndexTemplateAction>() {
@Override
public TransportPutIndexTemplateAction get() {
return transportPutIndexTemplateAction;
}
};
DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(functions, new IndexNameExpressionResolver(Settings.EMPTY), indexTemplateActionProvider, executorService);
DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DEFAULT_SCHEMA_NAME, clusterService, docTableInfoFactory);
CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(new Schemas(Settings.EMPTY, ImmutableMap.<String, SchemaInfo>of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory)), new FulltextAnalyzerResolver(clusterService, new IndicesAnalysisService(Settings.EMPTY)), functions, new NumberOfShards(clusterService));
Analysis analysis = new Analysis(SessionContext.SYSTEM_SESSION, ParameterContext.EMPTY, ParamTypeHints.EMPTY);
CreateTableAnalyzedStatement analyzedStatement = analyzer.analyze((CreateTable) statement, analysis.parameterContext(), analysis.sessionContext());
Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
IndexMetaData indexMetaData = IndexMetaData.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
return newMeta(indexMetaData, analyzedStatement.tableIdent().name());
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.
the class AliasResolveRoutingIT method testResolveSearchRouting.
public void testResolveSearchRouting() throws Exception {
createIndex("test1");
createIndex("test2");
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
client().admin().indices().prepareAliases().addAliasAction(AliasActions.add().index("test1").alias("alias")).addAliasAction(AliasActions.add().index("test1").alias("alias10").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias20").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias21").routing("1")).addAliasAction(AliasActions.add().index("test1").alias("alias0").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias0").routing("0")).get();
ClusterState state = clusterService().state();
IndexNameExpressionResolver indexNameExpressionResolver = internalCluster().getInstance(IndexNameExpressionResolver.class);
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias"), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1", "alias"), equalTo(newMap("test1", newSet("0", "1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", "alias10"), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias0"), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias20", "alias21" }), equalTo(newMap("test2", newSet("0", "1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "test1", "alias10" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "test1" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1", new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", new String[] { "alias10", "alias20" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", new String[] { "alias10", "alias21" }), equalTo(newMap("test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1,2", new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1,2", new String[] { "test1", "alias10", "alias21" }), equalTo(newMap("test1", newSet("0", "1", "2"), "test2", newSet("1"))));
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.
the class GlobalCheckpointSyncActionTests method testTranslogSyncAfterGlobalCheckpointSync.
public void testTranslogSyncAfterGlobalCheckpointSync() throws Exception {
final IndicesService indicesService = mock(IndicesService.class);
final Index index = new Index("index", "uuid");
final IndexService indexService = mock(IndexService.class);
when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
final int id = randomIntBetween(0, 4);
final IndexShard indexShard = mock(IndexShard.class);
when(indexService.getShard(id)).thenReturn(indexShard);
final Translog translog = mock(Translog.class);
when(indexShard.getTranslog()).thenReturn(translog);
final GlobalCheckpointSyncAction action = new GlobalCheckpointSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction, new ActionFilters(Collections.emptySet()), new IndexNameExpressionResolver(Settings.EMPTY));
final ShardId shardId = new ShardId(index, id);
final GlobalCheckpointSyncAction.PrimaryRequest primaryRequest = new GlobalCheckpointSyncAction.PrimaryRequest(shardId);
if (randomBoolean()) {
action.shardOperationOnPrimary(primaryRequest, indexShard);
} else {
action.shardOperationOnReplica(new GlobalCheckpointSyncAction.ReplicaRequest(primaryRequest, randomNonNegativeLong()), indexShard);
}
verify(translog).sync();
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.
the class BroadcastReplicationTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService, new NamedWriteableRegistry(Collections.emptyList()), new NetworkService(Settings.EMPTY, Collections.emptyList()));
clusterService = createClusterService(threadPool);
transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
transportService.start();
transportService.acceptIncomingRequests();
broadcastReplicationAction = new TestBroadcastReplicationAction(Settings.EMPTY, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), null);
}
Aggregations