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);
}
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();
}
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;
}
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();
}
}
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);
}
}
Aggregations