Esempio n. 1
0
  private AvailabilityView getView(Endpoint ep) {
    AvailabilityView view = null;
    List<AvailabilityView> views =
        _db.getResults(ep, AvailabilityView.class, AvailabilityView.SCHEMA$);
    if (views.size() != 1) {
      Log.warn("We have {} AvailabilityView, expected was 1", views.size());
    }
    if (views.size() == 0) {
      view = new AvailabilityView();
      view.setEndpoint(ep);
      _db.insert(view);

    } else {
      view = views.get(0);
    }
    return view;
  }
Esempio n. 2
0
  /**
   * Computes the aggregated statistics for the Availability task
   *
   * @param ep
   */
  public boolean analyse(AResult ares) {
    try {
      log.info("[ANALYSE] {}", ares);

      Calendar now = Calendar.getInstance();
      now.setTimeInMillis(ares.getEndpointResult().getStart());
      log.debug("Start date: {}", now.getTime());

      Endpoint ep = ares.getEndpointResult().getEndpoint();
      Calendar[] dates = _dates.getDates(ares.getEndpointResult().getStart());

      // get the views
      AvailabilityView aview = getView(ep);
      EPView epview = getEPView(ep);

      // query mongodb for all AResults in the last 31 days
      List<AResult> results =
          _db.getResultsSince(
              ep,
              AResult.class,
              AResult.SCHEMA$,
              dates[LAST_31DAYS].getTimeInMillis(),
              now.getTimeInMillis());
      log.debug(
          "Query for {}< - >={} returned " + results.size() + " results",
          dates[LAST_31DAYS].getTime(),
          now.getTime());

      SummaryStatistics last24HoursStats = new SummaryStatistics();
      SummaryStatistics last7DaysStats = new SummaryStatistics();
      SummaryStatistics last31DaysStats = new SummaryStatistics();
      SummaryStatistics thisWeekStats = new SummaryStatistics();

      for (AResult res : results) {
        long start = res.getEndpointResult().getStart();
        Calendar next = Calendar.getInstance();
        next.setTimeInMillis(start);

        if (start > dates[LAST_24HOURS].getTimeInMillis()) {
          update(last24HoursStats, res);
          log.debug("  {} >24h {}", next.getTime(), dates[LAST_24HOURS].getTime());
        }
        if (start > dates[LAST_7DAYS].getTimeInMillis()) {
          update(last7DaysStats, res);
          log.debug("  {} >7d {}", next.getTime(), dates[LAST_7DAYS].getTime());
        }
        if (start > dates[LAST_31DAYS].getTimeInMillis()) {
          update(last31DaysStats, res);
          log.debug("  {} >31d {}", next.getTime(), dates[LAST_31DAYS].getTime());
        }
        if (start > dates[THIS_WEEK].getTimeInMillis()) {
          update(thisWeekStats, res);
          log.debug("  {} >week {}", next.getTime(), dates[THIS_WEEK].getTime());
        }
      }

      // Update the views
      EPViewAvailability epav = epview.getAvailability();

      double last24HouerMean = 0;
      if (!Double.isNaN(last24HoursStats.getMean())) last24HouerMean = last24HoursStats.getMean();
      epav.setUptimeLast24h(last24HouerMean);
      aview.setUptimeLast24h(last24HouerMean);

      boolean upNow = ares.getIsAvailable();
      aview.setUpNow(upNow);
      epav.setUpNow(upNow);

      double last7dayMean = 0;
      if (!Double.isNaN(last7DaysStats.getMean())) last7dayMean = last7DaysStats.getMean();
      aview.setUptimeLast7d(last7dayMean);
      epav.setUptimeLast7d(last7dayMean);

      double thisweek = 0D;
      if (!Double.isNaN(thisWeekStats.getMean())) {
        thisweek = thisWeekStats.getMean();
      }

      Long key = dates[THIS_WEEK].getTimeInMillis();
      boolean exists = false;
      for (EPViewAvailabilityDataPoint dd : epav.getData().getValues()) {
        //			System.out.println(dd.getX()+" =?= "+key);
        if (dd.getX().equals(key)) {
          exists = true;
          dd.setY(thisweek);
        }
      }
      //		System.out.println(exists);
      if (!exists) {
        epav.getData().getValues().add(new EPViewAvailabilityDataPoint(key, thisweek));
        log.debug("Add new week: " + key);
      }

      //		if(thisweek<1D && thisweek>0D){
      //			System.out.println("Hello");
      //		}

      double last31dayMean = 0;
      if (!Double.isNaN(last31DaysStats.getMean())) last31dayMean = last31DaysStats.getMean();
      epav.setUptimeLast31d(last31dayMean);

      // update overallUp
      int runs = epav.getTestRuns();
      Double mean = epav.getUptimeOverall() * runs;
      if (mean == null) mean = 0D;
      if (upNow) mean += 1;
      epav.setTestRuns(runs + 1);
      epav.setUptimeOverall(mean / (double) (runs + 1));

      log.debug("  [AView] {}", aview);
      log.debug("  [EPView] {}", epview);
      aview.setLastUpdate(ares.getEndpointResult().getEnd());

      boolean succ = false;
      succ = _db.update(aview);
      succ = _db.update(epview);

      //		System.err.println("AView (after)="+aview);
      //		System.err.println("EPView (after)="+epview);

      return succ;
    } catch (Exception e) {
      log.warn("[EXEC] {}", e);
    }
    return false;
  }