Search in sources :

Example 6 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class ReloadUser method execute.

public static void execute(ManagerConnection c) {
    boolean status = false;
    if (status) {
        StringBuilder s = new StringBuilder();
        s.append(c).append("Reload userConfig success by manager");
        logger.warn(s.toString());
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = 1;
        ok.serverStatus = 2;
        ok.message = "Reload userConfig success".getBytes();
        ok.write(c);
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
    }
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket)

Example 7 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class ShowWhiteHost method setHost.

public static synchronized void setHost(ManagerConnection c, String ips) {
    OkPacket ok = new OkPacket();
    String[] users = ips.split(",");
    if (users.length < 2) {
        c.writeErrMessage(ErrorCode.ER_YES, "white host info error.");
        return;
    }
    String host = "";
    List<UserConfig> userConfigs = new ArrayList<UserConfig>();
    int i = 0;
    for (String user : users) {
        if (i == 0) {
            host = user;
            i++;
        } else {
            i++;
            UserConfig uc = MycatServer.getInstance().getConfig().getUsers().get(user);
            if (null == uc) {
                c.writeErrMessage(ErrorCode.ER_YES, "user doesn't exist in host.");
                return;
            }
            if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {
                c.writeErrMessage(ErrorCode.ER_YES, "host contains one root privileges user.");
                return;
            }
            userConfigs.add(uc);
        }
    }
    if (MycatServer.getInstance().getConfig().getFirewall().addWhitehost(host, userConfigs)) {
        try {
            FirewallConfig.updateToFile(host, userConfigs);
        } catch (Exception e) {
            LOGGER.warn("set while host error : " + e.getMessage());
            c.writeErrMessage(ErrorCode.ER_YES, "white host set success ,but write to file failed :" + e.getMessage());
        }
        ok.packetId = 1;
        ok.affectedRows = 1;
        ok.serverStatus = 2;
        ok.message = "white host set to succeed.".getBytes();
        ok.write(c);
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "host duplicated.");
    }
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) ArrayList(java.util.ArrayList) UserConfig(io.mycat.config.model.UserConfig) ConfigException(io.mycat.config.util.ConfigException)

Example 8 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class StopHeartbeat method execute.

public static void execute(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> keys = ManagerParseStop.getPair(stmt);
    if (keys.getKey() != null && keys.getValue() != null) {
        long time = keys.getValue().intValue() * 1000L;
        Map<String, PhysicalDBPool> dns = MycatServer.getInstance().getConfig().getDataHosts();
        for (String key : keys.getKey()) {
            PhysicalDBPool dn = dns.get(key);
            if (dn != null) {
                dn.getSource().setHeartbeatRecoveryTime(TimeUtil.currentTimeMillis() + time);
                ++count;
                StringBuilder s = new StringBuilder();
                s.append(dn.getHostName()).append(" stop heartbeat '");
                logger.warn(s.append(FormatUtil.formatTime(time, 3)).append("' by manager.").toString());
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool)

Example 9 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class RollbackUser method execute.

public static void execute(ManagerConnection c) {
    boolean status = false;
    if (status) {
        StringBuilder s = new StringBuilder();
        s.append(c).append("Rollback user success by manager");
        logger.warn(s.toString());
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = 1;
        ok.serverStatus = 2;
        ok.message = "Rollback user success".getBytes();
        ok.write(c);
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
    }
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket)

Example 10 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class KillHandler method getOkPacket.

private static OkPacket getOkPacket() {
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = 0;
    packet.serverStatus = 2;
    return packet;
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket)

Aggregations

OkPacket (io.mycat.net.mysql.OkPacket)18 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 UserStat (io.mycat.statistic.stat.UserStat)2 BackendConnection (io.mycat.backend.BackendConnection)1 UserConfig (io.mycat.config.model.UserConfig)1 ConfigException (io.mycat.config.util.ConfigException)1 FrontendConnection (io.mycat.net.FrontendConnection)1 NIOConnection (io.mycat.net.NIOConnection)1 ErrorPacket (io.mycat.net.mysql.ErrorPacket)1 HeartbeatPacket (io.mycat.net.mysql.HeartbeatPacket)1 RouteResultsetNode (io.mycat.route.RouteResultsetNode)1 ServerConnection (io.mycat.server.ServerConnection)1 QueryResult (io.mycat.statistic.stat.QueryResult)1 ArrayList (java.util.ArrayList)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1