Java Code Examples for org.elasticsearch.common.settings.Settings#getAsLong()

The following examples show how to use org.elasticsearch.common.settings.Settings#getAsLong() . 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: IndexMetaData.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Adds human readable version and creation date settings.
 * This method is used to display the settings in a human readable format in REST API
 */
public static Settings addHumanReadableSettings(Settings settings) {
    Settings.Builder builder = Settings.builder().put(settings);
    Version version = settings.getAsVersion(SETTING_VERSION_CREATED, null);
    if (version != null) {
        builder.put(SETTING_VERSION_CREATED_STRING, version.toString());
    }
    Version versionUpgraded = settings.getAsVersion(SETTING_VERSION_UPGRADED, null);
    if (versionUpgraded != null) {
        builder.put(SETTING_VERSION_UPGRADED_STRING, versionUpgraded.toString());
    }
    Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null);
    if (creationDate != null) {
        DateTime creationDateTime = new DateTime(creationDate, DateTimeZone.UTC);
        builder.put(SETTING_CREATION_DATE_STRING, creationDateTime.toString());
    }
    return builder.build();
}
 
Example 2
Source File: SearchIndexServiceImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new search index statistics objects per specified parameters.
 *
 * @param settings the search index settings
 * @param docsStats the search index docs stats
 * @param indexCount the count of index
 *
 * @return the newly created search index statistics object
 */
protected SearchIndexStatistics createSearchIndexStatistics(Settings settings, DocsStats docsStats, long indexCount)
{
    SearchIndexStatistics searchIndexStatistics = new SearchIndexStatistics();

    Long creationDate = settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1L);
    if (creationDate.longValue() != -1L)
    {
        DateTime creationDateTime = new DateTime(creationDate, DateTimeZone.UTC);
        searchIndexStatistics.setIndexCreationDate(HerdDateUtils.getXMLGregorianCalendarValue(creationDateTime.toDate()));
    }

    searchIndexStatistics.setIndexNumberOfActiveDocuments(docsStats.getCount());
    searchIndexStatistics.setIndexNumberOfDeletedDocuments(docsStats.getDeleted());
    searchIndexStatistics.setIndexUuid(settings.get(IndexMetaData.SETTING_INDEX_UUID));
    searchIndexStatistics.setIndexCount(indexCount);

    return searchIndexStatistics;
}
 
Example 3
Source File: IndexMetaData.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Adds human readable version and creation date settings.
 * This method is used to display the settings in a human readable format in REST API
 */
public static Settings addHumanReadableSettings(Settings settings) {
    Settings.Builder builder = Settings.builder().put(settings);
    Version version = SETTING_INDEX_VERSION_CREATED.get(settings);
    if (version != Version.V_EMPTY) {
        builder.put(SETTING_VERSION_CREATED_STRING, version.toString());
    }
    Version versionUpgraded = settings.getAsVersion(SETTING_VERSION_UPGRADED, null);
    if (versionUpgraded != null) {
        builder.put(SETTING_VERSION_UPGRADED_STRING, versionUpgraded.toString());
    }
    Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null);
    if (creationDate != null) {
        ZonedDateTime creationDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(creationDate), ZoneOffset.UTC);
        builder.put(SETTING_CREATION_DATE_STRING, creationDateTime.toString());
    }
    return builder.build();
}
 
Example 4
Source File: AuditLogSink.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
protected AuditLogSink(String name, Settings settings, String settingsPrefix, AuditLogSink fallbackSink) {
    this.name = name.toLowerCase();
	this.settings = Objects.requireNonNull(settings);
    this.settingsPrefix = settingsPrefix;
    this.fallbackSink = fallbackSink;

    retryCount = settings.getAsInt(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_RETRY_COUNT, 0);
    delayMs = settings.getAsLong(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_RETRY_DELAY_MS, 1000L);
}
 
Example 5
Source File: PublishClusterStateVersionAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public PublishClusterStateVersionAction(Settings settings, ClusterService clusterService, TransportService transportService, ClusterStateOpLog clusterStateOpLog) {
    super(settings);
    this.clusterService = clusterService;
    this.transportService = transportService;
    this.clusterStateOpLog = clusterStateOpLog;
    this.pullFullClusterStateAction = new PullFullClusterStateAction(settings, clusterService, transportService, clusterStateOpLog);
    this.fullStateSyncOps = settings.getAsLong(SETTING_FULL_STATE_SYNC_THRESHOLD, 30L);
    this.publishTimeout = settings.getAsTime(PUBLISH_TIMEOUT, publishTimeout);
    this.transportService.registerRequestHandler(PUBLISH_VERSION_ACTION_NAME, BytesTransportRequest.class, ThreadPool.Names.GENERIC, new PublishClusterStateVersionRequestHandler());
}
 
