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, "集群创建成功");
}
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, "执行成功");
}
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);
}
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();
}
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();
}
Aggregations