stackstorm 18. 源码分析之----stackstorm表结构分析

本文详细分析了StackStorm中的多个数据库表结构,包括action_d_b、action_execution_d_b、trigger_type_d_b和trigger_instance_d_b等,涵盖了动作、执行、触发器类型和触发器实例等核心组件,揭示了StackStorm的工作原理和数据流转。
摘要由CSDN通过智能技术生成

1 查看stackstorm的mongodb中的表结构

1.1 查看mongodb的用户名和密码


StackStorm - /etc/st2/st2.conf
database.username - MongoDB database username.
database.password - MongoDB database password.
messaging.url - RabbitMQ transport url (amqp://<username>:<password>@<hostname>:5672)
Mistral - /etc/mistral/mistral.conf

database.connection - PostgreSQL database connection string (postgresql+psycopg2://<username>:<password>@<hostname>/mistral)
transport_url - RabbitMQ transport url (rabbit://<username>:<password>@<hostname>:5672)


参考: https://docs.stackstorm.com/install/rhel7.html#install-webui-and-setup-ssl-termination

1.2 登录mongodb的st2数据库


use st2
db.auth("stackstorm","OLQaFY714tcl9WRoBn4OHJjK")
结果如下:
1

终于可以了

查看st2的表:
> show collections;
action_alias_d_b
action_d_b
action_execution_d_b
action_execution_output_d_b
action_execution_scheduling_queue_item_d_b
action_execution_state_d_b
api_key_d_b
config_d_b
config_schema_d_b
group_to_role_mapping_d_b
key_value_pair_d_b
live_action_d_b
pack_d_b
permission_grant_d_b
policy_d_b
policy_type_d_b
role_d_b
rule_d_b
rule_enforcement_d_b
rule_type_d_b
runner_type_d_b
sensor_type_d_b
task_execution_d_b
token_d_b
trace_d_b
trigger_d_b
trigger_instance_d_b
trigger_type_d_b
user_d_b
user_role_assignment_d_b
workflow_execution_d_b


2 action表结构分析


首先相关的表有:
action_alias_d_b
action_d_b
action_execution_d_b
action_execution_output_d_b
action_execution_scheduling_queue_item_d_b
action_execution_state_d_b

接下来一个一个表分析。

2.1 action_d_b分析


db.action_d_b.findOne()
输出结果样例如下:
> db.action_d_b.findOne()
{
    "_id" : ObjectId("5c3823a59dc6d67dc88dbda1"),
    "uid" : "action:core:announcement",
    "metadata_file" : "actions/announcement.yaml",
    "name" : "announcement",
    "ref" : "core.announcement",
    "description" : "Action that broadcasts the announcement to all stream consumers.",
    "enabled" : true,
    "entry_point" : "",
    "pack" : "core",
    "runner_type" : {
        "name" : "announcement"
    },
    "parameters" : {
        "message" : {
            "type" : "object",
            "description" : "Message to broadcast."
        },
        "experimental" : {
            "default" : true,
            "immutable" : true
        }
    },
    "output_schema" : {
        
    },
    "notify" : {
        
    }
}

分析:
这里介绍了core.announcement这个action的具体信息。

查看:
db.action_d_b.findOne({'ref': 'default.counter'})
输出样例结果如下:
> db.action_d_b.findOne({'ref': 'default.counter'})
{
    "_id" : ObjectId("5c6f61f59dc6d64891ab5330"),
    "uid" : "action:default:counter",
    "metadata_file" : "actions/counterActionMeta.yaml",
    "name" : "counter",
    "ref" : "default.counter",
    "description" : "counter action description",
    "enabled" : true,
    "entry_point" : "counterAction.py",
    "pack" : "default",
    "runner_type" : {
        "name" : "python-script"
    },
    "parameters" : {
        "count" : {
            "position" : 1,
            "required" : true,
            "type" : "integer",
            "description" : "the count parameter"
        },
        "age" : {
            "position" : 2,
            "required" : true,
            "type" : "integer",
            "description" : "the age parameter"
        },
        "cmd" : {
            "position" : 0,
            "required" : true,
            "type" : "string",
            "description" : "the cmd parameter"
        },
        "params" : {
            "position" : 3,
            "required" : true,
            "type" : "string",
            "description" : "the params parameter"
        }
    },
    "output_schema" : {
        
    },
    "notify" : {
        
    }
}

分析:
uid: 作用尚不清楚 , 样例: "action:default:counter"
name: action的名称, 样例: counter
ref : 可以被其他actionchain或者mistral或者rule引用的动作名称, 样例: "default.counter"
metadata_file: action的元数据文件 , 样例: "actions/counterActionMeta.yaml"
entry_point: action的脚本文件, 样例: "counterAction.py"
pack: action所在的包名称
runner_type: 运行该action的运行器的类型, 是一个字典,样例: {"name" : "python-script"},
parameters: 该action脚本文件需要的参数,是字典,字典中每个元素(也就是该action脚本的一个参数信息)是一个字典,样例如下:
            {
                "count" : {
                    "position" : 1,
                    "required" : true,
                    "type" : "integer",
                    "description" : "the count parameter"
                },
                "age" : {
                    "position" : 2,
                    "required" : true,
                    "type" : "integer",
                    "description" : "the age parameter"
                },
                "cmd" : {
                    "position" : 0,
                    "required" : true,
                    "type" : "string",
                    "description" : "the cmd parameter"
                },
                "params" : {
                    "position" : 3,
                    "required" : true,
                    "type" : "string",
                    "description" : "the params parameter"
                }
            }


而counterActionMeta.yaml
内容如下:
name: "counter"
description: "counter action description"
runner_type: "python-script"
enabled: true
entry_point: "counterAction.py"
parameters:
    cmd:
        type: "string"
        description: "the cmd parameter"
        required: true
        position: 0
    count:
        type: "integer"
        description: "the count parameter"
        required: true
        position: 1
    age:
        type: "integer"
        description: "the age parameter"
        required: true
        position: 2
    params:
        type: "string"
        description: "the params parameter"
        required: true
        position: 3

比较action的元数据文件和mongodb中action_d_b这个表中定义的动作
两者很很相似。
可以推断: action的元数据文件用于action_d_b这个表中定义对应的动作


查看:
db.action_d_b.findOne({'ref': 'default.multiTask'})
输出结果样例如下:
> db.action_d_b.findOne({'ref': 'default.multiTask'})
{
    "_id" : ObjectId("5c8f2acd9dc6d64fd709a7ae"),
    "uid" : "action:default:multiTask",
    "metadata_file" : "actions/multiTaskMistralMeta.yaml",
    "name" : "multiTask",
    "ref" : "default.multiTask",
    "description" : "multi task mistral description",
    "enabled" : true,
    "entry_point" : "workflows/multiTaskMistral.yaml",
    "pack" : "default",
    "runner_type" : {
        "name" : "mistral-v2"
    },
    "parameters" : {
        "count" : {
            "required" : true,
            "type" : "integer"
        },
        "age" : {
            "default" : 20,
            "type" : "integer"
        },
        "cmd" : {
            "required" : true,
            "type" : "string"
        },
        "params" : {
            "type" : "string"
        },
        "timeout" : {
            "default" : 60,
            "type" : "integer"
        }
    },
    "output_schema" : {
        
    },
    "notify" : {
        
    }
}

分析: 同上


总结:
action_d_b实际就是st2的动作表,里面包含了每个动作的详细信息,例如:
动作名称,元数据文件,脚本文件,参数,是否开启,锁在的pakc等。


2.2 action_alias_d_b分析


db.action_alias_d_b.findOne()
1) 查询任意一条数据
> db.action_alias_d_b.findOne()
{
    "_id" : ObjectId("5c3823aa9dc6d67dc88dbddb"),
    "uid" : "action_alias:packs:pack_get",
    "metadata_file" : "aliases/pack_get.yaml",
    "name" : "pack_get",
    "ref" : "packs.pack_get",
    "description" : "Get information about installed StackStorm pack.",
    "pack" : "packs",
    "enabled" : true,
    "action_ref" : "packs.get",
    "formats" : [
        {
            "representation" : [
                "pack get { { pack }}"
            ],
            "display" : "pack get <pack>"
        }
    ],
    "ack" : {
        "enabled" : false
    },
    "result" : {
        "format" : "{% if execution.status == \"succeeded\" %}\n{% if execution.result.result.pack %}\nGetting back to you about the installed `{ { execution.parameters.pack }}` pack:{~}\nHere's the full entry: ```{ { execution.result.result.pack|to_yaml_string }}```\n{% if execution.result.result.git_status %}\nGit status: ```{ { execution.result.result.git_status }}```\n{% endif %}\n{% else %}\nThe requested pack is not present in your StackStorm installation.\nTo install the pack: `pack install { { execution.parameters.pack }}`\n{% endif %}\n{% else %}\nCouldn't locate *{ {execution.parameters.pack}}*. :({~}\n{% if execution.result.stderr %}*Stderr:* ```{ { execution.result.stderr }}```{% endif %}\n{% endif %}\n"
    }
}


2) 查看所有数据
结果如下:
> db.action_alias_d_b.find()
{ "_id" : ObjectId("5c3823aa9dc6d67dc88dbddb"), "uid" : "action_alias:packs:pack_get", "metadata_file" : "aliases/pack_get.yaml", "name" : "pack_get", "ref" : "packs.pack_get", "description" : "Get information about installed StackStorm pack.", "pack" : "packs", "enabled" : true, "action_ref" : "packs.get", "formats" : [ { "representation" : [ "pack get { { pack }}" ], "display" : "pack get <pack>" } ], "ack" : { "enabled" : false }, "result" : { "format" : "{% if execution.status == \"succeeded\" %}\n{% if execution.result.result.pack %}\nGetting back to you about the installed `{ { execution.parameters.pack }}` pack:{~}\nHere's the full entry: ```{ { execution.result.result.pack|to_yaml_string }}```\n{% if execution.result.result.git_status %}\nGit status: ```{ { execution.result.result.git_status }}```\n{% endif %}\n{% else %}\nThe requested pack is not present in your StackStorm installation.\nTo install the pack: `pack install { { execution.parameters.pack }}`\n{% endif %}\n{% else %}\nCouldn't locate *{ {execution.parameters.pack}}*. :({~}\n{% if execution.result.stderr %}*Stderr:* ```{ { execution.result.stderr }}```{% endif %}\n{% endif %}\n" } }
{ "_id" : ObjectId("5c3823aa9dc6d67dc88dbddc"), "uid" : "action_alias:packs:pack_install", "metadata_file" : "aliases/pack_install.yaml", "name" : "pack_install", "ref" : "packs.pack_install", "description" : "Install/upgrade StackStorm packs.", "pack" : "packs", "enabled" : true, "action_ref" : "packs.install", "formats" : [ { "representation" : [ "pack install { { packs }}" ], "display" : "pack install <pack>[,<pack>]" }, { "representation" : [ "pack install { { packs }}" ], "display" : "pack install <gitUrl>[,<gitUrl>]" } ], "ack" : { "append_url" : false, "enabled" : true, "format" : "Installing the requested pack(s) for you." }, "result" : { "format" : "{% if execution.status == \"succeeded\" %}\n  Successful deployment of *{ { execution.parameters.packs | join('*, *') }}* pack{% if execution.parameters.packs | length > 1 %}s{% endif %}!\n{% else %}\n  Failed to install `{ { execution.parameters.packs | join('`, `') }}` pack{% if execution.parameters.packs | length > 1 %}s{% endif %}.{~}\n  Please check `{ { execution.id }}` for details.\n{% endif %}\n" } }
{ "_id" : ObjectId("5c3823aa9dc6d67dc88dbddd"), "uid" : "action_alias:packs:pack_search", "metadata_file" : "aliases/pack_search.yaml", "name" : "pack_search", "ref" : "packs.pack_search", "description" : "Search for packs in StackStorm Exchange and other directories.", "pack" : "packs", "enabled" : true, "action_ref" : "packs.search", "formats" : [ { "representation" : [ "pack search { { query }}" ], "display" : "pack search <query>" } ], "ack" : { "append_url" : false, "enabled" : true, "format" : "Alright! Let me check if that matches anything in the StackStorm Exchange index." }, "result" : { "format" : "{% if execution.status == \"succeeded\" %}\n{% if execution.result.result | length %}\nGot something for you matching `{ { execution.parameters.query }}&

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值