/** * Create a timestamp based on the TimeResolution set to the cluster. * * @return a timestamp */ public long createTimestamp() { return chc.getClockResolution().createClock(); }
CassandraHost[] hosts = chc.buildCassandraHosts(); if ( hosts.length == 0 ) { throw new RuntimeException( "Fatal error: no Cassandra hosts configured" ); if ( StringUtils.isEmpty( host.getHost() ) ) { throw new RuntimeException( "Fatal error: Cassandra hostname cannot be empty" ); hostsString += host.getHost() + ","; cpProps.put( "cassandra.port", hosts[0].getPort() );
public static List<ColumnDefinition> getIndexMetadata( String indexes ) { if ( indexes == null ) { return null; } String[] index_entries = split( indexes, ',' ); List<ColumnDef> columns = new ArrayList<ColumnDef>(); for ( String index_entry : index_entries ) { String column_name = stringOrSubstringBeforeFirst( index_entry, ':' ).trim(); String comparer = substringAfterLast( index_entry, ":" ).trim(); if ( StringUtils.isBlank( comparer ) ) { comparer = "UUIDType"; } if ( StringUtils.isNotBlank( column_name ) ) { ColumnDef cd = new ColumnDef( bytebuffer( column_name ), comparer ); cd.setIndex_name( column_name ); cd.setIndex_type( IndexType.KEYS ); columns.add( cd ); } } return ThriftColumnDef.fromThriftList( columns ); }
protected CassandraHostConfigurator getCHCForTest() { CassandraHostConfigurator chc = new CassandraHostConfigurator("127.0.0.1:9170"); chc.setMaxActive(2); return chc; } }
@Override public KeyspaceDefinition execute(Cassandra.Client cassandra) throws HectorException { try { return new ThriftKsDef(cassandra.describe_keyspace(keyspace)); } catch (org.apache.cassandra.thrift.NotFoundException nfe) { setException(xtrans.translate(nfe)); return null; } catch (Exception e) { throw xtrans.translate(e); } } };
public static ColumnFamilyDefinition createColumnFamilyDefinition( String keyspace, String cfName, ComparatorType comparatorType, List<ColumnDefinition> columnMetadata) { return new ThriftCfDef(keyspace, cfName, comparatorType, columnMetadata); }
@Override public void batchMutate(BatchMutation batchMutate) throws HectorException { batchMutate(batchMutate.getMutationMap()); }
@Override public void batchMutate(BatchMutation batchMutate) throws HectorException { batchMutate(batchMutate.getMutationMap()); }
private ThriftKsDef toThriftImplementation(final KeyspaceDefinition cfdef) { if(cfdef instanceof ThriftKsDef) { return (ThriftKsDef) cfdef; } else { return new ThriftKsDef(cfdef); } } }
@Before public void setupCase() throws TTransportException, TException, IllegalArgumentException, NotFoundException, UnknownHostException, Exception { cassandraHostConfigurator = getCHCForTest(); cassandraCluster = new ThriftCluster(clusterName, cassandraHostConfigurator); }
@Override public void executeAndSetResult(Client cassandra, CassandraHost cassandraHost) throws Exception { operation.executeAndSetResult(new VirtualKeyspaceCassandraClient(cassandra, prefixBytes), cassandraHost); }
@Override public T execute(Client cassandra) throws Exception { return operation.execute(new VirtualKeyspaceCassandraClient(cassandra, prefixBytes)); }
@Override public Map<ByteBuffer, List<SuperColumn>> getSuperRangeSlices( ColumnParent columnParent, SlicePredicate predicate, KeyRange keyRange) throws HectorException { return ps.fromBytesMap(super.getSuperRangeSlices(columnParent, predicate, prefixKeyRange(keyRange))); }
/** * Makes a shallow copy of the mutation object. * @return */ public BatchMutation<K> makeCopy() { return new BatchMutation<K>(keySerializer, mutationMap, sizeHint); }
@Override public Builder maxRowCount(int maxRowCount) { super.maxRowCount(maxRowCount); return this; }
public Operation(OperationType operationType) { this.failCounter = (operationType == OperationType.READ) ? Counter.READ_FAIL : Counter.WRITE_FAIL; this.operationType = operationType; this.stopWatchTagName = operationType.name(); }
public static JmxMonitor getInstance() { if ( monitorInstance == null ) { monitorInstance = new JmxMonitor(); } return monitorInstance; }
@Override public void applyConnectionParams(String keyspace, ConsistencyLevelPolicy consistencyLevelPolicy, FailoverPolicy failoverPolicy, Map<String, String> credentials) { operation.applyConnectionParams(keyspace, consistencyLevelPolicy, failoverPolicy, credentials); }
/** Create the keyspace */ private void createKeySpace( String keyspace ) { logger.info( "Creating keyspace: {}", keyspace ); String strategy_class = getString( properties, "cassandra.keyspace.strategy", "org.apache.cassandra.locator.SimpleStrategy" ); logger.info( "Using strategy: {}", strategy_class ); int replication_factor = getIntValue( properties, "cassandra.keyspace.replication", 1 ); logger.info( "Using replication (may be overriden by strategy options): {}", replication_factor ); // try { ThriftKsDef ks_def = ( ThriftKsDef ) HFactory .createKeyspaceDefinition( keyspace, strategy_class, replication_factor, new ArrayList<ColumnFamilyDefinition>() ); @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, String> strategy_options = filter( ( Map ) properties, "cassandra.keyspace.strategy.options.", true ); if ( strategy_options.size() > 0 ) { logger.info( "Strategy options: {}", mapToFormattedJsonString( strategy_options ) ); ks_def.setStrategyOptions( strategy_options ); } cluster.addKeyspace( ks_def ); waitForCreation( keyspace ); logger.info( "Created keyspace {}", keyspace ); }
private BatchMutation<K> getPendingMutations() { if (pendingMutations == null) { pendingMutations = new BatchMutation<K>(keySerializer, sizeHint); } return pendingMutations; }