理解客户端

所有与 ecflow_server 的通讯都需要通过 ecflow_client。任何与服务器的通讯都需要知道服务器的地址和端口。同一台主机中可能运行多个服务,每个服务都有唯一的端口号。

本教程将会给出通过 shell 和在Python 脚本中使用客户端的例子。

客户端命令行接口

客户端命令的列表:

  1. $ecflow_client --help
  2. Client/server based work flow package:
  3. Ecflow version(4.8.0) boost(1.53.0) compiler(gcc 4.8.5) protocol(TEXT_ARCHIVE) Compiled on Jan 18 2018 13:37:13
  4. ecflow_client provides the command line interface, for interacting with the server:
  5. Try:
  6. ecflow_client --help=all # List all commands, verbosely
  7. ecflow_client --help=summary # One line summary of all commands
  8. ecflow_client --help=child # One line summary of child commands
  9. ecflow_client --help=user # One line summary of user command
  10. ecflow_client --help=<cmd> # Detailed help on each command
  11. Commands:
  12. abort alter begin ch_add ch_auto_add
  13. ch_drop ch_drop_user ch_register ch_rem ch_suites
  14. check checkJobGenOnly check_pt complete debug
  15. debug_server_off debug_server_on delete edit_history edit_script
  16. event file force force-dep-eval free-dep
  17. get get_state group halt help
  18. host init job_gen kill label
  19. load log meter migrate msg
  20. news order ping plug port
  21. reloadwsfile replace requeue restart restore_from_checkpt
  22. resume rid run server_load server_version
  23. show shutdown stats stats_reset status
  24. suites suspend sync sync_full terminate
  25. version wait why zombie_adopt zombie_block
  26. zombie_fail zombie_fob zombie_get zombie_kill zombie_remove

上面提到过,使用 ecflow_client 与服务器通讯需要设置 hostport,如下方法确定:

默认主机和端口为:localhost:3141

默认值被 ECF_NODEECF_PORT 环境变量覆盖。

环境变量被命令行参数 -–port-–host 覆盖,并且可以用于 --help参数显示的任意 shell 层命令。

例如在命令行 ping 一个服务可以输入命令:

  1. ecflow_client --ping --host=machineX --port=4141

运行结果如下:

  1. $ecflow_client --ping --host=login05 --port=33083
  2. ping server(login05:33083) succeeded in 00:00:00.023347 ~23 milliseconds

客户端 Python 接口

ecflow_client 提供的功能可以通过 Client Server API 实现。 Python 接口使用相同的算法确定 hostport,允许显式设定 hostport。参看 ecflow.Client

下面给出 python 的示例

  1. import ecflow
  2. try:
  3. # When no arguments specified uses ECF_HOST and/or ECF_PORT,
  4. # otherwise defaults to localhost:3141
  5. ci = ecflow.Client() # inherit from shell variables
  6. ci.ping()
  7. except RuntimeError as e:
  8. print("ping failed: " + str(e))
  9. try:
  10. # Explicitly set host and port using the same client
  11. # For alternative argument list see ecflow.Client.set_host_port()
  12. ci.set_host_port("login05:33083") # actually set the host and port (change to your host and port)
  13. ci.ping()
  14. except RuntimeError as e:
  15. print("ping failed: " + str(e))
  16. try:
  17. # Create a new client, Explicitly setting host and port.
  18. # For alternative argument list see ecflow.Client
  19. ci = ecflow.Client("localhost:1000") # another server
  20. ci.ping()
  21. except RuntimeError as e:
  22. print("ping failed: " + str(e))

上面只有第二次 ping 成功,执行结果如下所示:

  1. $python3 use_client.py
  2. ping failed: [13:31:17 30.1.2018] Request( --ping :wangdp ), Failed to connect to localhost:3141. After 2 attempts. Is the server running ?
  3. ping failed: [13:31:18 30.1.2018] Request( --ping :wangdp ), Failed to connect to localhost:1000. After 2 attempts. Is the server running ?

需要做什么

如果你的 ecflow_server 是用 ecflow_start.sh 启动的,并且需要用到 shell 接口,那么请设置 ECF_NODEECF_PORT 环境变量。 请注意,如果服务器通过 ecflow_start.sh 脚本 启动,那么默认的服务地址 localhost:3141就不正确。

如果服务运行在本地主机上,可以使用 netstat 确定端口号。

  1. netstat -lnptu

可以通过该命令检查 ecflow 服务的端口是否正在正常。

  1. $netstat -lnptu
  2. ...
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. ...
  5. tcp 0 0 0.0.0.0:33083 0.0.0.0:* LISTEN 127321/ecflow_serve
  6. ...