use of com.yahoo.dba.perf.myperf.common.ConfigBlock in project mysql_perf_analyzer by yahoo.
the class VarhistoryController method handleRequestImpl.
@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
int status = Constants.STATUS_OK;
String message = "OK";
logger.info("receive url " + req.getQueryString());
QueryParameters qps = null;
DBInstanceInfo dbinfo = null;
//first session check
boolean isSessionValid = WebAppUtil.hasValidSession(req);
if (!isSessionValid)
return this.respondFailure("session timeout. Please logout and re-login.", req);
qps = WebAppUtil.parseRequestParameter(req);
qps.setSql("mysql_global_variables");
dbinfo = this.frameworkContext.getDbInfoManager().findDB(qps.getGroup(), qps.getHost());
if (dbinfo == null)
return this.respondFailure("Cannot find record for DB (" + qps.getGroup() + ", " + qps.getHost() + ")", req);
//when we reach here, at least we have valid query and can connect to db
WebAppUtil.storeLastDbInfoRequest(qps.getGroup(), qps.getHost(), req);
ModelAndView mv = null;
ResultList rList = new ResultList();
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("VARIABLE_NAME", false, 1);
desc.addColumn("VARIABLE_VALUE", false, 2);
desc.addColumn("COMMENTS", false, 3);
rList.setColumnDescriptor(desc);
try {
ConfigHistory ch = ConfigHistory.load(new File(new File(this.frameworkContext.getFileReposirtoryPath()), "autoscan"), dbinfo);
if (ch != null && ch.getChanges().size() > 0) {
{
ResultRow row = new ResultRow();
List<String> cols = new ArrayList<String>();
cols.add("CHANGES");
cols.add("");
cols.add(ch.getStartingConfig().getTime() + " - " + ch.getLastCheckedConfig().getTime());
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
//list changed in reverse order
for (int i = ch.getChanges().size() - 1; i >= 0; i--) {
ConfigBlock cb = ch.getChanges().get(i);
ResultRow row = new ResultRow();
List<String> cols = new ArrayList<String>();
cols.add("CHANGE TIME");
cols.add(cb.getTime());
cols.add("Timestamp (UTC) when checked");
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
HashMap<String, String> changes = new HashMap<String, String>();
//scan changes with old value
for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
String key = e.getKey();
String val = e.getValue();
if (key.startsWith("+-")) {
changes.put(key.substring(2), val);
}
}
for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
String key = e.getKey();
String v = e.getValue();
row = new ResultRow();
cols = new ArrayList<String>();
if (key.startsWith("+-"))
//skip
continue;
else if (key.startsWith("+-"))
//removed
cols.add(key.substring(1));
else
cols.add(key);
cols.add(v);
if (changes.containsKey(key))
cols.add("Prev Value: " + changes.get(key));
else if (key.startsWith("-"))
cols.add("Removed");
else
cols.add("");
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
//add an empty line
row = new ResultRow();
cols = new ArrayList<String>();
cols.add("");
cols.add("");
cols.add("");
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
}
if (ch != null) {
ConfigBlock cb = ch.getStartingConfig();
ResultRow row = new ResultRow();
List<String> cols = new ArrayList<String>();
cols.add("FIRST RECORD TIME");
cols.add(cb.getTime());
if (ch != null && ch.getChanges().size() > 0)
cols.add("First Recorded Timestamp (UTC)");
else
cols.add("No Changes Since First Check (Timestamp UTC)");
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
String key = e.getKey();
String v = e.getValue();
row = new ResultRow();
cols = new ArrayList<String>();
cols.add(key);
cols.add(v);
cols.add("");
row.setColumns(cols);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
} else {
status = Constants.STATUS_BAD;
message = "No variable configuration history has been recorded yet.";
}
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Exception", ex);
status = Constants.STATUS_BAD;
message = "Exception: " + ex.getMessage();
}
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.addObject("json_result", ResultListUtil.toJSONString(rList, qps, status, message));
return mv;
}
use of com.yahoo.dba.perf.myperf.common.ConfigBlock in project mysql_perf_analyzer by yahoo.
the class GlobalVariableChangeScanTask method run.
@Override
public void run() {
Thread.currentThread().setName("GlobalVariableChangeScanTask");
conns = new UserDBConnections();
conns.setAppUser(appUser.getName());
conns.setFrameworkContext(context);
File root = new File(new File(this.context.getFileReposirtoryPath()), STORAGE_DIR);
//get all dbids
List<DBInstanceInfo> dbs = new ArrayList<DBInstanceInfo>();
for (Map.Entry<String, DBGroupInfo> e : context.getDbInfoManager().getClusters().entrySet()) {
DBGroupInfo g = e.getValue();
for (DBInstanceInfo i : g.getInstances()) {
dbs.add(i);
}
}
//now get current timestamp
sdf = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
for (//now we need scan for each db
DBInstanceInfo db : //now we need scan for each db
dbs) {
ConfigBlock cb = scanHost(db);
if (cb != null) {
updateConfigBlock(db, cb);
}
}
}
use of com.yahoo.dba.perf.myperf.common.ConfigBlock in project mysql_perf_analyzer by yahoo.
the class GlobalVariableChangeScanTask method scanHost.
private ConfigBlock scanHost(DBInstanceInfo dbinfo) {
boolean status = false;
DBCredential cred = DBUtils.findDBCredential(context, dbinfo.getDbGroupName(), appUser);
if (cred == null) {
logger.info("No credential for cluster " + dbinfo.getDbGroupName() + ", skip it");
//log the error
return null;
}
logger.info("Scan for host (" + dbinfo + ") as user " + cred.getUsername());
//find one connection is enough
DBConnectionWrapper conn = null;
Statement stmt = null;
ResultSet rs = null;
ConfigBlock cb = null;
try {
conn = conns.checkoutConnection(dbinfo, cred);
if (conn == null) {
logger.info("Failed to access " + dbinfo + ", skip it");
return null;
}
String sqlText = "select variable_name, variable_value from information_schema.global_variables";
stmt = conn.getConnection().createStatement();
rs = stmt.executeQuery(sqlText);
cb = new ConfigBlock();
while (rs != null && rs.next()) {
String key = rs.getString("variable_name");
//exclude a timestamp variable
if ("TIMESTAMP".equalsIgnoreCase(key))
continue;
cb.addVariable(key, rs.getString("variable_value"));
}
Calendar c = Calendar.getInstance();
Date dt = c.getTime();
cb.setTime(sdf.format(dt));
} catch (Exception ex) {
logger.log(Level.WARNING, "exception", ex);
} finally {
DBUtils.close(rs);
DBUtils.close(stmt);
if (conn != null)
conns.checkinConnectionAndClose(conn);
}
logger.info("Done configuration scan for host (" + dbinfo + ") as user " + cred.getUsername());
return cb;
}
Aggregations