示例#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());
      }
    }
  }
  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);
    }
  }
  void createColumnfamily(String cfname) {

    if (cfname.equals("") || cfname.trim().equals(null)) {
      return;
    } else {
      cfcreate = cfname.toLowerCase();
      if (checkExist(cfcreate) == false) {
        cfdef = HFactory.createColumnFamilyDefinition(keyspaceName, cfcreate);
        myCluster.addColumnFamily(cfdef, true);
      }
    }
  }
示例#4
0
  /**
   * Create a Column family for cassandra counters in a given Cluster intance
   *
   * @param name ColumnFamily Name
   * @param keySpace KeySpace name
   * @param cluster Cluster instance
   * @throws CassandraDataAccessException In case of an Error accessing database or data error
   */
  public static void createCounterColumnFamily(String name, String keySpace, Cluster cluster)
      throws CassandraDataAccessException {
    KeyspaceDefinition ksDef = cluster.describeKeyspace(keySpace);

    if (ksDef == null) {
      throw new CassandraDataAccessException(
          "Can't create Column family, keyspace " + keySpace + " does not exist");
    }
    ColumnFamilyDefinition cfDef =
        HFactory.createColumnFamilyDefinition(keySpace, name, ComparatorType.COUNTERTYPE);
    cfDef.setComparatorType(ComparatorType.UTF8TYPE);
    cfDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
    cfDef.setColumnType(ColumnType.STANDARD);

    List<ColumnFamilyDefinition> cfDefsList = ksDef.getCfDefs();
    HashSet<String> cfNames = new HashSet<String>();
    for (ColumnFamilyDefinition columnFamilyDefinition : cfDefsList) {
      cfNames.add(columnFamilyDefinition.getName());
    }
    if (!cfNames.contains(name)) {
      cluster.addColumnFamily(cfDef, true);
    }
  }
示例#5
0
  /**
   * Create a Column family in a Given Cluster instance
   *
   * @param name ColumnFamily Name
   * @param keySpace KeySpace name
   * @param cluster Cluster instance
   * @param comparatorType Comparator
   * @throws CassandraDataAccessException In case of an Error accessing database or data error
   */
  public static void createColumnFamily(
      String name, String keySpace, Cluster cluster, String comparatorType)
      throws CassandraDataAccessException {

    KeyspaceDefinition ksDef = cluster.describeKeyspace(keySpace);

    if (ksDef == null) {
      throw new CassandraDataAccessException(
          "Can't create Column family, keyspace " + keySpace + " does not exist");
    }

    ColumnFamilyDefinition cfDef =
        new ThriftCfDef(keySpace, /*"Queue"*/ name, ComparatorType.getByClassName(comparatorType));

    List<ColumnFamilyDefinition> cfDefsList = ksDef.getCfDefs();
    HashSet<String> cfNames = new HashSet<String>();
    for (ColumnFamilyDefinition columnFamilyDefinition : cfDefsList) {
      cfNames.add(columnFamilyDefinition.getName());
    }
    if (!cfNames.contains(name)) {
      cluster.addColumnFamily(cfDef, true);
    }
  }