Java Code Examples for org.elasticsearch.env.Environment#settings()

The following examples show how to use org.elasticsearch.env.Environment#settings() . 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: AnalysisModule.java    From crate with Apache License 2.0 6 votes vote down vote up
public AnalysisModule(Environment environment, List<AnalysisPlugin> plugins) throws IOException {
    NamedRegistry<AnalysisProvider<CharFilterFactory>> charFilters = setupCharFilters(plugins);
    NamedRegistry<org.apache.lucene.analysis.hunspell.Dictionary> hunspellDictionaries = setupHunspellDictionaries(plugins);
    HunspellService hunspellService = new HunspellService(environment.settings(), environment, hunspellDictionaries.getRegistry());
    NamedRegistry<AnalysisProvider<TokenFilterFactory>> tokenFilters = setupTokenFilters(plugins, hunspellService);
    NamedRegistry<AnalysisProvider<TokenizerFactory>> tokenizers = setupTokenizers(plugins);
    NamedRegistry<AnalysisProvider<AnalyzerProvider<?>>> analyzers = setupAnalyzers(plugins);
    NamedRegistry<AnalysisProvider<AnalyzerProvider<?>>> normalizers = setupNormalizers();

    Map<String, PreConfiguredCharFilter> preConfiguredCharFilters = setupPreConfiguredCharFilters(plugins);
    Map<String, PreConfiguredTokenFilter> preConfiguredTokenFilters = setupPreConfiguredTokenFilters(plugins);
    Map<String, PreConfiguredTokenizer> preConfiguredTokenizers = setupPreConfiguredTokenizers(plugins);
    Map<String, PreBuiltAnalyzerProviderFactory> preConfiguredAnalyzers = setupPreBuiltAnalyzerProviderFactories(plugins);

    analysisRegistry = new AnalysisRegistry(environment,
            charFilters.getRegistry(), tokenFilters.getRegistry(), tokenizers.getRegistry(),
            analyzers.getRegistry(), normalizers.getRegistry(),
            preConfiguredCharFilters, preConfiguredTokenFilters, preConfiguredTokenizers, preConfiguredAnalyzers);
}
 
Example 2
Source File: AzureRepository.java    From crate with Apache License 2.0 6 votes vote down vote up
public AzureRepository(RepositoryMetaData metadata,
                       Environment environment,
                       NamedXContentRegistry namedXContentRegistry,
                       AzureStorageService storageService,
                       ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, buildBasePath(metadata));
    this.chunkSize = Repository.CHUNK_SIZE_SETTING.get(metadata.settings());
    this.storageService = storageService;

    // If the user explicitly did not define a readonly value, we set it by ourselves depending on the location mode setting.
    // For secondary_only setting, the repository should be read only
    final LocationMode locationMode = Repository.LOCATION_MODE_SETTING.get(metadata.settings());
    if (Repository.READONLY_SETTING.exists(metadata.settings())) {
        this.readonly = Repository.READONLY_SETTING.get(metadata.settings());
    } else {
        this.readonly = locationMode == LocationMode.SECONDARY_ONLY;
    }
}
 
Example 3
Source File: FsRepository.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a shared file system repository.
 */
public FsRepository(RepositoryMetaData metadata, Environment environment, NamedXContentRegistry namedXContentRegistry,
                    ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, BlobPath.cleanPath());
    this.environment = environment;
    String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings());
    if (location.isEmpty()) {
        LOGGER.warn("the repository location is missing, it should point to a shared file system location"
            + " that is available on all master and data nodes");
        throw new RepositoryException(metadata.name(), "missing location");
    }
    Path locationFile = environment.resolveRepoFile(location);
    if (locationFile == null) {
        if (environment.repoFiles().length > 0) {
            LOGGER.warn("The specified location [{}] doesn't start with any "
                + "repository paths specified by the path.repo setting: [{}] ", location, environment.repoFiles());
            throw new RepositoryException(metadata.name(), "location [" + location
                + "] doesn't match any of the locations specified by path.repo");
        } else {
            LOGGER.warn("The specified location [{}] should start with a repository path specified by"
                + " the path.repo setting, but the path.repo setting was not set on this node", location);
            throw new RepositoryException(metadata.name(), "location [" + location
                + "] doesn't match any of the locations specified by path.repo because this setting is empty");
        }
    }

    if (CHUNK_SIZE_SETTING.exists(metadata.settings())) {
        this.chunkSize = CHUNK_SIZE_SETTING.get(metadata.settings());
    } else {
        this.chunkSize = REPOSITORIES_CHUNK_SIZE_SETTING.get(environment.settings());
    }
    this.basePath = BlobPath.cleanPath();
}
 
