Exemplo n.º 1
0
  public static String saveTopologyData(Customer cust, TopologyData3 td) {
    String text = null;
    try {
      boolean needRollback = true;
      Connection c =
          ManagementContainer.getInstance().getDBConnection(ManagementContainer.POOL_NAME);
      try {
        TopologyStats ts = saveTopologyData(cust, td, c);
        if (td.getRunType() != DirectoryData.TYPE_MANUAL_NOCOMMIT) {
          c.commit();
          needRollback = false;
        }

        switch (td.getRunType()) {
          case DirectoryData.TYPE_MANUAL_FORCED:
            text =
                s_topologySuccessMessageForced.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
            break;
          case DirectoryData.TYPE_MANUAL_NOCOMMIT:
            text =
                s_topologySuccessMessageNoCommit.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
            break;
          default:
            text =
                s_topologySuccessMessage.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
        }

        return text;
      } finally {
        if (needRollback) {
          c.rollback();
        }
        ManagementContainer.getInstance().safeReturnDBConnection(c, ManagementContainer.POOL_NAME);
        // report info **after** connection is closed
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("saveTopologyData completed: " + text);
        }
      }
    } catch (Exception e) {
      s_logger.error("Exception while saving the topology data.", e);
      return "An error occurred while saving the topology data.";
    }
  }
Exemplo n.º 2
0
  public void purgeLogEvents(final List<SearchConstraint> constraints, final int daysToKeep) {
    blockHereIfBadNfs();

    StringBuffer sql =
        new StringBuffer(
            "select u.mail_directory || '/logs/' || e.event_id || '.log' "
                + "from dat_client_log_events e, dat_user_account u "
                + "where event_time < current_timestamp - (? || ' days')::interval "
                + "and e.has_log_file != 0 "
                + "and e.user_id = u.object_id");
    appendWhereConstraints(sql, constraints, s_propToColumnMap);
    m_logCategory.info("Purge event logs query is\n" + sql);

    StringBuffer sql2 =
        new StringBuffer(
            "delete from dat_client_log_events "
                + "where event_time < current_timestamp - (? || ' days')::interval");
    if (!constraints.isEmpty()) {
      sql2.append(" and event_id in (select e.event_id from dat_client_log_events e ");
      appendWhere(sql2, constraints, s_propToColumnMap);
      sql2.append(")");
    }
    m_logCategory.info("Purge event logs query is\n" + sql2);

    try {
      Connection c = m_txManager.getConnection();
      PreparedStatement stmt = null;
      ResultSet rs = null;
      boolean needsRollback = true;
      try {
        stmt = c.prepareStatement(sql.toString());
        stmt.setInt(1, daysToKeep);
        rs = stmt.executeQuery();
        while (rs.next()) {
          File logFile = new File(getNfsRoot(), rs.getString(1));
          // nfs usage, but DB transaction takes no locks.
          if (logFile.exists()) {
            boolean ok = logFile.delete();
            if (!ok) {
              m_logger
                  .log("Unable to delete")
                  .param(LoggingConsts.FILENAME, logFile.getAbsolutePath())
                  .warn();
            }
          } // file exists.
        } // each row

        // Below, no nfs usage occurs.  We can use the same connection.
        // the 'sql delete' may use DB locks.
        stmt = c.prepareStatement(sql2.toString());
        stmt.setInt(1, daysToKeep);
        stmt.executeUpdate();
        c.commit();
        needsRollback = false;
      } finally {
        DbUtils.safeClose(rs);
        DbUtils.safeClose(stmt);
        if (needsRollback) {
          c.rollback();
        }
        m_txManager.returnConnection(c);
      }
    } catch (Exception ex) {
      m_logger.log("Error in purgeLogEvents").warn(ex);
    }
  }