@Override
  public String execute() throws Exception {
    Connection conn = null;
    List<Slice> slices = new LinkedList<Slice>();
    try {
      conn = Constants.DATASOURCE.getConnection();
      PreparedStatement stmt =
          conn.prepareStatement(SqlQuery.SERVICES_ON_HOSTS_BY_PROJECT.getSql());
      stmt.setInt(1, idProject);

      ResultSet rs = stmt.executeQuery();

      while (rs.next()) {
        String name = rs.getString("name") == null ? rs.getString("ip") : rs.getString("name");
        int count = rs.getInt("conteggio");
        Slice slice = new Slice();
        slice.setLabel(name + "[" + count + "]");
        slice.setTooltip(name + "\n" + count + " running services");
        slice.setValue(count);
        slices.add(slice);
      }
      rs.close();
      stmt.close();
    } catch (SQLException e) {
      return ERROR;
    } finally {
      if (conn != null) conn.close();
    }
    String[] colors = {
      "000000", "0000ff", "00ffff", "00ff00", "ffff00", "ff0000", "ff00ff", "ffffff"
    };
    if (slices.size() != 0) {
      int increment = 0;
      for (Slice slice : slices) {
        slice.setColour("#" + colors[increment]);
        increment = (increment + 1) % colors.length;
      }
      if (slices.size() % colors.length == 1) slices.get(slices.size() - 1).setColour(colors[1]);
    }
    pieChart = new PieChart();
    List<ElementPie> elements = new LinkedList<ElementPie>();
    ElementPie element = new ElementPie();
    element.setAlpha(0.9f);
    pieChart.setTitle(
        new Title(
            "Services Distribution",
            "{" + getText("avgProjectActivityPieChart.title.style") + "}"));
    element.setValues(slices);
    element.setGradientFill(true);
    element.setRadius(50);
    element.setStartAngle(0);
    elements.add(element);
    pieChart.setBg_colour(getText("chart.defaultBgColor"));
    pieChart.setBorder(1);
    pieChart.setAnimate(true);
    pieChart.setElements(elements);

    return SUCCESS;
  }
コード例 #2
0
  @Override
  public String execute() throws Exception {
    Connection conn = null;
    PreparedStatement cStmt = null;
    String query;
    try {
      conn = Constants.DATASOURCE.getConnection();
      Long step = (super.cF.getTimeInMillis() - super.cI.getTimeInMillis()) / 1000;
      step = step / super.spansNumber + (step % super.spansNumber == 0L ? 0 : 1); // round up

      cI.add(Calendar.SECOND, (int) (start * step));
      Calendar c = null;
      if (limit != null && limit <= super.spansNumber)
        (c = (Calendar) cI.clone()).add(Calendar.SECOND, (int) (limit * step));
      else c = (Calendar) cF.clone();
      if (c.before(cF)) cF = c;

      // CallableStatement cStmt = conn.prepareCall(SqlQuery.SP_RTT_CHART.getSql());
      // cStmt.setInt(1, super.idServiceInstance);
      // cStmt.setTimestamp(2, new Timestamp(super.cI.getTimeInMillis()));
      // cStmt.setTimestamp(3, new Timestamp(super.cF.getTimeInMillis()));
      // cStmt.setLong(4, step);

      table = new ActivityTable();
      List<ActivityRecord> records = new LinkedList<ActivityRecord>();
      DateFormat formatter = new DateFormat(getLocale().getLanguage());
      c = (Calendar) cI.clone();
      // boolean hadResults = cStmt.execute();
      boolean fullTime = step < 60;

      if (step > 0) {
        while (c.getTimeInMillis() < cF.getTimeInMillis()) {

          query =
              "SELECT AVG(elapsedTime) as avgRtt FROM  esgf_dashboard.service_status WHERE idServiceInstance=";
          query = query + super.idServiceInstance;
          query = query + " AND timestamp between '";
          query = query + new Timestamp(c.getTimeInMillis()) + "' AND '";

          // while(hadResults) {
          // ResultSet rs = cStmt.getResultSet();
          ActivityRecord record = new ActivityRecord();
          record.setStartDate(formatter.formatDate(c));
          record.setStartTime(formatter.formatTime(c, fullTime));
          c.add(Calendar.SECOND, step.intValue());

          query = query + new Timestamp(c.getTimeInMillis()) + "'";
          // System.out.println("|||->>> RTTTableAction Query = "+query);

          cStmt = conn.prepareStatement(query);
          ResultSet rs = cStmt.executeQuery();

          record.setEndDate(formatter.formatDate(c));
          record.setEndTime(formatter.formatTime(c, fullTime));
          record.setValues(new LinkedList<Number>());
          if (rs.next() && rs.getBigDecimal("avgRtt") != null)
            record
                .getValues()
                .add(Math.round(rs.getBigDecimal("avgRtt").doubleValue() / 10.) / 100.);
          else record.getValues().add(null);
          records.add(record);
          // hadResults = cStmt.getMoreResults();
        } // endwhile
      } // endif
      cStmt.close();
      table.setActivityRecords(records);
      table.setTotalCount(super.spansNumber);
    } catch (SQLException e) {
      return ERROR;
    } finally {
      if (conn != null) conn.close();
    }
    return SUCCESS;
  }