예제 #1
0
  @Override
  void handleRollupMetric(BasicRollup basicRollup) throws RuntimeException {
    MaxValue other = basicRollup.getMaxValue();

    if (init) {
      if (other.isFloatingPoint()) {
        this.setDoubleValue(other.toDouble());
      } else {
        this.setLongValue(other.toLong());
      }

      this.init = false;
      return;
    }

    if (this.isFloatingPoint() && !other.isFloatingPoint()) {
      if (this.toDouble() < (double) other.toDouble()) {
        this.setLongValue(other.toLong());
      }
    } else if (!this.isFloatingPoint() && other.isFloatingPoint()) {
      if ((double) this.toLong() < other.toDouble()) {
        this.setDoubleValue(other.toDouble());
      }
    } else if (!this.isFloatingPoint() && !other.isFloatingPoint()) {
      this.setLongValue(Math.max(this.toLong(), other.toLong()));
    } else {
      this.setDoubleValue(Math.max(this.toDouble(), other.toDouble()));
    }
  }
  /**
   * Create a single {@link com.rackspacecloud.blueflood.service.SingleRollupWriteContext} from the
   * given {@link com.rackspacecloud.blueflood.types.IMetric} and Granularity.
   *
   * @param destGran
   * @param metric
   * @return
   * @throws IOException
   */
  protected SingleRollupWriteContext createSingleRollupWriteContext(
      Granularity destGran, IMetric metric) throws IOException {

    Locator locator = metric.getLocator();

    Points<SimpleNumber> points = new Points<SimpleNumber>();
    points.add(
        new Points.Point<SimpleNumber>(
            metric.getCollectionTime(), new SimpleNumber(metric.getMetricValue())));

    BasicRollup rollup = BasicRollup.buildRollupFromRawSamples(points);

    return new SingleRollupWriteContext(
        rollup,
        locator,
        destGran,
        CassandraModel.getBasicColumnFamily(destGran),
        metric.getCollectionTime());
  }
  boolean hasAllZeroData(MetricData dataPoints) {
    boolean allZeroFlag = true;
    // Points should be of type BasicRollup. Will throw an exception if they are not.
    Map<Long, Points.Point<BasicRollup>> points = dataPoints.getData().getPoints();

    for (Map.Entry<Long, Points.Point<BasicRollup>> entry : points.entrySet()) {
      BasicRollup basicRollup = entry.getValue().getData();

      if ((basicRollup.getMaxValue().isFloatingPoint()
              ? basicRollup.getMaxValue().toDouble() != 0.0
              : basicRollup.getMaxValue().toLong() != 0)
          && (basicRollup.getMinValue().isFloatingPoint()
              ? basicRollup.getMinValue().toDouble() != 0.0
              : basicRollup.getMinValue().toLong() != 0)
          && (basicRollup.getAverage().isFloatingPoint()
              ? basicRollup.getAverage().toDouble() != 0.0
              : basicRollup.getAverage().toLong() != 0)) {
        allZeroFlag = false;
        break;
      }
    }
    return allZeroFlag;
  }