Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #26] CRUD the basic tables of Topic, Group, GroupMember, and Operation #28

Merged
merged 22 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions eventmesh-dashboard-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
10 changes: 8 additions & 2 deletions eventmesh-dashboard-console/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.eventmesh.dashboard</groupId>
Expand Down Expand Up @@ -75,6 +75,12 @@
<artifactId>spring-aspects</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>


</dependencies>
Expand Down

This file was deleted.

Pil0tXia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

package org.apache.eventmesh.dashboard.console;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootApplication
@ComponentScan({"org.apache.eventmesh.dashboard.service", "org.apache.eventmesh.dashboard.console"})
@EnableTransactionManagement
public class EventmeshConsoleApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity;
package org.apache.eventmesh.dashboard.console.entity.group;

import java.sql.Timestamp;

Expand All @@ -35,7 +35,6 @@ public class GroupEntity {

private Integer memberCount;


private String members;

private Integer type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity;
package org.apache.eventmesh.dashboard.console.entity.groupmember;

import java.sql.Timestamp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity;
package org.apache.eventmesh.dashboard.console.entity.log;

import java.sql.Timestamp;

Expand All @@ -34,7 +34,7 @@ public class LogEntity {

private String operationType;

private String operationTarget;
private String targetType;

private Integer status;

Expand All @@ -44,5 +44,8 @@ public class LogEntity {

private Timestamp endTime;

private String operationUser;

private String resultContent;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity;
package org.apache.eventmesh.dashboard.console.entity.topic;

import java.sql.Timestamp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,105 @@
package org.apache.eventmesh.dashboard.console.log;

import org.apache.eventmesh.dashboard.console.annotation.EmLog;
import org.apache.eventmesh.dashboard.console.entity.LogEntity;
import org.apache.eventmesh.dashboard.console.log.service.LogService;
import org.apache.eventmesh.dashboard.console.entity.log.LogEntity;
import org.apache.eventmesh.dashboard.console.service.log.LogService;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Objects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

@Aspect
@Service
public class OprLog implements Ordered {
public class OprLog implements Ordered, ApplicationContextAware {

private int order = LOWEST_PRECEDENCE - 1000; // Specify the order of execution

@Autowired
private LogService logService;

private ApplicationContext applicationContext;


@Pointcut("within(org.apache.eventmesh.dashboard.console.service..*)")
public void pointCut() {
}


@Around("pointCut()")
public Object logStart(ProceedingJoinPoint joinPoint) throws Throwable {
if (Objects.isNull(this.logService)) {
this.logService = applicationContext.getBean(LogService.class);
}
EmLog declaredAnnotation = this.getTargetEmlog(joinPoint);
//Get the Emlog annotation on the method
if (Objects.isNull(declaredAnnotation)) {
return joinPoint.proceed();
}
LogEntity logEntity = this.productLoEntity(declaredAnnotation, joinPoint);
logService.addLog(logEntity);
logEntity.setEndTime(new Timestamp(System.currentTimeMillis()));
Object proceed = null;
try {
proceed = joinPoint.proceed();
logEntity.setStatus(2);
logEntity.setResultContent(Objects.isNull(proceed) ? "" : proceed.toString());
return proceed;
} catch (Throwable e) {
logEntity.setStatus(3);
throw new RuntimeException(e);
} finally {
logEntity.setResultContent(proceed.toString());
logService.updateLog(logEntity);
}


}

public LogEntity productLoEntity(EmLog declaredAnnotation, ProceedingJoinPoint joinPoint) throws NoSuchFieldException, IllegalAccessException {
LogEntity logEntity = new LogEntity();
Object[] args = joinPoint.getArgs();
Object model = args[0];
//Obtaining the Input Parameter of the Operation Method (Specified as the First)
Field clusterPhyId = model.getClass().getDeclaredField("clusterId");
clusterPhyId.setAccessible(true);
Long opClusterPhyId = (Long) clusterPhyId.get(model);
//The clusterId is obtained from the parameter object, and the operation is described as the object itself
logEntity.setClusterId(opClusterPhyId);
logEntity.setDescription(model.toString());
logEntity.setOperationType(declaredAnnotation.OprType());
logEntity.setTargetType(declaredAnnotation.OprTarget());
logEntity.setStatus(1);
logEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
return logEntity;
}

public EmLog getTargetEmlog(ProceedingJoinPoint joinPoint) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Method mostSpecificMethod = ClassUtils.getMostSpecificMethod(method, joinPoint.getTarget().getClass());
EmLog declaredAnnotation = mostSpecificMethod.getAnnotation(EmLog.class);
//Get the Emlog annotation on the method
if (declaredAnnotation != null) {
//It is a method of operation
logEntity.setOperationType(declaredAnnotation.OprType());
logEntity.setOperationType(declaredAnnotation.OprTarget());
Object[] args = joinPoint.getArgs();
Object model = args[0];
//Obtaining the Input Parameter of the Operation Method (Specified as the First)
Field clusterPhyId = model.getClass().getDeclaredField("clusterId");
clusterPhyId.setAccessible(true);
Long opClusterPhyId = (Long) clusterPhyId.get(model);
String opDescription = model.toString();
logEntity.setClusterId(opClusterPhyId);
logEntity.setDescription(opDescription);
//The clusterId is obtained from the parameter object, and the operation is described as the object itself
logEntity.setStatus(1);
logEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
logService.addLog(logEntity);
Object proceed = joinPoint.proceed();
if (proceed == null) {
//An exception occurred with the target method
logEntity.setStatus(3);
logEntity.setEndTime(new Timestamp(System.currentTimeMillis()));
Integer integer1 = logService.updateLog(logEntity);
return proceed;
} else {
//The target approach is successful
logEntity.setEndTime(new Timestamp(System.currentTimeMillis()));
logEntity.setStatus(2);
Integer integer1 = logService.updateLog(logEntity);
return proceed;
}
} else {
//It is not part of the operation method
return joinPoint.proceed();
}
return declaredAnnotation;
}

@Override
public int getOrder() {
return order;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}

This file was deleted.

Loading
Loading