Search in sources :

Example 81 with Feature

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

the class DockerNetworkController method list.

/**
 * @return json
 */
@PostMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String list(@ValidatorItem String id, String name, String networkId) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id);
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("name", name);
    parameter.put("id", networkId);
    List<JSONObject> listContainer = (List<JSONObject>) plugin.execute("listNetworks", 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) PostMapping(org.springframework.web.bind.annotation.PostMapping) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 82 with Feature

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

the class DockerInfoController method del.

@GetMapping(value = "del", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id) throws Exception {
    DockerInfoModel infoModel = dockerInfoService.getByKey(id, getRequest());
    if (infoModel != null) {
        // 检查是否为最后一个 docker 需要删除证书文件
        DockerInfoModel dockerInfoModel = new DockerInfoModel();
        dockerInfoModel.setHost(infoModel.getHost());
        long count = dockerInfoService.count(dockerInfoService.dataBeanToEntity(dockerInfoModel));
        if (count <= 1) {
            // 删除文件
            FileUtil.del(infoModel.generateCertPath());
        }
        dockerInfoService.delByKey(id);
    }
    return JsonMessage.getString(200, "删除成功");
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 83 with Feature

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

the class DockerInfoController method leaveForce.

/**
 * 强制退出集群
 *
 * @param id 集群ID
 * @return json
 */
@GetMapping(value = "swarm-leave-force", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public JsonMessage<String> leaveForce(@ValidatorItem String id) throws Exception {
    // 
    DockerSwarmInfoMode dockerSwarmInfoMode = new DockerSwarmInfoMode();
    dockerSwarmInfoMode.setDockerId(id);
    long count = dockerSwarmInfoService.count(dockerSwarmInfoMode);
    Assert.state(count <= 0, "需要先解绑集群才能强制退出集群");
    // 
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("force", true);
    plugin.execute("leaveSwarm", parameter, JSONObject.class);
    // 
    dockerInfoService.unbind(id);
    return new JsonMessage<>(200, "强制解绑成功");
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JsonMessage(cn.jiangzeyin.common.JsonMessage) DockerSwarmInfoMode(io.jpom.model.docker.DockerSwarmInfoMode) JSONObject(com.alibaba.fastjson.JSONObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 84 with Feature

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

the class DockerInfoController method info.

@GetMapping(value = "info", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String info(@ValidatorItem String id) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
    JSONObject info = plugin.execute("info", dockerInfoModel.toParameter(), JSONObject.class);
    return JsonMessage.getString(200, "", info);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 85 with Feature

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

the class DockerSwarmInfoController method leave.

/**
 * 退出集群
 *
 * @param id 集群ID
 * @return json
 */
@GetMapping(value = "leave", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public JsonMessage<String> leave(@ValidatorItem String id, @ValidatorItem String nodeId) throws Exception {
    // 
    IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
    // 查询节点信息
    DockerInfoModel dockerInfoModel = new DockerInfoModel();
    dockerInfoModel.setSwarmNodeId(nodeId);
    List<DockerInfoModel> dockerInfoModels = dockerInfoService.queryList(dockerInfoModel, 2);
    Assert.state(CollUtil.size(dockerInfoModels) == 1, "当前节点未在系统中绑定或者绑定信息异常,不能操作");
    // 
    {
        DockerInfoModel dockerInfoModel1 = CollUtil.getFirst(dockerInfoModels);
        Map<String, Object> parameter = dockerInfoModel1.toParameter();
        parameter.put("force", true);
        plugin.execute("leaveSwarm", parameter, JSONObject.class);
    }
    {
        Map<String, Object> map = dockerInfoService.getBySwarmPluginMap(id, getRequest());
        map.put("nodeId", nodeId);
        plugin.execute("removeSwarmNode", map);
    }
    // 
    dockerInfoService.unbind(id);
    return new JsonMessage<>(200, "剔除成功");
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JsonMessage(cn.jiangzeyin.common.JsonMessage) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) 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