PNS:处理节点服务器

基本原理

许多数据处理流水线只能运行在特定的操作系统类型、版本、语言和库上。这些软件可能无法替换或修改,但需要与环境/格式不兼容的软件并排运行以形成完整的数据处理流水线,每个软件都是执行处理任务的“节点”。 Docker 容器通常是运行具有不兼容依赖项的软件的完美解决方案。

安装在 Docker 容器或普通服务器上的 PNS 允许此类处理任务在 PNS 内存空间、守护进程中运行,或者作为 OS 进程通过“交付人”协议接收输入和交付输出。

这个用于数据处理管道/网络节点的 Web API 服务器提供接口来配置处理节点中的数据处理任务软件 (PTS)、发出运行请求、传递必要的输入数据以及读取结果,所有这些都通过 Web API 进行 .

以下命令从安装的 fdi 目录运行。

基本配置

运行 Flask 服务器时,主机 IP 默认为 127.0.0.1,端口号为 5000。 它们可以在 pnsconfig.py 中配置。 默认配置可以被 ~/.config/pnslocal.py 覆盖。 将 pnsconfig.py 复制到 ~/.config/pnslocal.py

cp fdi/pns/config.py ~/.config/pnslocal.py

定制 ~/.config/pnslocal.py

在开发模式下,选择 dev 运行本地服务器。 serveruser 应该是 web 服务器的用户名,如果你运行 make runserver,通常是你的用户名。 如果选择了 dev,这是默认设置。

对于生产部署,选择 servertestexternal。 根据 Web 服务器的种类(例如 apache)设置 serveruser

ptsuser 通常是处理软件需要的用户。 默认设置为 serveruserptsuser 必须有写权限才能读写 inputdiroutputdir,它们归 serveruser 所有,模式为 o0775

在服务器端(或在您的计算机上,既可以是服务器也可以是客户端)通过更改 Makefile 中 pnshome 目录中变量 PNSDIR 的值来编辑 Makefile,如果您不想要默认值 (~/pns)。

然后运行部署命令

make installpns

创建 pns 主目录并复制演示 PTS 脚本集。

运行 FLASK 服务器

如有需要可编辑 ~/.config/pnslocal.py。然后

python3 fdi/pns/runflaskserver.py --username=<username> --password=<password> [--ip=<host ip>] [--port=<port>]

[] 中的内容,如上面的 [--ip=<host ip>] [--port=<port>] 是可选的。

<> 表示您需要替换为实际信息(例如 --port=<port> 变为 --port=5000)。

或者你可以运行

python3 fdi/pns/runflaskserver.py -u <username> -p <password> [-i <host ip>] [-o <port>]

在调试模式下:

python3 fdi/pns/runflaskserver.py --username=foo --password=bar -v

或只是

make runserver

使用默认设置

不要为生产使用运行调试模式。

发出运行请求时使用用户名和密码。

注解

服务器的日志级别在配置文件中设置。 上面使用的 runflaskserver-v 开关会将级别设置为 logging.DEBUGrequestsfilelockurllib3 包被固定到 logging.WARN

测试和验证安装

一次性运行所有测试

make test3 [T='-u <username> -p <password> [-i <host ip>] [-o <port>] [options]']

可以逐步进行测试以查明可能的问题:

1. 服务器单元测试

在服务器主机上运行此程序以验证服务器的内部基本功能是否适用于当前配置。 这无需启动服务器即可运行:

make test4

2.本地Flask服务器功能测试

~/.config/pnslocal.py``(安装和自定义见上文)中,设置 ``dev=True 并确保 IP 是本地的(127.0.0.1)。 在一个终端(见上文)和另一个终端(在服务器主机上)重新启动服务器,运行以下命令:

2a:测试 GET initPTS 脚本以查看读取 init 脚本是否有效:

make test3 T='getinit'

2b:测试PUT初始化测试:

make test3 T='-k putinittest'

2c1:如果测试通过,您可以一次性运行所有测试:

make test3

2c2:或者继续个别测试……

测试 POST 服务器内处理

make test3 T='-k _post'

测试 POST PTS 处理

make test3 T='-k _run'

test DELETE 通过删除输入和输出目录来清理服务器

