me.prettyprint.hector.api.Keyspace Java Examples

The following examples show how to use me.prettyprint.hector.api.Keyspace. 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: CpEntityManager.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Long> getEntityCounters( UUID entityId ) throws Exception {
    Map<String, Long> counters = new HashMap<String, Long>();
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    SliceCounterQuery<UUID, String> q = createCounterSliceQuery( ko, ue, se );
    q.setColumnFamily( ENTITY_COUNTERS.toString() );
    q.setRange( null, null, false, ALL_COUNT );
    //Adding graphite metrics
    Timer.Context timeEntityCounters = entGetEntityCountersTimer.time();
    QueryResult<CounterSlice<String>> r = q.setKey( entityId ).execute();
    timeEntityCounters.stop();
    for ( HCounterColumn<String> column : r.get().getColumns() ) {
        counters.put( column.getName(), column.getValue() );
    }
    return counters;
}
 
Example #2
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public Map<String, Long> getQueueCounters( UUID queueId ) throws Exception {

        Map<String, Long> counters = new HashMap<String, Long>();
        Keyspace ko = cass.getApplicationKeyspace( applicationId );
        SliceCounterQuery<UUID, String> q = createCounterSliceQuery( ko, ue, se );
        q.setColumnFamily( COUNTERS.getColumnFamily() );
        q.setRange( null, null, false, ALL_COUNT );
        QueryResult<CounterSlice<String>> r = q.setKey( queueId ).execute();
        for ( HCounterColumn<String> column : r.get().getColumns() ) {
            counters.put( column.getName(), column.getValue() );
        }
        return counters;
    }
 
Example #3
Source File: CpEntityManager.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public Results getAggregateCounters( UUID userId, UUID groupId, UUID queueId, String category,
    String counterName, CounterResolution resolution, long start, long finish, boolean pad ) {

    start = resolution.round( start );
    finish = resolution.round( finish );
    long expected_time = start;
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    SliceCounterQuery<String, Long> q = createCounterSliceQuery( ko, se, le );
    q.setColumnFamily( APPLICATION_AGGREGATE_COUNTERS.toString() );
    q.setRange( start, finish, false, ALL_COUNT );

    //Adding graphite metrics
    Timer.Context timeGetAggregateCounters = aggCounterTimer.time();
    QueryResult<CounterSlice<Long>> r = q.setKey(
            counterUtils.getAggregateCounterRow( counterName, userId, groupId, queueId, category, resolution ) )
                                         .execute();
    timeGetAggregateCounters.stop();

    List<AggregateCounter> counters = new ArrayList<AggregateCounter>();
    for ( HCounterColumn<Long> column : r.get().getColumns() ) {
        AggregateCounter count = new AggregateCounter( column.getName(), column.getValue() );
        if ( pad && !( resolution == CounterResolution.ALL ) ) {
            while ( count.getTimestamp() != expected_time ) {
                counters.add( new AggregateCounter( expected_time, 0 ) );
                expected_time = resolution.next( expected_time );
            }
            expected_time = resolution.next( expected_time );
        }
        counters.add( count );
    }
    if ( pad && !( resolution == CounterResolution.ALL ) ) {
        while ( expected_time <= finish ) {
            counters.add( new AggregateCounter( expected_time, 0 ) );
            expected_time = resolution.next( expected_time );
        }
    }
    return Results.fromCounters( new AggregateCounterSet( counterName, userId, groupId, category, counters ) );
}
 
Example #4
Source File: ConsumerTransaction.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * @param ko
 */
public ConsumerTransaction( UUID applicationId, Keyspace ko, LockManager lockManager, CassandraService cass, int lockTimeout )
{
    super( ko );
    this.applicationId = applicationId;
    this.lockManager = lockManager;
    this.cass = cass;
    this.lockTimeout = lockTimeout;
}
 
