Author: jbellis
Date: Wed Oct 6 18:45:33 2010
New Revision: 1005200
URL: http://svn.apache.org/viewvc?rev=1005200&view=rev
Log:
meaningful error message for invalid replication strategy class. patch by
Aaron Morton; reviewed by jbellis for CASSANDRA-1556
Modified:
cassandra/trunk/CHANGES.txt
cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
cassandra/trunk/test/system/test_avro_system.py
cassandra/trunk/test/system/test_thrift_server.py
Modified: cassandra/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1005200&r1=1005199&r2=1005200&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Wed Oct 6 18:45:33 2010
@@ -13,6 +13,8 @@ dev
* take advantage of AVRO-495 to simplify our avro IDL (CASSANDRA-1436)
* extend authorization hierarchy to column family (CASSANDRA-1554)
* deletion support in secondary indexes (CASSANDRA-1571)
+ * meaningful error message for invalid replication strategy class
+ (CASSANDRA-1566)
0.7-beta2
Modified:
cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=1005200&r1=1005199&r2=1005200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Wed
Oct 6 18:45:33 2010
@@ -670,7 +670,7 @@ public class CassandraServer implements
KSMetaData ksmeta = new KSMetaData(
ksDef.name.toString(),
- (Class<? extends
AbstractReplicationStrategy>)Class.forName(ksDef.strategy_class.toString()),
+
FBUtilities.<AbstractReplicationStrategy>classForName(ksDef.strategy_class.toString(),
"keyspace replication strategy"),
strategyOptions,
ksDef.replication_factor,
cfDefs.toArray(new CFMetaData[cfDefs.size()]));
@@ -678,10 +678,6 @@ public class CassandraServer implements
return DatabaseDescriptor.getDefsVersion().toString();
}
- catch (ClassNotFoundException e)
- {
- throw newInvalidRequestException(e);
- }
catch (ConfigurationException e)
{
throw newInvalidRequestException(e);
Modified:
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1005200&r1=1005199&r2=1005200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
Wed Oct 6 18:45:33 2010
@@ -789,19 +789,13 @@ public class CassandraServer implements
}
KSMetaData ksm = new KSMetaData(ks_def.name,
- (Class<? extends
AbstractReplicationStrategy>) Class.forName(ks_def.strategy_class),
+
FBUtilities.<AbstractReplicationStrategy>classForName(ks_def.strategy_class,
"keyspace replication strategy"),
ks_def.strategy_options,
ks_def.replication_factor,
cfDefs.toArray(new
CFMetaData[cfDefs.size()]));
applyMigrationOnStage(new AddKeyspace(ksm));
return DatabaseDescriptor.getDefsVersion().toString();
}
- catch (ClassNotFoundException e)
- {
- InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
catch (ConfigurationException e)
{
InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
@@ -841,7 +835,7 @@ public class CassandraServer implements
public String system_rename_keyspace(String old_name, String new_name)
throws InvalidRequestException, TException
{
- state().hasColumnFamilyListAccess(Permission.WRITE);
+ state().hasKeyspaceListAccess(Permission.WRITE);
try
{
@@ -865,7 +859,7 @@ public class CassandraServer implements
/** update an existing keyspace, but do not allow column family
modifications. */
public String system_update_keyspace(KsDef ks_def) throws
InvalidRequestException, TException
{
- state().hasColumnFamilyListAccess(Permission.WRITE);
+ state().hasKeyspaceListAccess(Permission.WRITE);
if (ks_def.getCf_defs() != null && ks_def.getCf_defs().size() > 0)
throw new InvalidRequestException("Keyspace update must not
contain any column family definitions.");
Modified: cassandra/trunk/test/system/test_avro_system.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_system.py?rev=1005200&r1=1005199&r2=1005200&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_system.py (original)
+++ cassandra/trunk/test/system/test_avro_system.py Wed Oct 6 18:45:33 2010
@@ -42,7 +42,15 @@ class TestSystemOperations(AvroTester):
cfdef['keyspace'] = 'CreateKeyspace'
cfdef['name'] = 'CreateKsCf'
keyspace['cf_defs'] = [cfdef]
-
+
+ #test invalid strategy class
+ keyspace['strategy_class'] = 'InvalidStrategy'
+ avro_utils.assert_raises(AvroRemoteException,
+ self.client.request,
+ 'system_add_keyspace',
+ {'ks_def': keyspace})
+
+ keyspace['strategy_class'] =
'org.apache.cassandra.locator.SimpleStrategy'
s = self.client.request('system_add_keyspace', {'ks_def' : keyspace})
assert isinstance(s, unicode), 'returned type is %s, (not
\'unicode\')' % type(s)
Modified: cassandra/trunk/test/system/test_thrift_server.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_thrift_server.py?rev=1005200&r1=1005199&r2=1005200&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_thrift_server.py (original)
+++ cassandra/trunk/test/system/test_thrift_server.py Wed Oct 6 18:45:33 2010
@@ -1140,7 +1140,24 @@ class TestMutations(ThriftTester):
def invalid_rename():
client.system_rename_keyspace('Keyspace1', 'in-valid')
_expect_exception(invalid_rename, InvalidRequestException)
-
+
+ def test_invalid_strategy_class(self):
+ def add_invalid_keyspace():
+ client.system_add_keyspace(KsDef('ValidKs',
'InvalidStrategyClass', {}, 1, []))
+ exc = _expect_exception(add_invalid_keyspace, InvalidRequestException)
+ s = str(exc)
+ assert s.find("InvalidStrategyClass") > -1, s
+ assert s.find("keyspace replication strategy") > -1, s
+
+ def update_invalid_keyspace():
+ client.system_add_keyspace(KsDef('ValidKsForUpdate',
'org.apache.cassandra.locator.SimpleStrategy', {}, 1, []))
+ client.system_update_keyspace(KsDef('ValidKsForUpdate',
'InvalidStrategyClass', {}, 1, []))
+
+ exc = _expect_exception(update_invalid_keyspace,
InvalidRequestException)
+ s = str(exc)
+ assert s.find("InvalidStrategyClass") > -1, s
+ assert s.find("keyspace replication strategy") > -1, s
+
def test_invalid_cf_names(self):
def invalid_cf():
_set_keyspace('Keyspace1')