Search in sources :

Example 6 with QueryParameters

use of com.yahoo.dba.perf.myperf.common.QueryParameters in project mysql_perf_analyzer by yahoo.

the class InnoController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    int status = Constants.STATUS_OK;
    String message = "OK";
    String group = req.getParameter("group");
    String host = req.getParameter("host");
    QueryParameters qps = new QueryParameters();
    qps.setGroup(group);
    qps.setHost(host);
    qps.setSql("mysql_innodb_engine_status");
    ResultList rList = null;
    LinkedHashMap<String, ResultList> listMap = new LinkedHashMap<String, ResultList>();
    DBInstanceInfo dbinfo = null;
    DBConnectionWrapper connWrapper = null;
    try {
        dbinfo = this.frameworkContext.getDbInfoManager().findDB(group, host).copy();
        connWrapper = WebAppUtil.getDBConnection(req, this.frameworkContext, dbinfo);
        if (connWrapper == null) {
            status = Constants.STATUS_BAD;
            message = "failed to connect to target db (" + dbinfo + ")";
        } else {
            rList = this.frameworkContext.getQueryEngine().executeQueryGeneric(qps, connWrapper, qps.getMaxRows());
            logger.info("Done query " + qps.getSql() + " with " + (rList != null ? rList.getRows().size() : 0) + " records.");
            if (rList != null && rList.getRows().size() > 0) {
                logger.info(rList.getRows().get(0).getColumns().get(rList.getRows().get(0).getColumns().size() - 1));
                listMap = parse(rList.getRows().get(0).getColumns().get(rList.getRows().get(0).getColumns().size() - 1));
            }
            WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        }
    } catch (Throwable th) {
        logger.log(Level.SEVERE, "Exception", th);
        if (th instanceof SQLException) {
            SQLException sqlEx = SQLException.class.cast(th);
            String msg = th.getMessage();
            logger.info(sqlEx.getSQLState() + ", " + sqlEx.getErrorCode() + ", " + msg);
            //check if the connection is still good
            if (!DBUtils.checkConnection(connWrapper.getConnection())) {
                WebAppUtil.closeDBConnection(req, connWrapper, true, false);
            } else
                WebAppUtil.closeDBConnection(req, connWrapper, true, false);
        } else {
            if (connWrapper != null)
                WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        }
        status = Constants.STATUS_BAD;
        message = "Exception: " + th.getMessage();
    } finally {
    }
    ModelAndView mv = new ModelAndView(this.jsonView);
    if (req.getParameter("callback") != null && req.getParameter("callback").trim().length() > 0)
        //YUI datasource binding
        mv.addObject("callback", req.getParameter("callback"));
    mv = new ModelAndView(this.jsonView);
    mv.addObject("json_result", ResultListUtil.toMultiListJSONStringUpper(listMap, qps, status, message));
    return mv;
}
Also used : ResultList(com.yahoo.dba.perf.myperf.common.ResultList) SQLException(java.sql.SQLException) ModelAndView(org.springframework.web.servlet.ModelAndView) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) DBConnectionWrapper(com.yahoo.dba.perf.myperf.db.DBConnectionWrapper) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with QueryParameters

use of com.yahoo.dba.perf.myperf.common.QueryParameters in project mysql_perf_analyzer by yahoo.

the class TableMetaProcessor method queryMultiple.

@Override
public void queryMultiple(MyPerfContext context, DBInstanceInfo dbinfo, String appUser, DBConnectionWrapper connWrapper, QueryParameters qps, Map<String, ResultList> rListMap) throws java.sql.SQLException {
    for (int i = 0; i < TBL_QUERIES.length; i++) {
        QueryParameters qps2 = new QueryParameters();
        qps2.setSql(TBL_QUERIES[i]);
        qps2.getSqlParams().put("p_1", qps.getSqlParams().get("p_1"));
        qps2.getSqlParams().put("p_2", qps.getSqlParams().get("p_2"));
        ResultList rList = null;
        try {
            rList = context.getQueryEngine().executeQueryGeneric(qps2, connWrapper, qps.getMaxRows());
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Error when retrieve meta data", th);
            if (th instanceof SQLException) {
                //check if the connection is still good
                if (!DBUtils.checkConnection(connWrapper.getConnection())) {
                    throw SQLException.class.cast(th);
                }
            }
            Sql sql = context.getSqlManager().getSql(qps2.getSql());
            if (sql != null && sql.isErrorInline()) {
                rList = new ResultList();
                ColumnDescriptor desc = new ColumnDescriptor();
                desc.addColumn("Status", false, 0);
                desc.addColumn("Message", false, 1);
                rList.setColumnDescriptor(desc);
                ResultRow row = new ResultRow();
                row.setColumnDescriptor(desc);
                row.addColumn("Error");
                row.addColumn(th.getMessage());
                rList.addRow(row);
            }
        }
        rListMap.put(TBL_QUERIES[i], rList);
    }
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) SQLException(java.sql.SQLException) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) Sql(com.yahoo.dba.perf.myperf.common.Sql)

Aggregations

QueryParameters (com.yahoo.dba.perf.myperf.common.QueryParameters)7 ResultList (com.yahoo.dba.perf.myperf.common.ResultList)6 ResultRow (com.yahoo.dba.perf.myperf.common.ResultRow)5 ColumnDescriptor (com.yahoo.dba.perf.myperf.common.ColumnDescriptor)4 DBInstanceInfo (com.yahoo.dba.perf.myperf.common.DBInstanceInfo)4 SQLException (java.sql.SQLException)4 Map (java.util.Map)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 DBConnectionWrapper (com.yahoo.dba.perf.myperf.db.DBConnectionWrapper)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ColumnInfo (com.yahoo.dba.perf.myperf.common.ColumnInfo)1 ConfigBlock (com.yahoo.dba.perf.myperf.common.ConfigBlock)1 ConfigHistory (com.yahoo.dba.perf.myperf.common.ConfigHistory)1 DBCredential (com.yahoo.dba.perf.myperf.common.DBCredential)1 Sql (com.yahoo.dba.perf.myperf.common.Sql)1 File (java.io.File)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1