Example #5
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasMessagesInQueue( String queuePath, UUID consumerId ) {

    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    UUID queueId = CassandraMQUtils.getQueueId( queuePath );

    if ( consumerId == null ) {
        consumerId = queueId;
    }

    NoTransactionSearch search = new NoTransactionSearch( ko );

    QueueBounds bounds = search.getQueueBounds( queueId );

    //Queue doesn't exist
    if ( bounds == null ) {
        return false;
    }

    UUID consumerPosition = search.getConsumerQueuePosition( queueId, consumerId );

    //queue exists, but the consumer does not, meaning it's never read from the Q
    if ( consumerPosition == null ) {
        return true;
    }

    //check our consumer position against the newest message.  If it's equal or larger,
    // we're read to the end of the queue
    //note that this does not take transactions into consideration, just the client pointer relative to the largest
    //message in the queue
    return UUIDUtils.compare( consumerPosition, bounds.getNewest() ) < 0;
}
 
Example #6
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasOutstandingTransactions( String queuePath, UUID consumerId ) {
    UUID queueId = CassandraMQUtils.getQueueId( queuePath );

    //no consumer id set, use the same one as the overall queue
    if ( consumerId == null ) {
        consumerId = queueId;
    }

    Keyspace ko = cass.getApplicationKeyspace( applicationId );

    return new ConsumerTransaction( applicationId, ko, lockManager, cass , lockTimeout)
            .hasOutstandingTransactions( queueId, consumerId );
}
 
Example #7
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public UUID renewTransaction( String queuePath, UUID transactionId, QueueQuery query )
        throws TransactionNotFoundException {
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    return new ConsumerTransaction( applicationId, ko, lockManager, cass, lockTimeout )
            .renewTransaction( queuePath, transactionId, query );
}
 
Example #8
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getQueueCounterNames( String queuePath ) throws Exception {
    Set<String> names = new HashSet<String>();
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    SliceQuery<String, String, ByteBuffer> q = createSliceQuery( ko, se, se, be );
    q.setColumnFamily( QueuesCF.QUEUE_DICTIONARIES.toString() );
    q.setKey( CassandraPersistenceUtils.key( getQueueId( queuePath ), DICTIONARY_COUNTERS ).toString() );
    q.setRange( null, null, false, ALL_COUNT );

    List<HColumn<String, ByteBuffer>> columns = q.execute().get().getColumns();
    for ( HColumn<String, ByteBuffer> column : columns ) {
        names.add( column.getName() );
    }
    return names;
}
 
Example #9
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public AggregateCounterSet getAggregateCounters( UUID queueId, String category, String counterName,
                                                 CounterResolution resolution, long start, long finish,
                                                 boolean pad ) {

    start = resolution.round( start );
    finish = resolution.round( finish );
    long expected_time = start;
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    SliceCounterQuery<String, Long> q = createCounterSliceQuery( ko, se, le );
    q.setColumnFamily( APPLICATION_AGGREGATE_COUNTERS.getColumnFamily() );
    q.setRange( start, finish, false, ALL_COUNT );
    QueryResult<CounterSlice<Long>> r = q.setKey(
            counterUtils.getAggregateCounterRow( counterName, null, null, queueId, category, resolution ) )
                                         .execute();
    List<AggregateCounter> counters = new ArrayList<AggregateCounter>();
    for ( HCounterColumn<Long> column : r.get().getColumns() ) {
        AggregateCounter count = new AggregateCounter( column.getName(), column.getValue() );
        if ( pad && !( resolution == CounterResolution.ALL ) ) {
            while ( count.getTimestamp() != expected_time ) {
                counters.add( new AggregateCounter( expected_time, 0 ) );
                expected_time = resolution.next( expected_time );
            }
            expected_time = resolution.next( expected_time );
        }
        counters.add( count );
    }
    if ( pad && !( resolution == CounterResolution.ALL ) ) {
        while ( expected_time <= finish ) {
            counters.add( new AggregateCounter( expected_time, 0 ) );
            expected_time = resolution.next( expected_time );
        }
    }
    return new AggregateCounterSet( counterName, queueId, category, counters );
}
 
