Search in sources :

Example 1 with AppUser

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

the class MetaDB method changePasssword.

/**
   * Update user password hash
   * @param user
   * @param newPwd
   * @return
   */
public boolean changePasssword(String user, String newPwd) {
    if (user == null)
        return false;
    String sql2 = "update " + APPUSER_TABLENAME + " set MD5HASH=? where USERNAME=?";
    Connection conn = null;
    PreparedStatement pstmt = null;
    try {
        conn = getConnection();
        //first, check if we have record
        AppUser appUser = this.retrieveUserInfo(conn, user);
        if (appUser == null)
            return false;
        appUser.setPassword(newPwd);
        appUser.setMd5Hash(appUser.calMd5(newPwd));
        pstmt = conn.prepareStatement(sql2);
        pstmt.setString(1, appUser.getMd5Hash());
        pstmt.setString(2, appUser.getName().toLowerCase());
        pstmt.execute();
        conn.commit();
        return true;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception", ex);
        if (conn != null)
            try {
                conn.rollback();
            } catch (Exception iex) {
            }
        throw new RuntimeException(ex);
    } finally {
        DBUtils.close(pstmt);
        DBUtils.close(conn);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) AppUser(com.yahoo.dba.perf.myperf.common.AppUser) SQLException(java.sql.SQLException)

Example 2 with AppUser

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

the class MetaDB method retrieveAllUsers.

/**
   * List all registered users
   * @return
   */
public java.util.List<AppUser> retrieveAllUsers() {
    String sql = "select * from " + APPUSER_TABLENAME + " order by username";
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    java.util.ArrayList<AppUser> userList = new java.util.ArrayList<AppUser>();
    try {
        conn = getConnection();
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs != null && rs.next()) {
            AppUser user = new AppUser();
            user.setName(rs.getString("USERNAME"));
            //user.setMd5Hash(rs.getString("MD5HASH"));
            user.setUserprivilege(rs.getShort("USER_PRIVILEGE"));
            user.setEmail(rs.getString("EMAIL"));
            user.setVerified("1".equals(rs.getString("VERIFIED")));
            userList.add(user);
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception", ex);
    } finally {
        DBUtils.close(rs);
        DBUtils.close(stmt);
        DBUtils.close(conn);
    }
    return userList;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) AppUser(com.yahoo.dba.perf.myperf.common.AppUser) SQLException(java.sql.SQLException)

Example 3 with AppUser

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

the class UdmController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    String message = "OK";
    String cmd = req.getParameter("cmd");
    boolean isValid = true;
    UserDefinedMetrics udm = null;
    logger.info("receive cmd " + cmd + ", url " + req.getQueryString());
    //it a form request
    if ((cmd == null || cmd.isEmpty()) && !WebAppUtil.hasValidSession(req)) {
        return new ModelAndView(new RedirectView(nosessView));
    }
    //first session check
    boolean isSessionValid = WebAppUtil.hasValidSession(req);
    if (!isSessionValid)
        return this.respondFailure("session timeout. Please logout and re-login.", req);
    AppUser appUser = AppUser.class.cast(req.getSession().getAttribute(AppUser.SESSION_ATTRIBUTE));
    ModelAndView mv = null;
    //By default, just display the page
    if (//or any invalid command
    cmd == null || cmd.isEmpty())
        message = null;
    if ("test".equals(cmd) || "publish".equals(cmd)) {
        if (appUser.isAdminUser())
            return this.processNewUDM(req, resp);
        else
            return this.respondFailure("Non admin user is not allowed to add UDM", req);
    } else if ("test_alert".equals(cmd) || "publish_alert".equals(cmd)) {
        if (appUser.isAdminUser())
            return this.processNewAlert(req, resp);
        else
            return this.respondFailure("Non admin user is not allowed to add UDM", req);
    } else if (//display
    "udm_detail".equalsIgnoreCase(cmd)) {
        String name = req.getParameter("name");
        udm = this.frameworkContext.getMetricsDef().getUdmManager().getUDMByName(name);
        if (udm != null) {
            mv = new ModelAndView(this.jsonView);
            String res = "{\"resp\":{\"status\": 0, \"message\":\"OK\", \"udm\": " + udm.toJSON(true) + "}}";
            //logger.info("UDM detail: "+res);
            mv.addObject("json_result", res);
            return mv;
        } else
            return this.respondFailure("UDM " + name + " not found", req);
    } else if (//display
    "alert_detail".equalsIgnoreCase(cmd)) {
        String name = req.getParameter("name");
        AlertDefinition alert = this.frameworkContext.getMetricsDef().getUdmManager().getAlertByName(name);
        if (alert != null) {
            mv = new ModelAndView(this.jsonView);
            String res = "{\"resp\":{\"status\": 0, \"message\":\"OK\", \"alert\": " + alert.toJSON(true) + "}}";
            //logger.info("UDM detail: "+res);
            mv.addObject("json_result", res);
            return mv;
        } else
            return this.respondFailure("ALERT " + name + " not found", req);
    } else if (//display
    "udmdb_detail".equalsIgnoreCase(cmd))
        return processUDMDBDetail(req, resp);
    else if (//display
    "udmdb_update".equalsIgnoreCase(cmd))
        return processUDMDBUpdate(req, resp, appUser);
    else if (//display
    "alertdb_update".equalsIgnoreCase(cmd))
        return this.processAlertDBUpdate(req, resp, appUser);
    mv = new ModelAndView(this.formView);
    //udm list
    List<String> udms = new ArrayList<String>();
    for (Map.Entry<String, UserDefinedMetrics> e : this.frameworkContext.getMetricsDef().getUdmManager().getUdms().entrySet()) {
        udms.add(e.getKey());
    }
    mv.addObject("udms", udms);
    //alerts
    List<String> alerts = new ArrayList<String>();
    for (Map.Entry<String, AlertDefinition> e : this.frameworkContext.getMetricsDef().getUdmManager().getAlerts().entrySet()) {
        alerts.add(e.getKey());
    }
    mv.addObject("alerts", alerts);
    //predefined
    Map<String, String> predefined = new TreeMap<String, String>();
    String[] predefinedGroups = this.frameworkContext.getMetricsDef().getGroupNames();
    for (String gname : predefinedGroups) {
        MetricsGroup g = this.frameworkContext.getMetricsDef().getGroupByName(gname);
        List<MetricsGroup> subGroups = g.getSubGroups();
        if (subGroups != null && subGroups.size() > 0) {
            for (MetricsGroup subG : subGroups) predefined.put(gname + "." + subG.getGroupName(), subG.isAuto() ? "y" : "n");
        } else
            predefined.put(gname, g.isAuto() ? "y" : "n");
    }
    mv.addObject("predefined", predefined);
    if (WebAppUtil.hasValidSession(req)) {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().listDbsByUserInfo(WebAppUtil.findUserFromRequest(req), retrieveAppUser(req).isRestrictedUser()));
        mv.addObject("mydbSize", this.frameworkContext.getDbInfoManager().getMyDatabases(WebAppUtil.findUserFromRequest(req), retrieveAppUser(req).isRestrictedUser()).size());
    } else {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().getClusters().keySet());
        mv.addObject("mydbSize", 0);
    }
    mv.addObject("dbMap", this.frameworkContext.getDbInfoManager().getClusters());
    mv.addObject("help_key", "udm");
    if (!isValid && message != null)
        mv.addObject("message", message);
    else if (message != null)
        mv.addObject("okmessage", message);
    if (cmd != null)
        mv.addObject("cmd", cmd);
    mv.addObject("u", appUser);
    return mv;
}
Also used : UserDefinedMetrics(com.yahoo.dba.perf.myperf.common.UserDefinedMetrics) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) AppUser(com.yahoo.dba.perf.myperf.common.AppUser) TreeMap(java.util.TreeMap) MetricsGroup(com.yahoo.dba.perf.myperf.common.MetricsGroup) RedirectView(org.springframework.web.servlet.view.RedirectView) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) AlertDefinition(com.yahoo.dba.perf.myperf.common.AlertDefinition)