Example 4
Source File: UnsafeBootstrapMasterCommand.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean validateBeforeLock(Terminal terminal, Environment env) {
    Settings settings = env.settings();
    terminal.println(Terminal.Verbosity.VERBOSE, "Checking node.master setting");
    Boolean master = Node.NODE_MASTER_SETTING.get(settings);
    if (master == false) {
        throw new ElasticsearchException(NOT_MASTER_NODE_MSG);
    }

    return true;
}
 
Example 5
Source File: URLRepository.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a read-only URL-based repository
 */
public URLRepository(RepositoryMetaData metadata, Environment environment,
                     NamedXContentRegistry namedXContentRegistry, ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, BlobPath.cleanPath());

    if (URL_SETTING.exists(metadata.settings()) == false && REPOSITORIES_URL_SETTING.exists(environment.settings()) == false) {
        throw new RepositoryException(metadata.name(), "missing url");
    }
    this.environment = environment;
    supportedProtocols = SUPPORTED_PROTOCOLS_SETTING.get(environment.settings());
    urlWhiteList = ALLOWED_URLS_SETTING.get(environment.settings()).toArray(new URIPattern[]{});
    basePath = BlobPath.cleanPath();
    url = URL_SETTING.exists(metadata.settings())
        ? URL_SETTING.get(metadata.settings()) : REPOSITORIES_URL_SETTING.get(environment.settings());
}
 
Example 6
Source File: HdfsRepository.java    From crate with Apache License 2.0 5 votes vote down vote up
public HdfsRepository(RepositoryMetaData metadata, Environment environment,
                      NamedXContentRegistry namedXContentRegistry, ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, BlobPath.cleanPath());

    this.environment = environment;
    this.chunkSize = metadata.settings().getAsBytesSize("chunk_size", null);

    String uriSetting = getMetadata().settings().get("uri");
    if (Strings.hasText(uriSetting) == false) {
        throw new IllegalArgumentException("No 'uri' defined for hdfs snapshot/restore");
    }
    uri = URI.create(uriSetting);
    if ("hdfs".equalsIgnoreCase(uri.getScheme()) == false) {
        throw new IllegalArgumentException(String.format(Locale.ROOT,
            "Invalid scheme [%s] specified in uri [%s]; only 'hdfs' uri allowed for hdfs snapshot/restore",
            uri.getScheme(), uriSetting));
    }
    if (Strings.hasLength(uri.getPath()) && uri.getPath().equals("/") == false) {
        throw new IllegalArgumentException(String.format(Locale.ROOT,
            "Use 'path' option to specify a path [%s], not the uri [%s] for hdfs snapshot/restore", uri.getPath(), uriSetting));
    }

    pathSetting = getMetadata().settings().get("path");
    // get configuration
    if (pathSetting == null) {
        throw new IllegalArgumentException("No 'path' defined for hdfs snapshot/restore");
    }
}
 
Example 7
Source File: BootstrapProxy.java    From crate with Apache License 2.0 4 votes vote down vote up
private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
    Settings settings = environment.settings();
    initializeNatives(
        BootstrapSettings.MEMORY_LOCK_SETTING.get(settings),
        BootstrapSettings.CTRLHANDLER_SETTING.get(settings));

    // initialize probes before the security manager is installed
    initializeProbes();

    if (addShutdownHook) {
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            try {
                IOUtils.close(node);
                LoggerContext context = (LoggerContext) LogManager.getContext(false);
                Configurator.shutdown(context);
            } catch (IOException ex) {
                throw new ElasticsearchException("failed to stop node", ex);
            }
        }));
    }

    try {
        // look for jar hell
        final Logger logger = LogManager.getLogger(JarHell.class);
        JarHell.checkJarHell(logger::debug);
    } catch (IOException | URISyntaxException e) {
        throw new BootstrapException(e);
    }

    IfConfig.logIfNecessary();

    node = new CrateNode(environment) {

        @Override
        protected void validateNodeBeforeAcceptingRequests(BoundTransportAddress boundTransportAddress,
                                                           List<BootstrapCheck> bootstrapChecks) throws NodeValidationException {
            BootstrapChecks.check(settings, boundTransportAddress, bootstrapChecks);
        }
    };

}