Search in sources :

Example 1 with DockerInfoModel

use of io.jpom.model.docker.DockerInfoModel in project Jpom by dromara.

the class DockerLogHandler method init.

@Override
protected void init(WebSocketSession session, Map<String, Object> attributes) throws URISyntaxException, IOException {
    super.init(session, attributes);
    // 
    DockerInfoModel dockerInfoModel = (DockerInfoModel) attributes.get("dataItem");
    this.sendMsg(session, "连接成功:" + dockerInfoModel.getName() + StrUtil.CRLF);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel)

Example 2 with DockerInfoModel

use of io.jpom.model.docker.DockerInfoModel 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)

Example 3 with DockerInfoModel

use of io.jpom.model.docker.DockerInfoModel in project Jpom by dromara.

the class DockerCliHandler method afterConnectionEstablishedImpl.

@Override
public void afterConnectionEstablishedImpl(WebSocketSession session) throws Exception {
    Map<String, Object> attributes = session.getAttributes();
    DockerInfoModel dockerInfoModel = (DockerInfoModel) attributes.get("dataItem");
    String containerId = (String) attributes.get("containerId");
    super.logOpt(this.getClass(), attributes, attributes);
    // 
    HandlerItem handlerItem;
    try {
        handlerItem = new HandlerItem(session, dockerInfoModel, containerId);
        handlerItem.startRead();
    } catch (Exception e) {
        // 输出超时日志 @author jzy
        DefaultSystemLog.getLog().error("docker 控制台连接超时", e);
        sendBinary(session, "docker 控制台连接超时");
        this.destroy(session);
        return;
    }
    HANDLER_ITEM_CONCURRENT_HASH_MAP.put(session.getId(), handlerItem);
    // 
    Thread.sleep(1000);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException)

Example 4 with DockerInfoModel

use of io.jpom.model.docker.DockerInfoModel in project Jpom by dromara.

the class DockerInfoService method updateDockerSwarmTag.

/**
 * 更新集群 标签
 *
 * @param swarmId 集群ID
 * @param tag     新增标签
 * @param delTag  删除标签
 */
public void updateDockerSwarmTag(String swarmId, String tag, String delTag) {
    DockerInfoModel queryWhere = new DockerInfoModel();
    queryWhere.setSwarmId(swarmId);
    List<DockerInfoModel> dockerInfoModels = this.listByBean(queryWhere);
    for (DockerInfoModel dockerInfoModel : dockerInfoModels) {
        // 处理标签
        Collection<String> allTag = StrUtil.splitTrim(dockerInfoModel.getTags(), StrUtil.COLON);
        allTag = ObjectUtil.defaultIfNull(allTag, new ArrayList<>());
        if (StrUtil.isNotEmpty(delTag)) {
            allTag.remove(delTag);
        }
        if (!allTag.contains(tag)) {
            allTag.add(tag);
        }
        allTag = allTag.stream().filter(StrUtil::isNotEmpty).collect(Collectors.toSet());
        String newTags = CollUtil.join(allTag, StrUtil.COLON, StrUtil.COLON, StrUtil.COLON);
        // 
        Entity where = Entity.create().set("id", dockerInfoModel.getId());
        Entity update = Entity.create().set("tags", newTags);
        this.update(update, where);
    }
}
Also used : Entity(cn.hutool.db.Entity) DockerInfoModel(io.jpom.model.docker.DockerInfoModel) StrUtil(cn.hutool.core.util.StrUtil)

Example 5 with DockerInfoModel

use of io.jpom.model.docker.DockerInfoModel in project Jpom by dromara.

the class DockerInfoService method unbind.

/**
 * 解绑集群信息
 *
 * @param id docker id
 */
public void unbind(String id) {
    DockerInfoModel update = new DockerInfoModel();
    update.setId(id);
    update.setSwarmId(StrUtil.EMPTY);
    update.setSwarmNodeId(StrUtil.EMPTY);
    this.update(update);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel)

Aggregations

DockerInfoModel (io.jpom.model.docker.DockerInfoModel)36 JSONObject (com.alibaba.fastjson.JSONObject)23 ClassFeature (io.jpom.permission.ClassFeature)23 Feature (io.jpom.permission.Feature)23 MethodFeature (io.jpom.permission.MethodFeature)23 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 IPlugin (io.jpom.plugin.IPlugin)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)7 DockerSwarmInfoMode (io.jpom.model.docker.DockerSwarmInfoMode)6 File (java.io.File)5 List (java.util.List)5 JsonMessage (cn.jiangzeyin.common.JsonMessage)4 StrUtil (cn.hutool.core.util.StrUtil)3 Entity (cn.hutool.db.Entity)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 JSONArray (com.alibaba.fastjson.JSONArray)2 DockerInfoService (io.jpom.service.docker.DockerInfoService)2 IOException (java.io.IOException)2 Consumer (java.util.function.Consumer)2