use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class LZ4Compressor method validateCompressionLevel.
public static Integer validateCompressionLevel(String compressionLevel) throws ConfigurationException {
if (compressionLevel == null)
return DEFAULT_HIGH_COMPRESSION_LEVEL;
ConfigurationException ex = new ConfigurationException("Invalid value [" + compressionLevel + "] for parameter '" + LZ4_HIGH_COMPRESSION_LEVEL + "'. Value must be between 1 and 17.");
Integer level;
try {
level = Integer.valueOf(compressionLevel);
} catch (NumberFormatException e) {
throw ex;
}
if (level < 1 || level > 17) {
throw ex;
}
return level;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class SSTableExport method main.
/**
* Given arguments specifying an SSTable, and optionally an output file, export the contents of the SSTable to JSON.
*
* @param args
* command lines arguments
* @throws ConfigurationException
* on configuration failure (wrong params given)
*/
@SuppressWarnings("resource")
public static void main(String[] args) throws ConfigurationException {
CommandLineParser parser = new PosixParser();
try {
cmd = parser.parse(options, args);
} catch (ParseException e1) {
System.err.println(e1.getMessage());
printUsage();
System.exit(1);
}
String[] keys = cmd.getOptionValues(KEY_OPTION);
HashSet<String> excludes = new HashSet<>(Arrays.asList(cmd.getOptionValues(EXCLUDE_KEY_OPTION) == null ? new String[0] : cmd.getOptionValues(EXCLUDE_KEY_OPTION)));
if (cmd.getArgs().length != 1) {
String msg = "You must supply exactly one sstable";
if (cmd.getArgs().length == 0 && (keys != null && keys.length > 0 || !excludes.isEmpty()))
msg += ", which should be before the -k/-x options so it's not interpreted as a partition key.";
System.err.println(msg);
printUsage();
System.exit(1);
}
String ssTableFileName = new File(cmd.getArgs()[0]).absolutePath();
if (!new File(ssTableFileName).exists()) {
System.err.println("Cannot find file " + ssTableFileName);
System.exit(1);
}
Descriptor desc = Descriptor.fromFilename(ssTableFileName);
try {
TableMetadata metadata = Util.metadataFromSSTable(desc);
if (cmd.hasOption(ENUMERATE_KEYS_OPTION)) {
try (KeyIterator iter = new KeyIterator(desc, metadata)) {
JsonTransformer.keysToJson(null, Util.iterToStream(iter), cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
}
} else {
SSTableReader sstable = SSTableReader.openNoValidation(desc, TableMetadataRef.forOfflineTools(metadata));
IPartitioner partitioner = sstable.getPartitioner();
final ISSTableScanner currentScanner;
if ((keys != null) && (keys.length > 0)) {
List<AbstractBounds<PartitionPosition>> bounds = Arrays.stream(keys).filter(key -> !excludes.contains(key)).map(metadata.partitionKeyType::fromString).map(partitioner::decorateKey).sorted().map(DecoratedKey::getToken).map(token -> new Bounds<>(token.minKeyBound(), token.maxKeyBound())).collect(Collectors.toList());
currentScanner = sstable.getScanner(bounds.iterator());
} else {
currentScanner = sstable.getScanner();
}
Stream<UnfilteredRowIterator> partitions = Util.iterToStream(currentScanner).filter(i -> excludes.isEmpty() || !excludes.contains(metadata.partitionKeyType.getString(i.partitionKey().getKey())));
if (cmd.hasOption(DEBUG_OUTPUT_OPTION)) {
AtomicLong position = new AtomicLong();
partitions.forEach(partition -> {
position.set(currentScanner.getCurrentPosition());
if (!partition.partitionLevelDeletion().isLive()) {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + partition.partitionLevelDeletion());
}
if (!partition.staticRow().isEmpty()) {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + partition.staticRow().toString(metadata, true));
}
partition.forEachRemaining(row -> {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + row.toString(metadata, false, true));
position.set(currentScanner.getCurrentPosition());
});
});
} else if (cmd.hasOption(PARTITION_JSON_LINES)) {
JsonTransformer.toJsonLines(currentScanner, partitions, cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
} else {
JsonTransformer.toJson(currentScanner, partitions, cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
}
}
} catch (IOException e) {
e.printStackTrace(System.err);
}
System.exit(0);
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class GenerateTokens method main.
public static void main(String[] args) {
Options options = null;
int rf = 0;
int tokens = 0;
int nodes = 0;
IPartitioner partitioner = null;
int[] racksDef = null;
OutputHandler logger = null;
try {
// disable the summary statistics logging, since this is a command-line tool with dedicated output
((Logger) LoggerFactory.getLogger(TokenAllocation.class)).setLevel(Level.ERROR);
Util.initDatabaseDescriptor();
options = getOptions();
CommandLine cmd = parseCommandLine(args, options);
rf = Integer.parseInt(cmd.getOptionValue(RF));
tokens = Integer.parseInt(cmd.getOptionValue(TOKENS));
nodes = Integer.parseInt(cmd.getOptionValue(NODES));
logger = new OutputHandler.SystemOutput(cmd.hasOption(VERBOSE), true, true);
partitioner = FBUtilities.newPartitioner(cmd.getOptionValue(PARTITIONER, Murmur3Partitioner.class.getSimpleName()));
racksDef = getRacks(cmd.getOptionValue(RACKS, cmd.getOptionValue(NODES)));
if (Arrays.stream(racksDef).sum() != nodes) {
throw new AssertionError(String.format("The sum of nodes in each rack %s must equal total node count %s.", cmd.getOptionValue(RACKS), cmd.getOptionValue(NODES)));
}
} catch (NumberFormatException e) {
System.err.println("Invalid integer " + e.getMessage());
System.out.println();
printUsage(options);
System.exit(1);
} catch (AssertionError | ConfigurationException | ParseException t) {
System.err.println(t.getMessage());
System.out.println();
printUsage(options);
System.exit(1);
}
try {
logger.output(String.format("Generating tokens for %d nodes with %d vnodes each for replication factor %d and partitioner %s", nodes, tokens, rf, partitioner.getClass().getSimpleName()));
for (OfflineTokenAllocator.FakeNode node : OfflineTokenAllocator.allocate(rf, tokens, racksDef, logger, partitioner)) logger.output(String.format("Node %d rack %d: %s", node.nodeId(), node.rackId(), node.tokens().toString()));
} catch (Throwable t) {
logger.warn("Error running tool.", t);
System.exit(1);
}
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class YamlConfigurationLoader method loadConfig.
public Config loadConfig(URL url) throws ConfigurationException {
try {
logger.debug("Loading settings from {}", url);
byte[] configBytes;
try (InputStream is = url.openStream()) {
configBytes = ByteStreams.toByteArray(is);
} catch (IOException e) {
// getStorageConfigURL should have ruled this out
throw new AssertionError(e);
}
Constructor constructor = new CustomConstructor(Config.class, Yaml.class.getClassLoader());
Map<Class<?>, Map<String, Replacement>> replacements = getNameReplacements(Config.class);
PropertiesChecker propertiesChecker = new PropertiesChecker(replacements);
constructor.setPropertyUtils(propertiesChecker);
Yaml yaml = new Yaml(constructor);
Config result = loadConfig(yaml, configBytes);
propertiesChecker.check();
return result;
} catch (YAMLException e) {
throw new ConfigurationException("Invalid yaml: " + url, e);
}
}
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);
}
Aggregations