Examples of KeyspaceDefinition


Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

  private void testIfTheEmbeddedCassandraServerIsUpOnHost(String hostAndPort) {
        Random random = new Random();
    Cluster cluster = HFactory.getOrCreateCluster("TestCluster" + random.nextInt(), new CassandraHostConfigurator(hostAndPort));
    assertThat(cluster.getConnectionManager().getActivePools().size(), is(1));
    KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace("system");
    assertThat(keyspaceDefinition, notNullValue());
    assertThat(keyspaceDefinition.getReplicationFactor(), is(1));
  }
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

   * when the Keyspace is created. Currently consistency level is .ONE which
   * permits consistency to wait until one replica has responded.
   */
  public void checkKeyspace() {
    // "describe keyspace <keyspaceName>;" query
    KeyspaceDefinition keyspaceDefinition = this.cluster.describeKeyspace(this.cassandraMapping.getKeyspaceName());
    if (keyspaceDefinition == null) {
      List<ColumnFamilyDefinition> columnFamilyDefinitions = this.cassandraMapping.getColumnFamilyDefinitions();     
      keyspaceDefinition = HFactory.createKeyspaceDefinition(this.cassandraMapping.getKeyspaceName(), "org.apache.cassandra.locator.SimpleStrategy", 1, columnFamilyDefinitions);     
      this.cluster.addKeyspace(keyspaceDefinition, true);
      LOG.info("Keyspace '" + this.cassandraMapping.getKeyspaceName() + "' in cluster '" + this.cassandraMapping.getClusterName() + "' was created on host '" + this.cassandraMapping.getHostName() + "'");
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

        assertNotNull(keyspace);

        String keyspaceName = "Presto_Database";
        String columnFamilyName = "Presto_Test";
        List<ColumnFamilyDefinition> columnFamilyDefinitions = createColumnFamilyDefinitions(keyspaceName, columnFamilyName);
        KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(
                keyspaceName,
                StrategyModel.SIMPLE_STRATEGY.value(),
                1,
                columnFamilyDefinitions);
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

        assertNotNull(keyspace);

        String keyspaceName = "Presto_Database";
        String columnFamilyName = "Presto_Test";
        List<ColumnFamilyDefinition> columnFamilyDefinitions = createColumnFamilyDefinitions(keyspaceName, columnFamilyName);
        KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(
                keyspaceName,
                StrategyModel.SIMPLE_STRATEGY.value(),
                1,
                columnFamilyDefinitions);
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

  /**
   * Check if keyspace already exists.
   */
  public boolean keyspaceExists() {
    KeyspaceDefinition keyspaceDefinition = this.cluster.describeKeyspace(this.cassandraMapping.getKeyspaceName());
    return (keyspaceDefinition != null);
  }
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

   * when the Keyspace is created. Currently consistency level is .ONE which
   * permits consistency to wait until one replica has responded.
   */
  public void checkKeyspace() {
    // "describe keyspace <keyspaceName>;" query
    KeyspaceDefinition keyspaceDefinition = this.cluster.describeKeyspace(this.cassandraMapping.getKeyspaceName());
    if (keyspaceDefinition == null) {
      List<ColumnFamilyDefinition> columnFamilyDefinitions = this.cassandraMapping.getColumnFamilyDefinitions();

      // GORA-197
      for (ColumnFamilyDefinition cfDef : columnFamilyDefinitions) {
        cfDef.setComparatorType(ComparatorType.BYTESTYPE);
      }

      keyspaceDefinition = HFactory.createKeyspaceDefinition(this.cassandraMapping.getKeyspaceName(),
          "org.apache.cassandra.locator.SimpleStrategy", 1, columnFamilyDefinitions);     
      this.cluster.addKeyspace(keyspaceDefinition, true);
      // LOG.info("Keyspace '" + this.cassandraMapping.getKeyspaceName() + "' in cluster '" + this.cassandraMapping.getClusterName() + "' was created on host '" + this.cassandraMapping.getHostName() + "'");
     
      // Create a customized Consistency Level
      ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel();
      Map<String, HConsistencyLevel> clmap = new HashMap<String, HConsistencyLevel>();

      // Define CL.ONE for ColumnFamily "ColumnFamily"
      clmap.put("ColumnFamily", HConsistencyLevel.ONE);

      // In this we use CL.ONE for read and writes. But you can use different CLs if needed.
      configurableConsistencyLevel.setReadCfConsistencyLevels(clmap);
      configurableConsistencyLevel.setWriteCfConsistencyLevels(clmap);

      // Then let the keyspace know
      HFactory.createKeyspace("Keyspace", this.cluster, configurableConsistencyLevel);

      keyspaceDefinition = null;
    }
    else {
      List<ColumnFamilyDefinition> cfDefs = keyspaceDefinition.getCfDefs();
      if (cfDefs == null || cfDefs.size() == 0) {
        LOG.warn(keyspaceDefinition.getName() + " does not have any column family.");
      }
      else {
        for (ColumnFamilyDefinition cfDef : cfDefs) {
          ComparatorType comparatorType = cfDef.getComparatorType();
          if (! comparatorType.equals(ComparatorType.BYTESTYPE)) {
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

 
  @Test
  public void mockingBirdDemo() {

    KeyspaceDefinition ksDef = HFactory.createKeyspaceDefinition("mockingbird");
    cluster.addKeyspace(ksDef, true);
    Keyspace moch = HFactory.createKeyspace("mockingbird", cluster);
    CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(moch, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
    cqlQuery.setQuery("create columnfamily mockingbird (key 'org.apache.cassandra.db.marshal.UTF8Type' primary key) with  "
            + "comparator = 'org.apache.cassandra.db.marshal.UTF8Type' "
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

public class MapReduceJoinIntegrationTest extends IronIntegrationTest {

  @Test
  public void mapReduceJoin() {

     KeyspaceDefinition ksDef = HFactory.createKeyspaceDefinition("mr");
    cluster.addKeyspace(ksDef, true);
    Keyspace mr = HFactory.createKeyspace("mr", cluster);
    CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(mr, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
    cqlQuery.setQuery("create columnfamily dollarbyuser (key 'org.apache.cassandra.db.marshal.UTF8Type' primary key) with  "
            + "comparator = 'org.apache.cassandra.db.marshal.UTF8Type' "
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

        this.snapshotCFName = eventCFName + "Snapshot";

        //connect to cluster
        Cluster cluster = HFactory.getOrCreateCluster(clusterName, hosts);
        //dynamically create keyspace
        KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keyspaceName);
        if (keyspaceDefinition == null) {
            ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
                    keyspaceName, eventCFName, ComparatorType.COMPOSITETYPE);
            cfDef.setComparatorTypeAlias("(LongType, UTF8Type)");
View Full Code Here

Examples of me.prettyprint.hector.api.ddl.KeyspaceDefinition

//----------------------------------------------------------------------------------------------------------------------

    public static void createColumnFamily(Cluster cluster, ColumnFamilyDefinition definition) {
        try {
            LOGGER.info("Attempting to create column family {}:{}...", definition.getKeyspaceName(), definition.getName());
            final KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(definition.getKeyspaceName());
            for (ColumnFamilyDefinition columnFamilyDefinition : keyspaceDefinition.getCfDefs()) {
                if (columnFamilyDefinition.getName().equals(definition.getName())) {
                    LOGGER.info("Column family {}:{} already exists.", keyspaceDefinition.getName(), definition.getName());
                    return;
                }
            }
            cluster.addColumnFamily(definition, true);
            LOGGER.info("Column family {}:{} created successfully.", definition.getKeyspaceName(), definition.getName());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.