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;
}
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.");
}
}
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);
}
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;
}
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());
}
}
Aggregations