Search in sources :

Example 6 with ClusterState

use of org.elasticsearch.cluster.ClusterState in project crate by crate.

the class CreateAlterPartitionedTableAnalyzerTest method init.

@Before
public void init() throws Exception {
    String analyzerSettings = FulltextAnalyzerResolver.encodeSettings(Settings.builder().put("search", "foobar").build()).toUtf8();
    MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("crate.analysis.custom.analyzer.ft_search", analyzerSettings).build()).build();
    ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build();
    e = SQLExecutor.builder(new NoopClusterService(state)).enableDefaultTables().build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 7 with ClusterState

use of org.elasticsearch.cluster.ClusterState in project rssriver by dadoonet.

the class RssRiver method isMappingExist.

/**
     * Check if a mapping already exists in an index
     * @param index Index name
     * @param type Mapping name
     * @return true if mapping exists
     */
private boolean isMappingExist(String index, String type) {
    ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
    IndexMetaData imd = cs.getMetaData().index(index);
    if (imd == null)
        return false;
    MappingMetaData mdd = imd.mapping(type);
    if (mdd != null)
        return true;
    return false;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 8 with ClusterState

use of org.elasticsearch.cluster.ClusterState in project elasticsearch by elastic.

the class ScriptContextTests method makeScriptService.

ScriptService makeScriptService() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "false").put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "false").build();
    MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"));
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
    List<ScriptContext.Plugin> customContexts = Arrays.asList(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    ScriptService scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    ClusterState empty = ClusterState.builder(new ClusterName("_name")).build();
    ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE);
    smd = ScriptMetaData.putStoredScript(smd, "1", new StoredScriptSource(MockScriptEngine.NAME, "1", Collections.emptyMap()));
    MetaData.Builder mdb = MetaData.builder(empty.getMetaData()).putCustom(ScriptMetaData.TYPE, smd);
    ClusterState stored = ClusterState.builder(empty).metaData(mdb).build();
    scriptService.clusterChanged(new ClusterChangedEvent("test", stored, empty));
    return scriptService;
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Arrays(java.util.Arrays) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) Environment(org.elasticsearch.env.Environment) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) MetaData(org.elasticsearch.cluster.metadata.MetaData) Environment(org.elasticsearch.env.Environment) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with ClusterState

use of org.elasticsearch.cluster.ClusterState 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"))));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 10 with ClusterState

use of org.elasticsearch.cluster.ClusterState in project elasticsearch by elastic.

the class ParentFieldLoadingIT method testChangingEagerParentFieldLoadingAtRuntime.

public void testChangingEagerParentFieldLoadingAtRuntime() throws Exception {
    assertAcked(prepareCreate("test").setSettings(indexSettings).addMapping("parent").addMapping("child", "_parent", "type=parent"));
    ensureGreen();
    client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
    refresh();
    ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), equalTo(0L));
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource(childMapping(true)).setUpdateAllTypes(true).get();
    assertAcked(putMappingResponse);
    Index test = resolveIndex("test");
    assertBusy(new Runnable() {

        @Override
        public void run() {
            ClusterState clusterState = internalCluster().clusterService().state();
            ShardRouting shardRouting = clusterState.routingTable().index("test").shard(0).getShards().get(0);
            String nodeName = clusterState.getNodes().get(shardRouting.currentNodeId()).getName();
            boolean verified = false;
            IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
            IndexService indexService = indicesService.indexService(test);
            if (indexService != null) {
                MapperService mapperService = indexService.mapperService();
                DocumentMapper documentMapper = mapperService.documentMapper("child");
                if (documentMapper != null) {
                    verified = documentMapper.parentFieldMapper().fieldType().eagerGlobalOrdinals();
                }
            }
            assertTrue(verified);
        }
    });
    // Need to add a new doc otherwise the refresh doesn't trigger a new searcher
    // Because it ends up in its own segment, but isn't of type parent or child, this doc doesn't contribute to the size of the fielddata cache
    client().prepareIndex("test", "dummy", "dummy").setSource("{}", XContentType.JSON).get();
    refresh();
    response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) ClusterStatsResponse(org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) MapperService(org.elasticsearch.index.mapper.MapperService)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)564 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)211 MetaData (org.elasticsearch.cluster.metadata.MetaData)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)150 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)123 Settings (org.elasticsearch.common.settings.Settings)100 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)85 ClusterName (org.elasticsearch.cluster.ClusterName)82 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)75 Matchers.containsString (org.hamcrest.Matchers.containsString)72 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)62 ShardId (org.elasticsearch.index.shard.ShardId)61 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)59 ArrayList (java.util.ArrayList)57 IOException (java.io.IOException)55 Index (org.elasticsearch.index.Index)53 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)49 CountDownLatch (java.util.concurrent.CountDownLatch)47 HashSet (java.util.HashSet)45 List (java.util.List)45