@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; }
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; }
SliceCounterQuery<String, Long> q = createCounterSliceQuery( ko, se, le ); q.setColumnFamily( APPLICATION_AGGREGATE_COUNTERS.toString() ); q.setRange( start, finish, false, ALL_COUNT );
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 ) )
/** * Constructor * * @param query Base SliceQuery to execute * @param start Starting point of the range * @param finish Finish point of the range. Allows for a dynamically * determined point * @param reversed Whether or not the columns should be reversed * @param count the amount of columns to retrieve per batch */ public SliceCounterIterator(SliceCounterQuery<K, N> query, N start, SliceCounterFinish<N> finish, boolean reversed, int count) { this.query = query; this.start = start; this.finish = finish; this.reversed = reversed; this.count = count; this.query.setRange(this.start, this.finish.function(), this.reversed, this.count); }
private void refresh() { query.setRange(start, finish.function(), reversed, count); columns = 0; List<HCounterColumn<N>> list = query.execute().get().getColumns(); iterator = Iterators.peekingIterator(list.iterator()); if (iterator.hasNext()) { // The lower bound column may have been removed prior to the query executing, // so check to see if the first column returned by the current query is the same // as the lower bound column. If both columns are the same, skip the column N first = list.get(0).getName(); if (first.equals(start)) { next(); } } } /**
/** * Constructor * * @param query Base SliceQuery to execute * @param start Starting point of the range * @param finish Finish point of the range. Allows for a dynamically * determined point * @param reversed Whether or not the columns should be reversed * @param count the amount of columns to retrieve per batch */ public SliceCounterIterator(SliceCounterQuery<K, N> query, N start, SliceCounterFinish<N> finish, boolean reversed, int count) { this.query = query; this.start = start; this.finish = finish; this.reversed = reversed; this.count = count; this.query.setRange(this.start, this.finish.function(), this.reversed, this.count); }
private void refresh() { query.setRange(start, finish.function(), reversed, count); columns = 0; List<HCounterColumn<N>> list = query.execute().get().getColumns(); iterator = Iterators.peekingIterator(list.iterator()); if (iterator.hasNext()) { // The lower bound column may have been removed prior to the query executing, // so check to see if the first column returned by the current query is the same // as the lower bound column. If both columns are the same, skip the column N first = list.get(0).getName(); if (first.equals(start)) { next(); } } } /**
/** * Get counters for the specified label in the given mailbox * * @param mailbox * @param labelId * @return */ public static LabelCounters get(final String mailbox, final Integer labelId) { Composite startRange = new Composite(); startRange.addComponent(0, CN_TYPE_LABEL, Composite.ComponentEquality.EQUAL); startRange.addComponent(1, labelId.toString(), Composite.ComponentEquality.EQUAL); Composite endRange = new Composite(); endRange.addComponent(0, CN_TYPE_LABEL, Composite.ComponentEquality.EQUAL); endRange.addComponent(1, labelId.toString(), Composite.ComponentEquality.GREATER_THAN_EQUAL); SliceCounterQuery<String, Composite> sliceQuery = createCounterSliceQuery(CassandraDAOFactory.getKeyspace(), strSe, new CompositeSerializer()); sliceQuery.setColumnFamily(CF_COUNTERS); sliceQuery.setKey(mailbox); sliceQuery.setRange(startRange, endRange, false, 5); QueryResult<CounterSlice<Composite>> r = sliceQuery.execute(); Map<Integer, LabelCounters> counters = compositeColumnsToCounters(mailbox, r.get().getColumns()); LabelCounters labelCounters = counters.containsKey(labelId) ? counters.get(labelId) : new LabelCounters(); logger.debug("Fetched counters for single label {} with {}", labelId, labelCounters); return labelCounters; }
/** * Get counters for all label in the given mailbox * * @param mailbox * @return */ public static Map<Integer, LabelCounters> getAll(final String mailbox) { Composite startRange = new Composite(); startRange.addComponent(0, CN_TYPE_LABEL, Composite.ComponentEquality.EQUAL); Composite endRange = new Composite(); endRange.addComponent(0, CN_TYPE_LABEL, Composite.ComponentEquality.GREATER_THAN_EQUAL); SliceCounterQuery<String, Composite> sliceQuery = createCounterSliceQuery(CassandraDAOFactory.getKeyspace(), strSe, new CompositeSerializer()); sliceQuery.setColumnFamily(CF_COUNTERS); sliceQuery.setKey(mailbox); sliceQuery.setRange(startRange, endRange, false, LabelConstants.MAX_LABEL_ID); QueryResult<CounterSlice<Composite>> r = sliceQuery.execute(); return compositeColumnsToCounters(mailbox, r.get().getColumns()); }