Skip to content

Commit

Permalink
docs: add plugin doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Nov 18, 2021
1 parent 8bbfdea commit c150d15
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 0 deletions.
96 changes: 96 additions & 0 deletions docs/en/latest/plugins/openwhisk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: serverless
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

## Summary

- [**Description**](#description)
- [**Attributes**](#attributes)
- [**Example**](#example)

## Description

This plugin is used to support integration with the [Apache OpenWhisk](https://openwhisk.apache.org) serverless platform and can be set up on a route in place of Upstream, which will take over the request and send it to the OpenWhisk API endpoint.

Users can call the OpenWhisk action via APISIX, pass the request parameters via JSON and get the response content.

## Attributes

| Name | Type | Requirement | Default | Valid | Description |
| -- | -- | -- | -- | -- | -- |
| api_host | string | yes |   |   | OpenWhisk API host (eg. https://localhost:3233) |
| ssl_verify | bool | no | true |   | Whether to verify the certificate |
| service_token | string | yes |   |   | OpenWhisk ServiceToken (The format is `xxx:xxx`,Passed through Basic Auth when calling the API) |
| namespace | string | yes |   |   | OpenWhisk Namespace (eg. guest) |
| action | string | yes |   |   | OpenWhisk Action (eg. hello) |
| result | bool | no | true |   | Whether to get Action metadata (default to execute function and get response; false to get Action metadata but not execute Action, including runtime, function body, restrictions, etc.) |
| timeout | integer | no | 60000ms |   |Functions and HTTP call timeout |
| keepalive | bool | no | true |   | HTTP keepalive |
| keepalive_timeout | integer | no | 60000ms |   | keepalive idle timeout |
| keepalive_pool | integer | no | 5 |   | Connection pool limit |

## Example

First, you need to run the OpenWhisk environment. Here is an example of using OpenWhisk standalone mode.

```shell
docker run --rm -d \
-h openwhisk --name openwhisk \
-p 3233:3233 -p 3232:3232 \
-v /var/run/docker.sock:/var/run/docker.sock \
openwhisk/standalone:nightly
docker exec openwhisk waitready
```

Then, you need to create an Action for testing.

```shell
wsk property set --apihost "http://localhost:3233" --auth "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP"
wsk action update test <(echo 'function main(){return {"ready":true}}') --kind nodejs:14
```

Here is an example of creating a Route and enabling this plugin

```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"plugins": {
"openwhisk-serverless": {
"api_host": "http://localhost:3233",
"service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP",
"namespace": "guest",
"action": "test"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {}
}
}'
```

Finally, you can send a request to this route and you will get the following response. And you can disable it by removing the openwhsik plugin from the route.

```json
{"ready": true}
```
96 changes: 96 additions & 0 deletions docs/zh/latest/plugins/openwhisk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: openwhisk
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

## Summary

- [**描述**](#描述)
- [**属性**](#属性)
- [**使用示例**](#使用示例)

## 描述

这个插件是用于支持集成 [Apache OpenWhisk](https://openwhisk.apache.org) 无服务器平台的插件,它可以被设置在路由上以替代 Upstream,其将接管请求并发送至 OpenWhisk 的 API 端点。

用户可以通过 APISIX 调用 OpenWhisk action,通过 JSON 传递请求参数并获取响应内容。

## 属性

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| -- | -- | -- | -- | -- | -- |
| api_host | string ||   |   | OpenWhisk API 地址(例: https://localhost:3233) |
| ssl_verify | bool || true |   | 是否认证证书 |
| service_token | string ||   |   | OpenWhisk 服务令牌 (格式为 `xxx:xxx`,调用 API 时通过 Basic Auth 传递) |
| namespace | string ||   |   | OpenWhisk 命名空间 |
| action | string ||   |   | OpenWhisk Action 名称(例:hello) |
| result | bool || true |   | 是否获取 Action 元数据(默认为执行函数并获取响应值;设置为 false 时,获取元数据,包含运行时、程序内容、限制等) |
| timeout | integer || 60000 |   | 函数和 HTTP 的超时时间 (ms) |
| keepalive | bool || true |   | 是否启用 HTTP 长连接以避免过多的请求 |
| keepalive_timeout | integer || 60000 |   | HTTP 长连接超时时间 (ms) |
| keepalive_pool | integer || 5 |   | 连接池连接数限制 |

## 使用示例

首先,你需要运行起 OpenWhisk 环境,以下是一个使用 OpenWhisk 独立模式的示例

```shell
docker run --rm -d \
-h openwhisk --name openwhisk \
-p 3233:3233 -p 3232:3232 \
-v /var/run/docker.sock:/var/run/docker.sock \
openwhisk/standalone:nightly
docker exec openwhisk waitready
```

之后,你需要创建一个 Action 用于测试

```shell
wsk property set --apihost "http://localhost:3233" --auth "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP"
wsk action update test <(echo 'function main(){return {"ready":true}}') --kind nodejs:14
```

以下是一个示例,创建 Route 并启用此插件

```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"plugins": {
"openwhisk-serverless": {
"api_host": "http://localhost:3233",
"service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP",
"namespace": "guest",
"action": "test"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {}
}
}'
```

最后,你可以向这个路由发送请求,你将得到以下响应。同时,你可以通过移除路由中的 openwhsik 插件禁用它

```json
{"ready": true}
```

0 comments on commit c150d15

Please sign in to comment.