Search in sources :

Example 1 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project brisk by riptano.

the class CassandraStorage method getDefaultMarshallers.

private List<AbstractType> getDefaultMarshallers(CfDef cfDef) throws IOException {
    ArrayList<AbstractType> marshallers = new ArrayList<AbstractType>();
    AbstractType comparator = null;
    AbstractType default_validator = null;
    try {
        comparator = TypeParser.parse(cfDef.comparator_type);
        default_validator = TypeParser.parse(cfDef.default_validation_class);
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    marshallers.add(comparator);
    marshallers.add(default_validator);
    return marshallers;
}
Also used : ConfigurationException(org.apache.cassandra.config.ConfigurationException) AbstractType(org.apache.cassandra.db.marshal.AbstractType) IOException(java.io.IOException)

Example 2 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class SecondaryIndex method createInstance.

/**
 * This is the primary way to create a secondary index instance for a CF column.
 * It will validate the index_options before initializing.
 *
 * @param baseCfs the source of data for the Index
 * @param cdef the meta information about this column (index_type, index_options, name, etc...)
 *
 * @return The secondary index instance for this column
 * @throws ConfigurationException
 */
public static SecondaryIndex createInstance(ColumnFamilyStore baseCfs, ColumnDefinition cdef) throws ConfigurationException {
    SecondaryIndex index;
    switch(cdef.getIndexType()) {
        case KEYS:
            index = new KeysIndex();
            break;
        case CUSTOM:
            assert cdef.getIndexOptions() != null;
            String class_name = cdef.getIndexOptions().get(CUSTOM_INDEX_OPTION_NAME);
            assert class_name != null;
            try {
                index = (SecondaryIndex) Class.forName(class_name).newInstance();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        default:
            throw new RuntimeException("Unknown index type: " + cdef.getIndexName());
    }
    index.addColumnDef(cdef);
    index.validateOptions();
    index.setBaseCfs(baseCfs);
    return index;
}
Also used : KeysIndex(org.apache.cassandra.db.index.keys.KeysIndex) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.config.ConfigurationException)

Example 3 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class CliTest method testCli.

@Test
public void testCli() throws IOException, TException, ConfigurationException, ClassNotFoundException, TimedOutException, NotFoundException, SchemaDisagreementException, NoSuchFieldException, InvalidRequestException, UnavailableException, InstantiationException, IllegalAccessException {
    new EmbeddedCassandraService().start();
    // new error/output streams for CliSessionState
    ByteArrayOutputStream errStream = new ByteArrayOutputStream();
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    // checking if we can connect to the running cassandra node on localhost
    CliMain.connect("127.0.0.1", 9170);
    // setting new output stream
    CliMain.sessionState.setOut(new PrintStream(outStream));
    CliMain.sessionState.setErr(new PrintStream(errStream));
    // re-creating keyspace for tests
    try {
        // dropping in case it exists e.g. could be left from previous run
        CliMain.processStatement("drop keyspace TestKeySpace;");
    } catch (Exception e) {
    // TODO check before drop so we don't have this fragile ignored exception block
    }
    CliMain.processStatement("create keyspace TestKeySpace;");
    for (String statement : statements) {
        errStream.reset();
        // System.out.println("Executing statement: " + statement);
        CliMain.processStatement(statement);
        String result = outStream.toString();
        // System.out.println("Result:\n" + result);
        assertEquals(errStream.toString() + " processing " + statement, "", errStream.toString());
        if (statement.startsWith("drop ") || statement.startsWith("create ") || statement.startsWith("update ")) {
            assert Pattern.compile("(.{8})-(.{4})-(.{4})-(.{4})-(.{12}).*", Pattern.DOTALL).matcher(result).matches() : String.format("\"%s\" failed: %s", statement, result);
        } else if (statement.startsWith("set ")) {
            assertTrue(result.contains("Value inserted."));
            assertTrue(result.contains("Elapsed time:"));
        } else if (statement.startsWith("incr ")) {
            assertTrue(result.contains("Value incremented."));
        } else if (statement.startsWith("decr ")) {
            assertTrue(result.contains("Value decremented."));
        } else if (statement.startsWith("get ")) {
            if (statement.contains("where")) {
                assertTrue(result.startsWith("-------------------" + System.getProperty("line.separator") + "RowKey:"));
            } else if (statement.contains("Counter")) {
                assertTrue(result.startsWith("=> (counter=") || result.startsWith("Value was not found"));
            } else {
                assertTrue(result.startsWith("=> (column=") || result.startsWith("Value was not found"));
            }
            assertTrue(result.contains("Elapsed time:"));
        } else if (statement.startsWith("truncate ")) {
            assertTrue(result.contains(" truncated."));
        } else if (statement.startsWith("assume ")) {
            assertTrue(result.contains("successfully."));
        }
        // reset stream so we have only output from next statement all the time
        outStream.reset();
        // no errors to the end user.
        errStream.reset();
    }
}
Also used : PrintStream(java.io.PrintStream) EmbeddedCassandraService(org.apache.cassandra.service.EmbeddedCassandraService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) Test(org.junit.Test)

Example 4 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class CreateColumnFamilyStatement method getCFMetaData.

/**
 * Returns a CFMetaData instance based on the parameters parsed from this
 * <code>CREATE</code> statement, or defaults where applicable.
 *
 * @param keyspace keyspace to apply this column family to
 * @return a CFMetaData instance corresponding to the values parsed from this statement
 * @throws InvalidRequestException on failure to validate parsed parameters
 */
public CFMetaData getCFMetaData(String keyspace, List<String> variables) throws InvalidRequestException {
    validate(variables);
    CFMetaData newCFMD;
    try {
        AbstractType<?> comparator = cfProps.getComparator();
        newCFMD = new CFMetaData(keyspace, name, ColumnFamilyType.Standard, comparator, null);
        newCFMD.comment(cfProps.getProperty(CFPropDefs.KW_COMMENT)).readRepairChance(getPropertyDouble(CFPropDefs.KW_READREPAIRCHANCE, CFMetaData.DEFAULT_READ_REPAIR_CHANCE)).replicateOnWrite(getPropertyBoolean(CFPropDefs.KW_REPLICATEONWRITE, CFMetaData.DEFAULT_REPLICATE_ON_WRITE)).gcGraceSeconds(getPropertyInt(CFPropDefs.KW_GCGRACESECONDS, CFMetaData.DEFAULT_GC_GRACE_SECONDS)).defaultValidator(cfProps.getValidator()).minCompactionThreshold(getPropertyInt(CFPropDefs.KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD)).maxCompactionThreshold(getPropertyInt(CFPropDefs.KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD)).mergeShardsChance(0.0).columnMetadata(getColumns(comparator)).keyValidator(TypeParser.parse(CFPropDefs.comparators.get(getKeyType()))).keyAlias(keyAlias).compactionStrategyOptions(cfProps.compactionStrategyOptions).compressionParameters(CompressionParameters.create(cfProps.compressionParameters)).validate();
    } catch (ConfigurationException e) {
        throw new InvalidRequestException(e.toString());
    }
    return newCFMD;
}
Also used : ConfigurationException(org.apache.cassandra.config.ConfigurationException) CFMetaData(org.apache.cassandra.config.CFMetaData) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 5 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class DefinitionsUpdateVerbHandler method doVerb.

/**
 * someone sent me their data definitions
 */
public void doVerb(final Message message, String id) {
    try {
        // these are the serialized row mutations that I must apply.
        // check versions at every step along the way to make sure migrations are not applied out of order.
        Collection<Column> cols = MigrationManager.makeColumns(message);
        for (Column col : cols) {
            final UUID version = UUIDGen.getUUID(col.name());
            if (version.timestamp() > Schema.instance.getVersion().timestamp()) {
                final Migration m = Migration.deserialize(col.value(), message.getVersion());
                assert m.getVersion().equals(version);
                StageManager.getStage(Stage.MIGRATION).submit(new WrappedRunnable() {

                    protected void runMayThrow() throws Exception {
                        // check to make sure the current version is before this one.
                        if (Schema.instance.getVersion().timestamp() == version.timestamp())
                            logger.debug("Not appling (equal) " + version.toString());
                        else if (Schema.instance.getVersion().timestamp() > version.timestamp())
                            logger.debug("Not applying (before)" + version.toString());
                        else {
                            logger.debug("Applying {} from {}", m.getClass().getSimpleName(), message.getFrom());
                            try {
                                m.apply();
                                // update gossip, but don't contact nodes directly
                                m.passiveAnnounce();
                            } catch (ConfigurationException ex) {
                                // Trying to apply the same migration twice. This happens as a result of gossip.
                                logger.debug("Migration not applied " + ex.getMessage());
                            }
                        }
                    }
                });
            }
        }
    } catch (IOException ex) {
        throw new IOError(ex);
    }
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ConfigurationException(org.apache.cassandra.config.ConfigurationException) IOError(java.io.IOError) Migration(org.apache.cassandra.db.migration.Migration) IOException(java.io.IOException) UUID(java.util.UUID) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.config.ConfigurationException)

Aggregations

ConfigurationException (org.apache.cassandra.config.ConfigurationException)26 IOException (java.io.IOException)10 ByteBuffer (java.nio.ByteBuffer)6 HashMap (java.util.HashMap)4 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)4 Map (java.util.Map)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 AbstractType (org.apache.cassandra.db.marshal.AbstractType)3 File (java.io.File)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 Migration (org.apache.cassandra.db.migration.Migration)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 IOError (java.io.IOError)1 InputStream (java.io.InputStream)1