Commit 82f5470f by qiuchaofei

1.日志信息添加ip地址,2 保存关系时添加描述与作业号,3,孤岛分析添加环境id

parent 7eeed456
......@@ -31,8 +31,12 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@RestController
@Api(value = "把metadata写入neo4j数据库", tags = "metadata to neo4j")
public class MetaDataController {
......@@ -531,7 +535,24 @@ public class MetaDataController {
return metadataService.findAllNodeTypes();
}
private String getIp(){
HttpServletRequest request = getRequest();
if (request == null) {
return "127.0.0.1";
}else {
return request.getRemoteHost();
}
}
//获取请求对象
public static HttpServletRequest getRequest() {
ServletRequestAttributes requestAttributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return null;
} else {
return requestAttributes.getRequest();
}
}
/**
* 传入元数据id,显示的层数,查找出与该元数据有关系的数据
*/
......@@ -561,7 +582,7 @@ public class MetaDataController {
@RequestMapping(path = "/syschroRelationFromMongo", method = RequestMethod.POST)
public String synchroRelationFromMongo(String catalogName) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LogManager.logInfo(LogConstants.CTX_RELATION, "用户 "+ getUserName() + " 在 "+ sdf.format(new Date())+"同步环境:"+catalogName+" 的元数据。" );
LogManager.logInfo(LogConstants.CTX_RELATION, "ip: "+getIp()+",用户:"+ getUserName() + " 在 "+ sdf.format(new Date())+"同步环境:"+catalogName+" 的元数据。" );
logger.info("开始异步迁移元数据:从mongo到neo4j");
String flag = "success";
asyncDataFromMongoToNeo4j.asyncDataFromMongoToNeo4j(catalogName);
......@@ -574,7 +595,7 @@ public class MetaDataController {
@RequestMapping(path = "/synchroRelationByJobId", method = RequestMethod.POST)
public String synchroRelationByJobId(String catalogName,String jobId) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LogManager.logInfo(LogConstants.CTX_RELATION, "用户 "+ getUserName() + " 在 "+ sdf.format(new Date())+"同步环境:"+catalogName+" JobId:"+jobId+" 的元数据。" );
LogManager.logInfo(LogConstants.CTX_RELATION, "ip: "+getIp()+",用户:"+ getUserName() + " 在 "+ sdf.format(new Date())+"同步环境:"+catalogName+" JobId:"+jobId+" 的元数据。" );
logger.info("开始异步迁移元数据:从mongo到neo4j");
String flag = "success";
......
......@@ -269,51 +269,12 @@ public class RelationalGraphController {
private String getIp(){
HttpServletRequest request = getRequest();
if (request == null) {
return "127.0.0.1";
}else {
// return getIpAddr(request);
return request.getRemoteHost();
}
}
public String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
try {
ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if (ipAddress.equals("127.0.0.1")) {
// 根据网卡取本机配置的IP
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress = inet.getHostAddress();
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
// = 15
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
} catch (Exception e) {
ipAddress="";
}
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress;
}
//获取请求对象
public static HttpServletRequest getRequest() {
......@@ -353,7 +314,7 @@ public class RelationalGraphController {
@RequestMapping(path = "/getRelationObjectByTableId", method = RequestMethod.GET)
public Map<String,List<ReturnNode>> getRelationObjectByTableId(String tableId){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LogManager.logInfo(LogConstants.CTX_RELATION, "ip: "+getIp()+",用户"+ getUserName() + " 在 "+ sdf.format(new Date()) + " 查看了 "+tableId+"的关系分析" );
LogManager.logInfo(LogConstants.CTX_RELATION, "ip: "+getIp()+",用户:"+ getUserName() + " 在 "+ sdf.format(new Date()) + " 查看了 "+tableId+"的关系分析" );
long start = System.currentTimeMillis();
Map<String, List<ReturnNode>> relationObjects = tableService.getRelationObjectByTableId (tableId);
......
......@@ -190,7 +190,8 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
// (m{metadataId:"Table=1=d644b631fa8c434e928bcd1f1665b060"})
// create (n)<-[r:Composition]-(m)
// return n,m,r
String cypher = " match ( n {metadataId:\""+startId+"\"}),(m { metadataId:\""+endId+"\"}) merge (n)-[r:"+relationType+"]->(m) set r.jobId ="+jobId;
String cypher = " match ( n {metadataId:\""+startId+"\"}),(m { metadataId:\""+endId+"\"}) merge (n)-[r:"+relationType+"]->(m) " +
"set r.jobId =\""+jobId+"\"";
// logger.info("运行保存关系完成:" + cypher);
session.run(cypher);
......@@ -206,9 +207,9 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
// merge (n)-[r:流向]->(m)
// set r={jobId:"0",descriptio:"0" }
String cypher = "match (n { metadataId:\""+startId+"\"}), ( m { metadataId:\""+endId+"\"} ) " +
"merge (n)-[r:"+relationType+"]->(m) set r = {jobId:"+jobId+",description:"+description+" }";// set r.jobId ="+description + " and r.description = "+ description;
"merge (n)-[r:"+relationType+"]->(m) set r = {jobId:\""+jobId+"\",description:"+description+" }";// set r.jobId ="+description + " and r.description = "+ description;
// logger.info("运行保存关系完成:" + cypher);
logger.info("运行保存关系完成:" + cypher);
session.run(cypher);
}
......
......@@ -28,21 +28,22 @@ public class DataRelationAnalyServiceImpl implements DataRelationAnalyService {
public Map<String, ReturnNode> findTableWithoutRelations(String parentId) {
Map<String, ReturnNode> returnNodeMap = new HashMap<>();
//区分传入的id是系统还是schema,还是为空,为空则找出所有的孤立点
//区分传入的id是环境id,系统id还是schema,还是为空,为空则找出所有的孤立点
//match (n:Neo4jTable) where not ((n)-[:`流向`]-(:Neo4jTable)) return n
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = "";
String condition = "";
if(parentId !=null && parentId .startsWith("System=")){
condition= "<-[r1:Composition]-(:Neo4jSchema)<-[r2:Composition]-(m:Neo4jSystem{metadataId:\""+parentId+"\"})";
cypher = "match (n:Neo4jTable) " + condition + "where not ((n)-[:`流向`]-()) return n";
}else if(parentId !=null && parentId .startsWith("Schema=")){
condition= "<-[r1:Composition]-(m:Neo4jSchema{metadataId:\""+parentId+"\"})";
}else {
cypher = "match (n:Neo4jTable) " + condition + "where not ((n)-[:`流向`]-()) return n";
}else if(parentId !=null){
cypher = "match (n:Neo4jTable{isEnvironment:\""+parentId+"\"}) where not ((n)-[:`流向`]-()) return n";
}
String cypher = "match (n:Neo4jTable) " + condition + "where not ((n)-[:`流向`]-()) return n";
logger .info("查找孤立表的语句:"+cypher);
StatementResult result = session.run(cypher);
while(result.hasNext()){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment