Example usage for org.apache.cassandra.service CassandraDaemon CassandraDaemon

List of usage examples for org.apache.cassandra.service CassandraDaemon CassandraDaemon

Introduction

In this page you can find the example usage for org.apache.cassandra.service CassandraDaemon CassandraDaemon.

Prototype

public CassandraDaemon() 

Source Link

Usage

From source file:com.facebook.presto.cassandra.EmbeddedCassandra.java

License:Apache License

public static synchronized void start() throws Exception {
    if (initialized) {
        return;/*  www  .  j a  v  a 2  s.c om*/
    }

    log.info("Starting cassandra...");

    System.setProperty("cassandra.config", "file:" + prepareCassandraYaml());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false");

    CassandraDaemon cassandraDaemon = new CassandraDaemon();
    cassandraDaemon.activate();

    Cluster.Builder clusterBuilder = Cluster.builder().withProtocolVersion(V3).withClusterName("TestCluster")
            .addContactPointsWithPorts(ImmutableList.of(new InetSocketAddress(HOST, PORT)))
            .withMaxSchemaAgreementWaitSeconds(30);

    ReopeningCluster cluster = new ReopeningCluster(clusterBuilder::build);
    CassandraSession session = new NativeCassandraSession("EmbeddedCassandra",
            JsonCodec.listJsonCodec(ExtraColumnMetadata.class), cluster, new Duration(1, MINUTES));

    try {
        checkConnectivity(session);
    } catch (RuntimeException e) {
        cluster.close();
        cassandraDaemon.deactivate();
        throw e;
    }

    EmbeddedCassandra.session = session;
    initialized = true;
}

From source file:com.github.pmerienne.trident.state.cassandra.embedded.CassandraEmbeddedServerStarter.java

License:Apache License

public void start(final CassandraConfig config) {

    if (isAlreadyRunning()) {
        log.info("Cassandra is already running, not starting new one");
        return;//w  ww  . j  a  va 2s .c o  m
    }

    log.info("Starting Cassandra...");
    config.write();
    System.setProperty("cassandra.config", "file:" + config.getConfigFile().getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");

    final CountDownLatch startupLatch = new CountDownLatch(1);
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                CassandraDaemon cassandraDaemon = new CassandraDaemon();
                cassandraDaemon.init(null);
                cassandraDaemon.start();
                startupLatch.countDown();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            // cassandraDaemon.activate();
        }
    });

    try {
        startupLatch.await(30, SECONDS);
    } catch (InterruptedException e) {
        log.error("Timeout starting Cassandra embedded", e);
        throw new IllegalStateException("Timeout starting Cassandra embedded", e);
    }
}

From source file:com.googlecode.cassandra.jca.suite.DeploymentTestSuite.java

License:Open Source License

@BeforeClass
public static void beforeClass() throws Exception {
    System.out.println("public static void beforeClass()");
    cassandraDaemon = new CassandraDaemon();
    cassandraDaemon.init(null);//from  www  . j  ava  2s .  co m
    cassandraDaemon.start();
}

From source file:com.meteogroup.cassandra.embedded.EmbeddedCassandraLoader.java

License:Open Source License

public static void setupCassandra() throws Exception {
    System.setProperty("cassandra.config.loader", EmbeddedConfigurationLoader.class.getCanonicalName());
    cassandraDaemon = new CassandraDaemon();
    cassandraDaemon.init(null);/*from   www.j  a  va 2s  . c om*/
    cassandraDaemon.start();

    cassandraHost = DatabaseDescriptor.getRpcAddress().getHostName();
    cassandraNativePort = DatabaseDescriptor.getNativeTransportPort();
}

From source file:com.netflix.astyanax.test.EmbeddedCassandra.java

License:Apache License

public EmbeddedCassandra(File dataDir, String clusterName, int port, int storagePort) throws IOException {
    LOG.info("Starting cassandra in dir " + dataDir);
    this.dataDir = dataDir;
    dataDir.mkdirs();// w  ww.j  av a 2s  . com

    InputStream is = null;

    try {
        URL templateUrl = EmbeddedCassandra.class.getClassLoader().getResource("cassandra-template.yaml");
        Preconditions.checkNotNull(templateUrl, "Cassandra config template is null");
        String baseFile = Resources.toString(templateUrl, Charset.defaultCharset());

        String newFile = baseFile.replace("$DIR$", dataDir.getPath());
        newFile = newFile.replace("$PORT$", Integer.toString(port));
        newFile = newFile.replace("$STORAGE_PORT$", Integer.toString(storagePort));
        newFile = newFile.replace("$CLUSTER$", clusterName);

        File configFile = new File(dataDir, "cassandra.yaml");
        Files.write(newFile, configFile, Charset.defaultCharset());

        LOG.info("Cassandra config file: " + configFile.getPath());
        System.setProperty("cassandra.config", "file:" + configFile.getPath());

        try {
            cassandra = new CassandraDaemon();
            cassandra.init(null);
        } catch (IOException e) {
            LOG.error("Error initializing embedded cassandra", e);
            throw e;
        }
    } finally {
        Closeables.closeQuietly(is);
    }
    LOG.info("Started cassandra deamon");
}