Example #10
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet getSubscriptions( String subscriberQueuePath, String firstSubscriptionQueuePath, int limit ) {

    UUID subscriberQueueId = getQueueId( subscriberQueuePath );

    Keyspace ko = cass.getApplicationKeyspace( applicationId );

    if ( firstSubscriptionQueuePath != null ) {
        limit += 1;
    }

    List<HColumn<String, UUID>> columns = createSliceQuery( ko, ue, se, ue ).setKey( subscriberQueueId )
            .setColumnFamily( QUEUE_SUBSCRIPTIONS.getColumnFamily() )
            .setRange( normalizeQueuePath( firstSubscriptionQueuePath ), null, false, limit + 1 ).execute().get()
            .getColumns();

    QueueSet queues = new QueueSet();

    int count = Math.min( limit, columns.size() );
    if ( columns != null ) {
        for ( int i = firstSubscriptionQueuePath != null ? 1 : 0; i < count; i++ ) {
            HColumn<String, UUID> column = columns.get( i );
            queues.addQueue( column.getName(), column.getValue() );
        }
    }
    if ( columns.size() > limit ) {
        queues.setMore( true );
    }
    return queues;
}
 
Example #11
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet getSubscribers( String publisherQueuePath, String firstSubscriberQueuePath, int limit ) {

    UUID publisherQueueId = getQueueId( publisherQueuePath );

    Keyspace ko = cass.getApplicationKeyspace( applicationId );

    if ( firstSubscriberQueuePath != null ) {
        limit += 1;
    }

    List<HColumn<String, UUID>> columns = createSliceQuery( ko, ue, se, ue ).setKey( publisherQueueId )
            .setColumnFamily( QUEUE_SUBSCRIBERS.getColumnFamily() )
            .setRange( normalizeQueuePath( firstSubscriberQueuePath ), null, false, limit + 1 ).execute().get()
            .getColumns();

    QueueSet queues = new QueueSet();

    int count = Math.min( limit, columns.size() );
    if ( columns != null ) {
        for ( int i = firstSubscriberQueuePath != null ? 1 : 0; i < count; i++ ) {
            HColumn<String, UUID> column = columns.get( i );
            queues.addQueue( column.getName(), column.getValue() );
        }
    }
    if ( columns.size() > limit ) {
        queues.setMore( true );
    }
    return queues;
}
 
Example #12
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueResults getFromQueue( String queuePath, QueueQuery query ) {

    if ( query == null ) {
        query = new QueueQuery();
    }

    Keyspace ko = cass.getApplicationKeyspace( applicationId );

    QueueSearch search = null;

    if ( query.hasFilterPredicates() ) {
        search = new FilterSearch( ko );
    }

    else if ( query.getPosition() == LAST || query.getPosition() == CONSUMER ) {
        if ( query.getTimeout() > 0 ) {
            search = new ConsumerTransaction( applicationId, ko, lockManager, cass, lockTimeout );
        }
        else {
            search = new NoTransactionSearch( ko );
        }
    }
    else if ( query.getPosition() == START ) {

        search = new StartSearch( ko );
    }
    else if ( query.getPosition() == END ) {
        search = new EndSearch( ko );
    }
    else {
        throw new IllegalArgumentException( "You must specify a valid position or query" );
    }

    return search.getResults( queuePath, query );
}
 
