Search in sources :

Example 1 with UserDBConnections

use of com.yahoo.dba.perf.myperf.db.UserDBConnections in project mysql_perf_analyzer by yahoo.

the class LogoutController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    HttpSession sess = req.getSession();
    //do we have session
    if (sess != null) {
        UserDBConnections conns = UserDBConnections.class.cast(sess.getAttribute("UserDBConnections"));
        sess.removeAttribute("UserDBConnections");
        sess.invalidate();
        //make it async. 
        new Thread(new LogoutCleaner(conns)).start();
    //TODO Add the thread handle for central process
    }
    ModelAndView mv = new ModelAndView(new RedirectView(this.getNosessView()));
    return mv;
}
Also used : HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections)

Example 2 with UserDBConnections

use of com.yahoo.dba.perf.myperf.db.UserDBConnections in project mysql_perf_analyzer by yahoo.

the class AlertScannerRunner method scan.

private void scan() {
    conns = new UserDBConnections();
    conns.setAppUser(appUser.getName());
    conns.setFrameworkContext(frameworkContext);
    int count = 0;
    while (!dbqueue.isEmpty()) {
        try {
            DBInstanceInfo db = this.dbqueue.poll(1, TimeUnit.SECONDS);
            count++;
            if (db == null || !db.isAlertEnabled())
                continue;
            long startTime = System.currentTimeMillis();
            scanHost(db);
        //this.frameworkContext.getInstanceStatesManager().getStates(db.getDbid()).setLastScanTime(System.currentTimeMillis() - startTime);
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Exception: scan loop", ex);
        }
    }
    logger.info(Thread.currentThread() + " done scan alerts: " + count + " servers.");
}
Also used : UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections)

Example 3 with UserDBConnections

use of com.yahoo.dba.perf.myperf.db.UserDBConnections 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);
        }
    }
}
Also used : ConfigBlock(com.yahoo.dba.perf.myperf.common.ConfigBlock) ArrayList(java.util.ArrayList) DBGroupInfo(com.yahoo.dba.perf.myperf.common.DBGroupInfo) MyPerfContext(com.yahoo.dba.perf.myperf.common.MyPerfContext) UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections) File(java.io.File) Map(java.util.Map) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo)

Example 4 with UserDBConnections

use of com.yahoo.dba.perf.myperf.db.UserDBConnections in project mysql_perf_analyzer by yahoo.

the class MetricScannerRunner method scan.

private void scan() {
    running.set(true);
    conns = new UserDBConnections();
    conns.setAppUser(appUser.getName());
    conns.setFrameworkContext(frameworkContext);
    int count = 0;
    while (!dbqueue.isEmpty() && running.get()) {
        try {
            DBInstanceInfo db = this.dbqueue.poll(1, TimeUnit.SECONDS);
            count++;
            if (db == null || !db.isMetricsEnabled())
                continue;
            long startTime = System.currentTimeMillis();
            scanHost(db);
            //record total scan time for each server
            this.frameworkContext.getInstanceStatesManager().getStates(db.getDbid()).setLastScanTime(System.currentTimeMillis() - startTime);
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Exception: scan loop", ex);
        }
    }
    logger.info(Thread.currentThread() + " done scan metrics: " + count + " servers.");
}
Also used : UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections) SQLException(java.sql.SQLException)

Example 5 with UserDBConnections

use of com.yahoo.dba.perf.myperf.db.UserDBConnections in project mysql_perf_analyzer by yahoo.

the class WebAppUtil method closeDBConnection.

public static void closeDBConnection(HttpServletRequest req, DBConnectionWrapper conn, boolean hasError, boolean reuse) {
    try {
        //get session
        HttpSession sess = req.getSession();
        //get connection manager
        UserDBConnections conns = UserDBConnections.class.cast(sess.getAttribute("UserDBConnections"));
        //if none, we need add one
        if (conns == null) {
            //something wrong. 
            logger.info("Cannot find connection manager");
        } else {
            if (hasError)
                conns.checkinConnectionOnError(conn);
            else if (reuse)
                conns.checkinConnection(conn);
            else
                conns.checkinConnectionAndClose(conn);
        }
    } catch (Throwable th) {
        if (th instanceof RuntimeException)
            throw RuntimeException.class.cast(th);
        throw new RuntimeException(th);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections)

Aggregations

UserDBConnections (com.yahoo.dba.perf.myperf.db.UserDBConnections)6 HttpSession (javax.servlet.http.HttpSession)3 AppUser (com.yahoo.dba.perf.myperf.common.AppUser)1 ConfigBlock (com.yahoo.dba.perf.myperf.common.ConfigBlock)1 DBCredential (com.yahoo.dba.perf.myperf.common.DBCredential)1 DBGroupInfo (com.yahoo.dba.perf.myperf.common.DBGroupInfo)1 DBInstanceInfo (com.yahoo.dba.perf.myperf.common.DBInstanceInfo)1 MyPerfContext (com.yahoo.dba.perf.myperf.common.MyPerfContext)1 DBConnectionWrapper (com.yahoo.dba.perf.myperf.db.DBConnectionWrapper)1 File (java.io.File)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1