me.prettyprint.hector.api.beans.HCounterColumn Java Examples

The following examples show how to use me.prettyprint.hector.api.beans.HCounterColumn. 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: OpsCiStateDao.java    From oneops with Apache License 2.0 6 votes vote down vote up
public Map<Long,Map<String,Long>> getComponentStates(List<Long> manifestIds) {
  	
  	Map<Long,Map<String,Long>> result = new HashMap<Long,Map<String,Long>>();
  	MultigetSliceCounterQuery<Long, String> query =  HFactory.createMultigetSliceCounterQuery(keyspace, longSerializer, stringSerializer);
  	
  	query.setKeys(manifestIds);		
  	query.setColumnFamily(SchemaBuilder.COMPONENT_STATE_CF);
  	query.setRange(null, null, false, 1000);
  	QueryResult<CounterRows<Long,String>> qResult = query.execute();

  	CounterRows<Long,String> rows = qResult.get();

for (CounterRow<Long, String> row : rows) {
	if (row.getColumnSlice().getColumns().size() >0) {
		if (!result.containsKey(row.getKey())) {
			result.put(row.getKey(), new HashMap<String,Long>());
		}
		
	    for (HCounterColumn<String> col : row.getColumnSlice().getColumns()) {
	    	result.get(row.getKey()).put(col.getName(), col.getValue());
	    }
	}
}
  	
  	return result;
  }
 
Example #2
Source File: OpsCiStateDao.java    From oneops with Apache License 2.0 6 votes vote down vote up
public Map<String,Long> getComponentStates(Long manifestId) {
  	
  	Map<String,Long> result = new HashMap<String,Long>();
  	SliceCounterQuery<Long, String> query =  HFactory.createCounterSliceQuery(keyspace, longSerializer, stringSerializer);
  	query.setKey(manifestId);
  	query.setColumnFamily(SchemaBuilder.COMPONENT_STATE_CF);
  	query.setRange(null, null, false, 100);
  	QueryResult<CounterSlice<String>> qResult = query.execute();

  	CounterSlice<String> row = qResult.get();		
if (row != null && row.getColumns().size()>0) {
	for (HCounterColumn<String> col :row.getColumns()) {
		result.put(col.getName(), col.getValue());
	}
}
  	return result;
  }
 
Example #3
Source File: Cassandra12xCounterDAO.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public Long get(final K key) {

	final CounterQuery<K, String> counter = new ThriftCounterColumnQuery<K, String>(_keyspace, _serializer_k, STRING_SERIALIZER);
	counter.setColumnFamily(_cf_name).setKey(key).setName(COLUMN_NAME_AS_STRING);
	final HCounterColumn<String> c = counter.execute().get();

	if (c == null) {
		if (_default_value != null) {
			return _default_value;
		} else {
			return null;
		}
	} else {
		return c.getValue();
	}
}
 
Example #4
Source File: CounterUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private void handleAggregateCounterRow( Mutator<ByteBuffer> m, String key, long column, long value,
                                        UUID applicationId ) {
    if ( logger.isTraceEnabled() ) {
        logger.trace( "HACR: aggregateRow for app {} with key {} column {} and value {}",
                applicationId, key, column, value );
    }
    if ( "o".equals( counterType ) || "p".equals( counterType ) ) {
        if ( m != null ) {
            HCounterColumn<Long> c = createCounterColumn( column, value, le );
            m.addCounter( bytebuffer( key ), APPLICATION_AGGREGATE_COUNTERS.toString(), c );
        }
    }
    if ( "n".equals( counterType ) || "p".equals( counterType ) ) {
        // create and add Count
        PrefixedSerializer ps =
                new PrefixedSerializer( applicationId, ue, se );
        batcher.add(
                new Count( APPLICATION_AGGREGATE_COUNTERS.toString(), ps.toByteBuffer( key ), column, value ) );
    }
}
 
Example #5
Source File: CounterUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private Mutator<ByteBuffer> batchIncrementEntityCounter( Mutator<ByteBuffer> m, UUID entityId, String name,
                                                         Long value, long timestamp, UUID applicationId ) {
    if ( logger.isTraceEnabled() ) {
        logger.trace( "BIEC: Incrementing property {} of entity {} by value {}",
                name, entityId, value );
    }
    addInsertToMutator( m, ENTITY_DICTIONARIES, key( entityId, DICTIONARY_COUNTERS ), name, null, timestamp );
    if ( "o".equals( counterType ) || "p".equals( counterType ) ) {
        HCounterColumn<String> c = createCounterColumn( name, value );
        m.addCounter( bytebuffer( entityId ), ENTITY_COUNTERS.toString(), c );
    }
    if ( "n".equals( counterType ) || "p".equals( counterType ) ) {
        PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, ue );
        batcher.add( new Count( ENTITY_COUNTERS.toString(), ps.toByteBuffer( entityId ), name, value ) );
    }
    return m;
}
 
Example #6
Source File: CounterUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public Mutator<ByteBuffer> batchIncrementQueueCounter( Mutator<ByteBuffer> m, UUID queueId, String name, long value,
                                                       long timestamp, UUID applicationId ) {
    if ( logger.isTraceEnabled() ) {
        logger.trace( "BIQC: Incrementing property {} of queue {} by value {}",
                name, queueId, value );
    }
    m.addInsertion( bytebuffer( key( queueId, DICTIONARY_COUNTERS ).toString() ),
            QueuesCF.QUEUE_DICTIONARIES.toString(),
            createColumn( name, ByteBuffer.allocate( 0 ), timestamp, se, be ) );
    if ( "o".equals( counterType ) || "p".equals( counterType ) ) {
        HCounterColumn<String> c = createCounterColumn( name, value );
        ByteBuffer keybytes = bytebuffer( queueId );
        m.addCounter( keybytes, QueuesCF.COUNTERS.toString(), c );
    }
    if ( "n".equals( counterType ) || "p".equals( counterType ) ) {
        PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, ue );
        batcher.add( new Count( QueuesCF.COUNTERS.toString(), ps.toByteBuffer( queueId ), name, value ) );
    }
    return m;
}
 
Example #7
Source File: OpsCiStateDao.java    From oneops with Apache License 2.0 5 votes vote down vote up
public Long getComponentStatesTimestamp(Long manifestIds) {
    CounterQuery<Long, String> query =  HFactory.createCounterColumnQuery(keyspace, longSerializer, stringSerializer);
	query.setKey(manifestIds);
	query.setColumnFamily(SchemaBuilder.COMPONENT_STATE_CF);
	query.setName(COMPONENT_TIMESTAMP);
	QueryResult<HCounterColumn<String>> qResult = query.execute();
		
	HCounterColumn<String> col = qResult.get();
		
	if (col != null) {
		return col.getValue();
	} else {
		return null;
	}
}
 
Example #8
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 #9
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 #10
Source File: CountingMutator.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public <N> MutationResult insertCounter( final K key, final String cf, final HCounterColumn<N> c ) {
    return target.insertCounter( key, cf, c );
}
 
Example #11
Source File: CountingMutator.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public <N> Mutator<K> addCounter( final K key, final String cf, final HCounterColumn<N> c ) {
    target.addCounter( key, cf, c );
    checkAndFlush();
    return this;
}