Example #13
Source File: BackplaneConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9160");
    CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(cassandraHosts);
    hostConfigurator.setAutoDiscoverHosts(false);
    hostConfigurator.setMaxActive(env.getProperty("ea.cassandra.maxActive",Integer.class,Runtime.getRuntime().availableProcessors() * 3));
    hostConfigurator.setRetryDownedHosts(true);
    hostConfigurator.setRetryDownedHostsDelayInSeconds(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1));
    hostConfigurator.setMaxWaitTimeWhenExhausted(2000L);
    String cassandraClusterName = env.getProperty("ea.cassandra.cluster","ElasticActorsCluster");
    // it seems that there are issues with the CassandraHostRetryService and retrying downed hosts
    // if we don't let the HFactory manage the cluster then CassandraHostRetryService doesn't try to
    // be smart about finding out if a host was removed from the ring and so it will keep on retrying
    // all configured hosts (and ultimately fail-back when the host comes back online)
    // the default is TRUE, which will let HFactory manage the cluster
    Boolean manageClusterThroughHFactory = env.getProperty("ea.cassandra.hfactory.manageCluster", Boolean.class, Boolean.TRUE);
    Cluster cluster;
    if(manageClusterThroughHFactory) {
        cluster = HFactory.getOrCreateCluster(cassandraClusterName, hostConfigurator);
    } else {
        cluster = new ThriftCluster(cassandraClusterName, hostConfigurator, null);
    }
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","ElasticActors");
    Keyspace keyspace = HFactory.createKeyspace(cassandraKeyspaceName,cluster);
    persistentActorsColumnFamilyTemplate =
        new ThriftColumnFamilyTemplate<>(keyspace,"PersistentActors", CompositeSerializer.get(),StringSerializer.get());
    scheduledMessagesColumnFamilyTemplate =
        new ThriftColumnFamilyTemplate<>(keyspace,"ScheduledMessages",CompositeSerializer.get(), CompositeSerializer.get());
    actorSystemEventListenersColumnFamilyTemplate =
            new ThriftColumnFamilyTemplate<>(keyspace,"ActorSystemEventListeners", CompositeSerializer.get(),StringSerializer.get());
    // return
    // @TODO: make this configurable and use the ColumnSliceIterator
    scheduledMessagesColumnFamilyTemplate.setCount(Integer.MAX_VALUE);
    actorSystemEventListenersColumnFamilyTemplate.setCount(Integer.MAX_VALUE);
}
 
Example #14
Source File: HectorPolicyManagerImpl.java    From ck with Apache License 2.0 5 votes vote down vote up
public HectorPolicyManagerImpl(Keyspace keyspace) {
    super();
    if (keyspace == null) {
        throw new IllegalArgumentException("keyspace must not be null");
    }
    _keyspace = keyspace;
}
 
Example #15
Source File: POSSlicesQueryIterator.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new iterator with the given data.
 * 
 * @param dictionary the store dictionary.
 * @param isq the indexed slice query.
 * @param limit the result limit.
 * @param cf the column family name.
 * @param keyspace the keyspace.
 */
POSSlicesQueryIterator(
		final ITopLevelDictionary dictionary,
		final IndexedSlicesQuery<byte[], Composite, byte[]> isq,
		final int limit, 
		final String cf, 
		final Keyspace keyspace) {
	_dictionary = dictionary;
	_limit = limit;
	_cf = cf;
	_keyspace = keyspace;
	_rows = new IndexedSlicesIterator<byte[], Composite, byte[]>(isq, new byte[0]);
}
 
Example #16
Source File: CAndPCSlicesQueryIterator.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new iterator iterating over the results of the given query.
 * 
 * @param query The query.
 * @param limit The maximum amount of results to return.
 * @param cf The column family to query.
 * @param keyspace The keyspace to use.
 * @param dictionary the CumulusRDF dictionary.
 * @param isPC True, if this is a PC query, false, if this is a C query.
 */
CAndPCSlicesQueryIterator(
		final RangeSlicesQuery<byte[], Composite, byte[]> query,
		final int limit, 
		final String cf, 
		final Keyspace keyspace, 
		final ITopLevelDictionary dictionary,
		final boolean isPC) {
	_rows = new RangeSlicesIterator<byte[], Composite, byte[]>(query, new byte[0], new byte[0]);
	_limit = limit;
	_cf = cf;
	_keyspace = keyspace;
	_dictionary = dictionary;
	_isPC = isPC;
}
 