Example 6
Source File: PluginSettings.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
public PluginSettings(final Settings settings) {
    this.settings = settings;
    this.kibanaIndexMode = settings.get(OPENSHIFT_KIBANA_INDEX_MODE, KibanaIndexMode.DEFAULT_MODE);
    if (!ArrayUtils.contains(new String[] { UNIQUE, SHARED_OPS, SHARED_NON_OPS }, kibanaIndexMode.toLowerCase())) {
        this.kibanaIndexMode = UNIQUE;
    }

    this.roleStrategy = settings.get(OPENSHIFT_ACL_ROLE_STRATEGY, DEFAULT_ACL_ROLE_STRATEGY);
    if (!ArrayUtils.contains(new String[] { PROJECT, USER }, roleStrategy.toLowerCase())) {
        this.kibanaIndexMode = USER;
    }

    this.cdmProjectPrefix = settings.get(OPENSHIFT_CONFIG_PROJECT_INDEX_PREFIX,
            OPENSHIFT_DEFAULT_PROJECT_INDEX_PREFIX);
    this.defaultKibanaIndex = settings.get(KIBANA_CONFIG_INDEX_NAME, DEFAULT_USER_PROFILE_PREFIX);
    this.searchGuardIndex = settings.get(SEARCHGUARD_CONFIG_INDEX_NAME, DEFAULT_SECURITY_CONFIG_INDEX);
    this.kibanaVersion = settings.get(KIBANA_CONFIG_VERSION, DEFAULT_KIBANA_VERSION);
    this.kbnVersionHeader = settings.get(KIBANA_VERSION_HEADER, DEFAULT_KIBANA_VERSION_HEADER);
    this.opsIndexPatterns = new HashSet<String>(Arrays.asList(settings.getAsArray(OPENSHIFT_KIBANA_OPS_INDEX_PATTERNS, DEFAULT_KIBANA_OPS_INDEX_PATTERNS)));
    this.expireInMillis = settings.getAsLong(OPENSHIFT_CONTEXT_CACHE_EXPIRE_SECONDS,
            DEFAULT_OPENSHIFT_CONTEXT_CACHE_EXPIRE_SECONDS) * 1000;

    LOGGER.info("Using kibanaIndexMode: '{}'", this.kibanaIndexMode);
    LOGGER.debug("searchGuardIndex: {}", this.searchGuardIndex);
    LOGGER.debug("roleStrategy: {}", this.roleStrategy);

}
 
Example 7
Source File: SSLRequestHelper.java    From deprecated-security-ssl with Apache License 2.0 4 votes vote down vote up
private static boolean validate(X509Certificate[] x509Certs, final Settings settings, final Path configPath) {
    
    final boolean validateCrl = settings.getAsBoolean(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_VALIDATE, false);
    
    if(log.isTraceEnabled()) {
        log.trace("validateCrl: "+validateCrl);
    }
    
    if(!validateCrl) {
        return true;
    }
    
    final Environment env = new Environment(settings, configPath);
    
    try {
    
        Collection<? extends CRL> crls = null;
        final String crlFile = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_FILE);

        if(crlFile != null) {
            final File crl = env.configFile().resolve(crlFile).toAbsolutePath().toFile();
            try(FileInputStream crlin = new FileInputStream(crl)) {
                crls = CertificateFactory.getInstance("X.509").generateCRLs(crlin);
            }
            
            if(log.isTraceEnabled()) {
                log.trace("crls from file: "+crls.size());
            }
        } else {
            if(log.isTraceEnabled()) {
                log.trace("no crl file configured");
            }
        }
     
        final String truststore = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_TRUSTSTORE_FILEPATH);
        CertificateValidator validator = null;
        
        if(truststore != null) {
            final String truststoreType = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_TRUSTSTORE_TYPE, "JKS");
            final String truststorePassword = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_TRUSTSTORE_PASSWORD, "changeit");
            //final String truststoreAlias = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_TRUSTSTORE_ALIAS, null);

            final KeyStore ts = KeyStore.getInstance(truststoreType);
            try(FileInputStream fin = new FileInputStream(new File(env.configFile().resolve(truststore).toAbsolutePath().toString()))) {
                ts.load(fin, (truststorePassword == null || truststorePassword.length() == 0) ?null:truststorePassword.toCharArray());
            }
            validator = new CertificateValidator(ts, crls);
        } else {
            final File trustedCas = env.configFile().resolve(settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_PEMTRUSTEDCAS_FILEPATH, "")).toAbsolutePath().toFile();
            try(FileInputStream trin = new FileInputStream(trustedCas)) {
                Collection<? extends Certificate> cert =  (Collection<? extends Certificate>) CertificateFactory.getInstance("X.509").generateCertificates(trin);
                validator = new CertificateValidator(cert.toArray(new X509Certificate[0]), crls);
            }               
        }
        
        validator.setEnableCRLDP(!settings.getAsBoolean(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_DISABLE_CRLDP, false));
        validator.setEnableOCSP(!settings.getAsBoolean(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_DISABLE_OCSP, false));
        validator.setCheckOnlyEndEntities(settings.getAsBoolean(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_CHECK_ONLY_END_ENTITIES, true));
        validator.setPreferCrl(settings.getAsBoolean(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_PREFER_CRLFILE_OVER_OCSP, false));
        Long dateTimestamp = settings.getAsLong(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_CRL_VALIDATION_DATE, null);
        if(dateTimestamp != null && dateTimestamp.longValue() < 0) {
            dateTimestamp = null;
        }
        validator.setDate(dateTimestamp==null?null:new Date(dateTimestamp.longValue()));
        validator.validate(x509Certs);
        
        return true;
        
    } catch (Exception e) {
        if(log.isDebugEnabled()) {
            log.debug("Unable to validate CRL: "+ExceptionsHelper.stackTrace(e));
        }
        log.warn("Unable to validate CRL: "+ExceptionUtils.getRootCause(e));
    }
    
    return false;
}
 
Example 8
Source File: PriorityComparator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private long timeCreated(Settings settings) {
    return settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1l);
}
 
Example 9
Source File: PriorityComparator.java    From crate with Apache License 2.0 4 votes vote down vote up
private long timeCreated(Settings settings) {
    return settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1L);
}