Search in sources :

Example 31 with ResultSetBuilder

use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.

the class ShowProcessListSQLHandler method onExecute.

@Override
protected Future<Void> onExecute(SQLRequest<MySqlShowProcessListStatement> request, MycatDataContext dataContext, Response response) {
    Map<Thread, Process> processMap = new LinkedHashMap<>(Process.getProcessMap());
    MySqlShowProcessListStatement ast = request.getAst();
    boolean full = ast.isFull();
    int maxCount = full ? Integer.MAX_VALUE : 100;
    MycatUser currentUser = full ? null : dataContext.getUser();
    ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
    resultSetBuilder.addColumnInfo("Id", JDBCType.INTEGER);
    resultSetBuilder.addColumnInfo("User", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("Host", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("db", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("Command", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("Time", JDBCType.BIGINT);
    resultSetBuilder.addColumnInfo("State", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("Info", JDBCType.VARCHAR);
    long timestamp = System.currentTimeMillis();
    int currentCount = 0;
    for (Map.Entry<Thread, Process> entry : processMap.entrySet()) {
        Thread holdThread = entry.getKey();
        Process process = entry.getValue();
        if (currentUser != null && !Objects.equals(process.getUser(), currentUser.getUserName())) {
            continue;
        }
        resultSetBuilder.addObjectRowPayload(Arrays.asList(process.getId(), process.getUser(), process.getHost(), process.getDb(), process.getCommand(), timestamp - process.getCreateTimestamp().getTime(), process.getState(), process.getInfo()));
        currentCount++;
        if (currentCount >= maxCount) {
            break;
        }
    }
    return response.sendResultSet(resultSetBuilder.build());
// return response.proxySelectToPrototype(request.getAst().toString());
}
Also used : ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) MycatUser(io.mycat.MycatUser) Process(io.mycat.Process) MySqlShowProcessListStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcessListStatement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with ResultSetBuilder

use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.

the class MigrateUtil method show.

public static RowBaseIterator show(List<MigrateScheduler> schedulers) {
    ResultSetBuilder builder = ResultSetBuilder.create();
    builder.addColumnInfo("ID", JDBCType.VARCHAR);
    builder.addColumnInfo("NAME", JDBCType.VARCHAR);
    builder.addColumnInfo("PROCESS", JDBCType.VARCHAR);
    builder.addColumnInfo("COMPLETE", JDBCType.INTEGER);
    builder.addColumnInfo("INFO", JDBCType.VARCHAR);
    builder.addColumnInfo("ERROR", JDBCType.VARCHAR);
    builder.addColumnInfo("START_TIME", JDBCType.TIMESTAMP);
    builder.addColumnInfo("END_TIME", JDBCType.TIMESTAMP);
    builder.addColumnInfo("INPUT_ROW", JDBCType.BIGINT);
    builder.addColumnInfo("OUTPUT_ROW", JDBCType.BIGINT);
    for (MigrateScheduler scheduler : schedulers) {
        String id = scheduler.getId();
        String name = scheduler.getName();
        int complete = scheduler.getFuture().isComplete() ? 1 : 0;
        String process = scheduler.computeProcess() * 100 + "%";
        String info = scheduler.toString();
        builder.addObjectRowPayload(new Object[] { id, name, process, complete, info, scheduler.getFuture().cause(), scheduler.getStartTime(), scheduler.getEndTime(), scheduler.computeInputRow(), scheduler.getOutput().getRow().get() });
    }
    return builder.build();
}
Also used : ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) ToString(groovy.transform.ToString)

Aggregations

ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)32 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)13 JDBCType (java.sql.JDBCType)12 LocalDateTime (java.time.LocalDateTime)11 io.mycat.config (io.mycat.config)10 ReplicaSelectorManager (io.mycat.replica.ReplicaSelectorManager)10 IOException (java.io.IOException)10 Timestamp (java.sql.Timestamp)10 java.util (java.util)10 Collectors (java.util.stream.Collectors)10 NotNull (org.jetbrains.annotations.NotNull)10 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)9 NameMap (io.mycat.util.NameMap)9 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)8 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)8 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)8 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)7 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)7 ImmutableList (com.google.common.collect.ImmutableList)7 MysqlPayloadObject (io.mycat.api.collector.MysqlPayloadObject)7