Search in sources :

Example 86 with Feature

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

the class DockerSwarmInfoController method join.

/**
 * 加入集群
 *
 * @param id         集群ID
 * @param dockerId   容器ID
 * @param remoteAddr 集群ID
 * @param role       加入角色
 * @return json
 * @throws Exception 异常
 */
@PostMapping(value = "join", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String join(@ValidatorItem String id, @ValidatorItem String dockerId, @ValidatorItem String remoteAddr, @ValidatorItem String role) throws Exception {
    HttpServletRequest request = getRequest();
    DockerSwarmInfoMode swarmInfoMode1 = dockerSwarmInfoService.getByKey(id, request);
    Assert.notNull(swarmInfoMode1, "没有对应的集群");
    DockerInfoModel managerSwarmDocker = dockerInfoService.getByKey(swarmInfoMode1.getDockerId(), request);
    Assert.notNull(managerSwarmDocker, "对应的 docker 不存在");
    DockerInfoModel joinSwarmDocker = dockerInfoService.getByKey(dockerId, request);
    Assert.notNull(joinSwarmDocker, "对应的 docker 不存在:-1");
    JSONObject managerSwarmInfo;
    IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
    IPlugin checkPlugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
    {
        // 获取集群信息
        managerSwarmInfo = (JSONObject) plugin.execute("inSpectSwarm", managerSwarmDocker.toParameter());
        Assert.notNull(managerSwarmInfo, "集群信息不完整,不能加入改集群");
    }
    {
        // 检查节点存在的信息
        JSONObject info = checkPlugin.execute("info", joinSwarmDocker.toParameter(), JSONObject.class);
        Assert.notNull(info, "获取 docker 集群信息失败");
        JSONObject swarm = info.getJSONObject("swarm");
        Assert.notNull(swarm, "获取 docker 集群信息失败:-1");
        JSONArray remoteManagers = swarm.getJSONArray("remoteManagers");
        if (ArrayUtil.isNotEmpty(remoteManagers)) {
            Optional<Object> optional = remoteManagers.stream().filter(o -> {
                JSONObject jsonObject = (JSONObject) o;
                String addr = jsonObject.getString("addr");
                List<String> strings = StrUtil.splitTrim(addr, StrUtil.COLON);
                return StrUtil.equals(CollUtil.getFirst(strings), remoteAddr);
            }).findFirst();
            Assert.state(optional.isPresent(), "当前 docker 已经加入到其他集群啦");
            // 绑定数据
            String managerId = managerSwarmInfo.getString("id");
            dockerInfoService.bindDockerSwarm(joinSwarmDocker, swarmInfoMode1.getTag(), swarm, managerId);
            return JsonMessage.getString(200, "集群绑定成功");
        }
    }
    String roleToken;
    {
        // 准备加入集群
        JSONObject joinTokens = managerSwarmInfo.getJSONObject("joinTokens");
        Assert.notNull(joinTokens, "集群信息不完整,不能加入改集群:-1");
        roleToken = joinTokens.getString(role);
        Assert.hasText(roleToken, "不能已 " + role + " 角色加入集群");
    }
    Map<String, Object> parameter = joinSwarmDocker.toParameter();
    parameter.put("token", roleToken);
    parameter.put("remoteAddrs", remoteAddr);
    plugin.execute("joinSwarm", parameter);
    // 绑定数据
    JSONObject info = checkPlugin.execute("info", joinSwarmDocker.toParameter(), JSONObject.class);
    Assert.notNull(info, "获取 docker 集群信息失败");
    JSONObject swarm = info.getJSONObject("swarm");
    Assert.notNull(swarm, "获取 docker 集群信息失败:-1");
    String managerId = managerSwarmInfo.getString("id");
    dockerInfoService.bindDockerSwarm(joinSwarmDocker, swarmInfoMode1.getTag(), swarm, managerId);
    return JsonMessage.getString(200, "集群创建成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) Optional(java.util.Optional) DockerSwarmInfoMode(io.jpom.model.docker.DockerSwarmInfoMode) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 87 with Feature

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

the class DockerVolumeController method del.

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

Example 88 with Feature

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

the class NodeScriptController method syncProject.

/**
 * 同步脚本模版
 *
 * @return json
 */
@GetMapping(value = "sync", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String syncProject() {
    // 
    NodeModel node = getNode();
    int cache = nodeScriptServer.delCache(node.getId(), getRequest());
    String msg = nodeScriptServer.syncExecuteNode(node);
    return JsonMessage.getString(200, "主动清除 " + cache + StrUtil.SPACE + msg);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 89 with Feature

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

the class NodeScriptController method upload.

/**
 * 导入脚本
 *
 * @return json
 */
@RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.UPLOAD)
public String upload() {
    NodeModel node = getNode();
    JsonMessage<String> stringJsonMessage = NodeForward.requestMultipart(node, getMultiRequest(), NodeUrl.Script_Upload);
    if (stringJsonMessage.getCode() == HttpStatus.OK.value()) {
        nodeScriptServer.syncNode(node);
    }
    return stringJsonMessage.toString();
}
Also used : NodeModel(io.jpom.model.data.NodeModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 90 with Feature

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

the class NodeScriptController method del.

@RequestMapping(value = "del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id) {
    NodeModel node = getNode();
    HttpServletRequest request = getRequest();
    JsonMessage<Object> requestData = NodeForward.request(node, request, NodeUrl.Script_Del);
    if (requestData.getCode() == HttpStatus.OK.value()) {
        nodeScriptServer.syncNode(node);
        // 删除日志
        nodeScriptExecuteLogServer.delCache(id, node.getId(), request);
    }
    return requestData.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeModel(io.jpom.model.data.NodeModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

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