{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import time\n", "import requests" ] }, { "cell_type": "markdown", "source": [ "#### 创建task" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 9, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://192.168.199.109:18082/jpt/af_task\n" ] } ], "source": [ "host = '192.168.199.109:18082'\n", "\n", "with open('./config2.json', 'r') as f:\n", " datax_config_str = f.read()\n", "\n", "cmd_parameter = '-j \"-Xms2G -Xmx2G\" -p \"-Dct=hangzhou\" '\n", "name = f'datax_task_{int(time.time())}'\n", "\n", "data = {\n", " \"name\": name,\n", " \"file_urls\": [],\n", " \"script\": datax_config_str,\n", " # \"cmd\": \"echo 'hello'\",\n", " \"cmd_parameters\": \"\", # cmd_parameter,\n", " \"envs\": {\n", " 'last_key': 'lastTime',\n", " 'current_key': 'currentTime',\n", " 'partition_key': 'partition',\n", " 'partition_word': 'txn_date',\n", " 'partition_format': '%Y-%m-%d',\n", " 'partition_diff': 1,\n", " },\n", " \"run_image\": \"SXKJ:32775/pod_datax:0.9\",\n", " \"task_type\": \"datax\",\n", " \"user_id\": 33\n", "}\n", "\n", "print(f'http://{host}/jpt/af_task')\n", "ret = requests.post(url=f'http://{host}/jpt/af_task', json=data)\n", "# print(ret.json())\n" ], "metadata": { "collapsed": false } }, { "cell_type": "markdown", "source": [ "#### 创建job" ], "metadata": { "collapsed": false } }, { "cell_type": "markdown", "source": [ "##### 搜索task" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 17, "outputs": [], "source": [ "task_info = requests.get(url=f'http://{host}/jpt/af_task/getOnce/38').json()['data']" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 21, "outputs": [], "source": [ "data = {\n", " \"tasks\": [\n", " task_info\n", " ],\n", " \"name\": \"advanced_datax_job\",\n", " \"dependence\": [],\n", " \"cron\": \"string\",\n", " \"desc\": \"string\",\n", " \"route_strategy\": \"string\",\n", " \"block_strategy\": \"string\",\n", " \"executor_timeout\": 0,\n", " \"executor_fail_retry_count\": 0,\n", " \"trigger_status\": 1,\n", " \"job_type\": 1,\n", " \"user_id\": 0\n", "}" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 23, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "b'{\"code\":200,\"data\":{\"id\":25,\"name\":\"advanced_datax_job\",\"tasks\":[{\"id\":38,\"cmd\":\"\",\"envs\":{\"last_key\":\"lastTime\",\"current_key\":\"currentTime\",\"partition_key\":\"partition\",\"partition_diff\":\"1\",\"partition_word\":\"txn_date\",\"partition_format\":\"%Y-%m-%d\"},\"name\":\"datax_task_1665500001\",\"script\":\"{\\\\n \\\\\"job\\\\\": {\\\\n \\\\\"setting\\\\\": {\\\\n \\\\\"speed\\\\\": {\\\\n \\\\\"channel\\\\\": 3\\\\n },\\\\n \\\\\"errorLimit\\\\\": {\\\\n \\\\\"record\\\\\": 0,\\\\n \\\\\"percentage\\\\\": 0.02\\\\n }\\\\n },\\\\n \\\\\"content\\\\\": [\\\\n {\\\\n \\\\\"reader\\\\\": {\\\\n \\\\\"name\\\\\": \\\\\"mysqlreader\\\\\",\\\\n \\\\\"parameter\\\\\": {\\\\n \\\\\"username\\\\\": \\\\\"root\\\\\",\\\\n \\\\\"password\\\\\": \\\\\"happylay\\\\\",\\\\n \\\\\"splitPk\\\\\": \\\\\"\\\\\",\\\\n \\\\\"connection\\\\\": [\\\\n {\\\\n \\\\\"querySql\\\\\": [\\\\n \\\\\"select id, txn_amount, txn_type from test_4 where txn_date >= FROM_UNIXTIME(${lastTime}) and txn_date < FROM_UNIXTIME(${currentTime})\\\\\"\\\\n ],\\\\n \\\\\"jdbcUrl\\\\\": [\\\\n \\\\\"jdbc:mysql://192.168.199.107:10086/test-db?useSSL=false\\\\\"\\\\n ]\\\\n }\\\\n ]\\\\n }\\\\n },\\\\n \\\\\"writer\\\\\": {\\\\n \\\\\"name\\\\\": \\\\\"hdfswriter\\\\\",\\\\n \\\\\"parameter\\\\\": {\\\\n \\\\\"defaultFS\\\\\": \\\\\"hdfs://192.168.199.27:9000\\\\\",\\\\n \\\\\"fileType\\\\\": \\\\\"text\\\\\",\\\\n \\\\\"path\\\\\": \\\\\"/home/sxkj/bigdata/apache-hive-2.3.9-bin/warehouse/test_h4/${partition}\\\\\",\\\\n \\\\\"fileName\\\\\": \\\\\"000000\\\\\",\\\\n \\\\\"writeMode\\\\\": \\\\\"append\\\\\",\\\\n \\\\\"fieldDelimiter\\\\\": \\\\\",\\\\\",\\\\n \\\\\"column\\\\\": [\\\\n {\\\\n \\\\\"name\\\\\": \\\\\"id\\\\\",\\\\n \\\\\"type\\\\\": \\\\\"int\\\\\"\\\\n },\\\\n {\\\\n \\\\\"name\\\\\": \\\\\"txn_amount\\\\\",\\\\n \\\\\"type\\\\\": \\\\\"double\\\\\"\\\\n },\\\\n {\\\\n \\\\\"name\\\\\": \\\\\"txn_type\\\\\",\\\\n \\\\\"type\\\\\": \\\\\"string\\\\\"\\\\n }\\\\n ]\\\\n }\\\\n }\\\\n }\\\\n ]\\\\n }\\\\n}\",\"user_id\":33,\"file_urls\":[],\"run_image\":\"SXKJ:32775/pod_datax:0.9\",\"task_type\":\"datax\",\"create_time\":1665500002,\"update_time\":1665500002,\"cmd_parameters\":\"\"}],\"cron\":\"string\",\"route_strategy\":\"string\",\"executor_timeout\":0,\"trigger_status\":1,\"trigger_next_time\":null,\"update_time\":1665500889,\"user_id\":0,\"job_type\":1,\"dependence\":[],\"desc\":\"string\",\"block_strategy\":\"string\",\"executor_fail_retry_count\":0,\"trigger_last_time\":null,\"create_time\":1665500889},\"msg\":\"\"}'\n" ] } ], "source": [ "print(requests.post(url=f'http://{host}/jpt/af_job', json=data).content)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }