Search in sources :

Example 1 with InvalidRequestException

use of org.apache.cassandra.thrift.InvalidRequestException 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 2 with InvalidRequestException

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

the class CFMetaData method fromThrift.

public static CFMetaData fromThrift(org.apache.cassandra.thrift.CfDef cf_def) throws InvalidRequestException, ConfigurationException {
    ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
    if (cfType == null) {
        throw new InvalidRequestException("Invalid column type " + cf_def.column_type);
    }
    applyImplicitDefaults(cf_def);
    CFMetaData newCFMD = new CFMetaData(cf_def.keyspace, cf_def.name, cfType, TypeParser.parse(cf_def.comparator_type), cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type), cf_def.isSetId() ? cf_def.id : Schema.instance.nextCFId());
    if (cf_def.isSetGc_grace_seconds()) {
        newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds);
    }
    if (cf_def.isSetMin_compaction_threshold()) {
        newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold);
    }
    if (cf_def.isSetMax_compaction_threshold()) {
        newCFMD.maxCompactionThreshold(cf_def.max_compaction_threshold);
    }
    if (cf_def.isSetMerge_shards_chance()) {
        newCFMD.mergeShardsChance(cf_def.merge_shards_chance);
    }
    if (cf_def.isSetKey_alias()) {
        newCFMD.keyAlias(cf_def.key_alias);
    }
    if (cf_def.isSetKey_validation_class()) {
        newCFMD.keyValidator(TypeParser.parse(cf_def.key_validation_class));
    }
    if (cf_def.isSetCompaction_strategy())
        newCFMD.compactionStrategyClass = createCompactionStrategy(cf_def.compaction_strategy);
    if (cf_def.isSetCompaction_strategy_options())
        newCFMD.compactionStrategyOptions(new HashMap<String, String>(cf_def.compaction_strategy_options));
    if (cf_def.isSetBloom_filter_fp_chance())
        newCFMD.bloomFilterFpChance(cf_def.bloom_filter_fp_chance);
    if (cf_def.isSetCaching())
        newCFMD.caching(Caching.fromString(cf_def.caching));
    CompressionParameters cp = CompressionParameters.create(cf_def.compression_options);
    return newCFMD.comment(cf_def.comment).readRepairChance(cf_def.read_repair_chance).replicateOnWrite(cf_def.replicate_on_write).defaultValidator(TypeParser.parse(cf_def.default_validation_class)).keyValidator(TypeParser.parse(cf_def.key_validation_class)).columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata)).compressionParameters(cp).validate();
}
Also used : CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 3 with InvalidRequestException

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

the class CFPropDefs method getPropertyDouble.

// Return a property value, typed as a Double
public Double getPropertyDouble(String key, Double defaultValue) throws InvalidRequestException {
    Double result;
    String value = properties.get(key);
    if (value == null)
        result = defaultValue;
    else {
        try {
            result = Double.parseDouble(value);
        } catch (NumberFormatException e) {
            throw new InvalidRequestException(String.format("%s not valid for \"%s\"", value, key));
        }
    }
    return result;
}
Also used : InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 4 with InvalidRequestException

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

the class CFPropDefs method getPropertyInt.

// Return a property value, typed as an Integer
public Integer getPropertyInt(String key, Integer defaultValue) throws InvalidRequestException {
    Integer result;
    String value = properties.get(key);
    if (value == null)
        result = defaultValue;
    else {
        try {
            result = Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new InvalidRequestException(String.format("%s not valid for \"%s\"", value, key));
        }
    }
    return result;
}
Also used : InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 5 with InvalidRequestException

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

the class UpdateStatement method prepareRowMutations.

/**
 * {@inheritDoc}
 */
@Override
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<String> variables) throws InvalidRequestException {
    List<String> cfamsSeen = new ArrayList<String>();
    boolean hasCommutativeOperation = false;
    for (Map.Entry<Term, Operation> column : getColumns().entrySet()) {
        if (!column.getValue().isUnary())
            hasCommutativeOperation = true;
        if (hasCommutativeOperation && column.getValue().isUnary())
            throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");
    }
    CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation);
    if (hasCommutativeOperation)
        validateCommutativeForWrite(metadata, cLevel);
    QueryProcessor.validateKeyAlias(metadata, keyName);
    // Avoid unnecessary authorizations.
    if (!(cfamsSeen.contains(columnFamily))) {
        clientState.hasColumnFamilyAccess(columnFamily, Permission.WRITE);
        cfamsSeen.add(columnFamily);
    }
    List<IMutation> rowMutations = new LinkedList<IMutation>();
    for (Term key : keys) {
        if (timestamp != 0) {
            logger.warn("Supplied timestamp: " + timestamp + " ignored, server generating timestamp");
        }
        long opTimestamp = LamportClock.getVersion();
        rowMutations.add(mutationForKey(keyspace, key.getByteBuffer(getKeyType(keyspace), variables), metadata, opTimestamp, clientState, variables));
    }
    return rowMutations;
}
Also used : IMutation(org.apache.cassandra.db.IMutation) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) CFMetaData(org.apache.cassandra.config.CFMetaData)

Aggregations

InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)20 Cassandra (org.apache.cassandra.thrift.Cassandra)6 TException (org.apache.thrift.TException)6 ByteBuffer (java.nio.ByteBuffer)5 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)4 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)4 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)4 HashMap (java.util.HashMap)4 ConfigurationException (org.apache.cassandra.config.ConfigurationException)4 Map (java.util.Map)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 KsDef (org.apache.cassandra.thrift.KsDef)3 NotFoundException (org.apache.cassandra.thrift.NotFoundException)3 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)3 IOException (java.io.IOException)2 CfDef (org.apache.cassandra.db.migration.avro.CfDef)2 CfDef (org.apache.cassandra.thrift.CfDef)2 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 ByteBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry)1