Skip to content

Commit

Permalink
version 1.3.0 dashbaord support (#115)
Browse files Browse the repository at this point in the history
version 1.3.0 dashbaord support

* 增加Dashboard支持
* 修复由于ClassLoader不同导致的接口proxy创建失败
* 修复泛型导致的编译问题
* 兼容Oracle
  • Loading branch information
skyesx authored Apr 5, 2019
1 parent 6328601 commit 4ebdce8
Show file tree
Hide file tree
Showing 72 changed files with 2,147 additions and 46 deletions.
2 changes: 1 addition & 1 deletion easytrans-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-rm-datasource</artifactId>
<version>0.2.0</version>
<version>0.3.1</version>
</dependency>

<!-- for override a spring class method that imported common-logging -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import com.yiqiniu.easytrans.log.vo.LogCollection;
import com.yiqiniu.easytrans.protocol.TransactionId;

public interface TransactionLogReader {

Expand All @@ -16,4 +17,13 @@ public interface TransactionLogReader {
* @return
*/
List<LogCollection> getUnfinishedLogs(LogCollection locationId,int pageSize,Date createTimeCeiling);

/**
* 获取当前服务的未完成的日志
* get current service's unfinished logs by id
* @param ids transaction ids
* @return
*/
List<LogCollection> getTransactionLogById(List<TransactionId> ids);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yiqiniu.easytrans.monitor;

/**
* 本接口用户表明某个接口是EasyTransaction的Monitor接口
* 其只能被接口继承,否则不生效
* Monitor的接口方法的入参请用简单类型,如字符串和数字,否则可能出现问题
*
* @author deyou
* @date 2019.04.03
*/
public interface EtMonitor {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.yiqiniu.easytrans.monitor;

/**
*
* @author deyou
* @date 2019/04/02
*
*/
public interface MonitorConsumerFactory {

/**
* use for methods to call
* @param monitorInterface
* @return
*/
public <T extends EtMonitor> T getRemoteProxy(String appId, Class<T> monitorInterface);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.yiqiniu.easytrans.monitor;

/**
*
* @author deyou
*
*/
public interface StringCodecMonitor extends EtMonitor {
Object getString2IdMap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yiqiniu.easytrans.monitor;

/**
*
* @author deyou
*
*/
public interface TransactionLogMonitor extends EtMonitor {
Object getUnfinishedLogs(int pageSize,Long latestTimeStamp);

Object consistentProcess(String busCode, long trxId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.yiqiniu.easytrans.monitor.server;

import com.yiqiniu.easytrans.monitor.StringCodecMonitor;
import com.yiqiniu.easytrans.stringcodec.ListableStringCodec;
import com.yiqiniu.easytrans.stringcodec.StringCodec;

public class ServerSideStringCodecMonitor implements StringCodecMonitor {


private StringCodec stringCodec;

public ServerSideStringCodecMonitor(StringCodec stringCodec) {
super();
this.stringCodec = stringCodec;
}

@Override
public Object getString2IdMap() {

if(stringCodec instanceof ListableStringCodec) {
ListableStringCodec lsc = (ListableStringCodec) stringCodec;
return lsc.getMapStr2Id();
}

return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.yiqiniu.easytrans.monitor.server;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.yiqiniu.easytrans.core.ConsistentGuardian;
import com.yiqiniu.easytrans.log.TransactionLogReader;
import com.yiqiniu.easytrans.log.vo.LogCollection;
import com.yiqiniu.easytrans.monitor.TransactionLogMonitor;
import com.yiqiniu.easytrans.protocol.TransactionId;

public class ServerSideTransactionLogMonitor implements TransactionLogMonitor {

private String appId;
private TransactionLogReader logReader;
private ConsistentGuardian consistentGuardian;


public ServerSideTransactionLogMonitor(String appId, TransactionLogReader logReader, ConsistentGuardian consistentGuardian) {
super();
this.appId = appId;
this.logReader = logReader;
this.consistentGuardian = consistentGuardian;
}

@Override
public Object getUnfinishedLogs(int pageSize, Long latestTimeStamp) {
return logReader.getUnfinishedLogs(null, pageSize, latestTimeStamp != null?new Date(latestTimeStamp):new Date());
}

@Override
public Object consistentProcess(String busCode, long trxId) {
List<LogCollection> transactionLogById = logReader.getTransactionLogById(Arrays.asList(new TransactionId(appId,busCode,trxId)));
if(CollectionUtils.isEmpty(transactionLogById)) {
return false;
}

consistentGuardian.process(transactionLogById.get(0));
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Long branchRegister(BranchType branchType, String resourceId, String clie
Integer callSeq = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.CALL_SEQ);

// check locks
if (StringUtils.isEmpty(lockKey)) {
if (StringUtils.isNullOrEmpty(lockKey)) {
return callSeq== null?-1:callSeq.longValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class DefaultListableProviderFactory implements ListableProviderFactory,I
private Map<String,Class<?>> mapBusinessInterface = new HashMap<String,Class<?>>();
private ApplicationContext ctx;

private Map<Class<?>, List<? extends BusinessProvider<?>>> businessProviderTypeBeanMap;
@SuppressWarnings("rawtypes")
private Map<Class<?>, List<? extends BusinessProvider>> businessProviderTypeBeanMap;

// public DefaultListableProviderFactory(Map<Class<?>, List<? extends BusinessProvider<?>>> businessProviderTypeBeanMap){
// this.businessProviderTypeBeanMap = businessProviderTypeBeanMap;
Expand All @@ -54,7 +55,7 @@ public void afterPropertiesSet() throws Exception {
@SuppressWarnings("rawtypes")
private void initDefaultTypes(){

businessProviderTypeBeanMap = new HashMap<Class<?>, List<? extends BusinessProvider<?>>>(4);
businessProviderTypeBeanMap = new HashMap<Class<?>, List<? extends BusinessProvider>>(4);
Map<String, RpcBusinessProvider> rpcList = ctx.getBeansOfType(RpcBusinessProvider.class);
Map<String, MessageBusinessProvider> msgList = ctx.getBeansOfType(MessageBusinessProvider.class);

Expand Down Expand Up @@ -84,7 +85,7 @@ private void initDefaultTypes(){

//handle
for(Entry<Class<?>, Map<Class<?>, List<Object>>> entry :mapBusinessProvider.entrySet()){
List<? extends BusinessProvider<?>> beansOfType = businessProviderTypeBeanMap.get(entry.getKey());
List<? extends BusinessProvider> beansOfType = businessProviderTypeBeanMap.get(entry.getKey());
for(Object bean :beansOfType){
for(Entry<Class<?>, List<Object>> transactionTypeList:entry.getValue().entrySet()){
Class<?> transactionType = transactionTypeList.getKey();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yiqiniu.easytrans.stringcodec;

import java.util.Map;

/**
* @author xu deyou
*
*/
public interface ListableStringCodec extends StringCodec {
Map<String/*type*/, Map<String,Integer>> getMapStr2Id();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yiqiniu.easytrans.stringcodec.impl;

import java.nio.ByteBuffer;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.curator.framework.CuratorFramework;
Expand All @@ -15,9 +16,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yiqiniu.easytrans.stringcodec.StringCodec;
import com.yiqiniu.easytrans.stringcodec.ListableStringCodec;

public class ZooKeeperStringCodecImpl implements StringCodec {
public class ZooKeeperStringCodecImpl implements ListableStringCodec {

private static Logger LOG = LoggerFactory.getLogger(ZooKeeperStringCodecImpl.class);

Expand Down Expand Up @@ -184,4 +185,11 @@ public String findString(String stringType, int id) {
}
throw new RuntimeException("get string failed!" + stringType + "," + id);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, Map<String, Integer>> getMapStr2Id() {
Map map = mapStr2Id;
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static class Result implements Serializable{
private static final long serialVersionUID = 1L;
}



@SuppressWarnings("unchecked")
public <T,R extends Serializable,E extends EasyTransExecutor> T createTransactionCallInstance(Class<T> transactionApiClass, Class<? extends EasyTransRequest<R,E>> cfgClass) {
Expand All @@ -39,7 +38,7 @@ public <T,R extends Serializable,E extends EasyTransExecutor> T createTransactio


//create proxy that delegates to EasyTransFacade
Object instance = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{transactionApiClass}, new InvocationHandler() {
Object instance = Proxy.newProxyInstance(transactionApiClass.getClassLoader(), new Class[]{transactionApiClass}, new InvocationHandler() {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,27 @@ public static <T> List<Class<?>> getTypeArguments(Class<T> baseClass, Class<? ex
}
return typeArgumentsAsClasses;
}

public static Class<?> getClassWithMark(Class<?> monitorClass, Class<?> mark) {

Class<?>[] interfaces = monitorClass.getInterfaces();
for(Class<?> interfaze : interfaces) {
if(interfaze == mark) {
return monitorClass;
} else {
Class<?> result = getClassWithMark(interfaze, mark);
if(result != null) {
return result;
}
}
}

Class<?> superclass = monitorClass.getSuperclass();
if(superclass == null) {
return null;
} else {
return getClassWithMark(superclass, mark);
}
}

}
14 changes: 14 additions & 0 deletions easytrans-dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server_back.properties
*.class
*.log
*.log.*
.factorypath
/target/*
/.settings/*
/bin/*
/.project
/.classpath
/logs
/target/
.DS_Store
.springBeans
88 changes: 88 additions & 0 deletions easytrans-dashboard/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<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">
<modelVersion>4.0.0</modelVersion>
<name>EasyTransaction dashboard</name>

<artifactId>easytrans-dashboard</artifactId>

<parent>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>



<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!-- <dependency>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-starter</artifactId>
<exclusions>
<exclusion>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>
easytrans-log-database-starter
</artifactId>
</exclusion>
<exclusion>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>
easytrans-queue-kafka-starter
</artifactId>
</exclusion>
</exclusions>
</dependency> -->

<dependency>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-rpc-rest-ribbon-starter</artifactId>
</dependency>

<dependency>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-rpc-dubbo-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 4ebdce8

Please sign in to comment.