forked from github/dataease
Merge pull request #7679 from dataease/pr@dev-v2@perf_rmonitor
feat: 首次升级企业版监测游离资源
This commit is contained in:
commit
c815c7391b
@ -101,6 +101,21 @@
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dataease</groupId>
|
||||
<artifactId>xpack-base</artifactId>
|
||||
<version>${dataease.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dataease</groupId>
|
||||
<artifactId>xpack-permissions</artifactId>
|
||||
<version>${dataease.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dataease</groupId>
|
||||
<artifactId>xpack-sync</artifactId>
|
||||
<version>${dataease.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,12 @@
|
||||
package io.dataease.rmonitor.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class PerMonitorCheckBO implements Serializable {
|
||||
|
||||
private boolean valid;
|
||||
|
||||
private boolean emptyPermission;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.dataease.rmonitor.bo;
|
||||
|
||||
import io.dataease.model.TreeBaseModel;
|
||||
import io.dataease.model.TreeResultModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PerMonitorNodeBO implements TreeBaseModel<PerMonitorNodeBO>, TreeResultModel<PerMonitorNodeBO>, Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long pid;
|
||||
|
||||
private boolean leaf;
|
||||
|
||||
private int extraFlag;
|
||||
|
||||
private List<PerMonitorNodeBO> children;
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package io.dataease.rmonitor.manage;
|
||||
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.rmonitor.bo.PerMonitorCheckBO;
|
||||
import io.dataease.rmonitor.bo.PerMonitorNodeBO;
|
||||
import io.dataease.rmonitor.mapper.ResourceMonitorMapper;
|
||||
import io.dataease.rmonitor.mapper.entity.DatasetFreeResource;
|
||||
import io.dataease.rmonitor.mapper.entity.DsFreeResource;
|
||||
import io.dataease.rmonitor.mapper.entity.VisualFreeResource;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.TreeUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component("resourceMonitorManage")
|
||||
public class ResourceMonitorManage {
|
||||
|
||||
|
||||
@Resource(name = "resourceMonitorSyncManage")
|
||||
private ResourceMonitorSyncManage resourceMonitorSyncManage;
|
||||
|
||||
@Resource
|
||||
private ResourceMonitorMapper resourceMonitorMapper;
|
||||
|
||||
|
||||
private boolean existFreeResource() {
|
||||
int rCount = resourceMonitorMapper.dsCount() + resourceMonitorMapper.datasetCount() + resourceMonitorMapper.vCount();
|
||||
return rCount > 0;
|
||||
}
|
||||
|
||||
private Map<String, List<PerMonitorNodeBO>> freeResource() {
|
||||
Map<String, List<PerMonitorNodeBO>> result = new HashMap<>();
|
||||
|
||||
List<DsFreeResource> dsFreeResources = resourceMonitorMapper.queryFreeDs();
|
||||
if (CollectionUtils.isNotEmpty(dsFreeResources)) {
|
||||
List<PerMonitorNodeBO> dsBos = dsFreeResources.stream().map(node -> {
|
||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
||||
bo.setLeaf(StringUtils.equals("folder", node.getType()));
|
||||
return bo;
|
||||
}).collect(Collectors.toList());
|
||||
List<PerMonitorNodeBO> dsTree = TreeUtils.mergeTree(dsBos, PerMonitorNodeBO.class, false);
|
||||
result.put("datasource", dsTree);
|
||||
}
|
||||
|
||||
List<DatasetFreeResource> datasetFreeResources = resourceMonitorMapper.queryFreeDataset();
|
||||
if (CollectionUtils.isNotEmpty(datasetFreeResources)) {
|
||||
List<PerMonitorNodeBO> datasetBos = datasetFreeResources.stream().map(node -> {
|
||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
||||
bo.setLeaf(StringUtils.equals("folder", node.getNodeType()));
|
||||
return bo;
|
||||
}).collect(Collectors.toList());
|
||||
List<PerMonitorNodeBO> datasetTree = TreeUtils.mergeTree(datasetBos, PerMonitorNodeBO.class, false);
|
||||
result.put("dataset", datasetTree);
|
||||
}
|
||||
|
||||
List<VisualFreeResource> visualFreeResources = resourceMonitorMapper.queryFreeVusial();
|
||||
if (CollectionUtils.isNotEmpty(visualFreeResources)) {
|
||||
Map<String, List<VisualFreeResource>> baseMap = visualFreeResources.stream().collect(Collectors.groupingBy(VisualFreeResource::getType));
|
||||
for (Map.Entry<String, List<VisualFreeResource>> entry : baseMap.entrySet()) {
|
||||
List<VisualFreeResource> freeResource = entry.getValue();
|
||||
List<PerMonitorNodeBO> visualBos = freeResource.stream().map(node -> {
|
||||
PerMonitorNodeBO bo = BeanUtils.copyBean(new PerMonitorNodeBO(), node);
|
||||
bo.setLeaf(StringUtils.equals("folder", node.getNodeType()));
|
||||
return bo;
|
||||
}).collect(Collectors.toList());
|
||||
result.put(convertBusiFlag(entry.getKey()), TreeUtils.mergeTree(visualBos, PerMonitorNodeBO.class, false));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String convertBusiFlag(String key) {
|
||||
if (StringUtils.equals("dashboard", key)){
|
||||
return "panel";
|
||||
} else if (StringUtils.equals("dataV", key)) {
|
||||
return "screen";
|
||||
} else return key;
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
PerMonitorCheckBO checkBO = resourceMonitorSyncManage.checkXpackResource();
|
||||
return checkBO.isValid() && checkBO.isEmptyPermission() && existFreeResource();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete() {
|
||||
boolean existFree = existFreeResource();
|
||||
if (!existFree) DEException.throwException("无未同步资源!");
|
||||
resourceMonitorMapper.delFreeDs();
|
||||
resourceMonitorMapper.delFreeDataset();
|
||||
resourceMonitorMapper.delFreeVisual();
|
||||
}
|
||||
|
||||
public void sync() {
|
||||
//1、从xpack获取资源 如果xpack不存在 或者资源不为空 则直接返回 并且抛出异常“仅支持首次导入lic同步”
|
||||
//2、从core获取资源
|
||||
//3、根据类型分组 并组织成树形结构
|
||||
//4、分别遍历每一棵树 从上到下 同步到权限体系 给默认组织
|
||||
PerMonitorCheckBO checkBO = resourceMonitorSyncManage.checkXpackResource();
|
||||
if (!checkBO.isValid()) DEException.throwException("缺少许可证");
|
||||
if (!checkBO.isEmptyPermission()) DEException.throwException("仅支持license首次导入同步");
|
||||
Map<String, List<PerMonitorNodeBO>> freeResourceMap = freeResource();
|
||||
if (MapUtils.isEmpty(freeResourceMap)) DEException.throwException("无未同步资源!");
|
||||
for (Map.Entry<String, List<PerMonitorNodeBO>> entry : freeResourceMap.entrySet()) {
|
||||
resourceMonitorSyncManage.sync(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.dataease.rmonitor.manage;
|
||||
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.license.config.XpackInteract;
|
||||
import io.dataease.rmonitor.bo.PerMonitorCheckBO;
|
||||
import io.dataease.rmonitor.bo.PerMonitorNodeBO;
|
||||
import io.dataease.rmonitor.mapper.ResourceMonitorMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component("resourceMonitorSyncManage")
|
||||
public class ResourceMonitorSyncManage {
|
||||
|
||||
@Resource(name = "resourceMonitorMapper")
|
||||
private ResourceMonitorMapper resourceMonitorMapper;
|
||||
|
||||
@XpackInteract(value = "resourceMonitorSyncManage", replace = true)
|
||||
public void sync(String flag, List<PerMonitorNodeBO> treeNodes) {
|
||||
DEException.throwException("缺失许可证");
|
||||
}
|
||||
|
||||
@XpackInteract(value = "resourceMonitorSyncManage", replace = true)
|
||||
public PerMonitorCheckBO checkXpackResource() {
|
||||
return new PerMonitorCheckBO();
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package io.dataease.rmonitor.mapper;
|
||||
|
||||
import io.dataease.rmonitor.mapper.entity.DatasetFreeResource;
|
||||
import io.dataease.rmonitor.mapper.entity.DsFreeResource;
|
||||
import io.dataease.rmonitor.mapper.entity.VisualFreeResource;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ResourceMonitorMapper {
|
||||
|
||||
@Select("select count(id) from core_datasource")
|
||||
int dsCount();
|
||||
|
||||
@Select("select count(id) from core_dataset_group")
|
||||
int datasetCount();
|
||||
|
||||
@Select("select count(id) from data_visualization_info")
|
||||
int vCount();
|
||||
|
||||
@Select("select id, name, pid, type, status from core_datasource")
|
||||
List<DsFreeResource> queryFreeDs();
|
||||
|
||||
@Select("select id, name, pid, node_type from core_dataset_group")
|
||||
List<DatasetFreeResource> queryFreeDataset();
|
||||
|
||||
@Select("select id, name, pid, node_type, type from data_visualization_info")
|
||||
List<VisualFreeResource> queryFreeVusial();
|
||||
|
||||
@Delete("delete from core_datasource")
|
||||
void delFreeDs();
|
||||
|
||||
@Delete("delete from core_dataset_group")
|
||||
void delFreeDataset();
|
||||
@Delete("delete from data_visualization_info")
|
||||
void delFreeVisual();
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package io.dataease.rmonitor.mapper.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class BaseFreeResource implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long pid;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package io.dataease.rmonitor.mapper.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class DatasetFreeResource extends BaseFreeResource implements Serializable {
|
||||
|
||||
private String nodeType;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.rmonitor.mapper.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class DsFreeResource extends BaseFreeResource implements Serializable {
|
||||
|
||||
private String type;
|
||||
|
||||
private String status;
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package io.dataease.rmonitor.mapper.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class VisualFreeResource extends BaseFreeResource implements Serializable {
|
||||
|
||||
private String nodeType;
|
||||
|
||||
private String type;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.dataease.rmonitor.server;
|
||||
|
||||
import io.dataease.api.rmonitor.ResourceMonitorApi;
|
||||
import io.dataease.rmonitor.manage.ResourceMonitorManage;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/rmonitor")
|
||||
public class ResourceMonitorServer implements ResourceMonitorApi {
|
||||
|
||||
@Resource(name = "resourceMonitorManage")
|
||||
private ResourceMonitorManage resourceMonitorManage;
|
||||
|
||||
@Override
|
||||
public boolean existFree() {
|
||||
return resourceMonitorManage.check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
resourceMonitorManage.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync() {
|
||||
resourceMonitorManage.sync();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user