use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class WorkspaceController method create.
/**
* 编辑工作空间
*
* @param name 工作空间名称
* @param description 描述
* @return json
*/
@PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String create(String id, @ValidatorItem String name, @ValidatorItem String description) {
this.checkInfo(id, name);
//
WorkspaceModel workspaceModel = new WorkspaceModel();
workspaceModel.setName(name);
workspaceModel.setDescription(description);
if (StrUtil.isEmpty(id)) {
// 创建
workspaceService.insert(workspaceModel);
} else {
workspaceModel.setId(id);
workspaceService.update(workspaceModel);
}
return JsonMessage.getString(200, "操作成功");
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class UserBasicInfoController method myWorkspace.
/**
* 查询用户自己的工作空间
*
* @return msg
*/
@GetMapping(value = "my_workspace", produces = MediaType.APPLICATION_JSON_VALUE)
public String myWorkspace() {
UserModel user = getUser();
List<WorkspaceModel> models = userBindWorkspaceService.listUserWorkspaceInfo(user);
Assert.notEmpty(models, "当前账号没有绑定任何工作空间,请联系管理员处理");
return JsonMessage.getString(200, "", models);
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class NodeInfoController method receivePush.
/**
* 接收节点推送的信息
* <p>
* yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Agent jdk
* --auto-push-to-server http://127.0.0.1:3000/api/node/receive_push?token=462a47b8fba8da1f824370bb9fcdc01aa1a0fe20&workspaceId=DEFAULT
*
* @return json
*/
@RequestMapping(value = ServerOpenApi.RECEIVE_PUSH, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
public String receivePush(@ValidatorItem(msg = "token empty") String token, @ValidatorItem(msg = "ips empty") String ips, @ValidatorItem(msg = "loginName empty") String loginName, @ValidatorItem(msg = "loginPwd empty") String loginPwd, @ValidatorItem(msg = "workspaceId empty") String workspaceId, @ValidatorItem(value = ValidatorRule.NUMBERS, msg = "port error") int port, String ping) {
Assert.state(StrUtil.equals(token, JpomManifest.getInstance().randomIdSign()), "token error");
boolean exists = workspaceService.exists(new WorkspaceModel(workspaceId));
Assert.state(exists, "workspaceId error");
String sha1Id = SecureUtil.sha1(ips);
//
List<String> ipsList = StrUtil.split(ips, StrUtil.COMMA);
String clientIp = getClientIP();
if (!ipsList.contains(clientIp)) {
ipsList.add(clientIp);
}
List<String> canUseIps = ipsList.stream().filter(s -> this.testIpProt(s, ping)).collect(Collectors.toList());
List<NodeModel> canUseNode = canUseIps.stream().map(s -> {
NodeModel model = NodeInfoController.this.createModel(s, loginName, loginPwd, port, workspaceId);
try {
nodeService.testNode(model);
} catch (Exception e) {
DefaultSystemLog.getLog().warn("测试结果:{} {}", model.getUrl(), e.getMessage());
return null;
}
return model;
}).filter(Objects::nonNull).collect(Collectors.toList());
// 只返回能通的 IP
canUseIps = canUseNode.stream().map(NodeModel::getName).collect(Collectors.toList());
int size1 = CollUtil.size(canUseNode);
//
JSONObject jsonObject = new JSONObject();
jsonObject.put("allIp", ipsList);
jsonObject.put("canUseIp", canUseIps);
jsonObject.put("port", port);
jsonObject.put("id", sha1Id);
jsonObject.put("canUseNode", canUseNode);
//
exists = false;
for (NodeModel nodeModel : canUseNode) {
if (nodeService.existsByUrl(nodeModel.getUrl(), nodeModel.getWorkspaceId(), null)) {
// 存在
jsonObject.put("type", "exists");
exists = true;
break;
}
}
if (!exists) {
if (size1 == 1) {
// 只有一个 ip 可以使用
// 添加插件端
NodeModel first = CollUtil.getFirst(canUseNode);
nodeService.insertNotFill(first);
jsonObject.put("type", "success");
} else {
jsonObject.put("type", size1 == 0 ? "canUseIpEmpty" : "multiIp");
}
}
CACHE_RECEIVE_PUSH.put(sha1Id, jsonObject);
return JsonMessage.getString(200, "done", jsonObject);
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class BaseNodeService method syncExecuteNode.
/**
* 同步执行 同步节点信息
*
* @param nodeModel 节点信息
* @return json
*/
public String syncExecuteNode(NodeModel nodeModel) {
String nodeModelName = nodeModel.getName();
if (!nodeModel.isOpenStatus()) {
DefaultSystemLog.getLog().debug("{} 节点未启用", nodeModelName);
return "节点未启用";
}
try {
JSONArray jsonArray = this.getLitDataArray(nodeModel);
if (CollUtil.isEmpty(jsonArray)) {
Entity entity = Entity.create();
entity.set("nodeId", nodeModel.getId());
int del = super.del(entity);
//
DefaultSystemLog.getLog().debug("{} 节点没有拉取到任何{}", nodeModelName, dataName);
return "节点没有拉取到任何" + dataName;
}
// 查询现在存在的项目
T where = ReflectUtil.newInstance(this.tClass);
where.setWorkspaceId(nodeModel.getWorkspaceId());
where.setNodeId(nodeModel.getId());
List<T> cacheAll = super.listByBean(where);
cacheAll = ObjectUtil.defaultIfNull(cacheAll, Collections.EMPTY_LIST);
Set<String> cacheIds = cacheAll.stream().map(BaseNodeModel::dataId).collect(Collectors.toSet());
//
List<T> projectInfoModels = jsonArray.toJavaList(this.tClass);
List<T> models = projectInfoModels.stream().peek(item -> this.fullData(item, nodeModel)).filter(item -> {
// 检查对应的工作空间 是否存在
return workspaceService.exists(new WorkspaceModel(item.getWorkspaceId()));
}).filter(projectInfoModel -> {
// 避免重复同步
return StrUtil.equals(nodeModel.getWorkspaceId(), projectInfoModel.getWorkspaceId());
}).peek(item -> cacheIds.remove(item.dataId())).collect(Collectors.toList());
// 设置 临时缓存,便于放行检查
BaseServerController.resetInfo(UserModel.EMPTY);
//
models.forEach(BaseNodeService.super::upsert);
// 删除项目
Set<String> strings = cacheIds.stream().map(s -> BaseNodeModel.fullId(nodeModel.getWorkspaceId(), nodeModel.getId(), s)).collect(Collectors.toSet());
if (CollUtil.isNotEmpty(strings)) {
super.delByKey(strings, null);
}
String format = StrUtil.format("{} 节点拉取到 {} 个{},已经缓存 {} 个{},更新 {} 个{},删除 {} 个缓存", nodeModelName, CollUtil.size(jsonArray), dataName, CollUtil.size(cacheAll), dataName, CollUtil.size(models), dataName, CollUtil.size(strings));
DefaultSystemLog.getLog().debug(format);
return format;
} catch (Exception e) {
return this.checkException(e, nodeModelName);
} finally {
BaseServerController.removeEmpty();
}
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class DbUserOperateLogService method checkMonitor.
/**
* 判断当前操作是否需要报警
*
* @param userOperateLogV1 操作信息
* @param cacheInfo 操作缓存相关
*/
private void checkMonitor(UserOperateLogV1 userOperateLogV1, OperateLogController.CacheInfo cacheInfo) {
ClassFeature classFeature = EnumUtil.fromString(ClassFeature.class, userOperateLogV1.getClassFeature(), null);
MethodFeature methodFeature = EnumUtil.fromString(MethodFeature.class, userOperateLogV1.getMethodFeature(), null);
UserModel optUserItem = userService.getByKey(userOperateLogV1.getUserId());
if (classFeature == null || methodFeature == null || optUserItem == null) {
return;
}
Map<String, Object> dataMap = this.buildDataMsg(classFeature, cacheInfo, userOperateLogV1);
WorkspaceModel workspaceModel = workspaceService.getByKey(userOperateLogV1.getWorkspaceId());
String optTypeMsg = StrUtil.format(" 【{}】->【{}】", classFeature.getName(), methodFeature.getName());
List<MonitorUserOptModel> monitorUserOptModels = monitorUserOptService.listByType(userOperateLogV1.getWorkspaceId(), classFeature, methodFeature, userOperateLogV1.getUserId());
if (CollUtil.isEmpty(monitorUserOptModels)) {
return;
}
String context = this.buildContent(optUserItem, dataMap, workspaceModel, optTypeMsg, userOperateLogV1);
for (MonitorUserOptModel monitorUserOptModel : monitorUserOptModels) {
List<String> notifyUser = monitorUserOptModel.notifyUser();
if (CollUtil.isEmpty(notifyUser)) {
continue;
}
for (String userId : notifyUser) {
UserModel item = userService.getByKey(userId);
if (item == null) {
continue;
}
// 邮箱
String email = item.getEmail();
if (StrUtil.isNotEmpty(email)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.mail, email);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
// dingding
String dingDing = item.getDingDing();
if (StrUtil.isNotEmpty(dingDing)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.dingding, dingDing);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
// 企业微信
String workWx = item.getWorkWx();
if (StrUtil.isNotEmpty(workWx)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.workWx, workWx);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
}
}
}
Aggregations