Search in sources :

Example 11 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.

the class CreateColumnFamilyStatement method getColumns.

// Column definitions
private Map<ByteBuffer, ColumnDefinition> getColumns(AbstractType<?> comparator) throws InvalidRequestException {
    Map<ByteBuffer, ColumnDefinition> columnDefs = new HashMap<ByteBuffer, ColumnDefinition>();
    for (Map.Entry<Term, String> col : columns.entrySet()) {
        try {
            ByteBuffer columnName = comparator.fromString(col.getKey().getText());
            String validatorClassName = CFPropDefs.comparators.containsKey(col.getValue()) ? CFPropDefs.comparators.get(col.getValue()) : col.getValue();
            AbstractType<?> validator = TypeParser.parse(validatorClassName);
            columnDefs.put(columnName, new ColumnDefinition(columnName, validator, null, null, null));
        } catch (ConfigurationException e) {
            InvalidRequestException ex = new InvalidRequestException(e.toString());
            ex.initCause(e);
            throw ex;
        }
    }
    return columnDefs;
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) ByteBuffer(java.nio.ByteBuffer) HashMap(java.util.HashMap) Map(java.util.Map) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 12 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.

the class CreateColumnFamilyStatement method validate.

/** Perform validation of parsed params */
private void validate(List<String> variables) throws InvalidRequestException {
    cfProps.validate();
    // Column family name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));
    if (name.length() > 32)
        throw new InvalidRequestException(String.format("Column family names shouldn't be more than 32 character long (got \"%s\")", name));
    // Ensure that exactly one key has been specified.
    if (keyValidator.size() < 1)
        throw new InvalidRequestException("You must specify a PRIMARY KEY");
    else if (keyValidator.size() > 1)
        throw new InvalidRequestException("You may only specify one PRIMARY KEY");
    AbstractType<?> comparator;
    try {
        comparator = cfProps.getComparator();
    } catch (ConfigurationException e) {
        throw new InvalidRequestException(e.toString());
    }
    for (Map.Entry<Term, String> column : columns.entrySet()) {
        ByteBuffer name = column.getKey().getByteBuffer(comparator, variables);
        if (keyAlias != null && keyAlias.equals(name))
            throw new InvalidRequestException("Invalid column name: " + column.getKey().getText() + ", because it equals to the key_alias.");
    }
}
Also used : ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) HashMap(java.util.HashMap) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 13 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.

the class DropIndexStatement method generateMutation.

public UpdateColumnFamily generateMutation(String keyspace) throws InvalidRequestException, ConfigurationException, IOException {
    CfDef cfDef = null;
    KSMetaData ksm = Schema.instance.getTableDefinition(keyspace);
    for (CFMetaData cfm : ksm.cfMetaData().values()) {
        cfDef = getUpdatedCFDef(cfm.toAvro());
        if (cfDef != null)
            break;
    }
    if (cfDef == null)
        throw new InvalidRequestException("Index '" + index + "' could not be found in any of the ColumnFamilies of keyspace '" + keyspace + "'");
    return new UpdateColumnFamily(cfDef);
}
Also used : UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) CfDef(org.apache.cassandra.db.migration.avro.CfDef)

Example 14 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.

the class UpdateStatement method mutationForKey.

/**
     * Compute a row mutation for a single key
     *
     *
     * @param keyspace working keyspace
     * @param key key to change
     * @param metadata information about CF
     * @param timestamp global timestamp to use for every key mutation
     *
     * @param clientState
     * @return row mutation
     *
     * @throws InvalidRequestException on the wrong request
     */
private IMutation mutationForKey(String keyspace, ByteBuffer key, CFMetaData metadata, Long timestamp, ClientState clientState, List<String> variables) throws InvalidRequestException {
    AbstractType<?> comparator = getComparator(keyspace);
    // if true we need to wrap RowMutation into CounterMutation
    boolean hasCounterColumn = false;
    RowMutation rm = new RowMutation(keyspace, key);
    for (Map.Entry<Term, Operation> column : getColumns().entrySet()) {
        ByteBuffer colName = column.getKey().getByteBuffer(comparator, variables);
        Operation op = column.getValue();
        if (op.isUnary()) {
            if (hasCounterColumn)
                throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");
            ByteBuffer colValue = op.a.getByteBuffer(getValueValidator(keyspace, colName), variables);
            validateColumn(metadata, colName, colValue);
            rm.add(new QueryPath(columnFamily, null, colName), colValue, (timestamp == null) ? getTimestamp(clientState) : timestamp, getTimeToLive());
        } else {
            hasCounterColumn = true;
            if (!column.getKey().getText().equals(op.a.getText()))
                throw new InvalidRequestException("Only expressions like X = X + <long> are supported.");
            long value;
            try {
                value = Long.parseLong(op.b.getText());
            } catch (NumberFormatException e) {
                throw new InvalidRequestException(String.format("'%s' is an invalid value, should be a long.", op.b.getText()));
            }
            rm.addCounter(new QueryPath(columnFamily, null, colName), value, timestamp, timestamp, null);
        }
    }
    return (hasCounterColumn) ? new CounterMutation(rm, getConsistencyLevel()) : rm;
}
Also used : ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) CounterMutation(org.apache.cassandra.db.CounterMutation) RowMutation(org.apache.cassandra.db.RowMutation) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 15 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.

the class RingCache method refreshEndpointMap.

public void refreshEndpointMap() {
    try {
        Cassandra.Client client = ConfigHelper.getClientFromOutputAddressList(conf);
        List<TokenRange> ring = client.describe_ring(ConfigHelper.getOutputKeyspace(conf));
        rangeMap = ArrayListMultimap.create();
        for (TokenRange range : ring) {
            Token<?> left = partitioner.getTokenFactory().fromString(range.start_token);
            Token<?> right = partitioner.getTokenFactory().fromString(range.end_token);
            Range<Token> r = new Range<Token>(left, right, partitioner);
            for (String host : range.endpoints) {
                try {
                    rangeMap.put(r, InetAddress.getByName(host));
                } catch (UnknownHostException e) {
                    // host strings are IPs
                    throw new AssertionError(e);
                }
            }
        }
    } catch (InvalidRequestException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (TException e) {
        logger_.debug("Error contacting seed list" + ConfigHelper.getOutputInitialAddress(conf) + " " + e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) UnknownHostException(java.net.UnknownHostException) Cassandra(org.apache.cassandra.thrift.Cassandra) Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) TokenRange(org.apache.cassandra.thrift.TokenRange) TokenRange(org.apache.cassandra.thrift.TokenRange) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Aggregations

InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)16 ByteBuffer (java.nio.ByteBuffer)4 ConfigurationException (org.apache.cassandra.config.ConfigurationException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IOException (java.io.IOException)2 CfDef (org.apache.cassandra.db.migration.avro.CfDef)2 Cassandra (org.apache.cassandra.thrift.Cassandra)2 TException (org.apache.thrift.TException)2 UnknownHostException (java.net.UnknownHostException)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 HashSet (java.util.HashSet)1 Utf8 (org.apache.avro.util.Utf8)1 Permission (org.apache.cassandra.auth.Permission)1 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 CounterMutation (org.apache.cassandra.db.CounterMutation)1 IMutation (org.apache.cassandra.db.IMutation)1 RowMutation (org.apache.cassandra.db.RowMutation)1 QueryPath (org.apache.cassandra.db.filter.QueryPath)1