Cassandra 3.10 Create Trigger, class doesn't exist

1.2k Views Asked by At

I have DSE 5.1 with Cassandra 3.10 and cql 5.0.1 installed on CentOS 7.3.1611 (Core).

I'm following the tutorial from DSE Triggers:

http://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cql_commands/cqlCreateTrigger.html?hl=trigger

Which send me to github: https://github.com/apache/cassandra/tree/trunk/examples/triggers

According to the tutorial, I am compiling the jar with ANT 1.10.1. The compiled jar contain the code:

package org.apache.cassandra.triggers;

import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;

import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.schema.Schema;
import org.apache.cassandra.db.Mutation;
import org.apache.cassandra.db.partitions.Partition;
import org.apache.cassandra.db.partitions.PartitionUpdate;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.UUIDGen;

public class AuditTrigger implements ITrigger
{
    private Properties properties = loadProperties();

    public Collection<Mutation> augment(Partition update)
    {
        String auditKeyspace = properties.getProperty("keyspace");
        String auditTable = properties.getProperty("table");

        TableMetadata metadata = Schema.instance.getTableMetadata(auditKeyspace, auditTable);
        PartitionUpdate.SimpleBuilder audit = PartitionUpdate.simpleBuilder(metadata, UUIDGen.getTimeUUID());

        audit.row()
             .add("keyspace_name", update.metadata().keyspace)
             .add("table_name", update.metadata().table)
             .add("primary_key", update.metadata().partitionKeyType.getString(update.partitionKey().getKey()));

        return Collections.singletonList(audit.buildAsMutation());
    }

    private static Properties loadProperties()
    {
        Properties properties = new Properties();
        InputStream stream = AuditTrigger.class.getClassLoader().getResourceAsStream("AuditTrigger.properties");
        try
        {
            properties.load(stream);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        finally
        {
            FileUtils.closeQuietly(stream);
        }
        return properties;
    }
}

The compiled jar, I am copying to the cassandra triggers location (/etc/cassandra/triggers). Then I run from cql the command:

CREATE TRIGGER test1 ON test.test USING 'org.apache.cassandra.triggers.AuditTrigger';

And send me the error:

ConfigurationException: Trigger class 'org.apache.cassandra.triggers.AuditTrigger' doesn't exist

I copied the jar in all the nodes of my cluster, restarted the cluster and ran the command:

nodetool reloadtriggers

With no success, I also put in the jvm.options the command:

-Dcassandra.triggers_dir=/etc/dse/cassandra/triggers

And in the cassandra-env.sh, I added the command:

JVM_OPTS="$JVM_OPTS -Dcassandra.triggers_dir=/etc/dse/cassandra/triggers"

And I am getting the same error. I tryied adding the jar in the cassandra lib folder (/usr/share/dse/cassandra/lib/) and it seems to not been loading the compiled jar.

When I run the command in cql:

 CREATE TRIGGER test1 ON test.test USING 'org.apache.cassandra.triggers.AuditTrigger';

I am still getting the same error

ConfigurationException: Trigger class 'org.apache.cassandra.triggers.AuditTrigger' doesn't exist

So, my question is, How can I make cassandra load my jar correctly and use it to create a trigger in cql?

0

There are 0 best solutions below