use of io.jpom.permission.Feature in project Jpom by dromara.
the class NodeProjectInfoController method clearAll.
/**
* 删除节点缓存的所有项目
*
* @return json
*/
@GetMapping(value = "clear_all_project", produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission(superUser = true)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String clearAll() {
Entity where = Entity.create();
where.set("id", " <> id");
int del = projectInfoCacheService.del(where);
return JsonMessage.getString(200, "成功删除" + del + "条项目缓存");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class NodeProjectInfoController method syncProject.
/**
* 同步节点项目
*
* @return json
*/
@GetMapping(value = "sync_project", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String syncProject(String nodeId) {
NodeModel nodeModel = nodeService.getByKey(nodeId);
Assert.notNull(nodeModel, "对应的节点不存在");
int count = projectInfoCacheService.delCache(nodeId, getRequest());
String msg = projectInfoCacheService.syncExecuteNode(nodeModel);
return JsonMessage.getString(200, "主动清除:" + count + StrUtil.SPACE + msg);
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class EditProjectController method saveProject.
/**
* 保存项目
*
* @param id id
* @return json
*/
@RequestMapping(value = "saveProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String saveProject(String id) {
// 防止和Jpom冲突
if (StrUtil.isNotEmpty(ConfigBean.getInstance().applicationTag) && ConfigBean.getInstance().applicationTag.equalsIgnoreCase(id)) {
return JsonMessage.getString(401, "当前项目id已经被Jpom占用");
}
NodeModel node = getNode();
JsonMessage<Object> request = NodeForward.request(node, getRequest(), NodeUrl.Manage_SaveProject);
if (request.getCode() == HttpStatus.OK.value()) {
projectInfoCacheService.syncNode(node, id);
}
return request.toString();
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class ProjectManageControl method deleteProject.
/**
* 删除项目
*
* @param id id
* @return json
*/
@PostMapping(value = "deleteProject", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteProject(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, String copyId) {
NodeModel nodeModel = getNode();
HttpServletRequest servletRequest = getRequest();
if (StrUtil.isEmpty(copyId)) {
// 检查节点分发
List<OutGivingModel> outGivingModels = outGivingServer.listByWorkspace(servletRequest);
if (outGivingModels != null) {
boolean match = outGivingModels.stream().anyMatch(outGivingModel -> outGivingModel.checkContains(nodeModel.getId(), id));
Assert.state(!match, "当前项目存在节点分发,不能直接删除");
// for (OutGivingModel outGivingModel : outGivingModels) {
// if (outGivingModel.checkContains(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, "当前项目存在节点分发,不能直接删除");
// }
// }
}
//
List<MonitorModel> monitorModels = monitorService.listByWorkspace(servletRequest);
if (monitorModels != null) {
boolean match = monitorModels.stream().anyMatch(monitorModel -> monitorModel.checkNodeProject(nodeModel.getId(), id));
// if (monitorService.checkProject(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, );
// }
Assert.state(!match, "当前项目存在监控项,不能直接删除");
}
boolean releaseMethod = buildService.checkReleaseMethod(nodeModel.getId() + StrUtil.COLON + id, servletRequest, BuildReleaseMethod.Project);
Assert.state(!releaseMethod, "当前项目存在构建项,不能直接删除");
}
JsonMessage<Object> request = NodeForward.request(nodeModel, servletRequest, NodeUrl.Manage_DeleteProject);
if (request.getCode() == HttpStatus.OK.value()) {
//
projectInfoCacheService.syncNode(nodeModel);
}
return request.toString();
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class DockerSwarmServiceController method pullImage.
/**
* @return json
*/
@GetMapping(value = "start-log", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String pullImage(@ValidatorItem String id, @ValidatorItem String type, @ValidatorItem String dataId) throws Exception {
IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoService.getBySwarmPluginMap(id, getRequest());
parameter.put(StrUtil.equalsIgnoreCase(type, "service") ? "serviceId" : "taskId", dataId);
//
String uuid = IdUtil.fastSimpleUUID();
File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), "docker-swarm-log", uuid + ".log");
LogRecorder logRecorder = LogRecorder.builder().file(file).build();
logRecorder.info("start pull {}", dataId);
Consumer<String> logConsumer = logRecorder::append;
parameter.put("charset", CharsetUtil.CHARSET_UTF_8);
parameter.put("consumer", logConsumer);
parameter.put("tail", 50);
ThreadUtil.execute(() -> {
try {
plugin.execute(StrUtil.equalsIgnoreCase(type, "service") ? "logService" : "logTask", parameter);
} catch (Exception e) {
logRecorder.error("拉取异常", e);
}
logRecorder.info("pull end");
});
return JsonMessage.getString(200, "开始拉取", uuid);
}
Aggregations