@Override
 public Settings nodeSettings(int nodeOrdinal) {
   Path configDir = createTempDir();
   Path scriptsDir = configDir.resolve("scripts");
   try {
     Files.createDirectories(scriptsDir);
     Files.write(
         scriptsDir.resolve("file_template_1.mustache"), TEMPLATE_CONTENTS.getBytes("UTF-8"));
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return Settings.builder()
       .put(super.nodeSettings(nodeOrdinal))
       .put(Environment.PATH_CONF_SETTING.getKey(), configDir)
       .build();
 }
Exemplo n.º 2
0
 /** Adds access to all configurable paths. */
 static void addFilePermissions(Permissions policy, Environment environment) {
   // read-only dirs
   addPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.binFile(), "read,readlink");
   addPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.libFile(), "read,readlink");
   addPath(
       policy, Environment.PATH_HOME_SETTING.getKey(), environment.modulesFile(), "read,readlink");
   addPath(
       policy, Environment.PATH_HOME_SETTING.getKey(), environment.pluginsFile(), "read,readlink");
   addPath(
       policy, Environment.PATH_CONF_SETTING.getKey(), environment.configFile(), "read,readlink");
   addPath(
       policy,
       Environment.PATH_SCRIPTS_SETTING.getKey(),
       environment.scriptsFile(),
       "read,readlink");
   // read-write dirs
   addPath(policy, "java.io.tmpdir", environment.tmpFile(), "read,readlink,write,delete");
   addPath(
       policy,
       Environment.PATH_LOGS_SETTING.getKey(),
       environment.logsFile(),
       "read,readlink,write,delete");
   if (environment.sharedDataFile() != null) {
     addPath(
         policy,
         Environment.PATH_SHARED_DATA_SETTING.getKey(),
         environment.sharedDataFile(),
         "read,readlink,write,delete");
   }
   for (Path path : environment.dataFiles()) {
     addPath(policy, Environment.PATH_DATA_SETTING.getKey(), path, "read,readlink,write,delete");
   }
   // TODO: this should be removed in ES 6.0! We will no longer support data paths with the cluster
   // as a folder
   assert Version.CURRENT.major < 6 : "cluster name is no longer used in data path";
   for (Path path : environment.dataWithClusterFiles()) {
     addPathIfExists(
         policy, Environment.PATH_DATA_SETTING.getKey(), path, "read,readlink,write,delete");
   }
   for (Path path : environment.repoFiles()) {
     addPath(policy, Environment.PATH_REPO_SETTING.getKey(), path, "read,readlink,write,delete");
   }
   if (environment.pidFile() != null) {
     // we just need permission to remove the file if its elsewhere.
     policy.add(new FilePermission(environment.pidFile().toString(), "delete"));
   }
 }
Exemplo n.º 3
0
 public void testThatTribeClientsIgnoreGlobalConfig() throws Exception {
   Path pathConf = getDataPath("elasticsearch.yml").getParent();
   Settings settings =
       Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), pathConf).build();
   assertTribeNodeSuccessfullyCreated(settings);
 }
  @Before
  public void setup() throws IOException {
    Settings settings =
        Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .put(Environment.PATH_CONF_SETTING.getKey(), this.getDataPath("config"))
            .put("node.name", getClass().getName())
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();
    final Client proxy =
        (Client)
            Proxy.newProxyInstance(
                Client.class.getClassLoader(),
                new Class<?>[] {Client.class},
                (proxy1, method, args) -> {
                  throw new UnsupportedOperationException("client is just a dummy");
                });
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    Index index = idxSettings.getIndex();
    SettingsModule settingsModule = new SettingsModule(settings);
    ScriptModule scriptModule = new ScriptModule();
    scriptModule.prepareSettings(settingsModule);
    // TODO: make this use a mock engine instead of mustache and it will no longer be messy!
    scriptModule.addScriptEngine(
        new ScriptEngineRegistry.ScriptEngineRegistration(
            MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES));
    settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED);
    injector =
        new ModulesBuilder()
            .add(
                new EnvironmentModule(new Environment(settings)),
                settingsModule,
                new ThreadPoolModule(new ThreadPool(settings)),
                new SearchModule(settings, new NamedWriteableRegistry()) {
                  @Override
                  protected void configureSearch() {
                    // skip so we don't need transport
                  }
                },
                scriptModule,
                new IndexSettingsModule(index, settings),
                new AbstractModule() {
                  @Override
                  protected void configure() {
                    bind(Client.class).toInstance(proxy); // not needed here
                    Multibinder.newSetBinder(binder(), ScoreFunctionParser.class);
                    bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
                    bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class);
                  }
                })
            .createInjector();

    AnalysisService analysisService =
        new AnalysisRegistry(null, new Environment(settings)).build(idxSettings);
    ScriptService scriptService = injector.getInstance(ScriptService.class);
    SimilarityService similarityService =
        new SimilarityService(idxSettings, Collections.emptyMap());
    MapperRegistry mapperRegistry = new IndicesModule().getMapperRegistry();
    MapperService mapperService =
        new MapperService(
            idxSettings, analysisService, similarityService, mapperRegistry, () -> context);
    IndicesFieldDataCache cache =
        new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {});
    IndexFieldDataService indexFieldDataService =
        new IndexFieldDataService(
            idxSettings, cache, injector.getInstance(CircuitBreakerService.class), mapperService);
    BitsetFilterCache bitsetFilterCache =
        new BitsetFilterCache(
            idxSettings,
            new BitsetFilterCache.Listener() {
              @Override
              public void onCache(ShardId shardId, Accountable accountable) {}

              @Override
              public void onRemoval(ShardId shardId, Accountable accountable) {}
            });
    IndicesQueriesRegistry indicesQueriesRegistry =
        injector.getInstance(IndicesQueriesRegistry.class);
    context =
        new QueryShardContext(
            idxSettings,
            bitsetFilterCache,
            indexFieldDataService,
            mapperService,
            similarityService,
            scriptService,
            indicesQueriesRegistry,
            null,
            null);
  }