package com.cloud.device.controller;
|
|
import com.cloud.common.exception.ApplicationException;
|
import com.cloud.device.constants.Constants;
|
import com.cloud.device.filter.AuthNoneIgnore;
|
import com.cloud.device.model.Cluster;
|
import com.cloud.device.model.Device;
|
import com.cloud.device.model.Node;
|
import com.cloud.device.service.ClusterService;
|
import com.cloud.device.service.DeviceService;
|
import com.cloud.device.service.NodeService;
|
import com.cloud.device.vo.ClusterNodeVo;
|
import com.cloud.device.vo.MenuTreeVo;
|
import com.cloud.device.vo.SharePersonParamVo;
|
import com.cloud.model.common.Page;
|
import com.cloud.model.common.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.awt.*;
|
import java.util.*;
|
import java.util.List;
|
|
/**
|
* 集群管理
|
*/
|
@Slf4j
|
@Api(value = "ClusterController", description = "集群管理")
|
@RequestMapping("/data/api-d/cluster")
|
@RestController
|
public class ClusterController {
|
|
@Autowired
|
private ClusterService clusterService;
|
|
@Autowired
|
private NodeService nodeService;
|
|
@Autowired
|
private DeviceService deviceService;
|
|
|
@RequestMapping("/findClusterInfoByNodeIp")
|
@ApiOperation(value = "通过集群内节点ip查找集群信息", notes = "通过集群内节点ip查找集群信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "nodeIp", value = "节点ip地址", required = true, dataType = "String", paramType = "query")
|
})
|
public Result findClusterInfoByNodeIp(@RequestParam String nodeIp){
|
try {
|
if(StringUtils.isNotEmpty(nodeIp)){
|
Map<String,Object> params = new HashMap<>();
|
params.put("nodeIp", nodeIp);
|
return Result.ok(Constants.RESULT_QUERY_OK, clusterService.findClusteInfoByNodeIp(params));
|
}else
|
return Result.error(new Exception("参数错误"));
|
|
} catch (Exception e) {
|
return Result.ok(Constants.RESULT_QUERY_FAIL, "未找到集群信息,请检查ip是否正确");
|
}
|
}
|
|
@RequestMapping("/save")
|
@ApiOperation(value = "保存集群和节点信息,包括节点下的设备信息", notes = "保存集群和节点信息,包括节点下的设备信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name="address",value="ip地址",required = true,dataType = "String",paramType = "query"),
|
@ApiImplicitParam(name = "cookie",value = "集群密码",required = true,dataType = "String",paramType = "query")
|
})
|
public Result save(String address, String cookie){
|
try{
|
if(StringUtils.isNotEmpty(address) && StringUtils.isNotEmpty(cookie)){
|
// if(clusterService.verifyClusterPwdByCServer(address, cookie))
|
return Result.ok(Constants.RESULT_SAVE_OK,clusterService.save(address, cookie));
|
}
|
|
}catch(Exception e){
|
log.error(e.getLocalizedMessage());
|
}
|
return Result.custom("集群保存失败",500,false,"集群保存失败");
|
}
|
|
@GetMapping("/delete")
|
@ApiOperation(value = "退出集群", notes = "退出集群", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "cookie", value = "cookie", required = true, dataType = "String", paramType = "query")
|
})
|
public Result deleteCluster(String id, String cookie){
|
try {
|
Cluster cluster = clusterService.selectById(id);
|
if(cluster != null && StringUtils.isNotEmpty(cluster.getAddress())){
|
// if(clusterService.verifyClusterPwdByCServer(cluster.getAddress(), cookie)){
|
// if(clusterService.deleteById(id,cookie))
|
// return Result.ok(Constants.RESULT_DELETE_OK, "退出成功");
|
//
|
// }else
|
// return Result.custom("退出失败,密码不匹配",500,false,"退出失败,密码不匹配");
|
|
if(clusterService.deleteById(id,cookie)){
|
return Result.ok(Constants.RESULT_DELETE_OK, "退出成功");
|
}else{
|
return Result.custom("退出失败,密码不匹配",401,false,"");
|
}
|
}
|
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
return Result.custom("退出失败",500,false,"退出失败");
|
}
|
|
@RequestMapping("/getClusterDeviceTree")
|
@ApiOperation(value = "获取集群设备树信息", notes = "获取集群设备树信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public List<MenuTreeVo> getClusterDeviceTree(){
|
try {
|
return clusterService.getClusterDeviceTree();
|
} catch (Exception e) {
|
log.error(e.getLocalizedMessage());
|
return new ArrayList<>();
|
}
|
}
|
|
@AuthNoneIgnore
|
@RequestMapping("/findAllNode")
|
@ApiOperation(value = "查询集群和节点信息", notes = "查询集群和节点信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "params", value = "忽略,无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "name", value = "集群名称,模糊查找", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "isContainerDb", value = "是否返回数据库列表,不传表示不需要,需要请传:1", required = false, dataType = "String", paramType = "query"),
|
})
|
public Result findAllNode(@RequestParam Map<String, Object> params){
|
try{
|
return Result.ok(Constants.RESULT_QUERY_OK,clusterService.findAllNode(params));
|
}catch(Exception e){
|
e.printStackTrace();
|
log.error(e.getLocalizedMessage());
|
return Result.error(e);
|
}
|
|
}
|
|
@RequestMapping("/getAllCluListData")
|
@ApiOperation(value = "获取所有集群设备级别信息,实时查询", notes = "获取所有集群设备级别信息,实时查询", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
|
})
|
public Result getAllCluListData(){
|
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK,clusterService.getAllCluListData());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/getAllCluDataBaseList")
|
@ApiOperation(value = "获取集群节点及同步库信息",notes = "获取集群节点及同步库信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
|
})
|
public Result getAllCluDataBaseList(){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, clusterService.getAllCluDataBaseList());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/getClusterTreeData")
|
@ApiOperation(value = "获取集群设备树(带全选)", notes = "获取集群设备树(带全选)", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public Result getClusterTreeData(){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, clusterService.getClusterTreeData());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@GetMapping("/findClusterList")
|
@ApiOperation(value = "查询集群-节点-设备列表", notes = "查询集群-节点-设备列表", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "type", value = "点击节点类型(1:集群,2:节点,3:设备)", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "id", value = "点击节点id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "condition", value = "设备名称/设备地址", required = false, dataType = "String", paramType = "query")
|
})
|
public Result findClusterList(String type, String id, String condition){
|
List<MenuTreeVo> result = new ArrayList<MenuTreeVo>();
|
|
try {
|
Cluster cluster = null;
|
Node node =null;
|
Device device = null;
|
if(id.equals("0")){//表示查询所有集群信息
|
//刷新整个集群的信息
|
|
result = clusterService.getAllClusterMenuInfo(condition);
|
}else{
|
if(type.equals(Constants.TYPE_CLUSTER)){//点击集群
|
cluster = clusterService.selectById(id);
|
}else if(type.equals(Constants.TYPE_NODE)){//点击节点
|
node = nodeService.selectById(id);
|
if(node !=null && StringUtils.isNotEmpty(node.getClusterId()))
|
cluster = clusterService.selectById(node.getClusterId());
|
}else if(type.equals(Constants.TYPE_DEVICE)){//点击设备
|
device = deviceService.selectById(id);
|
if(device !=null && StringUtils.isNotEmpty(device.getNodeId())){
|
node = nodeService.selectById(device.getNodeId());
|
if(node !=null && StringUtils.isNotEmpty(node.getClusterId()))
|
cluster = clusterService.selectById(node.getClusterId());
|
}
|
}
|
|
if(cluster !=null && StringUtils.isNotEmpty(cluster.getAddress())){
|
String clusterIp = cluster.getAddress().split(":")[0];
|
//20190311,学校设备多了之后,从这里做同步速度很慢,而且取到的分析设备信息有误(后续同步功能由消息队列完成)
|
// clusterService.save(clusterIp, null);//刷新集群下所有节点和设备信息
|
|
result.add(clusterService.refreshCluster(clusterIp, type, id));
|
}
|
}
|
|
return Result.ok(Constants.RESULT_QUERY_OK, result);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/findNodeById")
|
@ApiOperation(value = "根据节点Id,查询节点详细信息及归属的集群", notes = "根据节点Id,查询节点详细信息及归属的集群", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "nodeIds", value = "节点Ids,多个用逗号分隔", required = false, dataType = "String", paramType = "query")
|
})
|
public Result findNodeById(String nodeIds){
|
try{
|
return Result.ok(Constants.RESULT_QUERY_OK,clusterService.findNodesByIds(nodeIds));
|
}catch(Exception e){
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@PostMapping("/findClusterNodesByClusterIds")
|
@ApiOperation(value = "通过集群ids查询集群及节点信息", notes = "通过集群ids查询集群及节点信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
public Result findClusterNodesByClusterIds(@RequestBody Map<String,Object> params){
|
try {
|
String clusterIds = params.get("clusterIds").toString();
|
return Result.ok(Constants.RESULT_QUERY_OK,clusterService.findClusterNodesByClusterIds(clusterIds));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
|
|
public Result sharePersonToCluster(SharePersonParamVo sharePersonParamVo){
|
try{
|
return Result.ok("分享成功",clusterService.sharePersonToCluster(sharePersonParamVo));
|
}catch(Exception e){
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
|
}
|
}
|