Search in sources :

Example 21 with KeyspaceMetadata

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) TriggerMetadata(org.apache.cassandra.schema.TriggerMetadata) Test(org.junit.Test)

Example 22 with KeyspaceMetadata

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) TriggerMetadata(org.apache.cassandra.schema.TriggerMetadata) Test(org.junit.Test)

Example 23 with KeyspaceMetadata

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);
}
Also used : KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) UserType(org.apache.cassandra.db.marshal.UserType)

Example 24 with KeyspaceMetadata

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);
    }
}
Also used : KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata)

Example 25 with KeyspaceMetadata

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());
}
Also used : KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata)

Aggregations

KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)30 Test (org.junit.Test)17 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)12 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)11 Range (org.apache.cassandra.dht.Range)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 InetAddress (java.net.InetAddress)6 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)6 Token (org.apache.cassandra.dht.Token)6 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)4 HashMap (java.util.HashMap)3 UserType (org.apache.cassandra.db.marshal.UserType)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)3 TriggerMetadata (org.apache.cassandra.schema.TriggerMetadata)3 JavaBasedUDFunction (org.apache.cassandra.cql3.functions.JavaBasedUDFunction)1 UDAggregate (org.apache.cassandra.cql3.functions.UDAggregate)1 UDFunction (org.apache.cassandra.cql3.functions.UDFunction)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)1