Search in sources :

Example 6 with FilterRpcDO

use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.

the class FilterRouteServiceImpl method save.

@Override
public int save(FilterRouteDto routeDto) {
    FilterRouteDO routeDo = routeDto.buildRoute();
    FilterRpcDO rpcDo = routeDto.buildRpc();
    int success2 = routeDao.save(routeDo);
    Long routeId = routeDo.getId();
    rpcDo.setRouteId(routeId);
    if (routeDo.getRpc()) {
        int success1 = rpcDao.save(rpcDo);
        if (success1 > 0 && success2 > 0) {
            return CommonResponse.SUCCESS;
        } else {
            return CommonResponse.ERROR;
        }
    }
    return success2;
}
Also used : FilterRouteDO(io.github.tesla.filter.domain.FilterRouteDO) FilterRpcDO(io.github.tesla.filter.domain.FilterRpcDO)

Example 7 with FilterRpcDO

use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.

the class DynamicsRouteCacheComponent method doCache.

@Override
protected void doCache() {
    try {
        readWriteLock.writeLock().lock();
        // clear data
        ROUTE_CACHE.clear();
        RPC_CACHE.clear();
        // cache all data
        List<FilterRouteDO> routes = routeDao.list(Maps.newHashMap());
        for (FilterRouteDO route : routes) {
            FilterRouteDO routeCopy = route.copy();
            String path = routeCopy.getFromPath();
            ROUTE_CACHE.put(path, routeCopy);
        }
        List<FilterRpcDO> rpcs = rpcDao.list(Maps.newHashMap());
        for (FilterRpcDO rpc : rpcs) {
            FilterRpcDO rpcCopy = rpc.copy();
            RPC_CACHE.put(rpcCopy.getRouteId(), rpcCopy);
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
Also used : FilterRouteDO(io.github.tesla.filter.domain.FilterRouteDO) FilterRpcDO(io.github.tesla.filter.domain.FilterRpcDO)

Example 8 with FilterRpcDO

use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.

the class DubboTransformHttpRequestFilter method doFilter.

@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
    if (originalRequest instanceof FullHttpRequest && dubboClient != null) {
        FullHttpRequest request = (FullHttpRequest) originalRequest;
        String urlPath = request.uri();
        FilterRpcDO rpc = routeRuleCache.getRpc(urlPath);
        if (rpc != null) {
            ByteBuf jsonBuf = request.content();
            String jsonInput = jsonBuf.toString(CharsetUtil.UTF_8);
            String jsonOutput = dubboClient.doRemoteCall(rpc, jsonInput);
            return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonOutput.getBytes(CharsetUtil.UTF_8)));
        } else {
            // 如果从缓存没有查到dubbo的映射信息,说明不是泛化调用,返回空,继续走下一个filter或者去走rest服务发现等
            return null;
        }
    }
    return null;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) FilterRpcDO(io.github.tesla.filter.domain.FilterRpcDO)

Example 9 with FilterRpcDO

use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.

the class GrpcTransformHttpRequestFilter method doFilter.

@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
    if (originalRequest instanceof FullHttpRequest && grpcClient != null) {
        FullHttpRequest request = (FullHttpRequest) originalRequest;
        String urlPath = request.uri();
        FilterRpcDO rpc = routeRuleCache.getRpc(urlPath);
        if (rpc != null) {
            ByteBuf jsonBuf = request.content();
            String jsonInput = jsonBuf.toString(CharsetUtil.UTF_8);
            String jsonOutput = grpcClient.doRemoteCall(rpc, jsonInput);
            return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonOutput.getBytes(CharsetUtil.UTF_8)));
        } else {
            // 如果从缓存没有查到grpc的映射信息,说明不是泛化调用,返回空,继续走下一个filter或者去走rest服务发现等
            return null;
        }
    }
    return null;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) FilterRpcDO(io.github.tesla.filter.domain.FilterRpcDO)

Aggregations

FilterRpcDO (io.github.tesla.filter.domain.FilterRpcDO)9 FilterRouteDO (io.github.tesla.filter.domain.FilterRouteDO)6 FilterRouteDto (io.github.tesla.ops.filter.dto.FilterRouteDto)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 PageDO (io.github.tesla.ops.system.domain.PageDO)1