示例#1
0
  public static void createKeyspace(
      Cluster cluster, String name, String strategy, int replicationFactor, List<CfDef> cfDefList) {
    try {
      KsDef ksDef = new KsDef(name, strategy, replicationFactor, cfDefList);
      cluster.addKeyspace(new ThriftKsDef(ksDef));
      return;
    } catch (Throwable e) {
      System.out.println(
          "exception while creating keyspace, "
              + name
              + " - probably already exists : "
              + e.getMessage());
    }

    for (CfDef cfDef : cfDefList) {
      try {
        cluster.addColumnFamily(new ThriftCfDef(cfDef));
      } catch (Throwable e) {
        System.out.println(
            "exception while creating CF, "
                + cfDef.getName()
                + " - probably already exists : "
                + e.getMessage());
      }
    }
  }
示例#2
0
  public static Keyspace createKeySpace(Cluster cluster, String keySpace) {

    Keyspace keyspace;

    // Define the keySpace
    KeyspaceDefinition definition = new ThriftKsDef(keySpace);

    KeyspaceDefinition def = cluster.describeKeyspace(keySpace);
    if (def == null) {
      // Adding keySpace to the cluster
      cluster.addKeyspace(definition, true);
    }

    keyspace = HFactory.createKeyspace(keySpace, cluster);
    CassandraConsistencyLevelPolicy policy = new CassandraConsistencyLevelPolicy();
    keyspace.setConsistencyLevelPolicy(policy);
    return keyspace;
  }
 void addKeyspacetoCassandra() throws InvalidRequestException, TException {
   try {
     ColumnFamilyDefinition cfDef =
         HFactory.createColumnFamilyDefinition(
             keyspaceName, cfdatapoint, ComparatorType.BYTESTYPE);
     int replicationFactor = 1;
     KeyspaceDefinition newKeyspace =
         HFactory.createKeyspaceDefinition(
             keyspaceName,
             ThriftKsDef.DEF_STRATEGY_CLASS,
             replicationFactor,
             Arrays.asList(cfDef));
     // Add the schema to the cluster.
     myCluster.addKeyspace(newKeyspace);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void init(Cluster cluster) {
    if (cluster.describeKeyspace("SiddhiSnapshots") == null) {
      log.info("Adding  keyspace SiddhiSnapshots");
      cluster.addKeyspace(HFactory.createKeyspaceDefinition("SiddhiSnapshots"));
      keyspace = HFactory.createKeyspace("SiddhiSnapshots", cluster);
      cluster.addColumnFamily(
          HFactory.createColumnFamilyDefinition(keyspace.getKeyspaceName(), COLUMN_FAMILY_NAME));
      cluster.addColumnFamily(
          HFactory.createColumnFamilyDefinition(
              keyspace.getKeyspaceName(), INDEX_COLUMN_FAMILY_NAME));

    } else {
      if (log.isDebugEnabled()) {
        log.debug("keyspace SiddhiSnapshots exists");
      }
      keyspace = HFactory.createKeyspace("SiddhiSnapshots", cluster);
    }
  }
示例#5
0
 public static void addKeySpace(Cluster myCluster) {
   List<ColumnFamilyDefinition> cfDefs = new ArrayList<ColumnFamilyDefinition>();
   cfDefs.add(
       HFactory.createColumnFamilyDefinition(
           "deneme", "global", ComparatorType.getByClassName("DateType")));
   cfDefs.add(
       HFactory.createColumnFamilyDefinition(
           "deneme", "campaign1", ComparatorType.getByClassName("DateType")));
   cfDefs.add(
       HFactory.createColumnFamilyDefinition(
           "deneme", "campaign2", ComparatorType.getByClassName("DateType")));
   cfDefs.add(
       HFactory.createColumnFamilyDefinition(
           "deneme", "campaign3", ComparatorType.getByClassName("DateType")));
   KeyspaceDefinition ksdef =
       HFactory.createKeyspaceDefinition(
           "deneme", "org.apache.cassandra.locator.SimpleStrategy", 1, cfDefs);
   myCluster.addKeyspace(ksdef, true);
 }