Search in sources :

Example 76 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class PercentileSpeculativeRetryPolicy method fromString.

static PercentileSpeculativeRetryPolicy fromString(String str) {
    Matcher matcher = PATTERN.matcher(str);
    if (!matcher.matches())
        throw new IllegalArgumentException();
    String val = matcher.group("val");
    double percentile;
    try {
        percentile = Double.parseDouble(val);
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException(String.format("Invalid value %s for option '%s'", str, TableParams.Option.SPECULATIVE_RETRY));
    }
    if (percentile <= 0.0 || percentile >= 100.0) {
        throw new ConfigurationException(String.format("Invalid value %s for PERCENTILE option '%s': must be between (0.0 and 100.0)", str, TableParams.Option.SPECULATIVE_RETRY));
    }
    return new PercentileSpeculativeRetryPolicy(percentile);
}
Also used : Matcher(java.util.regex.Matcher) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 77 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class AuthConfig method applyAuth.

public static void applyAuth() {
    // some tests need this
    if (initialized)
        return;
    initialized = true;
    Config conf = DatabaseDescriptor.getRawConfig();
    IAuthenticator authenticator = new AllowAllAuthenticator();
    /* Authentication, authorization and role management backend, implementing IAuthenticator, IAuthorizer & IRoleMapper*/
    if (conf.authenticator != null)
        authenticator = FBUtilities.newAuthenticator(conf.authenticator);
    // is in use and non-default values are detected
    if (!(authenticator instanceof PasswordAuthenticator) && (conf.credentials_update_interval.toMillisecondsAsInt() != 0 || conf.credentials_validity.toMillisecondsAsInt() != 2000 || conf.credentials_cache_max_entries != 1000)) {
        logger.info("Configuration options credentials_update_interval, credentials_validity and " + "credentials_cache_max_entries may not be applicable for the configured authenticator ({})", authenticator.getClass().getName());
    }
    DatabaseDescriptor.setAuthenticator(authenticator);
    // authorizer
    IAuthorizer authorizer = new AllowAllAuthorizer();
    if (conf.authorizer != null)
        authorizer = FBUtilities.newAuthorizer(conf.authorizer);
    if (!authenticator.requireAuthentication() && authorizer.requireAuthorization())
        throw new ConfigurationException(conf.authenticator + " can't be used with " + conf.authorizer, false);
    DatabaseDescriptor.setAuthorizer(authorizer);
    // role manager
    IRoleManager roleManager;
    if (conf.role_manager != null)
        roleManager = FBUtilities.newRoleManager(conf.role_manager);
    else
        roleManager = new CassandraRoleManager();
    if (authenticator instanceof PasswordAuthenticator && !(roleManager instanceof CassandraRoleManager))
        throw new ConfigurationException("CassandraRoleManager must be used with PasswordAuthenticator", false);
    DatabaseDescriptor.setRoleManager(roleManager);
    if (conf.internode_authenticator != null)
        DatabaseDescriptor.setInternodeAuthenticator(FBUtilities.construct(conf.internode_authenticator, "internode_authenticator"));
    // network authorizer
    INetworkAuthorizer networkAuthorizer = FBUtilities.newNetworkAuthorizer(conf.network_authorizer);
    DatabaseDescriptor.setNetworkAuthorizer(networkAuthorizer);
    if (networkAuthorizer.requireAuthorization() && !authenticator.requireAuthentication()) {
        throw new ConfigurationException(conf.network_authorizer + " can't be used with " + conf.authenticator, false);
    }
    // Validate at last to have authenticator, authorizer, role-manager and internode-auth setup
    // in case these rely on each other.
    authenticator.validateConfiguration();
    authorizer.validateConfiguration();
    roleManager.validateConfiguration();
    networkAuthorizer.validateConfiguration();
    DatabaseDescriptor.getInternodeAuthenticator().validateConfiguration();
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Config(org.apache.cassandra.config.Config)

Example 78 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class AbstractReplicationStrategy method createInternal.

private static AbstractReplicationStrategy createInternal(String keyspaceName, Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> strategyOptions) throws ConfigurationException {
    AbstractReplicationStrategy strategy;
    Class<?>[] parameterTypes = new Class[] { String.class, TokenMetadata.class, IEndpointSnitch.class, Map.class };
    try {
        Constructor<? extends AbstractReplicationStrategy> constructor = strategyClass.getConstructor(parameterTypes);
        strategy = constructor.newInstance(keyspaceName, tokenMetadata, snitch, strategyOptions);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        throw new ConfigurationException(targetException.getMessage(), targetException);
    } catch (Exception e) {
        throw new ConfigurationException("Error constructing replication strategy class", e);
    }
    return strategy;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 79 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class AlibabaCloudSnitch method alibabaApiCall.

String alibabaApiCall(String url) throws ConfigurationException, IOException, SocketTimeoutException {
    // Populate the region and zone by introspection, fail if 404 on metadata
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    DataInputStream d = null;
    try {
        conn.setConnectTimeout(HTTP_CONNECT_TIMEOUT);
        conn.setRequestMethod("GET");
        int code = conn.getResponseCode();
        if (code != HttpURLConnection.HTTP_OK)
            throw new ConfigurationException("AlibabaSnitch was unable to execute the API call. Not an ecs node? and the returun code is " + code);
        // Read the information. I wish I could say (String) conn.getContent() here...
        int cl = conn.getContentLength();
        byte[] b = new byte[cl];
        d = new DataInputStream((FilterInputStream) conn.getContent());
        d.readFully(b);
        return new String(b, StandardCharsets.UTF_8);
    } catch (SocketTimeoutException e) {
        throw new SocketTimeoutException("Timeout occurred reading a response from the Alibaba ECS metadata");
    } finally {
        FileUtils.close(d);
        conn.disconnect();
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) HttpURLConnection(java.net.HttpURLConnection) SocketTimeoutException(java.net.SocketTimeoutException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) DataInputStream(java.io.DataInputStream) URL(java.net.URL)

Example 80 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class IndexMetadata method validateCustomIndexOptions.

private void validateCustomIndexOptions(TableMetadata table, Class<? extends Index> indexerClass, Map<String, String> options) {
    try {
        Map<String, String> filteredOptions = Maps.filterKeys(options, key -> !key.equals(IndexTarget.CUSTOM_INDEX_OPTION_NAME));
        if (filteredOptions.isEmpty())
            return;
        Map<?, ?> unknownOptions;
        try {
            unknownOptions = (Map) indexerClass.getMethod("validateOptions", Map.class, TableMetadata.class).invoke(null, filteredOptions, table);
        } catch (NoSuchMethodException e) {
            unknownOptions = (Map) indexerClass.getMethod("validateOptions", Map.class).invoke(null, filteredOptions);
        }
        if (!unknownOptions.isEmpty())
            throw new ConfigurationException(String.format("Properties specified %s are not understood by %s", unknownOptions.keySet(), indexerClass.getSimpleName()));
    } catch (NoSuchMethodException e) {
        logger.info("Indexer {} does not have a static validateOptions method. Validation ignored", indexerClass.getName());
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof ConfigurationException)
            throw (ConfigurationException) e.getTargetException();
        throw new ConfigurationException("Failed to validate custom indexer options: " + options);
    } catch (ConfigurationException e) {
        throw e;
    } catch (Exception e) {
        throw new ConfigurationException("Failed to validate custom indexer options: " + options);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ImmutableMap(com.google.common.collect.ImmutableMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnknownIndexException(org.apache.cassandra.exceptions.UnknownIndexException)

Aggregations

ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)84 IOException (java.io.IOException)12 URL (java.net.URL)6 HashMap (java.util.HashMap)6 Keyspace (org.apache.cassandra.db.Keyspace)5 DataInputStream (java.io.DataInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HttpURLConnection (java.net.HttpURLConnection)4 Map (java.util.Map)4 Matcher (java.util.regex.Matcher)4 File (org.apache.cassandra.io.util.File)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashSet (java.util.HashSet)2