From source file:com.spotify.cassandra.extra.EmbeddedCassandra.java

License:Apache License

/**
 * Create a new {@link com.spotify.cassandra.extra.EmbeddedCassandra} instance.
 *
 * This will allocate a temporary directory for data storage and pick random free ports.
 * Note that you need to {@link com.spotify.cassandra.extra.EmbeddedCassandra#start} the created
 * instance first before it becomes accessible.
 * @return a new EmbeddedCassandra instance.
 * @throws IOException if the instance can't be created.
 *///from  w w w  .  j  a  v a  2  s. c  om
public static EmbeddedCassandra create() throws IOException {
    final Path dataDir = Files.createTempDirectory("cassandra-embedded");
    final int thriftPort = findFreePort();
    final int storagePort = findFreePort();
    final int nativeTransportPort = findFreePort();
    final CassandraDaemon cassandra = new CassandraDaemon();
    return new EmbeddedCassandra(dataDir, thriftPort, storagePort, nativeTransportPort, cassandra);
}

From source file:ei.ne.ke.cassandra.EmbeddedCassandra.java

License:Apache License

/**
 * Constructor.//from  w ww.  j  av  a 2s  . c o m
 */
private EmbeddedCassandra() {
    if (!running) {
        running = true;
        cassandraService = new CassandraDaemon();
        cassandraService.activate();
    }
}

From source file:eu.redzoo.article.planetcassandra.reactive.EmbeddedCassandra.java

License:Apache License

public static void start() throws IOException {
    if (nativePort == 0) {
        nativePort = prepare();/*from ww w .  j  a  v a 2 s.  c om*/

        cassandraDaemon = new CassandraDaemon();
        cassandraDaemon.activate();

        long maxWaiting = System.currentTimeMillis() + 10000;

        while (System.currentTimeMillis() < maxWaiting) {
            if (cassandraDaemon.nativeServer.isRunning()) {
                return;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        }
        throw new RuntimeException("Embedded cassandra does not start at expected time!");
    }
}

From source file:grakn.core.server.GraknStorage.java

License:Open Source License

public static void main(String[] args) {
    try {/*from   ww w. ja  v  a2  s.  co m*/
        CassandraDaemon instance = new CassandraDaemon();
        instance.activate();
        persistPID();
    } catch (Exception e) {
        LOG.error("Cassandra Exception:", e);
        System.err.println(e.getMessage());
    }
}

From source file:info.archinnov.achilles.embedded.ServerStarter.java

License:Apache License

private void start(final CassandraConfig config) {

    if (isAlreadyRunning()) {
        log.debug("Cassandra is already running, not starting new one");
        return;//from   www  . j a  v  a 2s .  c o m
    }

    final String triggersDir = createTriggersFolder();

    log.info(" Random embedded Cassandra RPC port/Thrift port = {}", config.getRPCPort());
    log.info(" Random embedded Cassandra Native port/CQL3 port = {}", config.getCqlPort());
    log.info(" Random embedded Cassandra Storage port = {}", config.getStoragePort());
    log.info(" Random embedded Cassandra Storage SSL port = {}", config.getStorageSSLPort());
    log.info(" Embedded Cassandra triggers directory = {}", triggersDir);

    log.info("Starting Cassandra...");
    config.write();

    System.setProperty("cassandra.triggers_dir", triggersDir);
    System.setProperty("cassandra.config", "file:" + config.getConfigFile().getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");

    final CountDownLatch startupLatch = new CountDownLatch(1);
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            CassandraDaemon cassandraDaemon = new CassandraDaemon();
            cassandraDaemon.activate();
            startupLatch.countDown();
        }
    });

    try {
        startupLatch.await(30, SECONDS);
    } catch (InterruptedException e) {
        log.error("Timeout starting Cassandra embedded", e);
        throw new IllegalStateException("Timeout starting Cassandra embedded", e);
    }
}