Search in sources :

Example 76 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class DockerImagesController method createContainer.

/**
 * @return json
 */
@PostMapping(value = "create-container", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String createContainer(@RequestBody JSONObject jsonObject) throws Exception {
    Assert.hasText(jsonObject.getString("id"), "id 不能为空");
    Assert.hasText(jsonObject.getString("imageId"), "镜像不能为空");
    Assert.hasText(jsonObject.getString("name"), "容器名称不能为空");
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(jsonObject.getString("id"), getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.putAll(jsonObject);
    plugin.execute("createContainer", 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 77 with Feature

use of io.jpom.permission.Feature 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 78 with Feature

use of io.jpom.permission.Feature 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 79 with Feature

use of io.jpom.permission.Feature 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 80 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class DockerImagesController method getNowLog.

/**
 * 获取拉取的日志
 *
 * @param id   id
 * @param line 需要获取的行号
 * @return json
 */
@GetMapping(value = "pull-image-log", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getNowLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String id, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
    File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), "docker-log", id + ".log");
    if (!file.exists()) {
        return JsonMessage.getString(201, "还没有日志文件");
    }
    JSONObject data = FileUtils.readLogFile(file, line);
    return JsonMessage.getString(200, "ok", data);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

Feature (io.jpom.permission.Feature)129 MethodFeature (io.jpom.permission.MethodFeature)129 ClassFeature (io.jpom.permission.ClassFeature)128 JSONObject (com.alibaba.fastjson.JSONObject)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 File (java.io.File)36 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)22 NodeModel (io.jpom.model.data.NodeModel)21 GetMapping (org.springframework.web.bind.annotation.GetMapping)21 UserModel (io.jpom.model.data.UserModel)14 SystemPermission (io.jpom.permission.SystemPermission)14 BuildInfoModel (io.jpom.model.data.BuildInfoModel)12 SshModel (io.jpom.model.data.SshModel)10 Entity (cn.hutool.db.Entity)8 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)8 JSONArray (com.alibaba.fastjson.JSONArray)8 JsonMessage (cn.jiangzeyin.common.JsonMessage)7 List (java.util.List)7