Example 4 with AppUser

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

the class StatusController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    AppUser appUser = retrieveAppUser(req);
    HashSet<String> filteredGroups = new HashSet<String>();
    boolean useFilter = false;
    if (appUser != null && appUser.isRestrictedUser()) {
        useFilter = true;
        Set<String> mydbs = this.frameworkContext.getDbInfoManager().getMyDatabases(appUser.getName(), appUser.isRestrictedUser()).getMyDbList();
        if (mydbs != null) {
            for (String s : mydbs) filteredGroups.add(s);
        }
    }
    String dbgroup = req.getParameter("group");
    if (dbgroup == null || dbgroup.trim().length() == 0)
        dbgroup = "all";
    String dbhost = req.getParameter("host");
    java.util.Date now = new java.util.Date();
    //the first scan yet to complete
    long oneinterval = (this.frameworkContext.getMyperfConfig().getScannerIntervalSeconds() + 1) * 1000;
    boolean withinOneScan = (now.getTime() - this.frameworkContext.getStartTime().getTime()) <= oneinterval;
    long twointerval = (2 * this.frameworkContext.getMyperfConfig().getScannerIntervalSeconds() + 1) * 1000;
    ResultList rList = new ResultList();
    //if("all".equalsIgnoreCase(dbgroup))
    if (//we should have id either as all or a dbgroup
    dbhost == null || dbhost.isEmpty()) {
        ColumnDescriptor desc = new ColumnDescriptor();
        desc.addColumn("DBGROUP", false, 1);
        desc.addColumn("HOST", false, 2);
        desc.addColumn("QUERIES /SEC", true, 3);
        desc.addColumn("SYS CPU%", true, 4);
        desc.addColumn("USER CPU%", true, 5);
        desc.addColumn("IOWAIT%", true, 6);
        desc.addColumn("LOAD AVG", true, 7);
        desc.addColumn("REPL LAG", true, 8);
        desc.addColumn("FREE MEM (MB)", true, 9);
        desc.addColumn("SLOW QUERY /MIN", true, 10);
        desc.addColumn("THREADS RUNNING", true, 11);
        desc.addColumn("THREADS", true, 12);
        desc.addColumn("CONNECTIONS /SEC", true, 13);
        desc.addColumn("ABORTED CC /SEC", true, 14);
        desc.addColumn("DEADLOCKS", false, 15);
        desc.addColumn("STATUS", false, 16);
        desc.addColumn("LAST CHECK TIME", false, 17);
        desc.addColumn("LAST ALERT", false, 18);
        desc.addColumn("SCAN TIME", true, 19);
        rList.setColumnDescriptor(desc);
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        java.text.DecimalFormat df = new java.text.DecimalFormat("#.###");
        for (Map.Entry<String, DBGroupInfo> e : this.frameworkContext.getDbInfoManager().getClusters().entrySet()) {
            for (DBInstanceInfo dbinfo : e.getValue().getInstances()) {
                String dbgroupName = dbinfo.getDbGroupName();
                String dbHostName = dbinfo.getHostName();
                if (!"all".equals(dbgroup) && !dbgroup.equalsIgnoreCase(dbgroupName))
                    continue;
                if (useFilter && !filteredGroups.contains(dbgroupName))
                    continue;
                InstanceStates stateSnaps = this.frameworkContext.getInstanceStatesManager().getStates(dbinfo.getDbid());
                if (stateSnaps == null)
                    continue;
                //java.util.Date lastConnectTime = this.frameworkContext.getDbInfoManager().getLastAccessDate(dbgroupName, dbHostName);
                java.util.Date lastConnectTime = stateSnaps.getLastAccessTime();
                String dbstatus = "Green";
                if (lastConnectTime == null && withinOneScan)
                    dbstatus = "Unknown";
                else if (lastConnectTime == null)
                    dbstatus = "Red";
                else if (now.getTime() - lastConnectTime.getTime() > twointerval)
                    dbstatus = "Red";
                else if (now.getTime() - lastConnectTime.getTime() > oneinterval)
                    dbstatus = "Yellow";
                ResultRow row = new ResultRow();
                row.setColumnDescriptor(desc);
                List<String> vals = new ArrayList<String>();
                vals.add(dbgroupName);
                vals.add(dbHostName);
                StateSnapshot[] snaps = stateSnaps.copySnapshots();
                boolean isSnapValid = snaps[0].getTimestamp() >= 0L && snaps[1].getTimestamp() > snaps[0].getTimestamp();
                long interval = snaps[1].getTimestamp() - snaps[0].getTimestamp();
                if (isSnapValid) {
                    //sys CPU
                    double syscpu = 0.0f;
                    double usercpu = 0.0f;
                    double iowaits = 0.0f;
                    double loadAvg = 0.0f;
                    int activeThreads = 0;
                    if (snaps[0].getQueries() >= 0L && snaps[1].getQueries() >= 0L) {
                        //double val = ((double)(snaps[1].getQueries() - snaps[0].getQueries())*1000)/(double)interval;
                        double val = diffAvgNoNegative(snaps[1].getQueries(), snaps[0].getQueries(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
                        vals.add(df.format(val));
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[0].getSyscputime() >= 0L && snaps[1].getSyscputime() >= 0L) {
                        if (snaps[0].getSyscputime() == snaps[1].getSyscputime()) {
                            syscpu = 0.0;
                            vals.add("0.00");
                        } else {
                            double val = ((double) (snaps[1].getSyscputime() - snaps[0].getSyscputime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
                            vals.add(df.format(val));
                            syscpu = val;
                        }
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[0].getUsercputime() >= 0L && snaps[1].getUsercputime() >= 0L) {
                        if (snaps[0].getUsercputime() == snaps[1].getUsercputime()) {
                            usercpu = 0.0;
                            vals.add("0.00");
                        } else {
                            double val = ((double) (snaps[1].getUsercputime() - snaps[0].getUsercputime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
                            vals.add(df.format(val));
                            usercpu = val;
                        }
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[0].getIotime() >= 0L && snaps[1].getIotime() >= 0L) {
                        if (snaps[0].getIotime() == snaps[1].getIotime()) {
                            iowaits = 0.0;
                            vals.add("0.00");
                        } else {
                            double val = ((double) (snaps[1].getIotime() - snaps[0].getIotime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
                            vals.add(df.format(val));
                            iowaits = val;
                        }
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[1].getLoadAverage() >= 0.0f) {
                        vals.add(df.format(snaps[1].getLoadAverage()));
                        loadAvg = snaps[1].getLoadAverage();
                    } else
                        vals.add("0.00");
                    vals.add(String.valueOf(snaps[1].getReplLag()));
                    if (snaps[1].getAvailableMem() >= 0L) {
                        long val = snaps[1].getAvailableMem() / 1024;
                        vals.add(String.valueOf(val));
                    } else
                        vals.add("0.00");
                    if (snaps[0].getSlowQueryCount() >= 0L && snaps[1].getSlowQueryCount() >= 0L) {
                        double val = diffAvgNoNegative(snaps[1].getSlowQueryCount(), snaps[0].getSlowQueryCount(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 60000);
                        vals.add(df.format(val));
                    } else
                        vals.add("0.00");
                    vals.add(String.valueOf(snaps[1].getActiveThreads()));
                    activeThreads = snaps[1].getActiveThreads();
                    vals.add(String.valueOf(snaps[1].getThreads()));
                    if (snaps[0].getConnections() >= 0L && snaps[1].getConnections() >= 0L) {
                        //double val = ((double)(snaps[1].getConnections() - snaps[0].getConnections())*1000)/(double)interval;
                        double val = diffAvgNoNegative(snaps[1].getConnections(), snaps[0].getConnections(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
                        vals.add(df.format(val));
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[0].getAbortedConnectsClients() >= 0L && snaps[1].getAbortedConnectsClients() >= 0L) {
                        //double val = ((double)(snaps[1].getAbortedConnectsClients() - snaps[0].getAbortedConnectsClients())*1000)/(double)interval;
                        double val = diffAvgNoNegative(snaps[1].getAbortedConnectsClients(), snaps[0].getAbortedConnectsClients(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
                        vals.add(df.format(val));
                    } else {
                        vals.add("0.00");
                    }
                    if (snaps[0].getDeadlocks() >= 0L && snaps[1].getDeadlocks() >= 0L) {
                        double val = diffAvgNoNegative(snaps[1].getDeadlocks(), snaps[0].getDeadlocks(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), false, 1);
                        vals.add((long) val + "(" + snaps[0].getDeadlocks() + ")");
                    } else {
                        vals.add(String.valueOf(snaps[1].getDeadlocks()));
                    }
                    //hardcoded threshold now
                    if (iowaits > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "IO") || (syscpu + usercpu > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "CPU")) || loadAvg > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "LOADAVG") || activeThreads > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "THREAD"))
                        if (!"Red".equals(dbstatus))
                            dbstatus = "Yellow";
                } else {
                    vals.add("0.00");
                    vals.add("0.00");
                    vals.add("0.00");
                    vals.add("0.00");
                    if (snaps[1].getTimestamp() > 0L)
                        vals.add(String.valueOf(snaps[1].getReplLag()));
                    else
                        vals.add("0");
                    vals.add("0.00");
                    vals.add("0.00");
                    vals.add("0");
                    vals.add("0");
                    vals.add("0.00");
                    vals.add("0.00");
                    vals.add("0.00");
                    vals.add("0");
                }
                vals.add(dbstatus);
                if (lastConnectTime != null)
                    vals.add(sdf.format(lastConnectTime));
                else
                    vals.add("");
                Date altDt = stateSnaps.getLastAlertTime();
                if (altDt != null) {
                    String val = stateSnaps.getLastAlertValue();
                    if (val == null)
                        val = "";
                    //else if(val.indexOf('.')>0 && val.length()>=val.indexOf('.')+4)
                    //  val = val.substring(0, val.indexOf('.')+4);
                    String end_dt = stateSnaps.getLastAlertEndTime() != null ? sdf.format(stateSnaps.getLastAlertEndTime()) : "";
                    vals.add(sdf.format(altDt) + "-" + end_dt + "/" + stateSnaps.getLastAlertType() + "/" + val);
                } else
                    vals.add("");
                vals.add(String.valueOf(stateSnaps.getLastScanTime()));
                row.setColumns(vals);
                rList.addRow(row);
            }
        }
    } else {
        Date d1 = null;
        Date d2 = null;
        Calendar c = Calendar.getInstance();
        //7 days
        c.add(Calendar.DATE, -7);
        d1 = c.getTime();
        d2 = new Date();
        java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
        sdf2.setTimeZone(TimeZone.getTimeZone("UTC"));
        String startDate = sdf2.format(d1);
        String endDate = sdf2.format(d2);
        try {
            //TODO validate DB
            rList = this.frameworkContext.getAutoScanner().getMetricDb().retrieveMetricsStatus("mysql_globalstatus".toUpperCase(), this.frameworkContext.getDbInfoManager().findDB(dbgroup, dbhost).getDbid(), Long.parseLong(startDate), Long.parseLong(endDate));
            HashMap<String, Integer> connectCounter = new HashMap<String, Integer>(24 * 8);
            HashMap<String, Integer> slowCounter = new HashMap<String, Integer>(24 * 8);
            if (rList != null && rList.getRows().size() > 0) {
                for (ResultRow row : rList.getRows()) {
                    String ts = row.getColumns().get(1);
                    String h = ts.substring(0, ts.length());
                    if (connectCounter.containsKey(h))
                        connectCounter.put(h, connectCounter.get(h) + 1);
                    else
                        connectCounter.put(h, 1);
                    try {
                        if (slowCounter.containsKey(h))
                            slowCounter.put(h, connectCounter.get(h) + Integer.parseInt(row.getColumns().get(3)));
                        else
                            slowCounter.put(h, Integer.parseInt(row.getColumns().get(3)));
                    } catch (Exception ex) {
                    }
                }
            }
        } catch (Exception ex) {
        //logger.log(Level.WARNING, "Failed to retrieve metrics data", ex);
        }
    }
    ModelAndView mv = new ModelAndView(jsonView);
    String msg = "OK";
    mv.addObject("json_result", ResultListUtil.toJSONString(rList, null, 0, msg));
    return mv;
}
Also used : ResultList(com.yahoo.dba.perf.myperf.common.ResultList) HashMap(java.util.HashMap) Date(java.util.Date) InstanceStates(com.yahoo.dba.perf.myperf.common.InstanceStates) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.yahoo.dba.perf.myperf.common.AppUser) DBGroupInfo(com.yahoo.dba.perf.myperf.common.DBGroupInfo) HashSet(java.util.HashSet) ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) Calendar(java.util.Calendar) StateSnapshot(com.yahoo.dba.perf.myperf.common.StateSnapshot) Date(java.util.Date) HashMap(java.util.HashMap) Map(java.util.Map) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo)

Example 5 with AppUser

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

the class MyPerfBaseController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    setupDebug(req);
    boolean debug = this.isDebug(req);
    if (debug)
        logger.info("receive url path: " + req.getContextPath() + "," + req.getRequestURI() + ", " + req.getServletPath() + ", parameters: " + req.getQueryString());
    AppUser user = retrieveAppUser(req);
    if (//check if user valid when require login
    this.requireLogin && user == null) {
        if (this.nosessView != null)
            return new ModelAndView(new RedirectView(nosessView));
        return respondFailure("Session expired. Please relogin and try again.", req);
    } else if (this.requireLogin && !user.isVerified()) {
        //TODO use a message view
        return this.respondFailure("New user request has not been verified by administrator yet. Please contact administrator by email " + this.frameworkContext.getMyperfConfig().getAdminEmail() + ".", req);
    }
    return handleRequestImpl(req, resp);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) AppUser(com.yahoo.dba.perf.myperf.common.AppUser)

Aggregations

AppUser (com.yahoo.dba.perf.myperf.common.AppUser)10 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 Connection (java.sql.Connection)5 ArrayList (java.util.ArrayList)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 AlertDefinition (com.yahoo.dba.perf.myperf.common.AlertDefinition)1 ColumnDescriptor (com.yahoo.dba.perf.myperf.common.ColumnDescriptor)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 InstanceStates (com.yahoo.dba.perf.myperf.common.InstanceStates)1 MetricsGroup (com.yahoo.dba.perf.myperf.common.MetricsGroup)1 ResultList (com.yahoo.dba.perf.myperf.common.ResultList)1 ResultRow (com.yahoo.dba.perf.myperf.common.ResultRow)1 StateSnapshot (com.yahoo.dba.perf.myperf.common.StateSnapshot)1