org.elasticsearch.common.inject.ModulesBuilder Java Examples
The following examples show how to use
org.elasticsearch.common.inject.ModulesBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IkESPluginTest.java From es-ik with Apache License 2.0 | 6 votes |
@Test public void testDefaultsIcuAnalysis() { Index index = new Index("test"); Settings settings = ImmutableSettings.settingsBuilder() .put("path.home", "none") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), new IndexNameModule(index), new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor())) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer"); MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class)); }
Example #2
Source File: HanLpAnalysisTests.java From elasticsearch-analysis-hanlp with Apache License 2.0 | 6 votes |
@Test public void testDefaultsIcuAnalysis() { Index index = new Index("test"); Settings settings = settingsBuilder() .put("path.home", createTempDir()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), new IndexNameModule(index), new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new HanLpAnalysisBinderProcessor())) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); TokenizerFactory tokenizerFactory = analysisService.tokenizer("smartcn_tokenizer"); MatcherAssert.assertThat(tokenizerFactory, instanceOf(HanLpTokenizerTokenizerFactory.class)); }
Example #3
Source File: MapperTestUtils.java From Elasticsearch with Apache License 2.0 | 5 votes |
private static AnalysisService newAnalysisService(Settings indexSettings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector(); Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); }
Example #4
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static AnalysisService newAnalysisService(Settings indexSettings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector(); Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); }
Example #5
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static MapperService newMapperService(Settings settings, Client client) { Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", System.getProperty("path.home")) .put("client.type", "node") .put(settings) .build(); Index index = new Index("test"); Injector parentInjector = new ModulesBuilder() .add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))) .createInjector(); AnalysisModule analysisModule = new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class)); new AnalysisBaseformPlugin(settings).onModule(analysisModule); Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), analysisModule) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); return new MapperService(new Index("test"), indexSettings, analysisService, similarityLookupService, null, mapperRegistry); }
Example #6
Source File: TestingHelpers.java From crate with Apache License 2.0 | 5 votes |
public static Functions getFunctions() { return new ModulesBuilder() .add(new SessionSettingModule()) .add(new AggregationImplModule()) .add(new PredicateModule()) .add(new TableFunctionModule()) .add(new ScalarFunctionModule()) .add(new WindowFunctionModule()) .add(new OperatorModule()).createInjector().getInstance(Functions.class); }
Example #7
Source File: SqlExpressions.java From crate with Apache License 2.0 | 5 votes |
public SqlExpressions(Map<RelationName, AnalyzedRelation> sources, @Nullable FieldResolver fieldResolver, User user, AbstractModule... additionalModules) { ModulesBuilder modulesBuilder = new ModulesBuilder() .add(new SessionSettingModule()) .add(new OperatorModule()) .add(new AggregationImplModule()) .add(new ScalarFunctionModule()) .add(new WindowFunctionModule()) .add(new TableFunctionModule()) .add(new PredicateModule()); if (additionalModules != null) { for (AbstractModule module : additionalModules) { modulesBuilder.add(module); } } injector = modulesBuilder.createInjector(); functions = injector.getInstance(Functions.class); coordinatorTxnCtx = new CoordinatorTxnCtx(new SessionContext(Option.NONE, user)); expressionAnalyzer = new ExpressionAnalyzer( functions, coordinatorTxnCtx, ParamTypeHints.EMPTY, new FullQualifiedNameFieldProvider( sources, ParentRelations.NO_PARENTS, coordinatorTxnCtx.sessionContext().searchPath().currentSchema()), new SubqueryAnalyzer( new RelationAnalyzer(functions, mock(Schemas.class)), new StatementAnalysisContext(ParamTypeHints.EMPTY, Operation.READ, coordinatorTxnCtx) ) ); normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, null, fieldResolver); expressionAnalysisCtx = new ExpressionAnalysisContext(); }
Example #8
Source File: RowsBatchIteratorBenchmark.java From crate with Apache License 2.0 | 5 votes |
@Setup public void setup() { Functions functions = new ModulesBuilder().add(new EnterpriseFunctionsModule()) .createInjector().getInstance(Functions.class); lastValueIntFunction = (WindowFunction) functions.getQualified( Signature.window( LAST_VALUE_NAME, parseTypeSignature("E"), parseTypeSignature("E") ).withTypeVariableConstraints(typeVariable("E")), List.of(DataTypes.INTEGER), DataTypes.INTEGER ); }
Example #9
Source File: TransportClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Builds a new instance of the transport client. */ public TransportClient build() { Settings settings = InternalSettingsPreparer.prepareSettings(this.settings); settings = settingsBuilder() .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval .put(settings) .put("network.server", false) .put("node.client", true) .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) .build(); PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; final ThreadPool threadPool = new ThreadPool(settings); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); boolean success = false; try { ModulesBuilder modules = new ModulesBuilder(); modules.add(new Version.Module(version)); // plugin modules must be added here, before others or we can get crazy injection errors... for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); } modules.add(new PluginsModule(pluginsService)); modules.add(new SettingsModule(this.settings)); modules.add(new NetworkModule(namedWriteableRegistry)); modules.add(new ClusterNameModule(this.settings)); modules.add(new ThreadPoolModule(threadPool)); modules.add(new TransportModule(this.settings, namedWriteableRegistry)); modules.add(new SearchModule() { @Override protected void configure() { // noop } }); modules.add(new ActionModule(true)); modules.add(new ClientTransportModule()); modules.add(new CircuitBreakerModule(this.settings)); pluginsService.processModules(modules); Injector injector = modules.createInjector(); final TransportService transportService = injector.getInstance(TransportService.class); transportService.start(); transportService.acceptIncomingRequests(); TransportClient transportClient = new TransportClient(injector); success = true; return transportClient; } finally { if (!success) { ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); } } }
Example #10
Source File: TransportClient.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
public TransportClient build() { Settings settings = InternalSettingsPreparer.prepareSettings(this.settings); settings = settingsBuilder() .put("transport.ping.schedule", this.settings.get("ping.interval", "30s")) .put(settings) .put("network.server", false) .put("node.client", true) .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) .build(); PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; final ThreadPool threadPool = new ThreadPool(settings); final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); boolean success = false; try { ModulesBuilder modules = new ModulesBuilder(); modules.add(new Version.Module(version)); // plugin modules must be added here, before others or we can get crazy injection errors... for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); } modules.add(new PluginsModule(pluginsService)); modules.add(new SettingsModule(this.settings)); modules.add(new NetworkModule(namedWriteableRegistry)); modules.add(new ClusterNameModule(this.settings)); modules.add(new ThreadPoolModule(threadPool)); modules.add(new TransportModule(this.settings, namedWriteableRegistry)); modules.add(new SearchModule() { @Override protected void configure() { // noop } }); modules.add(new ActionModule(true)); modules.add(new ClientTransportModule(hostFailedListener)); modules.add(new CircuitBreakerModule(this.settings)); pluginsService.processModules(modules); Injector injector = modules.createInjector(); injector.getInstance(TransportService.class).start(); TransportClient transportClient = new TransportClient(injector); success = true; return transportClient; } finally { if (!success) { ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); } } }
Example #11
Source File: HyperLogLogDistinctAggregationBenchmark.java From crate with Apache License 2.0 | 4 votes |
@Setup public void setUp() throws Exception { hash = new MurmurHash3.Hash128(); InputCollectExpression inExpr0 = new InputCollectExpression(0); Functions functions = new ModulesBuilder() .add(new EnterpriseFunctionsModule()) .createInjector().getInstance(Functions.class); HyperLogLogDistinctAggregation hllAggregation = (HyperLogLogDistinctAggregation) functions.getQualified( Signature.aggregate( HyperLogLogDistinctAggregation.NAME, DataTypes.STRING.getTypeSignature(), DataTypes.LONG.getTypeSignature() ), List.of(DataTypes.STRING), DataTypes.STRING ); onHeapMemoryManager = new OnHeapMemoryManager(bytes -> {}); offHeapMemoryManager = new OffHeapMemoryManager(); hyperLogLogPlusPlus = new HyperLogLogPlusPlus(HyperLogLogPlusPlus.DEFAULT_PRECISION, onHeapMemoryManager::allocate); onHeapCollector = new AggregateCollector( Collections.singletonList(inExpr0), RamAccounting.NO_ACCOUNTING, onHeapMemoryManager, Version.CURRENT, AggregateMode.ITER_FINAL, new AggregationFunction[] { hllAggregation }, Version.CURRENT, new Input[][] { {inExpr0 } }, new Input[] { Literal.BOOLEAN_TRUE } ); offHeapCollector = new AggregateCollector( Collections.singletonList(inExpr0), RamAccounting.NO_ACCOUNTING, offHeapMemoryManager, Version.CURRENT, AggregateMode.ITER_FINAL, new AggregationFunction[] { hllAggregation }, Version.CURRENT, new Input[][] { {inExpr0 } }, new Input[] { Literal.BOOLEAN_TRUE } ); }
Example #12
Source File: HyperLogLogDistinctAggregationTest.java From crate with Apache License 2.0 | 4 votes |
@Before public void prepareFunctions() throws Exception { functions = new ModulesBuilder() .add(new EnterpriseFunctionsModule()) .createInjector().getInstance(Functions.class); }