use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class MessagingService method getServerSockets.
@SuppressWarnings("resource")
private List<ServerSocket> getServerSockets(InetAddress localEp) throws ConfigurationException {
final List<ServerSocket> ss = new ArrayList<ServerSocket>(2);
if (DatabaseDescriptor.getServerEncryptionOptions().internode_encryption != ServerEncryptionOptions.InternodeEncryption.none) {
try {
ss.add(SSLFactory.getServerSocket(DatabaseDescriptor.getServerEncryptionOptions(), localEp, DatabaseDescriptor.getSSLStoragePort()));
} catch (IOException e) {
throw new ConfigurationException("Unable to create ssl socket", e);
}
// setReuseAddress happens in the factory.
logger.info("Starting Encrypted Messaging Service on SSL port {}", DatabaseDescriptor.getSSLStoragePort());
}
if (DatabaseDescriptor.getServerEncryptionOptions().internode_encryption != ServerEncryptionOptions.InternodeEncryption.all) {
ServerSocketChannel serverChannel = null;
try {
serverChannel = ServerSocketChannel.open();
} catch (IOException e) {
throw new RuntimeException(e);
}
ServerSocket socket = serverChannel.socket();
try {
socket.setReuseAddress(true);
} catch (SocketException e) {
FileUtils.closeQuietly(socket);
throw new ConfigurationException("Insufficient permissions to setReuseAddress", e);
}
InetSocketAddress address = new InetSocketAddress(localEp, DatabaseDescriptor.getStoragePort());
try {
socket.bind(address, 500);
} catch (BindException e) {
FileUtils.closeQuietly(socket);
if (e.getMessage().contains("in use"))
throw new ConfigurationException(address + " is in use by another process. Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services");
else if (e.getMessage().contains("Cannot assign requested address"))
throw new ConfigurationException("Unable to bind to address " + address + ". Set listen_address in cassandra.yaml to an interface you can bind to, e.g., your private IP address on EC2");
else
throw new RuntimeException(e);
} catch (IOException e) {
FileUtils.closeQuietly(socket);
throw new RuntimeException(e);
}
String nic = FBUtilities.getNetworkInterface(localEp);
logger.info("Starting Messaging Service on {}:{}{}", localEp, DatabaseDescriptor.getStoragePort(), nic == null ? "" : String.format(" (%s)", nic));
ss.add(socket);
}
return ss;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class PropertyFileSnitch method reloadConfiguration.
public void reloadConfiguration(boolean isUpdate) throws ConfigurationException {
HashMap<InetAddress, String[]> reloadedMap = new HashMap<>();
String[] reloadedDefaultDCRack = null;
Properties properties = new Properties();
try (InputStream stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME)) {
properties.load(stream);
} catch (Exception e) {
throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if ("default".equals(key)) {
String[] newDefault = value.split(":");
if (newDefault.length < 2)
reloadedDefaultDCRack = new String[] { "default", "default" };
else
reloadedDefaultDCRack = new String[] { newDefault[0].trim(), newDefault[1].trim() };
} else {
InetAddress host;
String hostString = StringUtils.remove(key, '/');
try {
host = InetAddress.getByName(hostString);
} catch (UnknownHostException e) {
throw new ConfigurationException("Unknown host " + hostString, e);
}
String[] token = value.split(":");
if (token.length < 2)
token = new String[] { "default", "default" };
else
token = new String[] { token[0].trim(), token[1].trim() };
reloadedMap.put(host, token);
}
}
InetAddress broadcastAddress = FBUtilities.getBroadcastAddress();
String[] localInfo = reloadedMap.get(broadcastAddress);
if (reloadedDefaultDCRack == null && localInfo == null)
throw new ConfigurationException(String.format("Snitch definitions at %s do not define a location for " + "this node's broadcast address %s, nor does it provides a default", SNITCH_PROPERTIES_FILENAME, broadcastAddress));
// OutboundTcpConnectionPool.getEndpoint() converts our broadcast address to local,
// make sure we can be found at that as well.
InetAddress localAddress = FBUtilities.getLocalAddress();
if (!localAddress.equals(broadcastAddress) && !reloadedMap.containsKey(localAddress))
reloadedMap.put(localAddress, localInfo);
if (isUpdate && !livenessCheck(reloadedMap, reloadedDefaultDCRack))
return;
if (logger.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<InetAddress, String[]> entry : reloadedMap.entrySet()) sb.append(entry.getKey()).append(':').append(Arrays.toString(entry.getValue())).append(", ");
logger.trace("Loaded network topology from property file: {}", StringUtils.removeEnd(sb.toString(), ", "));
}
defaultDCRack = reloadedDefaultDCRack;
endpointMap = reloadedMap;
if (// null check tolerates circular dependency; see CASSANDRA-4145
StorageService.instance != null) {
if (isUpdate)
StorageService.instance.updateTopology();
else
StorageService.instance.getTokenMetadata().invalidateCachedRings();
}
if (gossipStarted)
StorageService.instance.gossipSnitchInfo();
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class CompactionParams method validate.
public void validate() {
try {
Map<?, ?> unknownOptions = (Map) klass.getMethod("validateOptions", Map.class).invoke(null, options);
if (!unknownOptions.isEmpty()) {
throw new ConfigurationException(format("Properties specified %s are not understood by %s", unknownOptions.keySet(), klass.getSimpleName()));
}
} catch (NoSuchMethodException e) {
logger.warn("Compaction strategy {} does not have a static validateOptions method. Validation ignored", klass.getName());
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ConfigurationException)
throw (ConfigurationException) e.getTargetException();
Throwable cause = e.getCause() == null ? e : e.getCause();
throw new ConfigurationException(format("%s.validateOptions() threw an error: %s %s", klass.getName(), cause.getClass().getName(), cause.getMessage()), e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Cannot access method validateOptions in " + klass.getName(), e);
}
String minThreshold = options.get(Option.MIN_THRESHOLD.toString());
if (minThreshold != null && !StringUtils.isNumeric(minThreshold)) {
throw new ConfigurationException(format("Invalid value %s for '%s' compaction sub-option - must be an integer", minThreshold, Option.MIN_THRESHOLD));
}
String maxThreshold = options.get(Option.MAX_THRESHOLD.toString());
if (maxThreshold != null && !StringUtils.isNumeric(maxThreshold)) {
throw new ConfigurationException(format("Invalid value %s for '%s' compaction sub-option - must be an integer", maxThreshold, Option.MAX_THRESHOLD));
}
if (minCompactionThreshold() <= 0 || maxCompactionThreshold() <= 0) {
throw new ConfigurationException("Disabling compaction by setting compaction thresholds to 0 has been removed," + " set the compaction option 'enabled' to false instead.");
}
if (minCompactionThreshold() <= 1) {
throw new ConfigurationException(format("Min compaction threshold cannot be less than 2 (got %d)", minCompactionThreshold()));
}
if (minCompactionThreshold() > maxCompactionThreshold()) {
throw new ConfigurationException(format("Min compaction threshold (got %d) cannot be greater than max compaction threshold (got %d)", minCompactionThreshold(), maxCompactionThreshold()));
}
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class CompressionParams method fromMap.
public static CompressionParams fromMap(Map<String, String> opts) {
Map<String, String> options = copyOptions(opts);
String sstableCompressionClass;
if (!opts.isEmpty() && isEnabled(opts) && !containsSstableCompressionClass(opts))
throw new ConfigurationException(format("Missing sub-option '%s' for the 'compression' option.", CLASS));
if (!removeEnabled(options)) {
sstableCompressionClass = null;
if (!options.isEmpty())
throw new ConfigurationException(format("If the '%s' option is set to false no other options must be specified", ENABLED));
} else {
sstableCompressionClass = removeSstableCompressionClass(options);
}
int chunkLength = removeChunkLength(options);
double minCompressRatio = removeMinCompressRatio(options);
CompressionParams cp = new CompressionParams(sstableCompressionClass, options, chunkLength, minCompressRatio);
cp.validate();
return cp;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class CompressionParams method createCompressor.
private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions) throws ConfigurationException {
if (compressorClass == null) {
if (!compressionOptions.isEmpty())
throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet() + ") since no compression class found");
return null;
}
if (compressionOptions.containsKey(CRC_CHECK_CHANCE)) {
if (!hasLoggedCrcCheckChanceWarning) {
logger.warn(CRC_CHECK_CHANCE_WARNING);
hasLoggedCrcCheckChanceWarning = true;
}
compressionOptions.remove(CRC_CHECK_CHANCE);
}
try {
Method method = compressorClass.getMethod("create", Map.class);
ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions);
// Check for unknown options
for (String provided : compressionOptions.keySet()) if (!compressor.supportedOptions().contains(provided))
throw new ConfigurationException("Unknown compression options " + provided);
return compressor;
} catch (NoSuchMethodException e) {
throw new ConfigurationException("create method not found", e);
} catch (SecurityException e) {
throw new ConfigurationException("Access forbiden", e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ConfigurationException)
throw (ConfigurationException) e.getTargetException();
Throwable cause = e.getCause() == null ? e : e.getCause();
throw new ConfigurationException(format("%s.create() threw an error: %s %s", compressorClass.getSimpleName(), cause.getClass().getName(), cause.getMessage()), e);
} catch (ExceptionInInitializerError e) {
throw new ConfigurationException("Cannot initialize class " + compressorClass.getName());
}
}
Aggregations