me.prettyprint.hector.api.ddl.KeyspaceDefinition Java Examples
The following examples show how to use
me.prettyprint.hector.api.ddl.KeyspaceDefinition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Cassandra12xCounterDAO.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Override public void createRequiredSchemaEntities() throws DataAccessLayerException { final String keyspaceName = _keyspace.getKeyspaceName(); KeyspaceDefinition ksdef = _factory.getCluster().describeKeyspace(keyspaceName); if (!hasColumnFamily(ksdef, _cf_name)) { ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspaceName, _cf_name); cfDef.setKeyValidationClass(ComparatorType.UTF8TYPE.getClassName()); cfDef.setComparatorType(ComparatorType.UTF8TYPE); cfDef.setCompactionStrategy("LeveledCompactionStrategy"); cfDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName()); cfDef.setColumnType(ColumnType.STANDARD); _factory.getCluster().addColumnFamily(cfDef, true); } setDefaultValue(-1L); }
Example #2
Source File: CassandraService.java From usergrid with Apache License 2.0 | 6 votes |
/** Return true if the column family exists */ public boolean cfExists( String keyspace, String cfName ) { KeyspaceDefinition ksDef = cluster.describeKeyspace( keyspace ); if ( ksDef == null ) { return false; } for ( ColumnFamilyDefinition cf : ksDef.getCfDefs() ) { if ( cfName.equals( cf.getName() ) ) { return true; } } return false; }
Example #3
Source File: Cassandra12xTripleIndexDAO.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Creates the CumulusRDF keyspace. * * @param keyspaceName the keyspace name. * @return the keyspace definition. */ protected KeyspaceDefinition createKeyspaceDefinition(final String keyspaceName) { return HFactory.createKeyspaceDefinition( keyspaceName, "org.apache.cassandra.locator.SimpleStrategy", _dataAccessLayerFactory.getReplication(), createColumnFamiliyDefinitions()); }
Example #4
Source File: Cassandra12xMapDAO.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override public void createRequiredSchemaEntities() throws DataAccessLayerException { final String keyspace_name = _keyspace.getKeyspaceName(); final KeyspaceDefinition ksdef = _factory.getCluster().describeKeyspace(keyspace_name); if (!hasColumnFamily(ksdef, _cf_name)) { final ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace_name, _cf_name); final Map<String, String> compressionOptions = new HashMap<String, String>(); compressionOptions.put("sstable_compression", "SnappyCompressor"); cfDef.setCompressionOptions(compressionOptions); cfDef.setColumnType(ColumnType.STANDARD); cfDef.setKeyValidationClass(ComparatorType.BYTESTYPE.getClassName()); cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName()); cfDef.setCompactionStrategy("LeveledCompactionStrategy"); if (_isBidirectional) { BasicColumnDefinition colDef = new BasicColumnDefinition(); colDef.setName(BytesArraySerializer.get().toByteBuffer(COLUMN_NAME)); colDef.setValidationClass(ComparatorType.BYTESTYPE.getClassName()); colDef.setIndexType(ColumnIndexType.KEYS); colDef.setIndexName(_cf_name + "_val_idx"); cfDef.addColumnDefinition(colDef); } _factory.getCluster().addColumnFamily(new ThriftCfDef(cfDef), true); } }
Example #5
Source File: Utils.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Returns true if a given keyspace has a column family. * * @param ksdef the keyspace. * @param cfname the column family name. * @return true if the keyspace has the column family, false otherwise. */ public static boolean hasColumnFamily(final KeyspaceDefinition ksdef, final String cfname) { for (final ColumnFamilyDefinition cfdef : ksdef.getCfDefs()) { if (cfdef.getName().equals(cfname)) { return true; } } return false; }
Example #6
Source File: SchemaBuilder.java From oneops with Apache License 2.0 | 4 votes |
public static void createSchema(Cluster cluster, String keyspaceName) { KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspaceName); if (keyspaceDef == null) { createFreshSchema(cluster, keyspaceName); return; } List<ColumnFamilyDefinition> existingCFs = keyspaceDef.getCfDefs(); Set<String> existingCFNames = new HashSet<String>(); for (ColumnFamilyDefinition existingCF : existingCFs) { existingCFNames.add(existingCF.getName()); } if (!existingCFNames.contains(THRESHOLDS_CF)) { ColumnFamilyDefinition cfThresholdsDef = HFactory.createColumnFamilyDefinition(keyspaceName, THRESHOLDS_CF, ComparatorType.BYTESTYPE); cfThresholdsDef.setColumnType(ColumnType.SUPER); cfThresholdsDef.setSubComparatorType(ComparatorType.BYTESTYPE); cluster.addColumnFamily(cfThresholdsDef,true); logger.info("Added column family " + THRESHOLDS_CF); } if (!existingCFNames.contains(MANIFESTMAP_CF)) { ColumnFamilyDefinition cfManifestMapDef = HFactory.createColumnFamilyDefinition(keyspaceName, MANIFESTMAP_CF, ComparatorType.BYTESTYPE); cluster.addColumnFamily(cfManifestMapDef,true); logger.info("Added column family " + MANIFESTMAP_CF); } if (!existingCFNames.contains(REALIZED_AS_CF)) { ColumnFamilyDefinition cfRealizedAsMapDef = HFactory.createColumnFamilyDefinition(keyspaceName, REALIZED_AS_CF, ComparatorType.LONGTYPE); cluster.addColumnFamily(cfRealizedAsMapDef,true); logger.info("Added column family " + REALIZED_AS_CF); } if (!existingCFNames.contains(OPS_EVENTS_CF)) { ColumnFamilyDefinition cfOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName, OPS_EVENTS_CF, ComparatorType.LONGTYPE); cluster.addColumnFamily(cfOpsDef,true); logger.info("Added column family " + OPS_EVENTS_CF); } if (!existingCFNames.contains(ORPHAN_CLOSE_EVENTS_CF)) { ColumnFamilyDefinition cfResetOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName, ORPHAN_CLOSE_EVENTS_CF, ComparatorType.LONGTYPE); cfResetOpsDef.setColumnType(ColumnType.SUPER); cfResetOpsDef.setSubComparatorType(ComparatorType.BYTESTYPE); cluster.addColumnFamily(cfResetOpsDef,true); logger.info("Added column family " + ORPHAN_CLOSE_EVENTS_CF); } if (!existingCFNames.contains(CI_STATE_HIST_CF)) { ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName, CI_STATE_HIST_CF, ComparatorType.LONGTYPE); cluster.addColumnFamily(cfCiStateHistDef,true); logger.info("Added column family " + CI_STATE_HIST_CF); } if (!existingCFNames.contains(CI_OPEN_EVENTS_CF)) { ColumnFamilyDefinition cfCiOpenEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName, CI_OPEN_EVENTS_CF, ComparatorType.BYTESTYPE); cfCiOpenEventsDef.setColumnType(ColumnType.SUPER); cfCiOpenEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE); cluster.addColumnFamily(cfCiOpenEventsDef,true); logger.info("Added column family " + CI_OPEN_EVENTS_CF); } if (!existingCFNames.contains(COMPONENT_STATE_CF)) { ColumnFamilyDefinition cfComponentStateDef = HFactory.createColumnFamilyDefinition(keyspaceName, COMPONENT_STATE_CF, ComparatorType.BYTESTYPE); cfComponentStateDef.setColumnType(ColumnType.STANDARD); cfComponentStateDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName()); cfComponentStateDef.setKeyValidationClass(ComparatorType.LONGTYPE.getClassName()); cluster.addColumnFamily(cfComponentStateDef,true); logger.info("Added column family " + COMPONENT_STATE_CF); } }
Example #7
Source File: SchemaBuilder.java From oneops with Apache License 2.0 | 4 votes |
private static void createFreshSchema(Cluster cluster, String keyspaceName) { ColumnFamilyDefinition cfThresholdsDef = HFactory.createColumnFamilyDefinition(keyspaceName, THRESHOLDS_CF, ComparatorType.BYTESTYPE); cfThresholdsDef.setColumnType(ColumnType.SUPER); cfThresholdsDef.setSubComparatorType(ComparatorType.BYTESTYPE); ColumnFamilyDefinition cfManifestMapDef = HFactory.createColumnFamilyDefinition(keyspaceName, MANIFESTMAP_CF, ComparatorType.BYTESTYPE); ColumnFamilyDefinition cfRealizedAsMapDef = HFactory.createColumnFamilyDefinition(keyspaceName, REALIZED_AS_CF, ComparatorType.LONGTYPE); ColumnFamilyDefinition cfOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName, OPS_EVENTS_CF, ComparatorType.LONGTYPE); ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName, CI_STATE_HIST_CF, ComparatorType.LONGTYPE); ColumnFamilyDefinition cfCiOpenEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName, CI_OPEN_EVENTS_CF, ComparatorType.BYTESTYPE); cfCiOpenEventsDef.setColumnType(ColumnType.SUPER); cfCiOpenEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE); ColumnFamilyDefinition cfComponentStateDef = HFactory.createColumnFamilyDefinition(keyspaceName, COMPONENT_STATE_CF, ComparatorType.BYTESTYPE); cfComponentStateDef.setColumnType(ColumnType.STANDARD); cfComponentStateDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName()); cfComponentStateDef.setKeyValidationClass(ComparatorType.LONGTYPE.getClassName()); ColumnFamilyDefinition cfOrphanEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName, ORPHAN_CLOSE_EVENTS_CF, ComparatorType.LONGTYPE); cfOrphanEventsDef.setColumnType(ColumnType.SUPER); cfOrphanEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE); KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspaceName, ThriftKsDef.DEF_STRATEGY_CLASS, 1, Arrays.asList(cfThresholdsDef,cfManifestMapDef, cfRealizedAsMapDef, cfOpsDef, cfCiStateHistDef, cfCiOpenEventsDef, cfComponentStateDef)); //Add the schema to the cluster. //"true" as the second param means that Hector will block until all nodes see the change. cluster.addKeyspace(newKeyspace, true); logger.info("Added keyspace " + keyspaceName); }
Example #8
Source File: CassandraService.java From usergrid with Apache License 2.0 | 4 votes |
/** Check if the keyspace exsts */ public boolean keySpaceExists( String keyspace ) { KeyspaceDefinition ksDef = cluster.describeKeyspace( keyspace ); return ksDef != null; }