List of usage examples for org.apache.cassandra.service CassandraDaemon CassandraDaemon
public CassandraDaemon(boolean runManaged)
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraService.java
License:Open Source License
public static synchronized void start() throws IOException { File tempDir;// w ww. j a va2 s. c om try { tempDir = Files.createTempDirectory("cassandra").toFile(); } catch (IOException e) { throw new RuntimeException("Cannot create data directory."); } tempDir.deleteOnExit(); System.setProperty("cassandra.config", new File(CASSANDRA_CONFIG).toURI().toString()); System.setProperty("cassandra.storagedir", tempDir.getPath()); daemon = new CassandraDaemon(true); daemon.init(null); daemon.start(); }
From source file:org.apache.ignite.cache.store.cassandra.bean.CassandraLifeCycleBean.java
License:Apache License
/** * Starts embedded Cassandra instance//from w w w . j av a 2s . co m */ private void startEmbeddedCassandra() { if (log != null) { log.info("-------------------------------"); log.info("| Starting embedded Cassandra |"); log.info("-------------------------------"); } try { if (jmxPort != null) System.setProperty(CASSANDRA_JMX_PORT_PROP, jmxPort); if (cassandraCfgFile != null) System.setProperty(CASSANDRA_CONFIG_PROP, FILE_PREFIX + cassandraCfgFile); embeddedCassandraDaemon = new CassandraDaemon(true); embeddedCassandraDaemon.init(null); embeddedCassandraDaemon.start(); } catch (Exception e) { throw new RuntimeException("Failed to start embedded Cassandra", e); } if (log != null) { log.info("------------------------------"); log.info("| Embedded Cassandra started |"); log.info("------------------------------"); } }
From source file:org.apache.jena.cassandra.CassandraSetup.java
License:Apache License
/** * Set up the daemon or detect that it is already running. * //from w ww . j a va 2 s . c o m * @throws IOException * @throws InterruptedException */ private void setupCassandraDaemon() throws IOException, InterruptedException { if (cassandraDaemon != null) { String portStr[] = System.getProperty("CassandraSetup_Ports").split(","); storagePort = Integer.valueOf(portStr[0]); sslStoragePort = Integer.valueOf(portStr[1]); nativePort = Integer.valueOf(portStr[2]); tempDir = new File(System.getProperty("CassandraSetup_Dir")); LOG.info(String.format("Cassandra dir: %s storage:%s ssl:%s native:%s", tempDir, storagePort, sslStoragePort, nativePort)); LOG.info("Cassandra already running."); } else { tempDir = Files.createTempDir(); File storage = new File(tempDir, "storage"); storage.mkdir(); System.setProperty("cassandra.storagedir", tempDir.toString()); File yaml = new File(tempDir, "cassandra.yaml"); URL url = CassandraSetup.class.getClassLoader().getResource("cassandraTest.yaml"); FileOutputStream yamlOut = new FileOutputStream(yaml); IOUtils.copy(url.openStream(), yamlOut); int[] ports = findFreePorts(3); storagePort = ports[0]; yamlOut.write(String.format(YAML_FMT, "storage_port", storagePort).getBytes()); sslStoragePort = ports[1]; yamlOut.write(String.format(YAML_FMT, "ssl_storage_port", sslStoragePort).getBytes()); nativePort = ports[2]; yamlOut.write(String.format(YAML_FMT, "native_transport_port", sslStoragePort).getBytes()); yamlOut.flush(); yamlOut.close(); System.setProperty("cassandra.config", yaml.toURI().toString()); System.setProperty("CassandraSetup_Ports", String.format("%s,%s,%s", storagePort, sslStoragePort, nativePort)); System.setProperty("CassandraSetup_Dir", tempDir.toString()); System.setProperty("cassandra-foreground", "true"); LOG.info(String.format("Cassandra dir: %s storage:%s ssl:%s native:%s", tempDir, storagePort, sslStoragePort, nativePort)); CountDownLatch latch = new CountDownLatch(1); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { cassandraDaemon = new CassandraDaemon(true); cassandraDaemon.activate(); latch.countDown(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { cassandraDaemon.deactivate(); if (tempDir != null) { FileUtils.deleteRecursive(tempDir); } LOG.warn("Cassandra stopped"); } })); } }); LOG.info("Waiting for Cassandra to start"); latch.await(); LOG.info("Cassandra started"); } }
From source file:org.hawkular.alerts.engine.cassandra.EmbeddedCassandra.java
License:Apache License
public static synchronized void start() { if (cassandraDaemon == null) { try {/* w w w.j a va 2 s. com*/ ConfigEditor editor = new ConfigEditor(); editor.initEmbeddedConfiguration(); cassandraDaemon = new CassandraDaemon(true); cassandraDaemon.activate(); } catch (Exception e) { logger.error("Error initializing embbeded Cassandra server", e); } } }
From source file:org.hawkular.commons.cassandra.EmbeddedCassandraService.java
License:Apache License
public void start(@Observes @Initialized(ApplicationScoped.class) Object ignore) { synchronized (lock) { String backend = System.getProperty(HAWKULAR_BACKEND_PROPERTY); String tmp = System.getenv(HAWKULAR_BACKEND_ENV_NAME); if (tmp != null) { backend = tmp;/*from w ww. jav a 2 s . com*/ logger.debug("== Using backend setting from environment: " + tmp); } if (cassandraDaemon == null && EMBEDDED_CASSANDRA_OPTION.equals(backend)) { try { File baseDir = new File(System.getProperty(JBOSS_DATA_DIR, "./"), HAWKULAR_DATA); File confDir = new File(baseDir, "conf"); File yamlFile = new File(confDir, CASSANDRA_YAML); if (yamlFile.exists()) { System.setProperty(CASSANDRA_CONFIG, yamlFile.toURI().toURL().toString()); } else { /* Create the file using defaults from CASSANDRA_YAML in the current jar */ URL defaultCassandraYamlUrl = getClass().getResource("/" + CASSANDRA_YAML); CassandraYaml.builder().load(defaultCassandraYamlUrl)// .baseDir(baseDir)// .clusterName(HAWKULAR_DATA)// .store(yamlFile)// .mkdirs()// .setCassandraConfigProp().setTriggersDirProp(); } cassandraDaemon = new CassandraDaemon(true); cassandraDaemon.activate(); } catch (Exception e) { logger.error("Error initializing embedded Cassandra server", e); } } else { logger.info("== Embedded Cassandra not started as selected backend was " + backend + " =="); } } }
From source file:org.hawkular.inventory.impl.tinkerpop.provider.TitanTest.java
License:Apache License
@BeforeClass public static void startCassandra() throws Exception { URL cassandraConfigFile = TitanTest.class.getResource("/cassandra-config.yaml"); System.setProperty("cassandra.config", cassandraConfigFile.toString()); CASSANDRA_DAEMON = new CassandraDaemon(true); CASSANDRA_DAEMON.activate();// w w w .j a v a2 s . c om INVENTORY = new TinkerpopInventory(); setupNewInventory(INVENTORY); setupData(INVENTORY); }
From source file:org.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(true); cassandraDaemon.activate();//w ww . j a va 2s. c o m cassandraDaemon.start(); cassandraHost = DatabaseDescriptor.getRpcAddress().getHostName(); cassandraRpcPort = DatabaseDescriptor.getRpcPort(); cassandraNativePort = DatabaseDescriptor.getNativeTransportPort(); cassandraNativeSSLPort = DatabaseDescriptor.getNativeTransportPort(); cassandraStoragePort = DatabaseDescriptor.getStoragePort(); cassandraStorageSSLPort = DatabaseDescriptor.getSSLStoragePort(); }
From source file:org.wildfly.extension.cassandra.CassandraService.java
License:Apache License
@Override public void start(StartContext context) throws StartException { try {//from w w w . j a v a 2s.co m CassandraLogger.LOGGER.infof("Starting embedded cassandra service '%s'", clusterName); // resolve the path location // includes the _clusterName_ suffix to avid conflicts when different configurations are started on the same base system if (null == serviceConfig.data_file_directories) serviceConfig.data_file_directories = new String[] { resolve(pathManager.getValue(), CASSANDRA_DATA_FILE_DIR, ServerEnvironment.SERVER_DATA_DIR) + "/" + clusterName }; if (null == serviceConfig.saved_caches_directory) serviceConfig.saved_caches_directory = resolve(pathManager.getValue(), CASSANDRA_SAVED_CACHES_DIR, ServerEnvironment.SERVER_DATA_DIR) + "/" + clusterName; if (null == serviceConfig.commitlog_directory) serviceConfig.commitlog_directory = resolve(pathManager.getValue(), CASSANDRA_COMMIT_LOG_DIR, ServerEnvironment.SERVER_DATA_DIR) + "/" + clusterName; // static injection needed due to the way C* initialises it's ConfigLoader DMRConfigLoader.CASSANDRA_CONFIG = serviceConfig; System.setProperty("cassandra.config.loader", DMRConfigLoader.class.getName()); cassandraDaemon = new CassandraDaemon(true); cassandraDaemon.activate(); } catch (Throwable e) { context.failed(new StartException(e)); } }