Search in sources :

Example 11 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerImagesController method list.

/**
 * @return json
 */
@PostMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String list(@ValidatorItem String id) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("name", getParameter("name"));
    parameter.put("showAll", getParameter("showAll"));
    parameter.put("dangling", getParameter("dangling"));
    List<JSONObject> listContainer = (List<JSONObject>) plugin.execute("listImages", parameter);
    return JsonMessage.getString(200, "", listContainer);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) IPlugin(io.jpom.plugin.IPlugin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 12 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerImagesController method del.

/**
 * @return json
 */
@GetMapping(value = "remove", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id, String imageId) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("imageId", imageId);
    plugin.execute("removeImage", parameter);
    return JsonMessage.getString(200, "执行成功");
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) IPlugin(io.jpom.plugin.IPlugin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 13 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerImagesController method inspect.

/**
 * @return json
 */
@GetMapping(value = "inspect", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String inspect(@ValidatorItem String id, String imageId) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("imageId", imageId);
    JSONObject inspectImage = (JSONObject) plugin.execute("inspectImage", parameter);
    return JsonMessage.getString(200, "", inspectImage);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) IPlugin(io.jpom.plugin.IPlugin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 14 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerInfoService method updateMonitor.

/**
 * 监控 容器
 *
 * @param dockerInfoModel docker
 */
public boolean updateMonitor(DockerInfoModel dockerInfoModel) {
    try {
        IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
        Map<String, Object> parameter = dockerInfoModel.toParameter();
        parameter.put("timeout", dockerInfoModel.getHeartbeatTimeout());
        // 
        JSONObject info = plugin.execute("info", parameter, JSONObject.class);
        // 
        DockerInfoModel update = new DockerInfoModel();
        update.setId(dockerInfoModel.getId());
        update.setStatus(1);
        update.setLastHeartbeatTime(SystemClock.now());
        // 
        update.setDockerVersion(info.getString("serverVersion"));
        JSONObject swarm = info.getJSONObject("swarm");
        if (swarm != null) {
            String nodeId = swarm.getString("nodeID");
            update.setSwarmNodeId(nodeId);
            if (StrUtil.isEmpty(nodeId)) {
                // 集群退出
                update.setSwarmId(StrUtil.EMPTY);
            }
        } else {
            update.setSwarmNodeId(StrUtil.EMPTY);
            update.setSwarmId(StrUtil.EMPTY);
        }
        update.setFailureMsg(StrUtil.EMPTY);
        super.update(update);
        // 
        this.updateSwarmStatus(dockerInfoModel.getId(), update.getStatus(), update.getFailureMsg());
        return true;
    } catch (Exception e) {
        log.error("监控 docker 异常", e);
        this.updateStatus(dockerInfoModel.getId(), 0, e.getMessage());
        return false;
    }
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) IPlugin(io.jpom.plugin.IPlugin)

Example 15 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerInfoService method localLocalDocker.

private void localLocalDocker() {
    try {
        IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
        String dockerHost = (String) plugin.execute("testLocal", new HashMap<>(1));
        Entity entity = Entity.create();
        entity.set("host", dockerHost);
        entity.set("workspaceId", Const.WORKSPACE_DEFAULT_ID);
        boolean exists = this.exists(entity);
        if (exists) {
            return;
        }
        DockerInfoModel.DockerInfoModelBuilder builder = DockerInfoModel.builder();
        builder.host(dockerHost).name("localhost").status(1);
        DockerInfoModel dockerInfoModel = builder.build();
        dockerInfoModel.setWorkspaceId(Const.WORKSPACE_DEFAULT_ID);
        dockerInfoModel.setModifyUser(UserModel.SYSTEM_ADMIN);
        this.insert(dockerInfoModel);
        Console.log("Automatically add local docker host: {}", dockerHost);
    } catch (Exception e) {
        Console.error("There is no docker service local {}", e.getMessage());
    }
}
Also used : Entity(cn.hutool.db.Entity) DockerInfoModel(io.jpom.model.docker.DockerInfoModel) IPlugin(io.jpom.plugin.IPlugin)

Aggregations

IPlugin (io.jpom.plugin.IPlugin)16 JSONObject (com.alibaba.fastjson.JSONObject)10 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)8 ClassFeature (io.jpom.permission.ClassFeature)5 Feature (io.jpom.permission.Feature)5 MethodFeature (io.jpom.permission.MethodFeature)5 HashMap (java.util.HashMap)5 File (java.io.File)4 JpomRuntimeException (io.jpom.system.JpomRuntimeException)2 CollUtil (cn.hutool.core.collection.CollUtil)1 BetweenFormatter (cn.hutool.core.date.BetweenFormatter)1 DateUtil (cn.hutool.core.date.DateUtil)1 SystemClock (cn.hutool.core.date.SystemClock)1 FileUtil (cn.hutool.core.io.FileUtil)1 IoUtil (cn.hutool.core.io.IoUtil)1 LineHandler (cn.hutool.core.io.LineHandler)1 ResourceUtil (cn.hutool.core.io.resource.ResourceUtil)1 CharPool (cn.hutool.core.text.CharPool)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1