Commit 2eae2111 by qiuweili123

增加hbase

parent 03237405
<?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">
<parent>
<artifactId>matrix-bigdata</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-bigdata-hbase-starter</artifactId>
</project>
\ No newline at end of file
<?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">
<parent>
<artifactId>matrix-bigdata</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-bigdata-spark-starter</artifactId>
</project>
\ No newline at end of file
<?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">
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-bigdata</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-bigdata-hbase-starter</module>
<module>matrix-bigdata-spark-starter</module>
</modules>
</project>
\ No newline at end of file
...@@ -8,4 +8,3 @@ xxl: ...@@ -8,4 +8,3 @@ xxl:
log-retention-days: #日志保存时间,默认7天 log-retention-days: #日志保存时间,默认7天
#app-name: 默认会读取spring.application.name或者-Dapp.id #app-name: 默认会读取spring.application.name或者-Dapp.id
admin-addresses: #xxl-admin访问地址,如开发环境 http://job.secoolocal.com admin-addresses: #xxl-admin访问地址,如开发环境 http://job.secoolocal.com
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<dependency> <dependency>
<groupId>com.secoo</groupId> <groupId>com.secoo</groupId>
<artifactId>secoo-xxl-job-core</artifactId> <artifactId>secoo-xxl-job-core</artifactId>
<version>2.1.0-secoo1.2</version> <version>2.1.0-secoo1.3</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -10,7 +10,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty; ...@@ -10,7 +10,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
@Data @Data
@ConfigurationProperties(prefix = MatrixMybatisBootProperties.PREFIX) @ConfigurationProperties(prefix = MatrixMybatisBootProperties.PREFIX)
public class MatrixMybatisBootProperties extends MatrixMybatisProperties { public class MatrixMybatisBootProperties extends MatrixMybatisProperties {
public static final String PREFIX = "matrix.mybatis"; public static final String PREFIX = "mybatis";
@NestedConfigurationProperty @NestedConfigurationProperty
private MatrixMybatisConfiguration configuration; private MatrixMybatisConfiguration configuration;
......
package com.secoo.mall.dubbo.filter;
import com.secoo.mall.dubbo.listener.ExceptionListener;
import org.apache.dubbo.rpc.*;
public abstract class AbsExceptionFilter extends ListenableFilter {
public AbsExceptionFilter() {
super.listener = getExceptionListener();
}
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
protected abstract ExceptionListener getExceptionListener();
}
package com.secoo.mall.dubbo.filter; package com.secoo.mall.dubbo.filter;
import org.apache.dubbo.common.constants.CommonConstants; import com.secoo.mall.dubbo.listener.ExceptionListener;
import org.apache.dubbo.common.extension.Activate; import com.secoo.mall.dubbo.listener.MatrixExceptionListener;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.service.GenericService;
import java.lang.reflect.Method;
/** /**
* 统一拦截异常。 * 统一拦截异常。
...@@ -17,85 +9,10 @@ import java.lang.reflect.Method; ...@@ -17,85 +9,10 @@ import java.lang.reflect.Method;
/*@Activate( /*@Activate(
group = {CommonConstants.PROVIDER} group = {CommonConstants.PROVIDER}
)*/ )*/
public class MatrixExceptionFilter extends ListenableFilter { public class MatrixExceptionFilter extends AbsExceptionFilter {
public MatrixExceptionFilter() {
super.listener = new MatrixExceptionFilter.ExceptionListener();
}
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
static class ExceptionListener implements Listener {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Override @Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) { protected ExceptionListener getExceptionListener() {
if (appResponse.hasException() && GenericService.class != invoker.getInterface()) { return new MatrixExceptionListener();
try {
Throwable exception = appResponse.getException();
// directly throw if it's checked exception
if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
return;
}
// directly throw if the exception appears in the signature
try {
Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
Class<?>[] exceptionClassses = method.getExceptionTypes();
for (Class<?> exceptionClass : exceptionClassses) {
if (exception.getClass().equals(exceptionClass)) {
return;
}
}
} catch (NoSuchMethodException e) {
return;
}
//防止报警信息错误
String msg = "Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage();
if (exception instanceof RuntimeException) {
logger.warn(msg, exception);
} else {
logger.error(msg, exception);
}
// directly throw if exception class and interface class are in the same jar file.
String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) {
return;
} }
// directly throw if it's JDK exception
String className = exception.getClass().getName();
if (className.startsWith("java.") || className.startsWith("javax.")) {
return;
}
// directly throw if it's dubbo exception
if (exception instanceof RpcException) {
return;
}
// otherwise, wrap with RuntimeException and throw back to the client
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
return;
} catch (Throwable e) {
logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
return;
}
}
}
@Override
public void onError(Throwable e, Invoker<?> invoker, Invocation invocation) {
logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
// For test purpose
public void setLogger(Logger logger) {
this.logger = logger;
}
}
} }
package com.secoo.mall.dubbo.filter; package com.secoo.mall.dubbo.filter;
import com.secoo.mall.common.core.exception.BusinessException; import com.secoo.mall.dubbo.listener.ExceptionListener;
import com.secoo.mall.common.core.exception.ParameterException; import com.secoo.mall.dubbo.listener.MatrixResponseExceptionListener;
import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.handler.ProtocolExceptionHandler;
import com.secoo.mall.common.util.response.ResponseUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.filter.ExceptionFilter;
import org.apache.dubbo.rpc.service.GenericService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
import java.lang.reflect.Method;
/** /**
* 统一拦截异常。 * 统一拦截异常。
...@@ -23,72 +10,9 @@ import java.lang.reflect.Method; ...@@ -23,72 +10,9 @@ import java.lang.reflect.Method;
/*@Activate( /*@Activate(
group = {CommonConstants.PROVIDER} group = {CommonConstants.PROVIDER}
)*/ )*/
public class MatrixResponseExceptionFilter extends ListenableFilter { public class MatrixResponseExceptionFilter extends AbsExceptionFilter {
private Logger log = LoggerFactory.getLogger(MatrixResponseExceptionFilter.class);
public MatrixResponseExceptionFilter() {
super.listener = new MatrixResponseExceptionFilter.ExceptionListener();
}
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
static class ExceptionListener extends ProtocolExceptionHandler implements Listener {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private ExceptionHandlerMethodResolver resolver;
public ExceptionListener() {
resolver = new ExceptionHandlerMethodResolver(this.getClass());
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
Exception exception = getException(appResponse.getException());
Method method = resolver.resolveMethod(exception);
try {
Object realResult = method.invoke(this, exception);
appResponse.setValue(realResult);
} catch (Exception e) {
appResponse.setValue(ResponseUtil.getFailResponse(new SystemInternalException()));
}
appResponse.setException(null);
}
}
@Override @Override
public void onError(Throwable e, Invoker<?> invoker, Invocation invocation) { protected ExceptionListener getExceptionListener() {
logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return new MatrixResponseExceptionListener();
}
private Exception getException(Throwable throwable) {
Exception exception = null;
String className = throwable.getClass().getSimpleName();
switch (className) {
case "BusinessException":
exception = (BusinessException) throwable;
break;
case "SystemInternalException":
exception = (SystemInternalException) throwable;
break;
case "ParameterException":
exception = (ParameterException) throwable;
break;
default:
exception = (Exception) throwable;
}
return exception;
} }
}
} }
package com.secoo.mall.dubbo.listener;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.service.GenericService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface ExceptionListener extends Filter.Listener {
Logger logger = LoggerFactory.getLogger(ExceptionListener.class);
@Override
default void onError(Throwable e, Invoker<?> invoker, Invocation invocation) {
logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
@Override
default void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
processResponse(appResponse, invoker, invocation);
}
}
void processResponse(Result appResponse, Invoker<?> invoker, Invocation invocation);
}
package com.secoo.mall.dubbo.listener;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.*;
import java.lang.reflect.Method;
public class MatrixExceptionListener implements ExceptionListener {
@Override
public void processResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
try {
Throwable exception = appResponse.getException();
// directly throw if it's checked exception
if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
return;
}
// directly throw if the exception appears in the signature
try {
Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
Class<?>[] exceptionClassses = method.getExceptionTypes();
for (Class<?> exceptionClass : exceptionClassses) {
if (exception.getClass().equals(exceptionClass)) {
return;
}
}
} catch (NoSuchMethodException e) {
return;
}
//防止报警信息错误
String msg = "Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage();
if (exception instanceof RuntimeException) {
logger.warn(msg, exception);
} else {
logger.error(msg, exception);
}
// directly throw if exception class and interface class are in the same jar file.
String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) {
return;
}
// directly throw if it's JDK exception
String className = exception.getClass().getName();
if (className.startsWith("java.") || className.startsWith("javax.")) {
return;
}
// directly throw if it's dubbo exception
if (exception instanceof RpcException) {
return;
}
// otherwise, wrap with RuntimeException and throw back to the client
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
return;
} catch (Throwable e) {
logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
return;
}
}
}
package com.secoo.mall.dubbo.listener;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.core.exception.ParameterException;
import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.handler.ProtocolExceptionHandler;
import com.secoo.mall.common.util.response.ResponseUtil;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
import java.lang.reflect.Method;
public class MatrixResponseExceptionListener extends ProtocolExceptionHandler implements ExceptionListener {
private ExceptionHandlerMethodResolver resolver;
public MatrixResponseExceptionListener() {
resolver = new ExceptionHandlerMethodResolver(this.getClass());
}
@Override
public void processResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
Exception exception = processException(appResponse.getException());
Method method = resolver.resolveMethod(exception);
try {
Object realResult = method.invoke(this, exception);
appResponse.setValue(realResult);
} catch (Exception e) {
appResponse.setValue(ResponseUtil.getFailResponse(new SystemInternalException()));
}
//将异常堆栈变为空
appResponse.setException(null);
}
protected Exception processException(Throwable throwable) {
Exception exception = null;
String className = throwable.getClass().getSimpleName();
switch (className) {
case "BusinessException":
exception = (BusinessException) throwable;
break;
case "SystemInternalException":
exception = (SystemInternalException) throwable;
break;
case "ParameterException":
exception = (ParameterException) throwable;
break;
default:
exception = (Exception) throwable;
}
return exception;
}
}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<module>matrix-datasource</module> <module>matrix-datasource</module>
<module>rocketmq-starter</module> <module>rocketmq-starter</module>
<module>matrix-job</module> <module>matrix-job</module>
<module>matrix-bigdata</module>
</modules> </modules>
...@@ -157,7 +158,13 @@ ...@@ -157,7 +158,13 @@
<artifactId>matrix-job-xxl-starter</artifactId> <artifactId>matrix-job-xxl-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>1.3.2.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-bigdata-hbase-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<!--普通jar-->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
......
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