API#
API 分类如下:
单机程序分布式并行化 API:提供开发无状态函数、有状态函数的接口。
函数服务 API:提供函数服务的开发、调用及管理接口。
如何调用 REST API#
调用 REST API 需要构造请求 URI,它通常由请求协议、服务端点及资源路径三部分组成。默认部署的 openYuanrong 集群采用 http 请求协议,服务端点由 frontend 和 meta service 组件提供。以注册函数 REST API 为例,完整的 URI 为:http://{meta service endpoint}/serverless/v1/functions。
获取 frontend 组件服务端点#
frontend 组件提供了调用服务、订阅流服务等 REST API,服务端点可通过以下方式获取。
主机上部署 openYuanrong 时,在默认部署路径生成的
/tmp/yr_sessions/latest/session.json文件中,组合cluster_info字段中的function_master.ip和frontend.port,即获得 frontend 组件的服务端点。session.json 文件示例:
... "cluster_info": { "for-join": { "function_master.ip": "192.168.2.2", "function_master.port": "47029", ... "frontend.port": "40021" } } ...K8s 上部署 openYuanrong 时,在 K8s 主节点通过 kubectl 命令获取。
echo "$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}'):$(kubectl get svc frontend-lb -o jsonpath='{.spec.ports[0].nodePort}')"
获取 meta service 组件服务端点#
meta service 组件提供了函数管理、资源池管理等 REST API,服务端点可通过以下方式获取。
主机上部署 openYuanrong 时,在默认部署路径生成的
/tmp/yr_sessions/latest/metaservice_config.json文件中,组合server字段中的ip和port,即获得 meta service 组件的服务端点。metaservice_config.json 文件示例:
... "server": { "ip": "192.168.2.2", "port": 34565 } ...K8s 上部署 openYuanrong 时,在 K8s 主节点通过 kubectl 命令获取。
echo "$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}'):$(kubectl get svc meta-service -o jsonpath='{.spec.ports[0].nodePort}')"