Cassandra 3.10创建触发器,类不存在

时间:2017-05-19 16:29:24

标签: cassandra datastax cql datastax-enterprise datastax-startup

我在CentOS 7.3.1611(Core)上安装了Cassandra 3.10和cql 5.0.1的DSE 5.1。

我按照DSE触发器的教程:

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

将我发送给github: https://github.com/apache/cassandra/tree/trunk/examples/triggers

根据教程,我正在使用ANT 1.10.1编译jar。编译后的jar包含代码:

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;
    }
}

编译后的jar,我正在复制到cassandra触发位置(/ etc / cassandra / triggers)。然后我从cql运行命令:

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

并将错误发送给我:

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

我在我的集​​群的所有节点中复制了jar,重新启动了集群并运行了命令:

nodetool reloadtriggers

没有成功,我还在jvm.options中输入命令:

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

在cassandra-env.sh中,我添加了命令:

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

我得到同样的错误。我试着在cassandra lib文件夹中添加jar(/ usr / share / dse / cassandra / lib /),似乎没有加载编译的jar。

当我在cql中运行命令时:

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

我仍然遇到同样的错误

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

所以,我的问题是,我怎样才能让cassandra正确加载我的jar并使用它在cql中创建一个触发器?

0 个答案:

没有答案