Example #17
Source File: CassandraCounterStore.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public CassandraCounterStore( Keyspace keyspace ) {
    this.keyspace = keyspace;
}
 
Example #18
Source File: NoTransactionSearch.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * @param ko
 */
public NoTransactionSearch( Keyspace ko )
{
    super( ko );
}
 
Example #19
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 *
 */
public AbstractSearch( Keyspace ko ) {
    this.ko = ko;
}
 
Example #20
Source File: StartSearch.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public StartSearch( Keyspace ko )
{
    super( ko );
}
 
Example #21
Source File: EndSearch.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public EndSearch( Keyspace ko )
{
    super( ko );
}
 
Example #22
Source File: FilterSearch.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 *
 */
public FilterSearch( Keyspace ko )
{
    super( ko );
}
 
Example #23
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public void commitTransaction( String queuePath, UUID transactionId, QueueQuery query ) {
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    new ConsumerTransaction( applicationId, ko, lockManager, cass, lockTimeout )
            .deleteTransaction( queuePath, transactionId, query );
}
 
Example #24
Source File: Util.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static String getExistingUserId(String credentialTypeName, String identifier, Keyspace keyspace) {

        identifier = createRowKeyForReverseLookup(identifier, credentialTypeName);
        ColumnQuery<String, String, String> usernameIndexQuery = HFactory.createColumnQuery(keyspace, stringSerializer,
                stringSerializer, stringSerializer);

        usernameIndexQuery.setColumnFamily(CFConstants.USERNAME_INDEX).setKey(identifier).setName(CFConstants.USER_ID);

        QueryResult<HColumn<String, String>> result = usernameIndexQuery.execute();

        HColumn<String, String> userIdCol = result.get();

        if (userIdCol == null) {
            return null;
        }

        return userIdCol.getValue();
    }
 
Example #25
Source File: DefaultCassandraArchivaManager.java    From archiva with Apache License 2.0 4 votes vote down vote up
@Override
public Keyspace getKeyspace()
{
    return keyspace;
}
 
Example #26
Source File: Util.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static String getExistingUserId(String credentialTypeName, String identifier, Keyspace keyspace) {

        identifier = createRowKeyForReverseLookup(identifier, credentialTypeName);
        ColumnQuery<String, String, String> usernameIndexQuery = HFactory.createColumnQuery(keyspace, stringSerializer,
                stringSerializer, stringSerializer);

        usernameIndexQuery.setColumnFamily(CFConstants.USERNAME_INDEX).setKey(identifier).setName(CFConstants.USER_ID);

        QueryResult<HColumn<String, String>> result = usernameIndexQuery.execute();

        HColumn<String, String> userIdCol = result.get();

        if (userIdCol == null) {
            return null;
        }

        return userIdCol.getValue();
    }
 
Example #27
Source File: CumulusDataAccessLayerFactory.java    From cumulusrdf with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the keyspace currently in use.
 * 
 * @return the keyspace currently in use.
 */
public Keyspace getKeyspace() {
	return _keyspace;
}
 
Example #28
Source File: CumulusDataAccessLayerFactory.java    From cumulusrdf with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the keyspace name in use.
 * 
 * @param keyspace the keyspace name in use.
 */
public void setKeyspace(final Keyspace keyspace) {
	_keyspace = keyspace;
}
 
Example #29
Source File: CountingMutator.java    From usergrid with Apache License 2.0 2 votes vote down vote up
/**
 * Create a mutator that will flush when the maximum size is reached
 * @param keyspace
 * @param keySerializer
 * @param <K>
 * @return
 */
public static <K> CountingMutator<K> createFlushingMutator( Keyspace keyspace, Serializer<K> keySerializer ) {
    Mutator<K> target = HFactory.createMutator( keyspace, keySerializer );

    return new CountingMutator<K>( target, MAX_SIZE );
}
 
Example #30
Source File: CassandraArchivaManager.java    From archiva with Apache License 2.0 votes vote down vote up
Keyspace getKeyspace();