Search in sources :

Example 66 with ConfigurationException

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;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 67 with ConfigurationException

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);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) Arrays(java.util.Arrays) File(org.apache.cassandra.io.util.File) Options(org.apache.commons.cli.Options) HelpFormatter(org.apache.commons.cli.HelpFormatter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) HashSet(java.util.HashSet) KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) AbstractBounds(org.apache.cassandra.dht.AbstractBounds) Descriptor(org.apache.cassandra.io.sstable.Descriptor) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Option(org.apache.commons.cli.Option) FBUtilities(org.apache.cassandra.utils.FBUtilities) CommandLineParser(org.apache.commons.cli.CommandLineParser) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) IOException(java.io.IOException) Bounds(org.apache.cassandra.dht.Bounds) Collectors(java.util.stream.Collectors) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) PartitionPosition(org.apache.cassandra.db.PartitionPosition) IPartitioner(org.apache.cassandra.dht.IPartitioner) ParseException(org.apache.commons.cli.ParseException) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) TableMetadata(org.apache.cassandra.schema.TableMetadata) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) PosixParser(org.apache.commons.cli.PosixParser) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) CommandLineParser(org.apache.commons.cli.CommandLineParser) HashSet(java.util.HashSet) IPartitioner(org.apache.cassandra.dht.IPartitioner) TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey) AbstractBounds(org.apache.cassandra.dht.AbstractBounds) Bounds(org.apache.cassandra.dht.Bounds) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractBounds(org.apache.cassandra.dht.AbstractBounds) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) ParseException(org.apache.commons.cli.ParseException) File(org.apache.cassandra.io.util.File)

Example 68 with ConfigurationException

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);
    }
}
Also used : Options(org.apache.commons.cli.Options) TokenAllocation(org.apache.cassandra.dht.tokenallocator.TokenAllocation) OfflineTokenAllocator(org.apache.cassandra.dht.tokenallocator.OfflineTokenAllocator) Logger(ch.qos.logback.classic.Logger) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) CommandLine(org.apache.commons.cli.CommandLine) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ParseException(org.apache.commons.cli.ParseException) OutputHandler(org.apache.cassandra.utils.OutputHandler) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 69 with ConfigurationException

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CustomClassLoaderConstructor(org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 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) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IOException(java.io.IOException)

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