Example #1
0
  public static List<String> getDestinationQueueNamesFromCounterColumns(
      String columnFamilyName, String rowName, Keyspace keyspace)
      throws CassandraDataAccessException {
    ArrayList<String> rowList = new ArrayList<String>();

    if (keyspace == null) {
      throw new CassandraDataAccessException("Can't access Data , no keyspace provided ");
    }

    if (columnFamilyName == null || rowName == null) {
      throw new CassandraDataAccessException(
          "Can't access data with columnFamily =" + columnFamilyName + " and rowName=" + rowName);
    }

    try {

      SliceCounterQuery<String, String> sliceQuery =
          HFactory.createCounterSliceQuery(keyspace, stringSerializer, stringSerializer);
      sliceQuery.setKey(rowName);
      sliceQuery.setColumnFamily(columnFamilyName);
      sliceQuery.setRange("", "", false, Integer.MAX_VALUE);

      QueryResult<CounterSlice<String>> result = sliceQuery.execute();
      CounterSlice<String> columnSlice = result.get();
      for (HCounterColumn<String> column : columnSlice.getColumns()) {
        rowList.add(column.getName());
      }
    } catch (Exception e) {
      throw new CassandraDataAccessException(
          "Error while accessing data from :" + columnFamilyName, e);
    }
    return rowList;
  }
  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;
  }
  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);
  }