Search in sources :

Example 1 with ConsoleCommandOp

use of io.jpom.socket.ConsoleCommandOp in project Jpom by dromara.

the class DockerLogHandler method handleTextMessage.

@Override
protected String handleTextMessage(Map<String, Object> attributes, WebSocketSession session, JSONObject json, ConsoleCommandOp consoleCommandOp) throws IOException {
    DockerInfoModel dockerInfoModel = (DockerInfoModel) attributes.get("dataItem");
    if (consoleCommandOp == ConsoleCommandOp.heart) {
        return null;
    }
    if (consoleCommandOp == ConsoleCommandOp.showlog) {
        super.logOpt(this.getClass(), attributes, json);
        String containerId = json.getString("containerId");
        Map<String, Object> map = dockerInfoModel.toParameter();
        map.put("containerId", containerId);
        int tail = json.getIntValue("tail");
        if (tail > 0) {
            map.put("tail", tail);
        }
        Consumer<String> consumer = s -> {
            try {
                SocketSessionUtil.send(session, s);
            } catch (IOException e) {
                log.error("发消息异常", e);
            }
        };
        map.put("charset", CharsetUtil.CHARSET_UTF_8);
        map.put("consumer", consumer);
        IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
        try {
            plugin.execute("logContainer", map);
        } catch (Exception e) {
            log.error("拉取 容器日志异常", e);
            return "执行异常:" + e.getMessage();
        }
    } else {
        return null;
    }
    return null;
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) SocketSessionUtil(io.jpom.util.SocketSessionUtil) ClassFeature(io.jpom.permission.ClassFeature) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ConsoleCommandOp(io.jpom.socket.ConsoleCommandOp) io.jpom.plugin(io.jpom.plugin) WebSocketSession(org.springframework.web.socket.WebSocketSession) Feature(io.jpom.permission.Feature) Consumer(java.util.function.Consumer) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) DockerInfoService(io.jpom.service.docker.DockerInfoService) Map(java.util.Map) CharsetUtil(cn.hutool.core.util.CharsetUtil) BaseProxyHandler(io.jpom.socket.BaseProxyHandler) JSONObject(com.alibaba.fastjson.JSONObject) MethodFeature(io.jpom.permission.MethodFeature) DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

CharsetUtil (cn.hutool.core.util.CharsetUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)1 ClassFeature (io.jpom.permission.ClassFeature)1 Feature (io.jpom.permission.Feature)1 MethodFeature (io.jpom.permission.MethodFeature)1 io.jpom.plugin (io.jpom.plugin)1 DockerInfoService (io.jpom.service.docker.DockerInfoService)1 BaseProxyHandler (io.jpom.socket.BaseProxyHandler)1 ConsoleCommandOp (io.jpom.socket.ConsoleCommandOp)1 SocketSessionUtil (io.jpom.util.SocketSessionUtil)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Slf4j (lombok.extern.slf4j.Slf4j)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1