void setEnvironment() throws InvalidRequestException, TException {
   try {
     myCluster = HFactory.getOrCreateCluster("Test Sample", "localhost:9160");
     ksdef = myCluster.describeKeyspace(keyspaceName);
     if (ksdef == null) addKeyspacetoCassandra();
     keyspace = HFactory.createKeyspace("mostkeyspace", myCluster);
   } catch (Exception e) {
     System.out.print("Unalble to setup environment");
     e.printStackTrace();
   }
 }
 public CassandraTransport(String clusterName, String clusterHosts, int maxUsers) {
   this._clusterName = clusterName;
   this._maxUsers = maxUsers;
   this._clusterHosts = clusterHosts;
   // Use a comma separated list of host:port pairs
   this._config = new CassandraHostConfigurator(clusterHosts);
   this._config.setMaxActive(this._maxUsers);
   this._config.setCassandraThriftSocketTimeout(this._socketTimeout);
   this._config.setAutoDiscoverHosts(true);
   this._config.setAutoDiscoveryDelayInSeconds(30);
   this._cluster = HFactory.getOrCreateCluster(this._clusterName, this._config);
 }
  public CassandraTransport(String clusterName, String clusterHost, int clusterPort, int maxUsers) {
    this._clusterName = clusterName;
    // this._clusterHost = clusterHost;
    // this._clusterPort = clusterPort;
    this._maxUsers = maxUsers;

    StringBuffer hostIp = new StringBuffer();
    hostIp.append(clusterHost).append(":").append(clusterPort);
    this._clusterHosts = hostIp.toString();
    this._config = new CassandraHostConfigurator(this._clusterHosts);
    this._config.setMaxActive(this._maxUsers);
    this._config.setCassandraThriftSocketTimeout(this._socketTimeout);
    this._config.setAutoDiscoverHosts(true);
    this._config.setAutoDiscoveryDelayInSeconds(30);

    this._cluster = HFactory.getOrCreateCluster(this._clusterName, this._config);
  }
Beispiel #4
0
  @BeforeClass
  public static void setupKeyspace()
      throws TTransportException, SecurityException, IllegalArgumentException, IOException,
          InterruptedException, NoSuchMethodException, IllegalAccessException,
          InvocationTargetException {
    startCassandraInstance("tmp/var/lib/cassandra");

    ArrayList<CfDef> cfDefList = new ArrayList<CfDef>(2);
    cfDefList.add(
        new CfDef("TestKeyspace", "TestBeanColumnFamily")
            .setComparator_type(BytesType.class.getSimpleName())
            .setKey_cache_size(0)
            .setRow_cache_size(0)
            .setGc_grace_seconds(86400));
    cfDefList.add(
        new CfDef("TestKeyspace", "CustomIdColumnFamily")
            .setComparator_type(BytesType.class.getSimpleName())
            .setKey_cache_size(0)
            .setRow_cache_size(0)
            .setGc_grace_seconds(86400));
    cfDefList.add(
        new CfDef("TestKeyspace", "SimpleTestBeanColumnFamily")
            .setComparator_type(BytesType.class.getSimpleName())
            .setKey_cache_size(0)
            .setRow_cache_size(0)
            .setGc_grace_seconds(86400));
    cfDefList.add(
        new CfDef("TestKeyspace", "NoAnonymousColumnFamily")
            .setComparator_type(BytesType.class.getSimpleName())
            .setKey_cache_size(0)
            .setRow_cache_size(0)
            .setGc_grace_seconds(86400));
    cfDefList.add(
        new CfDef("TestKeyspace", "ComplexColumnFamily")
            .setComparator_type(BytesType.class.getSimpleName())
            .setKey_cache_size(0)
            .setRow_cache_size(0)
            .setGc_grace_seconds(86400));
    cluster = HFactory.getOrCreateCluster("TestPool", "localhost:9161");
    createKeyspace(
        cluster, "TestKeyspace", "org.apache.cassandra.locator.SimpleStrategy", 1, cfDefList);
    keyspace = HFactory.createKeyspace("TestKeyspace", cluster);
  }
Beispiel #5
0
 public static void main(String[] args) {
   boolean drop = false;
   BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(20);
   ExecutorService executorService =
       new ThreadPoolExecutor(4, 4, 1, TimeUnit.HOURS, workQueue, new CallerRunsPolicy());
   if (args.length > 0 && args[0].equalsIgnoreCase("drop")) drop = true;
   Cluster myCluster = HFactory.getOrCreateCluster("Test Cluster", "localhost:9160");
   Keyspace createKeyspace = getKeySpace(myCluster, drop);
   long start = System.currentTimeMillis();
   for (int i = 0; i < 100000; i++) {
     executorService.execute(new CustomerAdd(createKeyspace, String.format("%1$026d", i)));
     if (i % 1000 == 0) System.out.println("customer " + i);
   }
   executorService.shutdown();
   try {
     executorService.awaitTermination(3, TimeUnit.MINUTES);
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   System.out.println(String.format("completed in %1$d", System.currentTimeMillis() - start));
   HFactory.shutdownCluster(myCluster);
 }
Beispiel #6
0
  static {
    if (configuration.getDataStore().equals(DataStore.CASSANDRA)) {
      // TODO make a CassandraFacade class that encapsulates all the cassandra stuff
      dataCluster = HFactory.getOrCreateCluster("data-cluster", tuskCassConf.getCluster());
      LOG.debug("Hector dataCluster=" + dataCluster);

      // This is the keyspace to use for the data we are storing
      KeyspaceDefinition keyspaceDef = dataCluster.describeKeyspace(tuskCassConf.getKeyspace());
      LOG.debug("Hector keyspaceDef=" + keyspaceDef);

      ksp = HFactory.createKeyspace(tuskCassConf.getKeyspace(), dataCluster);
      LOG.debug("Hector keyspace=" + ksp);

      cfTemplate =
          new ThriftColumnFamilyTemplate<String, String>(
              ksp, tuskCassConf.getColumnFamily(), StringSerializer.get(), StringSerializer.get());
      LOG.debug("Hector cfTemplate=" + cfTemplate);
    } else if (configuration.getDataStore().equals(DataStore.HBASE)) {
      // init is in ctor
    }

    //		System.setProperty("java.net.preferIPv4Stack", "true");
    //		ispnService = new InfinispanService();
  }
 /**
  * Creates an object to manipulate the operations on the UserFiles SuperColumn Family
  *
  * @param clusterName The cluster name from instance of Cassandra
  * @param keyspaceName The Keyspace name where the UserFiles SuperColumn Family was created
  */
 public UserFilesDaoOperations(String clusterName, String keyspaceName) {
   cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
   keyspaceOperator = HFactory.createKeyspace(keyspaceName, cluster);
 }
 @Override
 public void prepare(Map stormConf, TopologyContext context) {
   this.boltName = context.getThisComponentId();
   cluster = HFactory.getOrCreateCluster(cluster_name, cluster_host);
   keyspace = HFactory.createKeyspace(keyspace_name, cluster);
 }
Beispiel #9
0
 public StorageAccess(String keyPrefix) {
   this.keyPrefix = "/" + keyPrefix;
   cluster =
       HFactory.getOrCreateCluster(clusterName, new CassandraHostConfigurator(hostPortPairs));
 }