make test3 T='-k deleteclean'

现在是个好时机……

3. 获取公共访问 API 和信息

假设服务器地址和端口分别为 127.0.0.15000

在终端中运行 Flask 服务器(见上文)并在浏览器中打开它。 最新的 URL 显示在服务器声明消息中:

http://127.0.0.1:5000/v0.6/

显示了类似于下面的在线 API 文档页面。

{
"APIs": {
"DELETE": [
{
"URL": "http://127.0.0.1:5000/v0.6/clean",
"description": " Removing traces of past runnings the Processing Task Software.\n    "
}
],
"GET": [
{
"URL": "http://127.0.0.1:5000/v0.6/init",
"description": "the initPTS file"
},
{
"URL": "http://127.0.0.1:5000/v0.6/config",
"description": "the configPTS file"
},
{
"URL": "http://127.0.0.1:5000/v0.6/run",
"description": "the file running PTS"
},
{
"URL": "http://127.0.0.1:5000/v0.6/clean",
"description": "the cleanPTS file"
},
{
"URL": "http://127.0.0.1:5000/v0.6/input",
"description": " returns names and contents of all files in the dir, 'None' if dir not existing. "
},
{
"URL": "http://127.0.0.1:5000/v0.6/output",
"description": " returns names and contents of all files in the dir, 'None' if dir not existing. "
},
{
"URL": "http://127.0.0.1:5000/v0.6/pnsconfig",
"description": "PNS configuration"
}
],
"POST": [
{
"URL": "http://127.0.0.1:5000/v0.6/calc",
"description": " generates result product directly using data on PNS.\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/testcalc",
"description": " generate post test product.\n    put the 1st input (see maketestdata in test_all.py)\n    parameter to metadata\n    and 2nd to the product's dataset\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/echo",
"description": "Echo"
},
{
"URL": "http://127.0.0.1:5000/v0.6/run",
"description": " Generates a product by running script defined in the config under 'run'. Execution on the server host is in the pnshome directory and run result and status are returned.\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/testrun",
"description": "  Run 'runPTS' for testing, and as an example.\n    "
}
],
"PUT": [
{
"URL": "http://127.0.0.1:5000/v0.6/init",
"description": " Initialize the Processing Task Software by running the init script defined in the config. Execution on the server host is in the pnshome directory and run result and status are returned. If input/output directories cannot be created with serveruser as owner, Error401 will be given.\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/config",
"description": " Configure the Processing Task Software by running the config script. Ref init PTS.\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/pnsconf",
"description": " Configure the PNS itself by replacing the pnsconfig var\n    "
},
{
"URL": "http://127.0.0.1:5000/v0.6/inittest",
"description": "     Renames the 'init' 'config' 'run' 'clean' scripts to \"*.save\" and points it to the '.ori' scripts.\n    "
}
]
},
"timestamp": 1566130779.0208821
}

继续测试…

4. 从远程客户端运行测试

在远程主机上安装 pns,配置 IP 和端口,然后运行上面的测试。 这证明服务器和客户端的连接和防火墙配置正确。

使用 Apache 运行本地测试

在 ~/.config/pnslocal.py(见上文)中设置 dev=False 并设置 IP 和端口。假设服务器在 CentOS 上。根据本地设置编辑 pns/resources/pns.conf,然后

cp pns/resources/pns.conf /etc/httpd/conf.d
systemctl restart httpd
systemctl status http -l

然后使用正确的 IP 和端口运行上述内容(编辑 ~/.config/pnslocal.py 或在命令行中指定)。启动服务器并运行所有测试:

make test3

配置 PTS

要运行 PTS shell 脚本而不是 ‘hello’ 演示,请更改配置文件中的 `run` 参数,例如运行名为 runPTS.vvpp 的脚本。

run=[join(h, 'runPTS.vvpp'), ''],

重启 server. run

make test4

PTS API

TBW

Return on Common Errors

400

{'error': 'Bad request.', 'timestamp': ts}

401

{'error': 'Unauthorized. Authentication needed to modify.', 'timestamp': ts}

404

{'error': 'Not found.', 'timestamp': ts}

409

{'error': 'Conflict. Updating.', 'timestamp': ts}

资源

TBW