use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.
the class TriggersSchemaTest method newKsContainsCfWithTrigger.
@Test
public void newKsContainsCfWithTrigger() throws Exception {
TriggerMetadata td = TriggerMetadata.create(triggerName, triggerClass);
TableMetadata tm = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).triggers(Triggers.of(td)).build();
KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1), Tables.of(tm));
MigrationManager.announceNewKeyspace(ksm);
TableMetadata tm2 = Schema.instance.getTableMetadata(ksName, cfName);
assertFalse(tm2.triggers.isEmpty());
assertEquals(1, tm2.triggers.size());
assertEquals(td, tm2.triggers.get(triggerName).get());
}
use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.
the class TriggersSchemaTest method addTriggerToCf.
@Test
public void addTriggerToCf() throws Exception {
TableMetadata tm1 = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).build();
KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1), Tables.of(tm1));
MigrationManager.announceNewKeyspace(ksm);
TriggerMetadata td = TriggerMetadata.create(triggerName, triggerClass);
TableMetadata tm2 = Schema.instance.getTableMetadata(ksName, cfName).unbuild().triggers(Triggers.of(td)).build();
MigrationManager.announceTableUpdate(tm2);
TableMetadata tm3 = Schema.instance.getTableMetadata(ksName, cfName);
assertFalse(tm3.triggers.isEmpty());
assertEquals(1, tm3.triggers.size());
assertEquals(td, tm3.triggers.get(triggerName).get());
}
use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.
the class StressCQLSSTableWriter method getUDType.
/**
* Returns the User Defined type, used in this SSTable Writer, that can
* be used to create UDTValue instances.
*
* @param dataType name of the User Defined type
* @return user defined type
*/
public com.datastax.driver.core.UserType getUDType(String dataType) {
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(insert.keyspace());
UserType userType = ksm.types.getNullable(ByteBufferUtil.bytes(dataType));
return (com.datastax.driver.core.UserType) UDHelper.driverType(userType);
}
use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.
the class AlterKeyspaceStatement method validate.
public void validate(ClientState state) throws RequestValidationException {
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(name);
if (ksm == null)
throw new InvalidRequestException("Unknown keyspace " + name);
if (SchemaConstants.isSystemKeyspace(ksm.name))
throw new InvalidRequestException("Cannot alter system keyspace");
attrs.validate();
if (attrs.getReplicationStrategyClass() == null && !attrs.getReplicationOptions().isEmpty())
throw new ConfigurationException("Missing replication strategy class");
if (attrs.getReplicationStrategyClass() != null) {
// The strategy is validated through KSMetaData.validate() in announceKeyspaceUpdate below.
// However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
// so doing proper validation here.
KeyspaceParams params = attrs.asAlteredKeyspaceParams(ksm.params);
params.validate(name);
if (params.replication.klass.equals(LocalStrategy.class))
throw new ConfigurationException("Unable to use given strategy class: LocalStrategy is reserved for internal use.");
warnIfIncreasingRF(ksm, params);
}
}
use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.
the class AlterKeyspaceStatement method announceMigration.
public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException {
KeyspaceMetadata oldKsm = Schema.instance.getKeyspaceMetadata(name);
// In the (very) unlikely case the keyspace was dropped since validate()
if (oldKsm == null)
throw new InvalidRequestException("Unknown keyspace " + name);
KeyspaceMetadata newKsm = oldKsm.withSwapped(attrs.asAlteredKeyspaceParams(oldKsm.params));
MigrationManager.announceKeyspaceUpdate(newKsm, isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.UPDATED, keyspace());
}
Aggregations