微服务租户隔离架构设计

    目标

    1. 支持通过解析请求的标签按照路由标签对服务进行转发
    2. 支持服务的标签注册和修改

    2. 总体设计

    2.1 技术架构

    1. 整体技术架构主要修改点位RestFul请求需要带上路由标签等标签参数信息,然后在Gateway进行转发时会解析对应的标签完成接口的路由转发。整体如下图所示 ![arc](/projects/Linkis-1.2.0-zh/e544d8a47121a9151a4eb92ddf22b7d3.png)
    1. 如果存在多个对应的服务打上了同一个roteLabel则随机转发
    2. 如果对应的routeLabel没有对应的服务,则接口直接失败

    2.2 业务架构

    1. 此次的特性主要是为了完成Restful租户隔离转发功能。功能点设计的模块如下:

    [输入端] 输入端为请求Gatway的restful请求,且是参数中待用roure label的请求才会进行处理 [处理流程] Gateway会判断请求是否带有对应的RouteLabel,如果存在则基于RouteLabel来进行转发。 调用时序图如下:

    4. 数据结构:

    add route label for entrance

    1. echo "spring.eureka.instance.metadata-map.route=et1" >> $LINKIS_CONF_DIR/linkis-cg-entrance.properties
    2. sh $LINKIS_HOME/sbin/linkis-damemon.sh restart cg-entrance

    Time

    Use route label

    1. url:/api/v1/entrance/submit
    2. {
    3. "executionContent": {"code": "echo 1", "runType": "shell"},
    4. "params": {"variable": {}, "configuration": {}},
    5. "source": {"scriptPath": "ip"},
    6. "labels": {
    7. "engineType": "shell-1",
    8. "userCreator": "peacewong-IDE",
    9. "route": "et1"
    10. }
    11. }

    will be routed to a fixed service:

    1. {
    2. "method": "/api/entrance/submit",
    3. "message": "OK",
    4. "data": {
    5. "taskID": 45158,
    6. "execID": "exec_id018030linkis-cg-entrancelocalhost:9205IDE_peacewong_shell_0"
    7. }
    8. }

    or linkis-cli:

    Use non-existing label

    submit task:

    1. url:/api/v1/entrance/submit
    2. {
    3. "params": {"variable": {}, "configuration": {}},
    4. "source": {"scriptPath": "ip"},
    5. "labels": {
    6. "engineType": "shell-1",
    7. "userCreator": "peacewong-IDE",
    8. "route": "et1"
    9. }
    10. }
    1. "method": "/api/rest_j/v1/entrance/submit",
    2. "status": 1,
    3. "message": "GatewayErrorException: errCode: 11011 ,desc: Cannot route to the corresponding service, URL: /api/rest_j/v1/entrance/submit RouteLabel: [{\"stringValue\":\"et2\",\"labelKey\":\"route\",\"feature\":null,\"modifiable\":true,\"featureKey\":\"feature\",\"empty\":false}] ,ip: localhost ,port: 9101 ,serviceKind: linkis-mg-gateway",
    4. "data": {
    5. "data": "{\r\n \"executionContent\": {\"code\": \"echo 1\", \"runType\": \"shell\"},\r\n \"params\": {\"variable\": {}, \"configuration\": {}},\r\n \"source\": {\"scriptPath\": \"ip\"},\r\n \"labels\": {\r\n \"engineType\": \"shell-1\",\r\n \"userCreator\": \"peacewong-IDE\",\r\n \"route\": \"et2\"\r\n }\r\n}"
    6. }
    7. }

    submit task:

    1. url:/api/v1/entrance/submit
    2. {
    3. "executionContent": {"code": "echo 1", "runType": "shell"},
    4. "params": {"variable": {}, "configuration": {}},
    5. "source": {"scriptPath": "ip"},
    6. "labels": {
    7. "engineType": "shell-1",
    8. "userCreator": "peacewong-IDE"
    9. }

    6. 非功能性设计:

    6.1 安全

    不涉及安全问题,restful需要登录认证

    6.2 性能

    对Gateway转发性能影响较小,有缓存相应的label和instance的数据

    6.3 容量

    不涉及