Search in sources :

Example 41 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_in_ms != -1 || conf.credentials_validity_in_ms != 2000 || conf.credentials_cache_max_entries != 1000)) {
        logger.info("Configuration options credentials_update_interval_in_ms, credentials_validity_in_ms 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);
    // authenticator
    IInternodeAuthenticator internodeAuthenticator;
    if (conf.internode_authenticator != null)
        internodeAuthenticator = FBUtilities.construct(conf.internode_authenticator, "internode_authenticator");
    else
        internodeAuthenticator = new AllowAllInternodeAuthenticator();
    DatabaseDescriptor.setInternodeAuthenticator(internodeAuthenticator);
    // 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();
    internodeAuthenticator.validateConfiguration();
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Config(org.apache.cassandra.config.Config)

Example 42 with ConfigurationException

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

the class BootStrapper method getSpecifiedTokens.

private static Collection<Token> getSpecifiedTokens(final TokenMetadata metadata, Collection<String> initialTokens) {
    logger.info("tokens manually specified as {}", initialTokens);
    List<Token> tokens = new ArrayList<>(initialTokens.size());
    for (String tokenString : initialTokens) {
        Token token = metadata.partitioner.getTokenFactory().fromString(tokenString);
        if (metadata.getEndpoint(token) != null)
            throw new ConfigurationException("Bootstrapping to existing token " + tokenString + " is not allowed (decommission/removenode the old node first).");
        tokens.add(token);
    }
    return tokens;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 43 with ConfigurationException

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

the class CompressionParams method removeSstableCompressionClass.

/**
     * Removes the option specifying the name of the compression class
     *
     * @param options the options
     * @return the name of the compression class
     */
private static String removeSstableCompressionClass(Map<String, String> options) {
    if (options.containsKey(CLASS)) {
        if (options.containsKey(SSTABLE_COMPRESSION))
            throw new ConfigurationException(format("The '%s' option must not be used if the compression algorithm is already specified by the '%s' option", SSTABLE_COMPRESSION, CLASS));
        String clazz = options.remove(CLASS);
        if (clazz.isEmpty())
            throw new ConfigurationException(format("The '%s' option must not be empty. To disable compression use 'enabled' : false", CLASS));
        return clazz;
    }
    if (options.containsKey(SSTABLE_COMPRESSION) && !hasLoggedSsTableCompressionWarning) {
        hasLoggedSsTableCompressionWarning = true;
        logger.warn("The {} option has been deprecated. You should use {} instead", SSTABLE_COMPRESSION, CLASS);
    }
    return options.remove(SSTABLE_COMPRESSION);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 44 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)

Example 45 with ConfigurationException

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

the class DatabaseDescriptor method applySeedProvider.

public static void applySeedProvider() {
    // load the seeds for node contact points
    if (conf.seed_provider == null) {
        throw new ConfigurationException("seeds configuration is missing; a minimum of one seed is required.", false);
    }
    try {
        Class<?> seedProviderClass = Class.forName(conf.seed_provider.class_name);
        seedProvider = (SeedProvider) seedProviderClass.getConstructor(Map.class).newInstance(conf.seed_provider.parameters);
    }// there are about 5 checked exceptions that could be thrown here.
     catch (Exception e) {
        throw new ConfigurationException(e.getMessage() + "\nFatal configuration error; unable to start server.  See log for stacktrace.", true);
    }
    if (seedProvider.getSeeds().size() == 0)
        throw new ConfigurationException("The seed provider lists no seeds.", false);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) NoSuchFileException(java.nio.file.NoSuchFileException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IOException(java.io.IOException)

Aggregations

ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)61 IOException (java.io.IOException)11 URL (java.net.URL)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DataInputStream (java.io.DataInputStream)3 File (java.io.File)3 HttpURLConnection (java.net.HttpURLConnection)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 HashMap (java.util.HashMap)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FilterInputStream (java.io.FilterInputStream)2 InputStream (java.io.InputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 Map (java.util.Map)2 CFMetaData (org.apache.cassandra.config.CFMetaData)2 KSMetaData (org.apache.cassandra.config.KSMetaData)2 StartupException (org.apache.cassandra.exceptions.StartupException)2 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2