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);
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations