规则引擎Rule Engine

    API 参考

    除了通过http://creek.baidubce.com 来生成作业以外,用户还可以通过API来生成作业。对于windows平台接口返回.exe文件,对于linux/mac用户需要给文件添加执行权限。

    接口如下:

    HOST: creek.baidubce.com

    方法 API
    POST v1/creek/generate
    请求参数 说明 示例
    flag 保留字段,必须为exe exe
    architecture 目标运行环境的OS和CPU linux-amd64,完整的可选列表请参考简介

    RequestBody为作业定义,具体格式参考作业定义。

    示例:

    POST http://creek.baidubce.com/v1/creek/generate?flag=exe&architecture=linux-amd64
    
    body:
    {
        "sources": [{
            "schema": {
                "format": "CSV",
                "fields": [{
                        "name": "ts",
                        "type": "SQL_TIMESTAMP"
                    },
                    {
                        "name": "deviceid",
                        "type": "STRING"
                    },
                    {
                        "name": "temp",
                        "type": "DOUBLE"
                    }]
            },
            "watermark": 0,
            "name": "mysrc",
            "eventTime": "ts",
            "type": "STDIN"
        }],
        "sink": {
            "schema": {
                "format": "JSON"
            },
            "name": "mysink",
            "type": "STDOUT"
        },
        "name": "demojob",
        "timeType": "EVENTTIME",
        "sql": "INSERT INTO mysink SELECT TUMBLE_START(rowtime, INTERVAL '10' SECOND) as ts, deviceid, AVG(temp) AS avg_temperature  from mysrc group by TUMBLE(rowtime, INTERVAL '10' SECOND), deviceid"
    }

    通过Curl生成作业的脚本示例:

    #!/bin/bash
    creekGenUrl='http://creek.baidubce.com/v1/creek/generate?flag=exe&architecture=linux-amd64'
    if [ "$1" == "" ];then
        echo "usage: genCreek.sh <job.json>"
        exit 0
    fi
    
    if [ ! -f "$1" ];then
      echo "oops! file does not found: $1"
      exit 0
    fi
    
    json=$(cat "$1")
    code=$(curl --compressed -l -k -H 'Content-Type:application/json;charset=utf-8' -o creek -w %{http_code} -X POST -d "$json" $creekGenUrl)
    if [ $code -eq "200" ];then
             chmod 775 creek
    else
        echo "failed to generate creek, http code:$code"    
    fi
    上一篇
    自定义函数
    下一篇
    API参考