Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与Jenkins一起创建Cassandra数据库_Jenkins_Cassandra_Ddl - Fatal编程技术网

与Jenkins一起创建Cassandra数据库

与Jenkins一起创建Cassandra数据库,jenkins,cassandra,ddl,Jenkins,Cassandra,Ddl,有人知道如何通过Jenkins运行DDL脚本来创建Cassandra数据库吗?我试图在测试环境中通过Jenkins连接到Cassandra,以便上传测试基线数据集并对其运行集成测试 将DDL语句粘贴到@org.junit.Before带注释的方法中,并可能在@org.junit.Before之后清理(假设您使用的是junit),怎么样 IMHO测试应该是完全独立的(如果可能的话)-需要事先运行一些手动步骤不是一个好的做法(模式更改、您在新机器上或其他人需要第一次运行测试…)我创建了自己的解决方案

有人知道如何通过Jenkins运行DDL脚本来创建Cassandra数据库吗?我试图在测试环境中通过Jenkins连接到Cassandra,以便上传测试基线数据集并对其运行集成测试

将DDL语句粘贴到
@org.junit.Before
带注释的方法中,并可能在
@org.junit.Before
之后清理(假设您使用的是junit),怎么样


IMHO测试应该是完全独立的(如果可能的话)-需要事先运行一些手动步骤不是一个好的做法(模式更改、您在新机器上或其他人需要第一次运行测试…)

我创建了自己的解决方案来解决类似的问题。不仅用于测试,还用于随着时间的推移对模式进行更改时按顺序应用脚本。它将在詹金斯或任何地方起作用。有一个类可以按顺序旋转脚本列表,将每个脚本作为输入流打开。然后该类调用该类上的execute()方法:

package org.makeyourcase.persistence;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.SyntaxError;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class CqlFileRunner {

    private static final Logger LOG = Logger.getLogger(CqlFileRunner.class);

    @Value("${cassandra.node}")
    private String node;

    @Value("${cassandra.keyspace}")
    private String keyspace;

    @Autowired
    private CassandraClusterBuilderMaker cassandraClusterBuilderMaker;

    public void execute(InputStream commandStream) throws IOException {
        byte[] commandBuffer = new byte[commandStream.available()];
        IOUtils.readFully(commandStream, commandBuffer);

        Cluster cluster = cassandraClusterBuilderMaker.create().addContactPoint(node).build();
        Session session = cluster.connect(keyspace);

        List<String> commands = Arrays.asList(new String(commandBuffer, "UTF-8").split(";"));
        for(String command : commands){
            if(!command.trim().isEmpty()){
                command = command.trim() + ";";
                LOG.info("Execute:\n" + command);
                try {
                    session.execute(command);
                } catch (SyntaxError e) {
                    LOG.error("Command failed with " + e.getMessage());
                    throw e;
                }
            }
        }

    }
}
编辑:

从这篇原始文章开始,我提取了我在项目中使用的Java版本控制组件。我还创建了一个小样本项目,展示了如何集成它。这是赤裸裸的。有不同的方法解决这个问题,所以我选择了一个简单的方法来构建,并做我需要的事情。以下是两个github项目:

CREATE TABLE access_tiers (
    level bigint PRIMARY KEY,
    role text
);
ALTER TABLE access_tiers WITH caching = 'all' AND compression = {'sstable_compression' : ''};

INSERT INTO access_tiers (level, role) VALUES (200, 'user_tier2');
INSERT INTO access_tiers (level, role) VALUES (1000, 'user_tier3');
INSERT INTO access_tiers (level, role) VALUES (5000, 'user_tier4');
INSERT INTO access_tiers (level, role) VALUES (10000, 'user_tier5');
INSERT INTO access_tiers (level, role) VALUES (20000, 'user_tier6');
INSERT INTO access_tiers (level, role) VALUES (50000, 'moderator');