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;
}
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);
}
}
Aggregations