Skip to content

Commit

Permalink
cc_service.md翻译初稿 (#292)
Browse files Browse the repository at this point in the history
Signed-off-by: sc1000y <8299176+sc1000y@users.noreply.github.com>

PR fix

pr fix
  • Loading branch information
sc1000y committed Dec 15, 2020
1 parent 04c091e commit 4e78a8f
Showing 1 changed file with 64 additions and 61 deletions.
125 changes: 64 additions & 61 deletions docs/locale/zh_CN/source/cc_service.md
@@ -1,51 +1,52 @@
# Chaincode as an external service
# 将链码作为外部服务

Fabric v2.0 supports chaincode deployment and execution outside of Fabric that enables users to manage a chaincode runtime independently of the peer. This facilitates deployment of chaincode on Fabric cloud deployments such as Kubernetes. Instead of building and launching the chaincode on every peer, chaincode can now run as a service whose lifecycle is managed outside of Fabric. This capability leverages the Fabric v2.0 external builder and launcher functionality which enables operators to extend a peer with programs to build, launch, and discover chaincode. Before reading this topic you should become familiar with the [External Builder and Launcher](./cc_launcher.html) content.
Fabric v2.0支持将链码在Faric外部部署与执行以方便用户独立管理每个节点的代码运行环境。这有助于Kubernetes等Fabric云上部署链码。不再需要在每个节点构建和运行,链码现在可以作为一个服务运行,其生命周期在Fabric之外进行管理。此功能利用了Fabric v2.0外部构建器和启动器功能,使操作员能够通过程序扩展对等方来构建、启动和发现链码。在阅读本主题之前,您应该熟悉[外部构建器和启动器](./cc_launcher.html) 内容。

Prior to the availability of the external builders, the chaincode package content was required to be a set of source code files for a particular language which could be built and launched as a chaincode binary. The new external build and launcher functionality now allows users to optionally customize the build process. With respect to running the chaincode as an external service, the build process allows you to specify the endpoint information of the server where the chaincode is running. Hence the package simply consists of the externally running chaincode server endpoint information and TLS artifacts for secure connection. TLS is optional but highly recommended for all environments except a simple test environment.
在外部构建器可用之前,链码包内容要求是一组特定语言的源代码文件,可以作为链码二进制文件构建和启动。新的外部构建和启动程序功能现在允许用户有选择地定制构建过程。为了将链码作为外部服务运行,构建过程允许您指定正在运行链码的服务器的端点信息。因此,该包只包含外部运行的链码服务器端点信息和用于安全连接的TLS构件。TLS是可选的,但强烈建议用于除简单测试环境以外的所有环境。

The rest of this topic describes how to configure chaincode as an external service:

* [Packaging chaincode](#packaging-chaincode)
* [Configuring a peer to process external chaincode](#configuring-a-peer-to-process-external-chaincode)
* [External builder and launcher sample scripts](#external-builder-and-launcher-sample-scripts)
* [Writing chaincode to run as an external service](#writing-chaincode-to-run-as-an-external-service)
* [Deploying the chaincode](#deploying-the-chaincode)
* [Running the chaincode as an external service](#running-the-chaincode-as-an-external-service)
本主题的其余部分介绍如何将链码配置为外部服务:
* [打包链码](#packaging-chaincode)
* [设置一个节点来执行外部链码](#configuring-a-peer-to-process-external-chaincode)
* [外部构建器和启动器示例脚本](#external-builder-and-launcher-sample-scripts)
* [编写作为外部服务的链码](#writing-chaincode-to-run-as-an-external-service)
* [部署链码](#deploying-the-chaincode)
* [将链码作为外部服务执行](#running-the-chaincode-as-an-external-service)

**Note:** This is an advanced feature that will likely require custom packaging of the peer image. For example, the following samples use `jq` and `bash`, which are not included in the current official `fabric-peer` image.
**注意:** 这是一个需要定制封装peer镜像的高级功能。例如,接下来的示例需要用到的`jq``bash`并不包含在当前的`fabric-peer`官方镜像中。

## Packaging chaincode

With the Fabric v2.0 chaincode lifecycle, chaincode is [packaged](./cc_launcher.html#chaincode-packages) and installed in a `.tar.gz` format. The following `myccpackage.tgz` archive demonstrates the required structure:
## 打包链码
在Fabricv2.0的链码生命周期中,链码是被[打包为](./cc_launcher.md#链码包)`.tar.gz`的格式并安装的。下述`myccpackage.tgz`文件将展示所需要的结构。

```sh
$ tar xvfz myccpackage.tgz
metadata.json
code.tar.gz
```

The chaincode package should be used to provide two pieces of information to the external builder and launcher process
* identify if the chaincode is an external service. The `bin/detect` section describes an approach using the `metadata.json` file
* provide chaincode endpoint information in a `connection.json` file placed in the release directory. The `bin/run` section describes the `connection.json` file

There is plenty of flexibility to gathering the above information. The sample scripts in the [External builder and launcher sample scripts](#external-builder-and-launcher-sample-scripts) illustrate a simple approach to providing the information.
As an example of flexibility, consider packaging couchdb index files (see [Add the index to your chaincode folder](couchdb_tutorial.html#add-the-index-to-your-chaincode-folder)). Sample scripts below describe an approach to packaging the files into code.tar.gz.
链码包应向外部构建器和启动器进程提供两个信息
* 标记链码是否为外部服务。`bin/detect` 章节描述了使用`metadata.json`的要求。
*`connection.json` 中提供链码端点信息并放置在发布目录中。`bin/run` 章节描述了 `connection.json`文件。

收集上述信息可以有很多灵活的方法。[外部构建器和运行器示例脚本]示例脚本中展示了收集这些信息的简单方法。
作为一个灵活性的例子,考虑打包couchdb索引文件(参考[将索引添加至你的链码文件夹](couchdb_tutorial.html#add-the-index-to-your-chaincode-folder))。下列示例脚本展示了打包文件到 code.tar.gz的方法。

```
tar cfz code.tar.gz connection.json metadata
tar cfz $1-pkg.tgz metadata.json code.tar.gz
```

## Configuring a peer to process external chaincode
## 设置一个节点来执行外部链码

In this section we go over the configuration needed
* to detect if the chaincode package identifies an external chaincode service
* to create the `connection.json` file in the release directory
在本章节中文名将介绍所需的配置
* 检测链码是否被标记为外部链码服务
* 在发布目录中创建`connection.json`文件

### Modify the peer core.yaml to include the externalBuilder
### 修改 peer core.yaml文件以包含externalBuilder(外部构建器)

假设peer上的脚本被如下所示放置在`bin`文件夹下

Assume the scripts are on the peer in the `bin` directory as follows
```
<fully qualified path on the peer's env>
└── bin
Expand All @@ -54,35 +55,38 @@ Assume the scripts are on the peer in the `bin` directory as follows
└── release
```

Modify the `chaincode` stanza of the peer `core.yaml` file to include the `externalBuilders` configuration element:

修改peer的 `core.yaml``chaincode`段落以包含`externalBuilders`(外部构建器)配置元素:

```yaml
externalBuilders:
- name: myexternal
path: <fully qualified path on the peer's env>
```

### External builder and launcher sample scripts
### 外部构建器和启动器示例脚本

To help understand what each script needs to contain to work with the chaincode as an external service, this section contains samples of `bin/detect` `bin/build`, `bin/release`, and `bin/run` scripts.
为了帮助理解外部服务链码需要包含的每个脚本,本章节包含`bin/detect` `bin/build`, `bin/release`, `bin/run` 脚本。

**Note:** These samples use the `jq` command to parse json. You can run `jq --version` to check if you have it installed. Otherwise, install `jq` or suitably modify the scripts.
**注意:** 本示例使用了`jq`命令来分析json。你可以运行`jq --version`来检查你是否已安装。如果没有,则安装`jq`或适当调整脚本。

#### bin/detect

The `bin/detect script` is responsible for determining whether or not a buildpack should be used to build a chaincode package and launch it. For chaincode as an external service, the sample script looks for a `type` property set to `external` in the `metadata.json` file:
`bin/detect script` 负责确定是否应使用buildpack来生成链码包并启动它。对于作为外部服务的链码,示例脚本在`metadata.json`文件中设置`type`属性为`external`

```json
{"path":"","type":"external","label":"mycc"}
```

The peer invokes detect with two arguments:

Peer调用detect需要两个参数:

```
bin/detect CHAINCODE_SOURCE_DIR CHAINCODE_METADATA_DIR
```

A sample `bin/detect` script could contain:

`bin/detect`示例脚本包含:

```sh

Expand All @@ -102,13 +106,13 @@ exit 1

#### bin/build

For chaincode as an external service, the sample build script assumes the chaincode package's `code.tar.gz` file contains `connection.json` which it simply copies to the `BUILD_OUTPUT_DIR`. The peer invokes the build script with three arguments:
作为一个外部服务的链码,示例构建脚本假设链码包`code.tar.gz` 的文件内的`connection.json`仅简单复制`BUILD_OUTPUT_DIR`。节点需要三个参数调用构建脚本:

```
bin/build CHAINCODE_SOURCE_DIR CHAINCODE_METADATA_DIR BUILD_OUTPUT_DIR
```

A sample `bin/build` script could contain:
`bin/build`示例脚本包含:

```sh

Expand Down Expand Up @@ -138,17 +142,17 @@ exit 0

#### bin/release

For chaincode as an external service, the `bin/release` script is responsible for providing the `connection.json` to the peer by placing it in the `RELEASE_OUTPUT_DIR`. The `connection.json` file has the following JSON structure
作为外部服务的链码,`bin/release`脚本负责将 `connection.json`放置在`RELEASE_OUTPUT_DIR`以提供给peer。`connection.json` 文件包含下列JSON结构

* **address** - chaincode server endpoint accessible from peer. Must be specified in “<host>:<port>” format.
* **dial_timeout** - interval to wait for connection to complete. Specified as a string qualified with time units (e.g, "10s", "500ms", "1m"). Default is “3s” if not specified.
* **tls_required** - true or false. If false, "client_auth_required", "client_key", "client_cert", and "root_cert" are not required. Default is “true”.
* **client_auth_required** - if true, "client_key" and "client_cert" are required. Default is false. It is ignored if tls_required is false.
* **client_key** - PEM encoded string of the client private key.
* **client_cert** - PEM encoded string of the client certificate.
* **root_cert** - PEM encoded string of the server (peer) root certificate.
* **address** - 可供peer访问的链码服务端点. 必须写为 “<host>:<port>” 格式.
* **dial_timeout** - 等待连接完成的间隔。指定为带有时间单位的字符串(例如,“10s”、“500ms”、“1m”)。如果未指定,默认值为“3s”
* **tls_required** - true false. 如果为 false, "client_auth_required", "client_key", "client_cert" "root_cert" 则不需要填写. 默认 “true”.
* **client_auth_required** - 如果为 true, "client_key" and "client_cert" 需要填写. 默认 false. 它将忽略 tls_required false.
* **client_key** - 客户端的私钥PEM 加密字串。
* **client_cert** - 客户端的PEM加密证书字串。
* **root_cert** - 服务器(peer)根节点证书的PEM加密字串。

For example:
例如:

```json
{
Expand All @@ -162,14 +166,13 @@ For example:
}
```

As noted in the `bin/build` section, this sample assumes the chaincode package directly contains the `connection.json` file which the build script copies to the `BUILD_OUTPUT_DIR`. The peer invokes the release script with two arguments:
`bin/build`章节提示的,本示例假设链码包的`connection.json`文件直接复制到`BUILD_OUTPUT_DIR`。节点使用两个参数调用发布脚本:

```
bin/release BUILD_OUTPUT_DIR RELEASE_OUTPUT_DIR
```

A sample `bin/release` script could contain:

`bin/release`示例脚本包含:

```sh

Expand Down Expand Up @@ -197,9 +200,9 @@ fi
exit 1
```

## Writing chaincode to run as an external service
## 编写作为外部服务的链码

Currently, the chaincode as an external service model is only supported by GO chaincode shim. In Fabric v2.0, the GO shim API adds a `ChaincodeServer` type that developers should use to create a chaincode server. The `Invoke` and `Query` APIs are unaffected. Developers should write to the `shim.ChaincodeServer` API, then build the chaincode and run it in the external environment of choice. Here is a simple sample chaincode program to illustrate the pattern:
当前,外部服务模式的链码仅支持 GO chaincode shim.在Fabric v2.0中,GO shim API添加了`ChaincodeServer` 类型使开发者可以使用它来创建一个链码服务。`Invoke` and `Query` APIs 不受影响。开发者应将其写入`shim.ChaincodeServer` API,然后构建链码并运行在选择的外部环境中。下面是一个简单的链码程序示例来说明这个模式:

```go

Expand Down Expand Up @@ -243,26 +246,26 @@ func main() {
}
}
```
The key to running the chaincode as an external service is the use of `shim.ChaincodeServer`. This uses the new shim API `shim.ChaincodeServer` with the chaincode service properties described below:

* **CCID** (string)- CCID should match chaincode's package name on peer. This is the `CCID` associated with the installed chaincode as returned by the `peer lifecycle chaincode install <package>` CLI command. This can be obtained post-install using the "peer lifecycle chaincode queryinstalled" command.
* **Address** (string) - Address is the listen address of the chaincode server
* **CC** (Chaincode) - CC is the chaincode that handles Init and Invoke
* **TLSProps** (TLSProperties) - TLSProps is the TLS properties passed to chaincode server
* **KaOpts** (keepalive.ServerParameters) - KaOpts keepalive options, sensible defaults provided if nil
使用`shim.ChaincodeServer`是将链码作为外部服务的关键。新的shim API `shim.ChaincodeServer`服务配置参数的作用如下:

* **CCID** (string)- CCID 应匹配peer节点上链码的包名.这是`CCID`关联链码并使用 `peer lifecycle chaincode install <package>` 命令获取返回值。这可以在安装后使用`peer lifecycle chaincode queryinstalled`命令获得。
* **Address** (string) - 是链码服务的监听地址
* **CC** (Chaincode) - CC 是初始化(Init)和调用(Invoke)的链码。
* **TLSProps** (TLSProperties) - TLSProps 是发送给链码服务的TLS属性
* **KaOpts** (keepalive.ServerParameters) - KaOpts keepalive 属性, 如果为空,则提供合理的默认值

Then build the chaincode as suitable to your GO environment.
然后构建适合您的GO环境的链码

## Deploying the chaincode
## 部署链码

When the GO chaincode is ready for deployment, you can package the chaincode as explained in the [Packaging chaincode](#packaging-chaincode) section and deploy the chaincode as explained in the [Fabric chaincode lifecycle](./chaincode_lifecycle.html) concept topic.
当GO链码可以被部署时,你可以如[打包链码](#packaging-chaincode) 章节描述的一样打包,并按照[Fabric 链码生命周期](./chaincode_lifecycle.html) 中说明的进行部署。

## Running the chaincode as an external service
## 将链码作为外部服务运行

Create the chaincode as specified in the [Writing chaincode to run as an external service](#writing-chaincode-to-run-as-an-external-service) section. Run the built executable in your environment of choice, such as Kubernetes or directly as a process on the peer machine.
[编写外部服务链码](#writing-chaincode-to-run-as-an-external-service)章节描述的创建链码。在您选择的环境中运行构建可执行文件,如Kubernetes或直接在 peer 机器上作为一个进程运行。

Using this chaincode as an external service model, installing the chaincode on each peer is no longer required. With the chaincode endpoint deployed to the peer instead and the chaincode running, you can continue the normal process of committing the
chaincode definition to the channel and invoking the chaincode.
以外部服务模式使用链码便不需要再每个节点上安装链码。当链码端点部署并替换运行后,你依然能执行提交通道上定义的链码和调用链码。

<!---
Licensed under Creative Commons Attribution 4.0 International License https://creativecommons.org/licenses/by/4.0/
Expand Down

0 comments on commit 4e78a8f

Please sign in to comment.