Search in sources :

Example 36 with ConfigurationException

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

the class IndexMetadata method validate.

public void validate(TableMetadata table) {
    if (!isNameValid(name))
        throw new ConfigurationException("Illegal index name " + name);
    if (kind == null)
        throw new ConfigurationException("Index kind is null for index " + name);
    if (kind == Kind.CUSTOM) {
        if (options == null || !options.containsKey(IndexTarget.CUSTOM_INDEX_OPTION_NAME))
            throw new ConfigurationException(String.format("Required option missing for index %s : %s", name, IndexTarget.CUSTOM_INDEX_OPTION_NAME));
        String className = options.get(IndexTarget.CUSTOM_INDEX_OPTION_NAME);
        Class<Index> indexerClass = FBUtilities.classForName(className, "custom indexer");
        if (!Index.class.isAssignableFrom(indexerClass))
            throw new ConfigurationException(String.format("Specified Indexer class (%s) does not implement the Indexer interface", className));
        validateCustomIndexOptions(table, indexerClass, options);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Index(org.apache.cassandra.index.Index)

Example 37 with ConfigurationException

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

the class Indexes method validate.

public void validate(TableMetadata table) {
    /*
         * Index name check is duplicated in Keyspaces, for the time being.
         * The reason for this is that schema altering statements are not calling
         * Keyspaces.validate() as of yet. TODO: remove this once they do (on CASSANDRA-9425 completion)
         */
    Set<String> indexNames = new HashSet<>();
    for (IndexMetadata index : indexesByName.values()) {
        if (indexNames.contains(index.name))
            throw new ConfigurationException(format("Duplicate index name %s for table %s", index.name, table));
        indexNames.add(index.name);
    }
    indexesByName.values().forEach(i -> i.validate(table));
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 38 with ConfigurationException

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

the class SimpleStrategy method validateOptions.

public void validateOptions() throws ConfigurationException {
    String rf = configOptions.get("replication_factor");
    if (rf == null)
        throw new ConfigurationException("SimpleStrategy requires a replication_factor strategy option.");
    validateReplicationFactor(rf);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 39 with ConfigurationException

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

the class CassandraEmbeddedStoreManager method ensureKeyspaceExists.

private void ensureKeyspaceExists(String keyspaceName) throws BackendException {
    if (null != Schema.instance.getKeyspaceInstance(keyspaceName))
        return;
    // Keyspace not found; create it
    String strategyName = storageConfig.get(REPLICATION_STRATEGY);
    KSMetaData ksm;
    try {
        ksm = KSMetaData.newKeyspace(keyspaceName, strategyName, strategyOptions, true);
    } catch (ConfigurationException e) {
        throw new PermanentBackendException("Failed to instantiate keyspace metadata for " + keyspaceName, e);
    }
    try {
        MigrationManager.announceNewKeyspace(ksm);
        log.info("Created keyspace {}", keyspaceName);
    } catch (ConfigurationException e) {
        throw new PermanentBackendException("Failed to create keyspace " + keyspaceName, e);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 40 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)
     */
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);
    }
    if (cmd.getArgs().length != 1) {
        System.err.println("You must supply exactly one sstable");
        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)));
    String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath();
    if (!new File(ssTableFileName).exists()) {
        System.err.println("Cannot find file " + ssTableFileName);
        System.exit(1);
    }
    Descriptor desc = Descriptor.fromFilename(ssTableFileName);
    try {
        TableMetadata metadata = metadataFromSSTable(desc);
        if (cmd.hasOption(ENUMERATE_KEYS_OPTION)) {
            try (KeyIterator iter = new KeyIterator(desc, metadata)) {
                JsonTransformer.keysToJson(null, 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 = 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 {
                JsonTransformer.toJson(currentScanner, partitions, cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
            }
        }
    } catch (IOException e) {
        // throwing exception outside main with broken pipe causes windows cmd to hang
        e.printStackTrace(System.err);
    }
    System.exit(0);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) java.util(java.util) org.apache.commons.cli(org.apache.commons.cli) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) Descriptor(org.apache.cassandra.io.sstable.Descriptor) StreamSupport(java.util.stream.StreamSupport) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) SerializationHeader(org.apache.cassandra.db.SerializationHeader) FBUtilities(org.apache.cassandra.utils.FBUtilities) MetadataType(org.apache.cassandra.io.sstable.metadata.MetadataType) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) IOException(java.io.IOException) org.apache.cassandra.dht(org.apache.cassandra.dht) Collectors(java.util.stream.Collectors) File(java.io.File) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) PartitionPosition(org.apache.cassandra.db.PartitionPosition) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) TableMetadata(org.apache.cassandra.schema.TableMetadata) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) File(java.io.File)

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